示例#1
0
  /**
   * Installs a Tool in the Toolbar
   *
   * @param toolbar as JToolbar
   * @param tool, Tool to install
   */
  public void installToolInToolBar(JToolBar toolbar, final Tool tool) {
    final JButton button;
    button = new JButton();

    button.setMargin(new Insets(0, 0, 0, 0));

    if (tool.getItemType() != null) {
      button.setIcon(tool.getItemType().getIcon());
      button.setToolTipText(tool.getItemType().getDescription());

    } else {
      button.setText("Tool"); // For Debugging
    }
    toolbar.add(button);
    toolButtons.add(button);
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            WorkingView.this.setTool(tool, button);
          }
        });
    button.setContentAreaFilled(false);
    button.setBorderPainted(false);
    button.addMouseListener(
        new MouseAdapter() {
          public void mouseEntered(MouseEvent e) {
            ((JButton) e.getSource()).setBorderPainted(true);
          }

          public void mouseExited(MouseEvent e) {
            ((JButton) e.getSource()).setBorderPainted(false);
          }
        });
  }
示例#2
0
  /**
   * Sets the current Tool, the right listeners and the Cursor
   *
   * @param tool, Tool to set as current
   * @param button, JButton to set as current
   */
  public void setTool(Tool tool, JButton button) {
    // IF NO CURSORTOOL
    if (this.currentTool instanceof CursorTool && !(tool instanceof CursorTool)) {
      board.removeMouseListener(listeners[0]);

      // IF CURSORTOOL
    } else if (tool instanceof CursorTool && !(this.currentTool instanceof CursorTool)) {

      board.addMouseListener(listeners[0]);
    }
    if (tool == null) throw new IllegalArgumentException("Tool must not be null.");

    if (this.currentTool != tool) {
      if (this.currentButton != null) {
        this.currentButton.setEnabled(true);
      }
      this.currentButton = button;
      this.currentTool = tool;
    }
    if (tool instanceof CursorTool || tool instanceof ArrowTool || tool instanceof TextBoxTool) {
      board.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    } else {
      board.setCursor(tool.getItemType().getCursor());
    }
  }