protected void writeAttributes(DOMOutput out) throws IOException { Figure prototype = (Figure) out.getPrototype(); boolean isElementOpen = false; for (Map.Entry<AttributeKey, Object> entry : attributes.entrySet()) { AttributeKey key = entry.getKey(); if (forbiddenAttributes == null || !forbiddenAttributes.contains(key)) { Object prototypeValue = key.get(prototype); Object attributeValue = key.get(this); if (prototypeValue != attributeValue || (prototypeValue != null && attributeValue != null && !prototypeValue.equals(attributeValue))) { if (!isElementOpen) { out.openElement("a"); isElementOpen = true; } out.openElement(key.getKey()); out.writeObject(entry.getValue()); out.closeElement(); } } } if (isElementOpen) { out.closeElement(); } }
/** * Gets the stroke paint for the specified figure based on the attributes STROKE_GRADIENT, * STROKE_OPACITY, STROKE_PAINT and the bounds of the figure. Returns null if the figure is not * filled. */ public static Paint getStrokePaint(Figure f) { double opacity = STROKE_OPACITY.get(f); if (STROKE_GRADIENT.get(f) != null) { return STROKE_GRADIENT.get(f).getPaint(f, opacity); } Color color = STROKE_COLOR.get(f); if (color != null) { if (opacity != 1) { color = new Color((color.getRGB() & 0xffffff) | (int) (opacity * 255) << 24, true); } } return color; }
public <T> void removeAttribute(AttributeKey<T> key) { if (hasAttribute(key)) { T oldValue = key.get(this); attributes.remove(key); fireAttributeChanged(key, oldValue, key.getDefaultValue()); } }
/** * Returns the distance, that a Rectangle needs to grow (or shrink) to make hit detections on a * shape as specified by the FILL_UNDER_STROKE and STROKE_POSITION attributes of a figure. The * value returned is the number of units that need to be grown (or shrunk) perpendicular to a * stroke on an outline of the shape. */ public static double getPerpendicularHitGrowth(Figure f) { double grow; if (STROKE_COLOR.get(f) == null && STROKE_GRADIENT.get(f) == null) { grow = getPerpendicularFillGrowth(f); } else { double strokeWidth = AttributeKeys.getStrokeTotalWidth(f); grow = getPerpendicularDrawGrowth(f) + strokeWidth / 2d; } return grow; }
private Locator getLocator(Figure f) { return LAYOUT_LOCATOR.get(f); }
/** Gets an attribute from the figure. */ public <T> T getAttribute(AttributeKey<T> key) { return hasAttribute(key) ? key.get(attributes) : key.getDefaultValue(); }