Rectangle2D.Double bounds = createdFigure.getBounds(); if (bounds.width == 0 && bounds.height == 0) { getDrawing().remove(createdFigure); if (isToolDoneAfterCreation()) { fireToolDone(); createdFigure.willChange(); createdFigure.setBounds( constrainPoint(new Point(anchor.x, anchor.y)), constrainPoint(new Point( anchor.x + (int) Math.max(bounds.width, minimalSize.width), anchor.y + (int) Math.max(bounds.height, minimalSize.height)))); final Drawing addedDrawing = getDrawing(); getDrawing().fireUndoableEditHappened(new AbstractUndoableEdit() { Rectangle r = new Rectangle(anchor.x, anchor.y, 0, 0); r.add(evt.getX(), evt.getY()); maybeFireBoundsInvalidated(r); creationFinished(createdFigure); createdFigure = null; if (isToolDoneAfterCreation()) { fireToolDone();
@Override public void mousePressed(MouseEvent evt) { if (!isLeftClick(evt)) return; super.mousePressed(evt); adapter.mouseDown(getDisplay(), evt.getX(), evt.getY()); }
@Override public void mouseClicked(MouseEvent evt) { if (!isLeftClick(evt)) return; super.mouseClicked(evt); }
@Override public void mousePressed(MouseEvent evt) { super.mousePressed(evt); getView().clearSelection(); createdFigure = createFigure(); Point2D.Double p = constrainPoint(viewToDrawing(anchor)); anchor.x = evt.getX(); anchor.y = evt.getY(); createdFigure.setBounds(p, p); getDrawing().add(createdFigure); }
@SuppressWarnings("unchecked") @Override protected void creationFinished(final Figure figure) { super.creationFinished(figure); final JHotDrawService jHotDrawService = getDisplay().getContext().getService(JHotDrawService.class); jHotDrawService.linkOverlay((F)figure, getAdapter(), getDisplay()); }
@Override public void mouseDragged(MouseEvent evt) { super.mouseDragged(evt); adapter.mouseDrag(getDisplay(), evt.getX(), evt.getY()); }
@Override public void mouseReleased(MouseEvent evt) { if (!isLeftClick(evt)) return; super.mouseReleased(evt); }
ConnectionFigure lc; ButtonFactory.addToolTo(tb, editor, new CreationTool(new RectangleFigure()), "edit.createRectangle", labels); ButtonFactory.addToolTo(tb, editor, new CreationTool(new RoundRectangleFigure()), "edit.createRoundRectangle", labels); ButtonFactory.addToolTo(tb, editor, new CreationTool(new EllipseFigure()), "edit.createEllipse", labels); ButtonFactory.addToolTo(tb, editor, new CreationTool(new DiamondFigure()), "edit.createDiamond", labels); ButtonFactory.addToolTo(tb, editor, new CreationTool(new TriangleFigure()), "edit.createTriangle", labels); ButtonFactory.addToolTo(tb, editor, new CreationTool(new LineFigure()), "edit.createLine", labels); ButtonFactory.addToolTo(tb, editor, ct = new CreationTool(new LineFigure()), "edit.createArrow", labels); 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);
private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap<AttributeKey, Object> attributes; ResourceBundleUtil drawLabels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); ButtonFactory.addSelectionToolTo(tb, editor, createDrawingActions(editor), createSelectionActions(editor)); tb.addSeparator(); attributes = new HashMap<AttributeKey, Object>(); ButtonFactory.addToolTo(tb, editor, new CreationTool(new ODGRectFigure(), attributes), "edit.createRectangle", drawLabels); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, null); attributes.put(AttributeKeys.STROKE_COLOR, Color.black); ButtonFactory.addToolTo(tb, editor, new CreationTool(new ODGPathFigure(), attributes), "edit.createLine", drawLabels); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, Color.black); attributes.put(AttributeKeys.STROKE_COLOR, null); attributes = new HashMap<AttributeKey, Object>(); attributes.put(AttributeKeys.FILL_COLOR, null); attributes.put(AttributeKeys.STROKE_COLOR, null); }
btn = ButtonFactory.addToolTo(this, editor, creationTool = new CreationTool(new SVGRectFigure(), attributes), "createRectangle", labels); creationTool.setToolDoneAfterCreation(false); btn.setUI((PaletteButtonUI) PaletteButtonUI.createUI(btn)); gbc = new GridBagConstraints(); p.add(btn, gbc); btn = ButtonFactory.addToolTo(this, editor, creationTool = new CreationTool(new SVGEllipseFigure(), attributes), "createEllipse", labels); creationTool.setToolDoneAfterCreation(false); btn.setUI((PaletteButtonUI) PaletteButtonUI.createUI(btn)); gbc = new GridBagConstraints(); attributes.put(AttributeKeys.FILL_COLOR, null); attributes.put(PATH_CLOSED, false); btn = ButtonFactory.addToolTo(this, editor, creationTool = new CreationTool(new SVGPathFigure(), attributes), "createLine", labels); creationTool.setToolDoneAfterCreation(false); btn.setUI((PaletteButtonUI) PaletteButtonUI.createUI(btn)); gbc = new GridBagConstraints();
@Override public void activate(DrawingEditor editor) { super.activate(editor);
@Override protected Figure createFigure() { if (prototype instanceof CompositeFigure) { // we must not apply default attributs to the composite figure, // because this would change the look of the figures that we // read from the SVG file. return (Figure) prototype.clone(); } else { return super.createFigure(); } }
@Override public void mouseDragged(MouseEvent evt) { if (createdFigure != null) { Point2D.Double p = constrainPoint(new Point(evt.getX(), evt.getY())); createdFigure.willChange(); createdFigure.setBounds( constrainPoint(new Point(anchor.x, anchor.y)), p); createdFigure.changed(); } }
@SuppressWarnings("unchecked") @Override protected void creationFinished(final Figure figure) { super.creationFinished(figure); final JHotDrawService jHotDrawService = getDisplay().getContext().getService(JHotDrawService.class); jHotDrawService.linkOverlay((F)figure, getAdapter(), getDisplay()); }
@Override public void mouseDragged(MouseEvent evt) { super.mouseDragged(evt); adapter.mouseDrag(getDisplay(), evt.getX(), evt.getY()); }
@Override public void mouseReleased(MouseEvent evt) { if (!isLeftClick(evt)) return; super.mouseReleased(evt); }
ConnectionFigure lc; ButtonFactory.addToolTo(tb, editor, new CreationTool(new RectangleFigure()), "edit.createRectangle", labels); ButtonFactory.addToolTo(tb, editor, new CreationTool(new RoundRectangleFigure()), "edit.createRoundRectangle", labels); ButtonFactory.addToolTo(tb, editor, new CreationTool(new EllipseFigure()), "edit.createEllipse", labels); ButtonFactory.addToolTo(tb, editor, new CreationTool(new DiamondFigure()), "edit.createDiamond", labels); ButtonFactory.addToolTo(tb, editor, new CreationTool(new TriangleFigure()), "edit.createTriangle", labels); ButtonFactory.addToolTo(tb, editor, new CreationTool(new LineFigure()), "edit.createLine", labels); ButtonFactory.addToolTo(tb, editor, ct = new CreationTool(new LineFigure()), "edit.createArrow", labels); 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, new CreationTool(new RectangleFigure()), "edit.createRectangle", labels);
@Override public void activate(DrawingEditor editor) { super.activate(editor);
@Override public void mousePressed(MouseEvent evt) { if (!isLeftClick(evt)) return; super.mousePressed(evt); adapter.mouseDown(getDisplay(), evt.getX(), evt.getY()); }