public <T> void removeAttribute(AttributeKey<T> key) {
   if (hasAttribute(key)) {
     T oldValue = key.get(this);
     attributes.remove(key);
     fireAttributeChanged(key, oldValue, key.getDefaultValue());
   }
 }
  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();
    }
  }
Beispiel #3
0
 @Override
 public <T> void setAttribute(AttributeKey<T> key, T newValue) {
   if (key.equals(SVGAttributeKeys.TRANSFORM)
       || key.equals(SVGAttributeKeys.FONT_FACE)
       || key.equals(SVGAttributeKeys.FONT_BOLD)
       || key.equals(SVGAttributeKeys.FONT_ITALIC)
       || key.equals(SVGAttributeKeys.FONT_SIZE)) {
     invalidate();
   }
   super.setAttribute(key, newValue);
 }
Beispiel #4
0
 /**
  * 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;
 }
Beispiel #5
0
 /**
  * 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;
 }
 @SuppressWarnings("unchecked")
 protected void readAttributes(DOMInput in) throws IOException {
   if (in.getElementCount("a") > 0) {
     in.openElement("a");
     for (int i = in.getElementCount() - 1; i >= 0; i--) {
       in.openElement(i);
       String name = in.getTagName();
       Object value = in.readObject();
       AttributeKey key = getAttributeKey(name);
       if (key != null && key.isAssignable(value)) {
         if (forbiddenAttributes == null || !forbiddenAttributes.contains(key)) {
           setAttribute(key, value);
         }
       }
       in.closeElement();
     }
     in.closeElement();
   }
 }
 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();
 }
 /**
  * Sets an attribute of the figure. AttributeKey name and semantics are defined by the class
  * implementing the figure interface.
  */
 public <T> void setAttribute(AttributeKey<T> key, T newValue) {
   if (forbiddenAttributes == null || !forbiddenAttributes.contains(key)) {
     T oldValue = (T) key.put(attributes, newValue);
     fireAttributeChanged(key, oldValue, newValue);
   }
 }