public void updateTitle() { if (frame != null) { if (engine.getActivePathway() == null) { frame.setTitle(engine.getApplicationName()); } else { boolean changeStatus = engine.getActivePathway().hasChanged(); // get filename, or (New Pathway) if current pathway hasn't been opened yet String fname = (engine.getActivePathway().getSourceFile() == null) ? "(New Pathway)" : engine.getActivePathway().getSourceFile().getName(); frame.setTitle((changeStatus ? "*" : "") + fname + " - " + engine.getApplicationName()); } } }
public void applicationEvent(ApplicationEvent e) { switch (e.getType()) { case PATHWAY_OPENED: case PATHWAY_NEW: updateTitle(); engine.getActivePathway().addStatusFlagListener(SwingEngine.this); break; } }
public boolean exportPathway(final File f) { if (mayOverwrite(f)) { final ProgressKeeper pk = new ProgressKeeper(); final ProgressDialog d = new ProgressDialog( JOptionPane.getFrameForComponent(getApplicationPanel()), "", pk, false, true); // create a clone so we can safely act on it in a worker thread. final Pathway clone = engine.getActivePathway().clone(); SwingWorker<Boolean, Boolean> sw = new SwingWorker<Boolean, Boolean>() { private List<String> warnings; @Override protected Boolean doInBackground() { try { pk.setTaskName("Exporting pathway"); warnings = engine.exportPathway(f, clone); return true; } catch (ConverterException e) { handleConverterException(e.getMessage(), frame, e); return false; } finally { pk.finished(); } } @Override public void done() { if (warnings != null && warnings.size() > 0) { OkCancelDialog dlg = new OkCancelDialog(frame, "Conversion warnings", getFrame(), true); JTextArea area = new JTextArea(60, 30); for (String w : warnings) area.append(w + "\n"); dlg.setDialogComponent(area); dlg.pack(); dlg.setVisible(true); } } }; return processTask(pk, d, sw); } return false; }
public boolean savePathway() { Pathway pathway = engine.getActivePathway(); boolean result = true; // Overwrite the existing xml file. // If the target file is read-only, let the user select a new pathway if (pathway.getSourceFile() != null && pathway.getSourceFile().canWrite()) { try { engine.savePathway(pathway.getSourceFile()); } catch (ConverterException e) { handleConverterException(e.getMessage(), null, e); } } else { result = savePathwayAs(); } return result; }
/** * Call this when the user is about to perform an action that could lead to discarding the current * pathway. (For example when creating a new pathway) * * <p>Checks if there are any unsaved changes, and asks the user if they want to save those * changes. * * @return true if the user allows discarding the pathway, possibly after saving. */ public boolean canDiscardPathway() { Pathway pathway = engine.getActivePathway(); // checking not necessary if there is no pathway or if pathway is not changed. if (pathway == null || !pathway.hasChanged()) return true; int result = JOptionPane.showConfirmDialog( frame, "Save changes?", "Your pathway has changed. Do you want to save?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.CANCEL_OPTION) // cancel { return false; } else if (result == JOptionPane.YES_OPTION) // yes { // return false if save is cancelled. return (savePathway()); } // yes or no return true; }