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();
    }
  }
Exemplo n.º 3
0
  protected TextLayout getTextLayout() {
    if (textLayout == null) {
      String text = getText();
      if (text == null || text.length() == 0) {
        text = " ";
      }

      FontRenderContext frc = getFontRenderContext();
      HashMap<TextAttribute, Object> textAttributes = new HashMap<TextAttribute, Object>();
      textAttributes.put(TextAttribute.FONT, getFont());
      if (get(FONT_UNDERLINE)) {
        textAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
      }
      textLayout = new TextLayout(text, textAttributes, frc);
    }
    return textLayout;
  }
Exemplo n.º 4
0
  private Shape getTextShape() {
    if (cachedTextShape == null) {
      String text = getText();
      if (text == null || text.length() == 0) {
        text = " ";
      }

      FontRenderContext frc = getFontRenderContext();
      HashMap<TextAttribute, Object> textAttributes = new HashMap<TextAttribute, Object>();
      textAttributes.put(TextAttribute.FONT, getFont());
      if (FONT_UNDERLINE.get(this)) {
        textAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
      }
      TextLayout textLayout = new TextLayout(text, textAttributes, frc);

      AffineTransform tx = new AffineTransform();
      tx.translate(coordinates[0].x, coordinates[0].y);
      switch (TEXT_ANCHOR.get(this)) {
        case END:
          tx.translate(-textLayout.getAdvance(), 0);
          break;
        case MIDDLE:
          tx.translate(-textLayout.getAdvance() / 2d, 0);
          break;
        case START:
          break;
      }
      tx.rotate(rotates[0]);

      /*
      if (TRANSFORM.get(this) != null) {
          tx.preConcatenate(TRANSFORM.get(this));
      }*/

      cachedTextShape = tx.createTransformedShape(textLayout.getOutline(tx));
      cachedTextShape = textLayout.getOutline(tx);
    }
    return cachedTextShape;
  }
Exemplo n.º 5
0
  public static Map<String, String> getStyles(String str) throws IOException {
    HashMap<String, String> styles = new HashMap<String, String>();
    if (str == null) return styles;

    StreamTokenizer tt = new StreamTokenizer(new StringReader(str));
    tt.resetSyntax();
    tt.wordChars('!', '9');
    tt.wordChars('<', '~');
    tt.wordChars(128 + 32, 255);
    tt.whitespaceChars(0, ' ');

    while (tt.nextToken() != StreamTokenizer.TT_EOF) {
      if (tt.ttype != ';') {
        String key, value;
        if (tt.ttype != StreamTokenizer.TT_WORD) {
          throw new IOException(
              "Key token expected in " + str + " " + Integer.toHexString(tt.ttype));
        }
        key = tt.sval;
        if (tt.nextToken() != ':') {
          throw new IOException("Colon expected after " + key + " in " + str);
        }
        if (tt.nextToken() != StreamTokenizer.TT_WORD) {
          throw new IOException(
              "Value token expected after " + key + " in " + str + " " + tt.ttype);
        }
        value = tt.sval;
        while (tt.nextToken() == StreamTokenizer.TT_WORD) {
          value += ' ' + tt.sval;
        }
        tt.pushBack();
        styles.put(key, value);
      }
    }

    return styles;
  }
 @SuppressWarnings("unchecked")
 public void restoreAttributesTo(Object restoreData) {
   attributes.clear();
   setAttributes((HashMap<AttributeKey, Object>) restoreData);
 }
 public boolean hasAttribute(AttributeKey key) {
   return attributes.containsKey(key);
 }
 /** Applies all attributes of this figure to that figure. */
 @SuppressWarnings("unchecked")
 protected void applyAttributesTo(Figure that) {
   for (Map.Entry<AttributeKey, Object> entry : attributes.entrySet()) {
     entry.getKey().basicSet(that, entry.getValue());
   }
 }