Пример #1
0
 public void mousePressed(MouseEvent e) {
   // Set up view transform
   vt = parent.preview.getViewTransform();
   super.mousePressed(e);
 }
Пример #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);
    }
  }