1 /*******************************************************************************
\r
2 * Copyright (c) 2006 Sybase, Inc. and others.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * Sybase, Inc. - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.eclipse.jst.pagedesigner.css2.property;
\r
14 import java.util.Arrays;
\r
16 import org.eclipse.draw2d.ColorConstants;
\r
17 import org.eclipse.jst.pagedesigner.IHTMLConstants;
\r
18 import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
\r
19 import org.eclipse.jst.pagedesigner.css2.color.CSSColorManager;
\r
20 import org.eclipse.jst.pagedesigner.utils.DOMUtil;
\r
21 import org.w3c.dom.Element;
\r
22 import org.w3c.dom.css.CSSValue;
\r
25 * "color" will be in this type
\r
29 public class ColorPropertyMeta extends CSSPropertyMeta {
\r
30 private static final Object DEFAULT_COLOR = ColorConstants.black;
\r
32 private static final String[] KEYWORDS = new String[] {};
\r
34 private final static String[] NOTSUPPORT_TAG = { IHTMLConstants.TAG_H1,
\r
35 IHTMLConstants.TAG_H2, IHTMLConstants.TAG_H3,
\r
36 IHTMLConstants.TAG_H4, IHTMLConstants.TAG_H5, IHTMLConstants.TAG_H6 };
\r
40 public ColorPropertyMeta() {
\r
41 super(true, DEFAULT_COLOR);
\r
47 * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue,
\r
49 * org.eclipse.jst.pagedesigner.css2.property.AbstractStyle)
\r
51 public Object calculateCSSValueResult(CSSValue value, String propertyName,
\r
54 String text = value.getCssText();
\r
55 Object result = CSSColorManager.getInstance().getColor(text);
\r
56 if (result != null) {
\r
59 return this.getInitialValue(propertyName, style);
\r
65 * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues()
\r
67 protected String[] getKeywordValues() {
\r
74 * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element,
\r
75 * java.lang.String, java.lang.String,
\r
76 * org.eclipse.jst.pagedesigner.css2.ICSSStyle)
\r
78 public Object calculateHTMLAttributeOverride(Element element,
\r
79 String htmltag, String propertyName, ICSSStyle style) {
\r
80 if (Arrays.asList(NOTSUPPORT_TAG).contains(htmltag.toLowerCase())) {
\r
84 String colorAttr = null;
\r
85 // There are some conditions need to be dealt with hyperlink and text
\r
87 if (ICSSPropertyID.ATTR_COLOR.equalsIgnoreCase(propertyName)) {
\r
88 colorAttr = DOMUtil.getAttributeIgnoreCase(element,
\r
89 ICSSPropertyID.ATTR_COLOR);
\r
90 if (colorAttr == null
\r
91 && element.getLocalName().equalsIgnoreCase(
\r
92 IHTMLConstants.TAG_BODY)) {
\r
93 colorAttr = DOMUtil.getAttributeIgnoreCase(element,
\r
94 ICSSPropertyID.ATTR_TEXT);
\r
97 if (colorAttr != null) {
\r
98 colorAttr = colorAttr.trim();
\r
99 result = CSSColorManager.getInstance().getColor(colorAttr);
\r