/** Pastes Items from the Clipboard on the Board */ public void paste() { ComponentSelection clipboardContent = (ComponentSelection) tbe.getClipboard().getContents(this); if ((clipboardContent != null) && (clipboardContent.isDataFlavorSupported(ComponentSelection.itemFlavor))) { Object[] tempItems = null; try { tempItems = board.cloneItems(clipboardContent.getTransferData(ComponentSelection.itemFlavor)); } catch (UnsupportedFlavorException e1) { e1.printStackTrace(); } ItemComponent[] items = new ItemComponent[tempItems.length]; for (int i = 0; i < tempItems.length; i++) { items[i] = (ItemComponent) tempItems[i]; } PasteCommand del = new PasteCommand(items); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(del); tbe.addCommands(actCommands); board.addItem(items); } }
/** * 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()); } }
/** * Constructor for open a Board * * @param board */ public WorkingView(Board board) { this.sport = board.getSport(); this.board = board; tbe.setSaved(true); int value = board.getPath().lastIndexOf("\\"); tbe.getFrame().setTitle("TBE - Tactic Board Editor - " + board.getPath().substring(value + 1)); createWorkingView(); }
/** Deletes the selected Item of the Board and creates a DeleteCommand */ public void delete() { ItemComponent[] items = board.getSelectedItems(); DeleteCommand del = new DeleteCommand(items); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(del); tbe.addCommands(actCommands); board.removeItem(items); }
/** 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()); }
/** Cuts selected Iems of the Board and put it into the ClipBoard */ public void cut() { ItemComponent[] items = board.getSelectedItems(); CutCommand cut = new CutCommand(items); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(cut); tbe.addCommands(actCommands); ComponentSelection contents = new ComponentSelection(this.getBoard().cloneItems(items)); tbe.getClipboard().setContents(contents, cut); board.removeItem(items); }
/** * Checks if the Rotate, Add and Remove Buttons should be activated or not. Add and Remove only if * Arrow, Rotate only if Shape */ public void checkDefaultButtonVisibility() { if (board.getSelectionCount() == 1 && board.getSelectionCell() instanceof ArrowItem) { this.activatePoints(true); } else { this.activatePoints(false); } if (board.getSelectionCount() == 1 && board.getSelectionCell() instanceof ShapeItem) { this.activateRotation(true); } else { this.activateRotation(false); } }
/** * Constructor for a new Board * * @param sport */ public WorkingView(Sport sport) { this.sport = sport; GraphModel model = new DefaultGraphModel(); GraphLayoutCache view = new GraphLayoutCache(model, new TBECellViewFactory()); this.board = new Board(model, view, sport); board.getDescription().setDescription(sport.getName()); tbe.setSaved(false); createWorkingView(); }
/** * Activate/Deactivate Rotate-Button * * @param b */ public void activateRotation(boolean b) { if (showRotate && b) { rotatePanel.setVisible(b); rotateSlider.setValue(((ShapeItem) board.getSelectedItems()[0]).getRotation()); } else { rotatePanel.setVisible(false); } rotate.setEnabled(b); }
/** * Add/Remove a Point to/from an Arrow * * @param b boolean, true = add, false = remove */ public void addRemovePoint(boolean b) { if (board.getSelectionCount() == 1 && board.getSelectionCell() instanceof ArrowItem) { MoveCommand mc = new MoveCommand(board.getSelectedItems()); ArrowItem a = (ArrowItem) board.getSelectionCell(); if (b) { a.addPoint(); } else { a.removePoint(); } WorkingView.this.refresh(); board.setSelectionCell(a); setTool(cursorTool, cursorButton); board.addItem(a); mc.setMoveEnd(board.getSelectedItems()); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(mc); tbe.addCommands(actCommands); } }
/** Selects all Items of the Board */ public void selectAllItems() { board.setSelectionCells(board.getItems()); }
/** Copy selected Items from the Board into the Clipboard */ public void copy() { ItemComponent[] items = board.getSelectedItems(); ComponentSelection contents = new ComponentSelection(this.getBoard().cloneItems(items)); tbe.getClipboard().setContents(contents, tbe); }