@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);
    }
  }
 protected DrawingView createDrawingView(Drawing newDrawing) {
   Dimension d = getDrawingViewSize();
   DrawingView newDrawingView = new StandardDrawingView(this, d.width, d.height);
   newDrawingView.setDrawing(newDrawing);
   fireViewCreatedEvent(newDrawingView);
   return newDrawingView;
 }
示例#3
0
 public void execute() {
   PointConstrainer grid = fView.getConstrainer();
   if (grid != null) {
     fView.setConstrainer(null);
   } else {
     fView.setConstrainer(new GridConstrainer(fGrid.x, fGrid.y));
   }
 }
 /** Inserts a vector of figures and translates them by the given offset. */
 protected void insertFigures(Vector figures, int dx, int dy) {
   FigureEnumeration e = new FigureEnumerator(figures);
   while (e.hasMoreElements()) {
     Figure figure = e.nextFigure();
     figure.moveBy(dx, dy);
     figure = fView.add(figure);
     fView.addToSelection(figure);
   }
 }
 /** Refreshes the drawing if there is some accumulated damage */
 public synchronized void checkDamage() {
   Iterator each = drawing().drawingChangeListeners();
   while (each.hasNext()) {
     Object l = each.next();
     if (l instanceof DrawingView) {
       ((DrawingView) l).repairDamage();
     }
   }
 }
示例#6
0
  /** Handles a mouse click. */
  @Override
  public boolean handleMouseClick(Point2D.Double p, MouseEvent evt, DrawingView view) {
    if (evt.getClickCount() == 2 && view.getHandleDetailLevel() % 2 == 0) {
      willChange();
      final int index = splitSegment(p, 5f / view.getScaleFactor());
      if (index != -1) {
        final BezierPath.Node newNode = getNode(index);
        fireUndoableEditHappened(
            new AbstractUndoableEdit() {
              private static final long serialVersionUID = 1L;

              @Override
              public String getPresentationName() {
                ResourceBundleUtil labels =
                    ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");
                return labels.getString("edit.bezierPath.splitSegment.text");
              }

              @Override
              public void redo() throws CannotRedoException {
                super.redo();
                willChange();
                addNode(index, newNode);
                changed();
              }

              @Override
              public void undo() throws CannotUndoException {
                super.undo();
                willChange();
                removeNode(index);
                changed();
              }
            });
        changed();
        evt.consume();
        return true;
      }
    }
    return false;
  }
  @Override
  public boolean handleMouseClick(Point2D.Double p, MouseEvent evt, DrawingView view) {
    if (evt.getClickCount() == 2 /* && view.getHandleDetailLevel() == 0*/) {
      willChange();

      // Apply inverse of transform to point
      if (get(TRANSFORM) != null) {
        try {
          p = (Point2D.Double) get(TRANSFORM).inverseTransform(p, new Point2D.Double());
        } catch (NoninvertibleTransformException ex) {
          System.err.println(
              "Warning: SVGBezierFigure.handleMouseClick. Figure has noninvertible Transform.");
        }
      }

      final int index = splitSegment(p, (float) (5f / view.getScaleFactor()));
      if (index != -1) {
        final BezierPath.Node newNode = getNode(index);
        fireUndoableEditHappened(
            new AbstractUndoableEdit() {
              @Override
              public String getPresentationName() {
                ResourceBundleUtil labels =
                    ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels");
                return labels.getString("edit.bezierPath.splitSegment.text");
              }

              @Override
              public void redo() throws CannotRedoException {
                super.redo();
                willChange();
                addNode(index, newNode);
                changed();
              }

              @Override
              public void undo() throws CannotUndoException {
                super.undo();
                willChange();
                removeNode(index);
                changed();
              }
            });
        changed();
        evt.consume();
        return true;
      }
    }
    return false;
  }
 /** Copies the selection to the clipboard. */
 protected void copySelection() {
   FigureSelection selection = fView.getFigureSelection();
   Clipboard.getClipboard().setContents(selection);
 }
 /** Deletes the selection from the drawing. */
 protected void deleteSelection() {
   fView.drawing().removeAll(fView.selection());
   fView.clearSelection();
 }
示例#10
0
 /**
  * Creates the drawing view used in this application. You need to override this method to use a
  * DrawingView subclass in your application. By default a standard DrawingView is returned.
  */
 protected DrawingView createDrawingView() {
   DrawingView createdDrawingView = createDrawingView(createDrawing());
   createdDrawingView.drawing().setTitle(getDefaultDrawingTitle());
   return createdDrawingView;
 }