예제 #1
0
  /** 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);
    }
  }
예제 #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());
    }
  }
예제 #3
0
  /**
   * 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();
  }
예제 #4
0
  /** 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);
  }
예제 #5
0
  /** 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());
  }
예제 #6
0
  /** 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);
  }
예제 #7
0
 /**
  * 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);
   }
 }
예제 #8
0
 /**
  * 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();
 }
예제 #9
0
  /**
   * 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);
  }
예제 #10
0
 /**
  * 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);
   }
 }
예제 #11
0
 /** Selects all Items of the Board */
 public void selectAllItems() {
   board.setSelectionCells(board.getItems());
 }
예제 #12
0
 /** 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);
 }