예제 #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();
   }
 }
예제 #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());
    }
  }
예제 #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;
  }
예제 #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;
  }
예제 #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();
  }
예제 #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);
    }
  public FindSynonymsActionHandler(String word, int position, Chapter c, AbstractEditorPanel p) {

    this.word = word;
    this.position = position;
    // this.chapter = c;
    this.editorPanel = p;
    this.projectViewer = this.editorPanel.getViewer();

    final FindSynonymsActionHandler _this = this;

    // Show a panel of all the items.
    this.popup =
        new QPopup(
            "Synonyms for: " + word,
            Environment.getIcon(Constants.FIND_ICON_NAME, Constants.ICON_POPUP),
            null);

    JButton close =
        UIUtils.createButton(
            Constants.CLOSE_ICON_NAME, Constants.ICON_MENU, "Click to close", null);

    List<JButton> buts = new ArrayList();
    buts.add(close);

    this.popup.getHeader().setControls(UIUtils.createButtonBar(buts));

    close.addActionListener(
        new ActionAdapter() {

          public void actionPerformed(ActionEvent ev) {

            _this.popup.setVisible(false);

            _this.editorPanel.getEditor().removeHighlight(_this.highlight);
          }
        });

    p.addPopup(this.popup, true, true);
    /*
          this.highlight = this.editorPanel.getEditor ().addHighlight (position,
                                                                       position + word.length (),
                                                                       null,
                                                                       true);
    */
    this.popup.setOpaque(false);
    this.popup.setVisible(false);

    this.popup.setDraggable(this.editorPanel);
  }