Exemple #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);
           }
         });
   }
 }
Exemple #2
0
  public void actionPerformed(ActionEvent evt) {
    final DocumentOrientedApplication application = getApplication();
    if (application.isEnabled()) {
      application.setEnabled(false);
      // Search for an empty documentView
      DocumentView emptyProject = application.getCurrentView();
      if (emptyProject == null || emptyProject.getFile() != null || emptyProject.isModified()) {
        emptyProject = null;
        /*
        for (DocumentView aProject : application.getViews()) {
            if (aProject.getFile() == null &&
                    ! aProject.isModified()) {
                emptyProject = aProject;
                break;
            }
        }*/
      }

      final DocumentView p;
      boolean removeMe;
      if (emptyProject == null) {
        p = application.createView();
        application.add(p);
        removeMe = true;
        removeMe = true;
      } else {
        p = emptyProject;
        removeMe = false;
      }
      JFileChooser fileChooser = p.getOpenChooser();
      if (fileChooser.showOpenDialog(application.getComponent()) == JFileChooser.APPROVE_OPTION) {
        application.show(p);
        openFile(fileChooser, p);
      } else {
        if (removeMe) {
          application.remove(p);
        }
        application.setEnabled(true);
      }
    }
  }
Exemple #3
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);
          }
        });
  }