Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 098555a4378ac05f4f2485dc5ea910d8c39cb0bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.css2.property;

import java.util.Arrays;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.jst.pagedesigner.IHTMLConstants;
import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
import org.eclipse.jst.pagedesigner.css2.color.CSSColorManager;
import org.eclipse.jst.pagedesigner.utils.DOMUtil;
import org.eclipse.swt.graphics.Color;
import org.w3c.dom.Element;
import org.w3c.dom.css.CSSValue;

/**
 * "color" will be in this type
 * 
 * @author mengbo
 */
public class ColorPropertyMeta extends CSSPropertyMeta {
	private static final Object DEFAULT_COLOR = ColorConstants.black;

	private static final String[] KEYWORDS = new String[] {};

	private final static String[] NOTSUPPORT_TAG = { IHTMLConstants.TAG_H1,
			IHTMLConstants.TAG_H2, IHTMLConstants.TAG_H3,
			IHTMLConstants.TAG_H4, IHTMLConstants.TAG_H5, IHTMLConstants.TAG_H6 };

	public Color getDefaultColor() {
		return null;
	}

	/**
	 * @param inherit
	 * @param initvalue
	 */
	public ColorPropertyMeta() {
		super(true, DEFAULT_COLOR);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateCSSValueResult(org.w3c.dom.css.CSSValue,
	 *      java.lang.String,
	 *      org.eclipse.jst.pagedesigner.css2.property.AbstractStyle)
	 */
	public Object calculateCSSValueResult(CSSValue value, String propertyName,
			ICSSStyle style) {

		String text = value.getCssText();
		Object result = CSSColorManager.getInstance().getColor(text);
		if (result != null) {
			return result;
		} else {
			return this.getInitialValue(propertyName, style);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.property.CSSPropertyMeta#getKeywordValues()
	 */
	protected String[] getKeywordValues() {
		return KEYWORDS;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyMeta#calculateHTMLAttributeOverride(org.w3c.dom.Element,
	 *      java.lang.String, java.lang.String,
	 *      org.eclipse.jst.pagedesigner.css2.ICSSStyle)
	 */
	public Object calculateHTMLAttributeOverride(Element element,
			String htmltag, String propertyName, ICSSStyle style) {
		if (Arrays.asList(NOTSUPPORT_TAG).contains(htmltag.toLowerCase())) {
			return null;
		}
		Object result;
		String colorAttr = null;
		// There are some conditions need to be dealt with hyperlink and text
		// properties.
		if (ICSSPropertyID.ATTR_COLOR.equalsIgnoreCase(propertyName)) {
			colorAttr = DOMUtil.getAttributeIgnoreCase(element,
					ICSSPropertyID.ATTR_COLOR);
			if (colorAttr == null
					&& element.getLocalName().equalsIgnoreCase(
							IHTMLConstants.TAG_BODY)) {
				colorAttr = DOMUtil.getAttributeIgnoreCase(element,
						ICSSPropertyID.ATTR_TEXT);
			}
		}
		if (colorAttr != null) {
			colorAttr = colorAttr.trim();
			result = CSSColorManager.getInstance().getColor(colorAttr);
			return result;
		}
		return null;
	}
}

Back to the top