@Override @SuppressWarnings("unchecked") protected Set<Figure> getEditedFigures() { return (Set<Figure>) ((activeView == null) ? Collections.emptySet() : activeView.getSelectedFigures()); }
@SuppressWarnings("unchecked") public void pickAttributes() { DrawingEditor editor = getEditor(); Collection<Figure> selection = getView().getSelectedFigures(); if (selection.size() > 0) { Figure figure = (Figure) selection.iterator().next(); for (Map.Entry<AttributeKey, Object> entry : figure.getAttributes().entrySet()) { if (!excludedAttributes.contains(entry.getKey())) { editor.setDefaultAttribute(entry.getKey(), entry.getValue()); } } } }
protected boolean canUngroup() { return getView() != null && getView().getSelectionCount() == 1 && prototype != null && getView().getSelectedFigures().iterator().next().getClass().equals( prototype.getClass()) && ((CompositeFigure) getView().getSelectedFigures().iterator().next()).getChildCount() > 1; }
@Override protected Color getInitialColor() { Color initialColor = null; DrawingView v = getEditor().getActiveView(); if (v != null && v.getSelectedFigures().size() == 1) { Figure f = v.getSelectedFigures().iterator().next(); initialColor = f.get(key); } if (initialColor == null) { initialColor = super.getInitialColor(); } return initialColor; } }
protected boolean canUngroup() { return getView() != null && getView().getSelectionCount() == 1 && prototype != null && getView().getSelectedFigures().iterator().next().getClass().equals( prototype.getClass()); }
@Override protected boolean canUngroup() { if (super.canUngroup()) { return ((CompositeFigure) getView().getSelectedFigures().iterator().next()).getChildCount() > 1; } return false; }
@Override public void actionPerformed(java.awt.event.ActionEvent evt) { applyAttributesTo(attributes, getView().getSelectedFigures()); }
public void selectSame() { HashSet<Class> selectedClasses = new HashSet<Class>(); for (Figure selected : getView().getSelectedFigures()) { selectedClasses.add(selected.getClass()); } for (Figure f : getDrawing().getChildren()) { if (selectedClasses.contains(f.getClass())) { getView().addToSelection(f); } } } }
@Override protected Transferable createTransferable(JComponent c) { if (DEBUG) { System.out.println("DefaultDrawingViewTransferHandler .createTransferable(" + c + ")"); } Transferable retValue; if (c instanceof DrawingView) { DrawingView view = (DrawingView) c; retValue = createTransferable(view, view.getSelectedFigures()); } else { retValue = super.createTransferable(c); } return retValue; }
/** * Returns the bounds of the selected figures. */ protected Rectangle2D.Double getSelectionBounds() { Rectangle2D.Double bounds = null; for (Iterator i=getView().getSelectedFigures().iterator(); i.hasNext(); ) { Figure f = (Figure) i.next(); if (bounds == null) { bounds = f.getBounds(); } else { bounds.add(f.getBounds()); } } return bounds; }
protected boolean canGroup() { boolean canCombine = getView().getSelectionCount() > 1; if (canCombine) { for (Figure f : getView().getSelectedFigures()) { if (!(f instanceof SVGPathFigure)) { canCombine = false; break; } } } return canCombine; }
@Override protected boolean canGroup() { boolean canCombine = getView().getSelectionCount() > 1; if (canCombine) { for (Figure f : getView().getSelectedFigures()) { if (!(f instanceof ODGPathFigure)) { canCombine = false; break; } } } return canCombine; }
@Override public void actionPerformed(java.awt.event.ActionEvent e) { CompositeEdit edit; AffineTransform tx = new AffineTransform(); tx.translate(dx, dy); HashSet<Figure> transformedFigures = new HashSet<Figure>(); for (Figure f : getView().getSelectedFigures()) { if (f.isTransformable()) { transformedFigures.add(f); f.willChange(); f.transform(tx); f.changed(); } } fireUndoableEditHappened(new TransformEdit(transformedFigures, tx)); }
@Override protected void alignFigures(Collection selectedFigures, Rectangle2D.Double selectionBounds) { double y = selectionBounds.y; for (Iterator i=getView().getSelectedFigures().iterator(); i.hasNext(); ) { Figure f = (Figure) i.next(); if (f.isTransformable()) { f.willChange(); Rectangle2D.Double b = f.getBounds(); AffineTransform tx = new AffineTransform(); tx.translate(0, y - b.y); f.transform(tx); f.changed(); fireUndoableEditHappened(new TransformEdit(f, tx)); } } } }
@Override protected void alignFigures(Collection selectedFigures, Rectangle2D.Double selectionBounds) { double x = selectionBounds.x; for (Iterator i=getView().getSelectedFigures().iterator(); i.hasNext(); ) { Figure f = (Figure) i.next(); if (f.isTransformable()) { f.willChange(); Rectangle2D.Double b = f.getBounds(); AffineTransform tx = new AffineTransform(); tx.translate(x - b.x, 0); f.transform(tx); f.changed(); fireUndoableEditHappened(new TransformEdit(f, tx)); } } } }
/** * Deletes the selection. * Depending on the tool, this could be selected figures, selected points * or selected text. */ @Override public void editDelete() { getView().getDrawing().removeAll(getView().getSelectedFigures()); }
@Override public void actionPerformed(java.awt.event.ActionEvent e) { if (colorChooser == null) { colorChooser = new JColorChooser(); } Color initialColor = getInitialColor(); // FIXME - Reuse colorChooser object instead of calling static method here. ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); Color chosenColor = JColorChooser.showDialog((Component) e.getSource(), labels.getString("attribute.color.text"), initialColor); if (chosenColor != null) { HashMap<AttributeKey, Object> attr = new HashMap<AttributeKey, Object>(attributes); attr.put(key, chosenColor); applyAttributesTo(attr, getView().getSelectedFigures()); } }
@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 mouseDragged(MouseEvent e) { DrawingView v = getView(); Figure f = v.findFigure(e.getPoint()); if (f != null) { if (!v.getSelectedFigures().contains(f)) { v.clearSelection(); v.addToSelection(f); } v.getComponent().getTransferHandler().exportAsDrag(v.getComponent(), e, DnDConstants.ACTION_MOVE); } fireToolDone(); }
@Override public void actionPerformed(java.awt.event.ActionEvent e) { CompositeEdit edit = new CompositeEdit(labels.getString("edit.align.text")); fireUndoableEditHappened(edit); alignFigures(getView().getSelectedFigures(), getSelectionBounds()); fireUndoableEditHappened(edit); } protected abstract void alignFigures(Collection selectedFigures, Rectangle2D.Double selectionBounds);