Exemple #1
0
 /**
  * Removes an editor.
  *
  * @param promptSave true to let the user save the element if necessary, false to close it without
  *     confirmation.
  * @param editor The editor to remove.
  */
 public void removeEditor(AbstractEditorPanel editor, boolean promptSave) {
   if (!promptSave || editor.checkCurrentFileSaved()) {
     editor.close();
     remove(editor);
     repaint();
   }
 }
Exemple #2
0
  /**
   * Refreshs the title of a specified editor.
   *
   * @param id The index of the editor
   */
  public void refreshEditorTitle(String id) {

    AbstractEditorPanel editor = getEditor(id);

    if (editor != null) {
      TabComponent tabComponent = (TabComponent) getTabComponentAt(indexOfComponent(editor));
      tabComponent.setTitle(editor.getTitle());
    }
  }
Exemple #3
0
  /**
   * Returns all editors of the specified resource type currently open.
   *
   * @param resourceType A type of resource.
   * @return A list of the editors of this resource type currently open.
   */
  public ArrayList<AbstractEditorPanel> getEditors(ResourceType resourceType) {

    ArrayList<AbstractEditorPanel> editors = new ArrayList<AbstractEditorPanel>();
    for (int i = 0; i < getTabCount(); i++) {
      AbstractEditorPanel editor = (AbstractEditorPanel) getComponentAt(i);
      if (editor.getResourceType() == resourceType) {
        editors.add(editor);
      }
    }
    return editors;
  }
Exemple #4
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;
  }
Exemple #5
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();
  }
Exemple #6
0
    /**
     * Constructor.
     *
     * @param title the title of the tab component
     * @param editor the editor of the tab (used to close the tab)
     */
    public TabComponent(final AbstractEditorPanel editor) {

      setLayout(new BorderLayout());
      setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
      setOpaque(false);

      // title
      title = new JLabel(editor.getTitle());
      title.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
      add(title, BorderLayout.WEST);

      // close
      final JButton close = new JButton(Project.getEditorImageIconOrEmpty("icon_cross.png"));
      close.setPreferredSize(new Dimension(16, 16));
      close.setUI(new BasicButtonUI());
      close.setBorderPainted(false);
      close.setOpaque(false);
      close.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
              removeEditor(editor, true);
            }
          });
      close.addMouseListener(
          new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent me) {}

            @Override
            public void mousePressed(MouseEvent me) {}

            @Override
            public void mouseReleased(MouseEvent me) {}

            @Override
            public void mouseEntered(MouseEvent me) {

              close.setBorderPainted(true);
            }

            @Override
            public void mouseExited(MouseEvent me) {

              close.setBorderPainted(false);
            }
          });
      add(close, BorderLayout.EAST);
    }