Initialize
[sdk/ide/product.git] / org.eclipse.jst.pagedesigner / src / org / eclipse / jst / pagedesigner / css2 / property / ColorPropertyMeta.java
1 /*******************************************************************************\r
2  * Copyright (c) 2006 Sybase, Inc. and others.\r
3  *\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
8  *\r
9  * Contributors:\r
10  *     Sybase, Inc. - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.eclipse.jst.pagedesigner.css2.property;\r
13 \r
14 import java.util.Arrays;\r
15 \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
23 \r
24 /**\r
25  * "color" will be in this type\r
26  * \r
27  * @author mengbo\r
28  */\r
29 public class ColorPropertyMeta extends CSSPropertyMeta {\r
30         private static final Object DEFAULT_COLOR = ColorConstants.black;\r
31 \r
32         private static final String[] KEYWORDS = new String[] {};\r
33 \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
37 \r
38         /**\r
39          */\r
40         public ColorPropertyMeta() {\r
41                 super(true, DEFAULT_COLOR);\r
42         }\r
43 \r
44         /*\r
45          * (non-Javadoc)\r
46          * \r
47          * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue,\r
48          *      java.lang.String,\r
49          *      org.eclipse.jst.pagedesigner.css2.property.AbstractStyle)\r
50          */\r
51         public Object calculateCSSValueResult(CSSValue value, String propertyName,\r
52                         ICSSStyle style) {\r
53 \r
54                 String text = value.getCssText();\r
55                 Object result = CSSColorManager.getInstance().getColor(text);\r
56                 if (result != null) {\r
57                         return result;\r
58                 }\r
59         return this.getInitialValue(propertyName, style);\r
60         }\r
61 \r
62         /*\r
63          * (non-Javadoc)\r
64          * \r
65          * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues()\r
66          */\r
67         protected String[] getKeywordValues() {\r
68                 return KEYWORDS;\r
69         }\r
70 \r
71         /*\r
72          * (non-Javadoc)\r
73          * \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
77          */\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
81                         return null;\r
82                 }\r
83                 Object result;\r
84                 String colorAttr = null;\r
85                 // There are some conditions need to be dealt with hyperlink and text\r
86                 // properties.\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
95                         }\r
96                 }\r
97                 if (colorAttr != null) {\r
98                         colorAttr = colorAttr.trim();\r
99                         result = CSSColorManager.getInstance().getColor(colorAttr);\r
100                         return result;\r
101                 }\r
102                 return null;\r
103         }\r
104 }\r