@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; }
/** * Connects the figure to the new target. If there is no new target the connection reverts to its * original one. */ public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) { Connector target = findConnectionTarget(x, y, view.drawing()); if (target == null) { target = fOriginalTarget; } setPoint(x, y); connect(target); getConnection().updateConnection(); Connector oldConnector = ((ChangeConnectionHandle.UndoActivity) getUndoActivity()).getOldConnector(); // there has been no change so there is nothing to undo if ((oldConnector == null) || (target() == null) || (oldConnector.owner() == target().owner())) { setUndoActivity(null); } else { getUndoActivity().setAffectedFigures(new SingleFigureEnumerator(getConnection())); } if (getTargetFigure() != null) { getTargetFigure().connectorVisibility(false); setTargetFigure(null); } }
/** 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(); } } }
/** Finds a new target of the connection. */ public void invokeStep(int x, int y, int anchorX, int anchorY, DrawingView view) { Point p = new Point(x, y); Figure f = findConnectableFigure(x, y, view.drawing()); // track the figure containing the mouse if (f != getTargetFigure()) { if (getTargetFigure() != null) { getTargetFigure().connectorVisibility(false); } setTargetFigure(f); if (getTargetFigure() != null) { getTargetFigure().connectorVisibility(true); } } Connector target = findConnectionTarget(p.x, p.y, view.drawing()); if (target != null) { p = Geom.center(target.displayBox()); } setPoint(p.x, p.y); }
/** 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; }
/** Draws a pattern background pattern by replicating an image. */ protected void drawPattern(Graphics g, Image image, DrawingView view) { int iwidth = image.getWidth(view); int iheight = image.getHeight(view); Dimension d = view.getSize(); int x = 0; int y = 0; while (y < d.height) { while (x < d.width) { g.drawImage(image, x, y, view); x += iwidth; } y += iheight; x = 0; } }
/** * Tracks the end of the interaction. * * @param x the current x position * @param y the current y position * @param anchorX the x position where the interaction started * @param anchorY the y position where the interaction started */ public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) { invokeEnd(x - anchorX, y - anchorY, view.drawing()); }
/** * @param x the x position where the interaction started * @param y the y position where the interaction started * @param view the handles container */ public void invokeStart(int x, int y, DrawingView view) { invokeStart(x, y, view.drawing()); }
/** * 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; }
@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); } }