Skip to main content
summaryrefslogtreecommitdiffstats
blob: d4bb5692e3edaa04d23257bde9af698b421982d6 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*******************************************************************************
 * 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 org.eclipse.jst.pagedesigner.IHTMLConstants;
import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
import org.eclipse.jst.pagedesigner.utils.DOMUtil;
import org.w3c.dom.Element;

/**
 * @author mengbo
 */
public class VerticalAlignMeta extends LengthMeta {
	/**
	 * baseline keyword
	 */
	public static final String BASELINE = "baseline"; //$NON-NLS-1$

	/**
	 * middle keyword
	 */
	public static final String MIDDLE = "middle"; //$NON-NLS-1$

	/**
	 * sub keyword
	 */
	public static final String SUB = "sub"; //$NON-NLS-1$

	/**
	 * super keyword
	 */
	public static final String SUPER = "super"; //$NON-NLS-1$

	/**
	 * text-top keyword
	 */
	public static final String TEXT_TOP = "text-top"; //$NON-NLS-1$

	/**
	 * text-bottom keyword
	 */
	public static final String TEXT_BOTTOM = "text-bottom"; //$NON-NLS-1$

	/**
	 * top keyword
	 */
	public static final String TOP = "top"; //$NON-NLS-1$

	/**
	 * bottom keyword
	 */
	public static final String BOTTOM = "bottom"; //$NON-NLS-1$

	/**
	 * center keyword
	 */
	public static final String CENTER = "center"; //$NON-NLS-1$

	/**
	 * default vertical align
	 */
	public static final String DEFAULT_VERTICAL_ALIGN = BASELINE;

	private static final String[] KEYWORDS = new String[] { BASELINE, MIDDLE,
			SUB, SUPER, TEXT_TOP, TEXT_BOTTOM, TOP, BOTTOM };

	private static final String[] htmlAttributes = new String[] { IHTMLConstants.ATTR_VALIGN };

	/**
	 * Default constructor
	 */
	public VerticalAlignMeta() {
		super(true, DEFAULT_VERTICAL_ALIGN);
	}

	/**
	 * @param inherit
	 * @param initvalue
	 */
	public VerticalAlignMeta(boolean inherit, Object initvalue) {
		super(inherit, initvalue);
	}

	/*
	 * (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.CSSPropertyMeta#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) {
		for (int i = 0; i < htmlAttributes.length; i++) {
			String align = DOMUtil.getAttributeIgnoreCase(element,
					htmlAttributes[i]);
			if (TOP.equalsIgnoreCase(align)) {
				return TOP;
			}
			if (MIDDLE.equalsIgnoreCase(align)) {
				return MIDDLE;
			}
			if (BOTTOM.equalsIgnoreCase(align)) {
				return BOTTOM;
			}
			if (BASELINE.equalsIgnoreCase(align)) {
				return BASELINE;
			}
			if (CENTER.equalsIgnoreCase(align)) {
				return MIDDLE;
			}
		}
		return null;
	}

}

Back to the top