@Override public void redo() throws CannotRedoException { super.redo(); willChange(); addNode(index, newNode); changed(); }
@Override public void addNotify(Drawing drawing) { for (Figure child : new LinkedList<Figure>(children)) { child.addNotify(drawing); } super.addNotify(drawing); } @Override
@Override public DependencyFigure clone() { DependencyFigure that = (DependencyFigure) super.clone(); return that; }
@Override public void undo() throws CannotUndoException { super.undo(); willChange(); removeNode(index); changed(); } });
@Override public void figureChanged(FigureEvent e) { if (!owner.isChanging()) { if (e.getSource() == owner.getStartFigure() || e.getSource() == owner.getEndFigure()) { owner.willChange(); owner.updateConnection(); owner.changed(); } } } };
@Override public void remap(Map<Figure, Figure> oldToNew, boolean disconnectIfNotInMap) { willChange(); super.remap(oldToNew, disconnectIfNotInMap); Figure newStartFigure = null; Figure newEndFigure = null; if (getStartFigure() != null) { newStartFigure = (Figure) oldToNew.get(getStartFigure()); if (newStartFigure == null && !disconnectIfNotInMap) { newStartFigure = getStartFigure(); if (getEndFigure() != null) { newEndFigure = (Figure) oldToNew.get(getEndFigure()); if (newEndFigure == null && !disconnectIfNotInMap) { newEndFigure = getEndFigure(); setStartConnector(newStartFigure.findCompatibleConnector(getStartConnector(), true)); } else { if (disconnectIfNotInMap) { setStartConnector(null); setEndConnector(newEndFigure.findCompatibleConnector(getEndConnector(), false)); } else { if (disconnectIfNotInMap) { setEndConnector(null); updateConnection(); changed();
@Override public void updateConnection() { willChange(); if (getStartConnector() != null) { Point2D.Double start = getStartConnector().findStart(this); if (start != null) { setStartPoint(start); } } if (getEndConnector() != null) { Point2D.Double end = getEndConnector().findEnd(this); if (end != null) { setEndPoint(end); } } changed(); }
if (getLiner() == null && evt.getClickCount() == 2) { willChange(); final int index = splitSegment(p, (float) (5f / view.getScaleFactor())); if (index != -1) { final BezierPath.Node newNode = getNode(index); fireUndoableEditHappened(new AbstractUndoableEdit() { changed(); return true;
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 setLiner(Liner newValue) { Liner oldValue = liner; this.liner = newValue; firePropertyChange(LINER_PROPERTY, oldValue, newValue); }
@Override public void figureRemoved(FigureEvent evt) { // The commented lines below must stay commented out. // This is because, we must not set our connectors to null, // in order to support reconnection using redo. /* if (evt.getFigure() == owner.getStartFigure() || evt.getFigure() == owner.getEndFigure()) { owner.setStartConnector(null); owner.setEndConnector(null); }*/ owner.fireFigureRequestRemove(); }
/** * Draw the figure. This method is delegated to the encapsulated presentation figure. */ @Override public void draw(Graphics2D g) { super.draw(g); for (Figure child : children) { if (child.isVisible()) { child.draw(g); } } }
@Override public boolean contains(Point2D.Double p) { if (getDrawingArea().contains(p)) { for (Figure child : getChildrenFrontToBack()) { if (child.isVisible() && child.contains(p)) return true; } return super.contains(p); } return false; } // ATTRIBUTES
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 Collection<Handle> createHandles(int detailLevel) { java.util.List<Handle> handles = new LinkedList<Handle>(); switch (detailLevel) { case -1: handles.add(new BoundsOutlineHandle(getDecorator(), false, true)); break; case 0: handles.add(new MoveHandle(this, RelativeLocator.northWest())); handles.add(new MoveHandle(this, RelativeLocator.northEast())); handles.add(new MoveHandle(this, RelativeLocator.southWest())); handles.add(new MoveHandle(this, RelativeLocator.southEast())); for (Connector c : connectors) { handles.add(new ConnectorHandle(c, new LineConnectionFigure())); } break; } return handles; }
@Override public LabeledLineConnectionFigure clone() { LabeledLineConnectionFigure that = (LabeledLineConnectionFigure) super.clone(); that.childHandler = new ChildHandler(that); that.children = new ArrayList<Figure>(); for (Figure thisChild : this.children) { Figure thatChild = (Figure) thisChild.clone(); that.children.add(thatChild); thatChild.addFigureListener(that.childHandler); } return that; } @Override
ConnectionFigure cf = new LineConnectionFigure(); cf.setLiner(new ElbowLiner());
TextAreaFigure tc = new TextAreaFigure(); tc.setBounds(new Point2D.Double(220, 10), new Point2D.Double(310, 100)); ConnectionFigure cf = new LineConnectionFigure(); cf.setLiner(new ElbowLiner()); cf.setStartConnector(ta.findConnector(Geom.center(ta.getBounds()), cf));
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());
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());