protected Connector findConnector(Point2D.Double p, Figure f, ConnectionFigure prototype) { return f.findConnector(p, prototype); }
/** * Finds a connection end figure. */ @Nullable protected Connector findConnectableConnector(Figure connectableFigure, Point2D.Double p) { Connector target = (connectableFigure == null) ? null : connectableFigure.findConnector(p, getConnection()); if ((connectableFigure != null) && connectableFigure.isConnectable() && !connectableFigure.includes(getOwner()) && getConnection().canConnect(connector, target)) { return target; } return null; }
/** * Adjust the created connection. */ @Override public void mouseDragged(java.awt.event.MouseEvent e) { repaintConnectors(e); if (createdFigure != null) { createdFigure.willChange(); Point2D.Double endPoint = viewToDrawing(new Point(e.getX(), e.getY())); getView().getConstrainer().constrainPoint(endPoint); Figure endFigure = getDrawing().findFigureExcept(endPoint, createdFigure); endConnector = (endFigure == null) ? null : endFigure.findConnector(endPoint, prototype); if (endConnector != null && canConnect(createdFigure, startConnector, endConnector)) { endPoint = endConnector.getAnchor(); } Rectangle r = new Rectangle(getView().drawingToView(createdFigure.getEndPoint())); createdFigure.setEndPoint(endPoint); r.add(getView().drawingToView(endPoint)); r.grow(ANCHOR_WIDTH + 2, ANCHOR_WIDTH + 2); getView().getComponent().repaint(r); createdFigure.changed(); } }
/** * Manipulates connections in a context dependent way. If the * mouse down hits a figure start a new connection. If the mousedown * hits a connection split a segment or join two segments. */ @Override public void mousePressed(MouseEvent evt) { super.mousePressed(evt); getView().clearSelection(); Point2D.Double startPoint = viewToDrawing(anchor); Figure startFigure = getDrawing().findFigure(startPoint); startConnector = (startFigure == null) ? null : startFigure.findConnector(startPoint, prototype); if (startConnector != null && canConnect(prototype, startConnector)) { Point2D.Double anchor = startConnector.getAnchor(); createdFigure = createFigure(); createdFigure.setStartPoint(anchor); createdFigure.setEndPoint(anchor); getDrawing().add(createdFigure); Rectangle r = new Rectangle(getView().drawingToView(anchor)); r.grow(ANCHOR_WIDTH, ANCHOR_WIDTH); fireAreaInvalidated(r); } else { startConnector = null; createdFigure = null; } endConnector = null; }