@Override public void add(DrawingView view) { target.add(view); }
@Override public void setTool(Tool t) { target.setTool(t); }
public SelectionComponentDisplayer(DrawingEditor editor, JComponent component) { this.editor = editor; this.weakRef = new WeakReference<JComponent>(component); if (editor.getActiveView() != null) { view = editor.getActiveView(); view.addPropertyChangeListener(this); view.addFigureSelectionListener(this); } editor.addPropertyChangeListener(this); updateVisibility(); }
protected void drawTool(Graphics2D g) { if (editor != null && editor.getActiveView() == this && editor.getTool() != null) { editor.getTool().draw(g); } }
/** * Sets the target of the proxy. */ public void setTarget(@Nullable DrawingEditor newValue) { if (target != null) { target.removePropertyChangeListener(forwarder); } this.target = newValue; if (target != null) { target.addPropertyChangeListener(forwarder); } } /**
f.getContentPane().add(view.getComponent()); DrawingEditor editor = new DefaultDrawingEditor(); editor.setTool(new DelegationSelectionTool()); editor.add(view); editor.setActiveView(view);
public void setEditor(@Nullable DrawingEditor newValue) { DrawingEditor oldValue = editor; if (oldValue != null) { oldValue.remove(view); } editor = newValue; if (newValue != null) { newValue.add(view); } creationToolBar.setEditor(editor); fillToolBar.setEditor(editor); strokeToolBar.setEditor(editor); actionToolBar.setUndoManager(undoManager); actionToolBar.setEditor(editor); alignToolBar.setEditor(editor); arrangeToolBar.setEditor(editor); fontToolBar.setEditor(editor); figureToolBar.setEditor(editor); linkToolBar.setEditor(editor); DrawingView temp = (editor == null) ? null : editor.getActiveView(); if (editor != null) { editor.setActiveView(view); } canvasToolBar.setEditor(editor); viewToolBar.setEditor(editor); if (editor != null) { editor.setActiveView(temp); } }
if (!evt.isConsumed()) { if (evt.getSource() instanceof Container) { editor.setActiveView(editor.findView((Container) evt.getSource())); InputMap im = editor.getInputMap(); if (im != null) { obj = im.get(KeyStroke.getKeyStroke(evt.getKeyCode(), evt.getModifiers(), false)); al = editor.getActionMap().get(obj);
@Override public DrawingView getActiveView() { return (target == null) ? null : target.getActiveView(); }
@Override public void paintIcon(java.awt.Component c, java.awt.Graphics gr, int x, int y) { Graphics2D g = (Graphics2D) gr; super.paintIcon(c, g, x, y); Color color; DrawingView view = editor.getActiveView(); if (view != null && view.getSelectedFigures().size() == 1) { color = view.getSelectedFigures().iterator().next().get(key); } else { color = key.get(editor.getDefaultAttributes()); } if (color != null) { g.setColor(color); g.translate(x, y); g.fill(colorShape); g.translate(-x, -y); } } }
@Override public DrawingView findView(Container c) { return target.findView(c); }
@Override public void show(Component invoker, int x, int y) { if (colorChooser == null) { initialize(); } Color c; if (editor.getActiveView() != null && editor.getActiveView().getSelectionCount() > 0) { c = editor.getActiveView().getSelectedFigures().iterator().next().get(attributeKey); } else { c = editor.getDefaultAttribute(attributeKey); } colorChooser.setColor(c == null ? new Color(0, true) : c); super.show(invoker, x, y); }
@Override public void dispose() { if (editor != null) { if (editor.getActiveView() != null) { DrawingView view = editor.getActiveView(); view.removePropertyChangeListener(this); if (view.getDrawing() != null) { view.getDrawing().removeFigureListener(this); } } editor.removePropertyChangeListener(this); editor = null; } component = null; } }
@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); } }
@Override public void applyDefaultAttributesTo(Figure f) { target.applyDefaultAttributesTo(f); }
@Override public <T> T getDefaultAttribute(AttributeKey<T> key) { return target.getDefaultAttribute(key); }
if (editor.getDrawingViews().size() == 0) { zoomPopupButton.setText("100 %"); } else { zoomPopupButton.setText((int) (editor.getDrawingViews().iterator().next().getScaleFactor() * 100) + " %"); editor.addPropertyChangeListener(new PropertyChangeListener() {
/** Registers the event handler from the drawing editor and the * active drawing view. */ private void registerEventHandler() { if (editor != null) { editor.addPropertyChangeListener(new WeakPropertyChangeListener(eventHandler)); } } }