Esempio n. 1
0
  public static Color getColor(String value) {
    value = value.trim().toLowerCase();

    if (value.equals("none")) {
      return null;
    } else if (value.equals("currentColor")) {
      // indicates that painting shall be done using the color specified by the 'color' property.
      return CURRENT_COLOR;
    } else if (value.equals("inherit")) {
      // Each property may also have a specified value of 'inherit', which
      // means that, for a given element, the property takes the same
      // computed value as the property for the element's parent
      return INHERIT_COLOR;
    } else if (SVG_COLORS.containsKey(value)) {
      return SVG_COLORS.get(value);
    } else if (value.startsWith("#") && value.length() == 7) {
      return new Color(Integer.decode(value));
    } else if (value.startsWith("#") && value.length() == 4) {
      // Three digits hex value
      int th = Integer.decode(value);
      return new Color(
          (th & 0xf)
              | ((th & 0xf) << 4)
              | ((th & 0xf0) << 4)
              | ((th & 0xf0) << 8)
              | ((th & 0xf00) << 8)
              | ((th & 0xf00) << 12));
    } else if (value.startsWith("rgb")) {
      StringTokenizer tt = new StringTokenizer(value, "() ,");
      tt.nextToken();
      Color c =
          new Color(
              Integer.decode(tt.nextToken()),
              Integer.decode(tt.nextToken()),
              Integer.decode(tt.nextToken()));
      return c;
    } else {
      return null;
    }
  }
 @SuppressWarnings("unchecked")
 public void setAttributes(Map<AttributeKey, Object> map) {
   for (Map.Entry<AttributeKey, Object> entry : map.entrySet()) {
     setAttribute(entry.getKey(), entry.getValue());
   }
 }