001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.designer.cssengine;
042:
043: import org.apache.batik.css.engine.CSSEngine;
044: import org.apache.batik.css.engine.value.StringMap;
045: import org.apache.batik.css.engine.value.Value;
046: import org.w3c.css.sac.LexicalUnit;
047: import org.w3c.dom.DOMException;
048: import org.w3c.dom.css.CSSPrimitiveValue;
049: import org.apache.batik.css.engine.value.IdentifierProvider;
050:
051: /**
052: * This class provides a manager for the "vertical-align" CSS property
053: *
054: * @todo Fix percentage handling. Percentages are supposed to be
055: * relative to the line-height property's value for this element.
056: *
057: * @author Tor Norbye
058: */
059: public class VerticalAlignmentManager extends NonautoableLengthManager
060: implements IdentifierProvider {
061:
062: /*
063: // If percentage: from http://www.westciv.com/style_master/academy/css_tutorial/properties/text_layout.html
064: "Percentage values
065:
066: Specifying vertical-align as a percentage value gives rise to a quite complicated situation. The baseline of the element is raised above the baseline of its parent element. By how much? By that percentage of the element's line-height.
067:
068: For example, {vertical-align: 20%} with an element that has a line-height of 10pt, the baseline of the element will be raised 2 points above the baseline of its parent element.
069:
070: You can lower the baseline of an element below the baseline of its parent by using negative percentage values."
071: */
072:
073: protected final static StringMap values = new StringMap();
074: static {
075: values.put(CssConstants.CSS_BASELINE_VALUE,
076: CssValueConstants.BASELINE_VALUE);
077: values.put(CssConstants.CSS_SUB_VALUE,
078: CssValueConstants.SUB_VALUE);
079: values.put(CssConstants.CSS_SUPER_VALUE,
080: CssValueConstants.SUPER_VALUE);
081: values.put(CssConstants.CSS_TOP_VALUE,
082: CssValueConstants.TOP_VALUE);
083: values.put(CssConstants.CSS_TEXT_TOP_VALUE,
084: CssValueConstants.TEXT_TOP_VALUE);
085: values.put(CssConstants.CSS_MIDDLE_VALUE,
086: CssValueConstants.MIDDLE_VALUE);
087: values.put(CssConstants.CSS_BOTTOM_VALUE,
088: CssValueConstants.BOTTOM_VALUE);
089: values.put(CssConstants.CSS_TEXT_BOTTOM_VALUE,
090: CssValueConstants.TEXT_BOTTOM_VALUE);
091: }
092:
093: public boolean isInheritedProperty() {
094: return false;
095: }
096:
097: public String getPropertyName() {
098: return CssConstants.CSS_VERTICAL_ALIGN_PROPERTY;
099: }
100:
101: public Value getDefaultValue() {
102: return CssValueConstants.BASELINE_VALUE;
103: }
104:
105: public Value createValue(LexicalUnit lu, CSSEngine engine)
106: throws DOMException {
107: switch (lu.getLexicalUnitType()) {
108: case LexicalUnit.SAC_INHERIT:
109: return CssValueConstants.INHERIT_VALUE;
110:
111: case LexicalUnit.SAC_IDENT:
112: String s = lu.getStringValue().toLowerCase().intern();
113: Object v = values.get(s);
114: if (v == null) {
115: throw createInvalidIdentifierDOMException(s, engine);
116: }
117: return (Value) v;
118: }
119: return super .createValue(lu, engine);
120: }
121:
122: public Value createStringValue(short type, String value,
123: CSSEngine engine) throws DOMException {
124: if (type != CSSPrimitiveValue.CSS_IDENT) {
125: throw createInvalidStringTypeDOMException(type, engine);
126: }
127: Object v = values.get(value.toLowerCase().intern());
128: if (v == null) {
129: throw createInvalidIdentifierDOMException(value, engine);
130: }
131: return (Value) v;
132: }
133:
134: protected int getOrientation() {
135: return VERTICAL_ORIENTATION;
136: }
137:
138: public StringMap getIdentifierMap() {
139: return values;
140: }
141: }
|