コード例 #1
0
  /** Returns the next available session name in the series untitled1.tet, untitled2.tet, etc. */
  private String getNewSessionName() {
    String base = "untitled";
    String suffix = ".tet";
    int i = 0; // Sequence 1, 2, 3, ...

    loop:
    while (true) {
      i++;

      String name = base + i + suffix;

      for (Object _o : framesMap.keySet()) {
        if (_o instanceof SessionEditor) {
          SessionEditor sessionEditor = (SessionEditor) _o;
          SessionEditorWorkbench workbench = sessionEditor.getSessionWorkbench();
          SessionWrapper sessionWrapper = workbench.getSessionWrapper();

          if (sessionWrapper.getName().equals(name)) {
            continue loop;
          }
        }
      }

      return name;
    }
  }
コード例 #2
0
  /**
   * Queries the user as to whether they would like to save their sessions.
   *
   * @return true if the transaction was ended successfully, false if not (that is, canceled).
   */
  public boolean closeAllSessions() {
    while (existsSession()) {
      SessionEditor sessionEditor = getFrontmostSessionEditor();
      SessionEditorWorkbench workbench = sessionEditor.getSessionWorkbench();
      SessionWrapper wrapper = workbench.getSessionWrapper();

      if (!wrapper.isSessionChanged()) {
        closeFrontmostSession();
        continue;
      }

      String name = sessionEditor.getName();

      int ret =
          JOptionPane.showConfirmDialog(
              JOptionUtils.centeringComp(),
              "Would you like to save the changes you made to " + name + "?",
              "Advise needed...",
              JOptionPane.YES_NO_CANCEL_OPTION);

      if (ret == JOptionPane.NO_OPTION) {
        closeFrontmostSession();
        continue;
      } else if (ret == JOptionPane.CANCEL_OPTION) {
        return false;
      }

      SaveSessionAsAction action = new SaveSessionAsAction();
      action.actionPerformed(
          new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Dummy close action"));

      if (!action.isSaved()) {
        int ret2 =
            JOptionPane.showConfirmDialog(
                JOptionUtils.centeringComp(),
                "This session was not saved. Close session and continue anyway?",
                "Advise needed...",
                JOptionPane.OK_CANCEL_OPTION);

        if (ret2 == JOptionPane.CANCEL_OPTION) {
          return false;
        }
      }

      closeFrontmostSession();
    }

    return true;
  }
コード例 #3
0
  public void closeEmptySessions() {
    JInternalFrame[] frames = desktopPane.getAllFramesInLayer(0);

    for (JInternalFrame frame : frames) {
      Object o = frame.getContentPane().getComponents()[0];

      if (o instanceof SessionEditor) {
        SessionEditor sessionEditor = (SessionEditor) o;
        SessionEditorWorkbench workbench = sessionEditor.getSessionWorkbench();
        Graph graph = workbench.getGraph();
        if (graph.getNumNodes() == 0) {
          frame.dispose();
        }
      }
    }
  }