コード例 #1
0
ファイル: WorkingView.java プロジェクト: BackupTheBerlios/tbe
  /**
   * 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());
    }
  }
コード例 #2
0
ファイル: WorkingView.java プロジェクト: BackupTheBerlios/tbe
  /** Creates the WorkingView */
  private void createWorkingView() {
    workingViewLabels = getResourceBundle(tbe.getLang());
    this.setLayout(new BorderLayout());
    this.setBackground(Color.WHITE);
    Invoker.getInstance().clear();

    // Toolbar
    this.add(toolbar, BorderLayout.NORTH);

    // Attributebar
    sideBar = new SideBar(board);
    this.add(sideBar, BorderLayout.WEST);

    // gemeinsames Panel für Board und Legend
    rightPanel.setLayout(new BorderLayout());

    rightPanel.add(new JScrollPane(board), BorderLayout.CENTER);
    class ViewMouseListener extends MouseAdapter {
      public void mousePressed(MouseEvent e) {
        if (e.getButton() == 3 && !(currentTool instanceof CursorTool)) {
          setTool(cursorTool, cursorButton);
        } else {
          Point p = new Point(e.getX(), e.getY());
          WorkingView.this.getTool().mouseDown(p.x, p.y, e);
        }
        if (currentTool instanceof ArrowTool || currentTool instanceof TextBoxTool) {
          setTool(cursorTool, cursorButton);
        }
        board.requestFocus();
      }

      public void mouseReleased(MouseEvent e) {

        checkDefaultButtonVisibility();
      }
    }
    initDefaultTools();

    initSportTools();

    listeners[0] = board.getMouseListeners()[0];
    listeners[1] = new ViewMouseListener();
    board.addMouseListener(listeners[1]);

    // Legend
    legendBar = new LegendBar(board);
    rightPanel.add(legendBar, BorderLayout.SOUTH);

    this.add(rightPanel, BorderLayout.CENTER);
    this.activatePoints(false);

    tbe.getMenu().setVisibleToolbar(!this.toolbar.isVisible());
    tbe.getMenu().setVisibleLegend(!this.legendBar.isVisible());
    tbe.getMenu().setVisibleSidebar(!this.sideBar.isVisible());
  }