Пример #1
0
  /**
   * Adds an editor. No other editor with the same id must exist.
   *
   * @param editor The editor to add.
   */
  public void addEditor(AbstractEditorPanel editor) {

    if (getEditor(editor.getId()) != null) {
      throw new IllegalArgumentException(
          "There is already an editor with id '" + editor.getId() + "'");
    }

    add(editor);

    int index = getTabCount() - 1;
    JComponent tabComponent = new TabComponent(editor);
    setTabComponentAt(index, tabComponent);

    setSelectedIndex(index);
    repaint();
  }
Пример #2
0
  /**
   * Returns an existing editor with the specified id if any.
   *
   * @param id Id of the editor to search.
   * @return The existing editor with this id, or null if there is no editor with this id.
   */
  public AbstractEditorPanel getEditor(String id) {

    // TODO store editors in a map.
    AbstractEditorPanel[] editors = getEditors();

    if (editors != null) {
      for (AbstractEditorPanel editor : editors) {
        if (editor.getId().equals(id)) {
          return editor;
        }
      }
    }
    return null;
  }