예제 #1
0
 protected void fileOpened(final DocumentView documentView, File file, Object value) {
   final DocumentOrientedApplication application = getApplication();
   if (value == null) {
     documentView.setFile(file);
     documentView.setEnabled(true);
     Frame w = (Frame) SwingUtilities.getWindowAncestor(documentView.getComponent());
     if (w != null) {
       w.setExtendedState(w.getExtendedState() & ~Frame.ICONIFIED);
       w.toFront();
     }
     documentView.getComponent().requestFocus();
     application.addRecentFile(file);
     application.setEnabled(true);
   } else {
     if (value instanceof Throwable) {
       ((Throwable) value).printStackTrace();
     }
     JSheet.showMessageSheet(
         documentView.getComponent(),
         "<html>"
             + UIManager.getString("OptionPane.css")
             + "<b>Couldn't open the file \""
             + file
             + "\".</b><br>"
             + value,
         JOptionPane.ERROR_MESSAGE,
         new SheetListener() {
           public void optionSelected(SheetEvent evt) {
             // application.dispose(documentView);
           }
         });
   }
 }
예제 #2
0
 public void doIt(DocumentView documentView) {
   JFileChooser fileChooser = documentView.getOpenChooser();
   if (fileChooser.showOpenDialog(documentView.getComponent()) == JFileChooser.APPROVE_OPTION) {
     openFile(documentView, fileChooser);
   } else {
     documentView.setEnabled(true);
   }
 }
예제 #3
0
  protected void openFile(final DocumentView documentView, JFileChooser fileChooser) {
    final File file = fileChooser.getSelectedFile();

    documentView.setEnabled(false);

    // Open the file
    documentView.execute(
        new Worker() {
          public Object construct() {
            try {
              documentView.read(file);
              return null;
            } catch (IOException e) {
              return e;
            }
          }

          public void finished(Object value) {
            fileOpened(documentView, file, value);
          }
        });
  }
예제 #4
0
  protected void openFile(JFileChooser fileChooser, final DocumentView documentView) {
    final DocumentOrientedApplication application = getApplication();
    final File file = fileChooser.getSelectedFile();
    application.setEnabled(true);
    documentView.setEnabled(false);

    // Open the file
    documentView.execute(
        new Worker() {
          public Object construct() {
            try {
              documentView.read(file);
              return null;
            } catch (Throwable e) {
              return e;
            }
          }

          public void finished(Object value) {
            fileOpened(documentView, file, value);
          }
        });
  }
예제 #5
0
  protected void fileOpened(final DocumentView documentView, File file, Object value) {
    if (value == null) {
      documentView.setFile(file);
      documentView.setEnabled(true);
      getApplication().addRecentFile(file);
    } else {
      JSheet.showMessageSheet(
          documentView.getComponent(),
          "<html>"
              + UIManager.getString("OptionPane.css")
              + "<b>Couldn't open the file \""
              + file
              + "\".</b><br>"
              + value,
          JOptionPane.ERROR_MESSAGE,
          new SheetListener() {
            public void optionSelected(SheetEvent evt) {
              documentView.execute(
                  new Worker() {
                    public Object construct() {
                      try {
                        documentView.clear();
                        return null;
                      } catch (IOException ex) {
                        return ex;
                      }
                    }

                    public void finished(Object result) {
                      documentView.setEnabled(true);
                    }
                  });
            }
          });
    }
  }