/** * 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; }
/** * This method allows subclasses to do perform additonal user interactions * after the new figure has been created. * The implementation of this class just invokes fireToolDone. */ protected void creationFinished(Figure createdFigure) { if (isToolDoneAfterCreation()) { fireToolDone(); } }
/** * Creates the ConnectionFigure. By default the figure prototype is * cloned. */ @SuppressWarnings("unchecked") protected ConnectionFigure createFigure() { ConnectionFigure f = (ConnectionFigure) prototype.clone(); getEditor().applyDefaultAttributesTo(f); if (prototypeAttributes != null) { for (Map.Entry<AttributeKey, Object> entry : prototypeAttributes.entrySet()) { f.set(entry.getKey(), entry.getValue()); } } return f; }
/** * 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(); } }
final Drawing addedDrawing = getDrawing(); getDrawing().fireUndoableEditHappened(new AbstractUndoableEdit() { targetFigure = null; Point2D.Double anchor = startConnector.getAnchor(); Rectangle r = new Rectangle(getView().drawingToView(anchor)); r.grow(ANCHOR_WIDTH, ANCHOR_WIDTH); fireAreaInvalidated(r); anchor = endConnector.getAnchor(); r = new Rectangle(getView().drawingToView(anchor)); r.grow(ANCHOR_WIDTH, ANCHOR_WIDTH); fireAreaInvalidated(r); startConnector = endConnector = null; Figure finishedFigure = createdFigure; createdFigure = null; creationFinished(finishedFigure); } else { if (isToolDoneAfterCreation()) { fireToolDone();
Point2D.Double targetPoint = viewToDrawing(new Point(evt.getX(), evt.getY())); Figure aFigure = getDrawing().findFigureExcept(targetPoint, createdFigure); if (aFigure != null && !aFigure.isConnectable()) { aFigure = null; connectors = targetFigure.getConnectors(getPrototype()); for (Connector c : connectors) { if (invalidArea == null) { getView().getComponent().repaint( getView().drawingToView(invalidArea));
af = (AbstractAttributedFigure) ct.getPrototype(); af.set(END_DECORATION, new ArrowTip(0.35, 12, 11.3)); ButtonFactory.addToolTo(tb, editor, new ConnectionTool(new LineConnectionFigure()), "edit.createLineConnection", labels); ButtonFactory.addToolTo(tb, editor, cnt = new ConnectionTool(new LineConnectionFigure()), "edit.createElbowConnection", labels); lc = cnt.getPrototype(); lc.setLiner(new ElbowLiner()); ButtonFactory.addToolTo(tb, editor, cnt = new ConnectionTool(new LineConnectionFigure()), "edit.createCurvedConnection", labels); lc = cnt.getPrototype(); lc.setLiner(new CurvedLiner()); ButtonFactory.addToolTo(tb, editor, new BezierTool(new BezierFigure()), "edit.createScribble", labels);
@Override public void draw(Graphics2D g) { Graphics2D gg = (Graphics2D) g.create(); gg.transform(getView().getDrawingToViewTransform()); if (targetFigure != null) { for (Connector c : targetFigure.getConnectors(getPrototype())) { c.draw(gg); } } if (createdFigure != null) { createdFigure.draw(gg); Point p = getView().drawingToView(createdFigure.getStartPoint()); Ellipse2D.Double e = new Ellipse2D.Double( p.x - ANCHOR_WIDTH / 2, p.y - ANCHOR_WIDTH / 2, ANCHOR_WIDTH, ANCHOR_WIDTH); g.setColor(Color.GREEN); g.fill(e); g.setColor(Color.BLACK); g.draw(e); p = getView().drawingToView(createdFigure.getEndPoint()); e = new Ellipse2D.Double( p.x - ANCHOR_WIDTH / 2, p.y - ANCHOR_WIDTH / 2, ANCHOR_WIDTH, ANCHOR_WIDTH); g.setColor(Color.GREEN); g.fill(e); g.setColor(Color.BLACK); g.draw(e); } gg.dispose(); }
private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap<AttributeKey,Object> attributes; ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.net.Labels"); ButtonFactory.addSelectionToolTo(tb, editor); tb.addSeparator(); attributes = new HashMap<AttributeKey,Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.white); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); attributes.put(AttributeKeys.TEXT_COLOR, Color.black); ButtonFactory.addToolTo(tb, editor, new TextCreationTool(new NodeFigure(), attributes), "edit.createNode", labels); attributes = new HashMap<AttributeKey,Object>(); attributes.put(AttributeKeys.STROKE_COLOR, new Color(0x000099)); ButtonFactory.addToolTo(tb, editor, new ConnectionTool(new LineConnectionFigure(), attributes), "edit.createLink", labels); }
@Override public void deactivate(DrawingEditor editor) { if (createdFigure != null) { getDrawing().remove(createdFigure); createdFigure = null; } targetFigure = null; startConnector = endConnector = null; super.deactivate(editor); }
af = (AbstractAttributedFigure) ct.getPrototype(); af.set(END_DECORATION, new ArrowTip(0.35, 12, 11.3)); ButtonFactory.addToolTo(tb, editor, new ConnectionTool(new LineConnectionFigure()), "edit.createLineConnection", labels); ButtonFactory.addToolTo(tb, editor, cnt = new ConnectionTool(new LineConnectionFigure()), "edit.createElbowConnection", labels); lc = cnt.getPrototype(); lc.setLiner(new ElbowLiner()); ButtonFactory.addToolTo(tb, editor, cnt = new ConnectionTool(new LineConnectionFigure()), "edit.createCurvedConnection", labels); lc = cnt.getPrototype(); lc.setLiner(new CurvedLiner()); ButtonFactory.addToolTo(tb, editor, new BezierTool(new BezierFigure()), "edit.createScribble", labels);
private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap<AttributeKey, Object> attributes; ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.net.Labels"); ButtonFactory.addSelectionToolTo(tb, editor); tb.addSeparator(); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.white); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); attributes.put(AttributeKeys.TEXT_COLOR, Color.black); ButtonFactory.addToolTo(tb, editor, new TextCreationTool(new NodeFigure(), attributes), "edit.createNode", labels); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.STROKE_COLOR, new Color(0x000099)); ButtonFactory.addToolTo(tb, editor, new ConnectionTool(new LineConnectionFigure(), attributes), "edit.createLink", labels); }
private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap<AttributeKey, Object> attributes; ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.pert.Labels"); ResourceBundleUtil drawLabels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); ButtonFactory.addSelectionToolTo(tb, editor); tb.addSeparator(); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.white); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); attributes.put(AttributeKeys.TEXT_COLOR, Color.black); ButtonFactory.addToolTo(tb, editor, new CreationTool(new TaskFigure(), attributes), "edit.createTask", labels); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.STROKE_COLOR, new Color(0x000099)); ButtonFactory.addToolTo(tb, editor, new ConnectionTool(new DependencyFigure(), attributes), "edit.createDependency", labels); tb.addSeparator(); ButtonFactory.addToolTo(tb, editor, new TextAreaCreationTool(new TextAreaFigure()), "edit.createTextArea", drawLabels); }
private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap<AttributeKey,Object> attributes; ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.pert.Labels"); ResourceBundleUtil drawLabels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); ButtonFactory.addSelectionToolTo(tb, editor); tb.addSeparator(); attributes = new HashMap<AttributeKey,Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.white); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); attributes.put(AttributeKeys.TEXT_COLOR, Color.black); ButtonFactory.addToolTo(tb, editor, new CreationTool(new TaskFigure(), attributes), "edit.createTask", labels); attributes = new HashMap<AttributeKey,Object>(); attributes.put(AttributeKeys.STROKE_COLOR, new Color(0x000099)); ButtonFactory.addToolTo(tb, editor, new ConnectionTool(new DependencyFigure(), attributes), "edit.createDependency", labels); tb.addSeparator(); ButtonFactory.addToolTo(tb, editor, new TextAreaCreationTool(new TextAreaFigure()), "edit.createTextArea", drawLabels); }