Ejemplo n.º 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);
          }
        });
  }
Ejemplo n.º 2
0
 private void setTool(Tool t, String name) {
   if (fTool != null) {
     fTool.deactivate();
   }
   fTool = t;
   if (fTool != null) {
     showStatus(name);
     fTool.activate();
   }
 }
Ejemplo n.º 3
0
 protected void setTracker(Tool newTracker) {
   if (tracker != null) {
     tracker.deactivate(getEditor());
     tracker.removeToolListener(this);
   }
   tracker = newTracker;
   if (tracker != null) {
     tracker.activate(getEditor());
     tracker.addToolListener(this);
   }
 }
Ejemplo n.º 4
0
  public void toolDone(ToolEvent event) {
    // Empty
    Tool newTracker = getSelectAreaTracker();

    if (newTracker != null) {
      if (tracker != null) {
        tracker.deactivate(getEditor());
        tracker.removeToolListener(this);
      }
      tracker = newTracker;
      tracker.activate(getEditor());
      tracker.addToolListener(this);
    }
    fireToolDone();
  }
Ejemplo n.º 5
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());
    }
  }
Ejemplo n.º 6
0
 public void deactivate(DrawingEditor editor) {
   super.deactivate(editor);
   tracker.deactivate(editor);
 }
Ejemplo n.º 7
0
 @Override
 public void activate(DrawingEditor editor) {
   super.activate(editor);
   tracker.activate(editor);
 }
Ejemplo n.º 8
0
 /** Creates a new instance. */
 public SelectionTool() {
   tracker = getSelectAreaTracker();
   tracker.addToolListener(this);
 }
Ejemplo n.º 9
0
  @Override
  public void mousePressed(MouseEvent evt) {
    if (getView() != null && getView().isEnabled()) {
      super.mousePressed(evt);
      DrawingView view = getView();
      Handle handle = view.findHandle(anchor);
      Tool newTracker = null;
      if (handle != null) {
        newTracker = getHandleTracker(handle);
      } else {
        Figure figure;
        Drawing drawing = view.getDrawing();
        Point2D.Double p = view.viewToDrawing(anchor);
        if (isSelectBehindEnabled()
            && (evt.getModifiersEx() & (InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK))
                != 0) {
          // Select a figure behind the current selection
          figure = view.findFigure(anchor);
          while (figure != null && !figure.isSelectable()) {
            figure = drawing.findFigureBehind(p, figure);
          }
          HashSet<Figure> ignoredFigures = new HashSet<Figure>(view.getSelectedFigures());
          ignoredFigures.add(figure);
          Figure figureBehind =
              view.getDrawing().findFigureBehind(view.viewToDrawing(anchor), ignoredFigures);
          if (figureBehind != null) {
            figure = figureBehind;
          }
        } else {
          // Note: The search sequence used here, must be
          // consistent with the search sequence used by the
          // DefaultHandleTracker, the DefaultSelectAreaTracker and DelegationSelectionTool.

          // If possible, continue to work with the current selection
          figure = null;
          if (isSelectBehindEnabled()) {
            for (Figure f : view.getSelectedFigures()) {
              if (f.contains(p)) {
                figure = f;
                break;
              }
            }
          }
          // If the point is not contained in the current selection,
          // search for a figure in the drawing.
          if (figure == null) {
            figure = view.findFigure(anchor);
            while (figure != null && !figure.isSelectable()) {
              figure = drawing.findFigureBehind(p, figure);
            }
          }
        }

        if (figure != null && figure.isSelectable()) {
          newTracker = getDragTracker(figure);
        } else {
          if (!evt.isShiftDown()) {
            view.clearSelection();
            view.setHandleDetailLevel(0);
          }
          newTracker = getSelectAreaTracker();
        }
      }

      if (newTracker != null) {
        setTracker(newTracker);
      }
      tracker.mousePressed(evt);
    }
  }
Ejemplo n.º 10
0
 @Override
 public void mouseReleased(MouseEvent evt) {
   if (getView() != null && getView().isEnabled()) {
     tracker.mouseReleased(evt);
   }
 }
Ejemplo n.º 11
0
 @Override
 public void draw(Graphics2D g) {
   tracker.draw(g);
 }
Ejemplo n.º 12
0
 @Override
 public void mouseMoved(MouseEvent evt) {
   tracker.mouseMoved(evt);
 }
Ejemplo n.º 13
0
 public void mouseExited(MouseEvent evt) {
   super.mouseExited(evt);
   tracker.mouseExited(evt);
 }
Ejemplo n.º 14
0
 public void mouseDragged(MouseEvent evt) {
   if (getView() != null && getView().isEnabled()) {
     tracker.mouseDragged(evt);
   }
 }
Ejemplo n.º 15
0
 public void keyTyped(KeyEvent evt) {
   if (getView() != null && getView().isEnabled()) {
     tracker.keyTyped(evt);
   }
 }
Ejemplo n.º 16
0
 public void keyPressed(KeyEvent e) {
   if (getView() != null && getView().isEnabled()) {
     tracker.keyPressed(e);
   }
 }