/** * 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()); } }