@Override
  public void mouseMoved(MouseEvent evt) {
    Point point = evt.getPoint();
    updateCursor(editor.findView((Container) evt.getSource()), point);
    DrawingView view = editor.findView((Container) evt.getSource());
    updateCursor(view, point);
    if (view == null || editor.getActiveView() != view) {
      clearHoverHandles();
    } else {
      // Search first, if one of the selected figures contains
      // the current mouse location. Only then search for other
      // figures. This search sequence is consistent with the
      // search sequence of the SelectionTool.
      Figure figure = null;
      Point2D.Double p = view.viewToDrawing(point);
      for (Figure f : view.getSelectedFigures()) {
        if (f.contains(p)) {
          figure = f;
        }
      }
      if (figure == null) {
        figure = view.findFigure(point);
        Drawing drawing = view.getDrawing();
        while (figure != null && !figure.isSelectable()) {
          figure = drawing.findFigureBehind(p, figure);
        }
      }

      updateHoverHandles(view, figure);
    }
  }
Пример #2
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);
    }
  }