@Override public <T> T getDefaultAttribute(AttributeKey<T> key) { return target.getDefaultAttribute(key); }
protected Color getInitialColor() { Color initialColor = (Color) getEditor().getDefaultAttribute(key); if (initialColor == null) { initialColor = Color.red; } return initialColor; } }
@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 = (Color) editor.getDefaultAttribute(key); if (color != null) { g.setColor(color); g.translate(x, y); g.fill(colorShape); g.translate(-x, -y); } } }
@SuppressWarnings("unchecked") public void changeAttribute() { CompositeEdit edit = new CompositeEdit("attributes"); fireUndoableEditHappened(edit); DrawingEditor editor = getEditor(); Iterator i = getView().getSelectedFigures().iterator(); while (i.hasNext()) { Figure figure = (Figure) i.next(); figure.willChange(); for (int j = 0; j < keys.length; j++) { figure.set(keys[j], editor.getDefaultAttribute(keys[j])); } for (Map.Entry<AttributeKey, Object> entry : fixedAttributes.entrySet()) { figure.set(entry.getKey(), entry.getValue()); } figure.changed(); } fireUndoableEditHappened(edit); }
@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 show(Component invoker, int x, int y) { if (colorChooser == null) { initialize(); } Color c; if (editor.getActiveView() != null) { c = editor.getActiveView().getDrawing().get(attributeKey); } else { c = editor.getDefaultAttribute(attributeKey); } colorChooser.setColor(c == null ? new Color(0, true) : c); super.show(invoker, x, y); }
protected void updateAttributeEditor() { if (updateDepth++ == 0) { Set<Figure> figures = getEditedFigures(); if (editor==null) { attributeEditor.getComponent().setEnabled(false); } else if (activeView == null || figures.isEmpty()) { attributeEditor.getComponent().setEnabled(true); T value = editor.getDefaultAttribute(attributeKey); attributeEditor.setAttributeValue(value); attributeEditor.setMultipleValues(false); } else { attributeEditor.getComponent().setEnabled(true); T value = figures.iterator().next().get(attributeKey); boolean isMultiple = false; for (Figure f : figures) { T v = f.get(attributeKey); if ((v == null || value == null) && v != value || // v != null && value != null && !v.equals(value)) { isMultiple = true; break; } } attributeEditor.setAttributeValue(value); attributeEditor.setMultipleValues(isMultiple); } } updateDepth--; }