Exemplo n.º 1
0
  public boolean savePathwayAs() {
    PathwayChooser pc =
        new PathwayChooser(
            "Save",
            JFileChooser.SAVE_DIALOG,
            GlobalPreference.DIR_LAST_USED_SAVE,
            GPML_FORMAT_ONLY);
    int status = pc.show();

    if (status == JFileChooser.APPROVE_OPTION) {
      File toFile = pc.getSelectedFile();
      String fn = toFile.toString();
      if (!fn.toLowerCase().endsWith(Engine.PATHWAY_FILE_EXTENSION)) {
        toFile = new File(fn + "." + Engine.PATHWAY_FILE_EXTENSION);
      }
      try {
        if (mayOverwrite(toFile)) {
          engine.savePathway(toFile);
          return true;
        }
      } catch (ConverterException e) {
        handleConverterException(e.getMessage(), null, e);
      }
    }
    return false;
  }
Exemplo n.º 2
0
  public boolean openPathway(final File f) {
    final ProgressKeeper pk = new ProgressKeeper();
    final ProgressDialog d =
        new ProgressDialog(
            JOptionPane.getFrameForComponent(getApplicationPanel()), "", pk, false, true);

    engine.setWrapper(createWrapper());
    SwingWorker<Boolean, Boolean> sw =
        new SwingWorker<Boolean, Boolean>() {
          protected Boolean doInBackground() {
            pk.setTaskName("Opening pathway");
            try {
              engine.openPathway(f);
              return true;
            } catch (ConverterException e) {
              handleConverterException(e.getMessage(), null, e);
              return false;
            } finally {
              pk.finished();
            }
          }
        };

    return processTask(pk, d, sw);
  }
Exemplo n.º 3
0
 public SwingEngine(Engine engine) {
   this.engine = engine;
   gdbManager = new GdbManager();
   actions = new CommonActions(this);
   engine.addApplicationEventListener(this);
   // compat = new Compat(this);
   // engine.addApplicationEventListener(compat);
 }
Exemplo n.º 4
0
 public void applicationEvent(ApplicationEvent e) {
   switch (e.getType()) {
     case PATHWAY_OPENED:
     case PATHWAY_NEW:
       updateTitle();
       engine.getActivePathway().addStatusFlagListener(SwingEngine.this);
       break;
   }
 }
Exemplo n.º 5
0
  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;
  }
Exemplo n.º 6
0
  public boolean importPathway() {
    PathwayChooser pc =
        new PathwayChooser(
            "Import",
            JFileChooser.OPEN_DIALOG,
            GlobalPreference.DIR_LAST_USED_IMPORT,
            engine.getPathwayImporters());
    int status = pc.show();

    if (status == JFileChooser.APPROVE_OPTION) {
      File f = pc.getSelectedFile();
      return importPathway(f);
    }
    return false;
  }
Exemplo n.º 7
0
  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;
  }
Exemplo n.º 8
0
  public boolean exportPathway() {
    PathwayChooser pc =
        new PathwayChooser(
            "Export",
            JFileChooser.SAVE_DIALOG,
            GlobalPreference.DIR_LAST_USED_EXPORT,
            engine.getPathwayExporters());
    int status = pc.show();

    if (status == JFileChooser.APPROVE_OPTION) {
      File f = pc.getSelectedFile();

      PathwayFileFilter ff = (PathwayFileFilter) pc.getFileFilter();
      if (!f.toString().toUpperCase().endsWith("." + ff.getDefaultExtension().toUpperCase())) {
        f = new File(f.toString() + "." + ff.getDefaultExtension());
      }
      return exportPathway(f);
    }
    return false;
  }
Exemplo n.º 9
0
 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());
     }
   }
 }
Exemplo n.º 10
0
  /**
   * 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;
  }
Exemplo n.º 11
0
 /**
  * free all resources (such as listeners) held by this class. Owners of this class must explicitly
  * dispose of it to clean up.
  */
 public void dispose() {
   assert (!disposed);
   engine.removeApplicationEventListener(this);
   // engine.removeApplicationEventListener(compat);
   disposed = true;
 }
Exemplo n.º 12
0
 public void newPathway() {
   engine.setWrapper(createWrapper());
   engine.newPathway();
 }