/**
   * Adds a component to the middle layer of the desktop--that is, the layer for session node
   * editors. Note: The comp is a SessionEditor
   */
  public void addSessionEditor(SessionEditorIndirectRef editorRef) {
    SessionEditor editor = (SessionEditor) editorRef;

    JInternalFrame frame = new TetradInternalFrame(null);

    frame.getContentPane().add(editor);
    framesMap.put(editor, frame);
    editor.addPropertyChangeListener(this);

    // Set the "small" size of the frame so that it has sensible
    // bounds when the users unmazimizes it.
    Dimension fullSize = desktopPane.getSize();
    int smallSize = Math.min(fullSize.width - MARGIN, fullSize.height - MARGIN);
    Dimension size = new Dimension(smallSize, smallSize);
    setGoodBounds(frame, desktopPane, size);
    desktopPane.add(frame);

    // Set the frame to be maximized. This step must come after the frame
    // is added to the desktop. -Raul. 6/21/01
    try {
      frame.setMaximum(true);
    } catch (Exception e) {
      throw new RuntimeException("Problem setting frame to max: " + frame);
    }

    desktopPane.setLayer(frame, 0);
    frame.moveToFront();
    frame.setTitle(editor.getName());
    frame.setVisible(true);

    setMainTitle(editor.getName());
  }
  /** Returns true iff there exist a session in the desktop. */
  private boolean existsSession() {
    JInternalFrame[] allFrames = desktopPane.getAllFramesInLayer(0);

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

      if (o instanceof SessionEditor) {
        return true;
      }
    }

    return false;
  }
  public SessionEditor getFrontmostSessionEditor() {
    JInternalFrame[] allFrames = desktopPane.getAllFramesInLayer(0);

    if (allFrames.length == 0) {
      return null;
    }

    JInternalFrame frontmostFrame = allFrames[0];
    Object o = frontmostFrame.getContentPane().getComponents()[0];

    boolean isSessionEditor = o instanceof SessionEditor;
    return isSessionEditor ? (SessionEditor) o : null;
  }
  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();
        }
      }
    }
  }
  public boolean existsSessionByName(String filename) {
    JInternalFrame[] allFrames = desktopPane.getAllFramesInLayer(0);

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

      if (o instanceof SessionEditor) {
        SessionEditor editor = (SessionEditor) o;

        String editorName = editor.getName();
        if (editorName.equals(filename)) {
          return true;
        }
      }
    }

    return false;
  }