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.AbstractValueFactory;
045: import org.apache.batik.css.engine.value.ShorthandManager;
046: import org.w3c.css.sac.LexicalUnit;
047: import org.w3c.dom.DOMException;
048:
049: /**
050: * Represents the "border-style" shorthand property for setting
051: * border-left-style, border-right-style, border-top-style and
052: * border-bottom-style.
053: *
054: * @author Tor Norbye
055: */
056: public class BorderStyleShorthandManager extends AbstractValueFactory
057: implements ShorthandManager {
058:
059: public String getPropertyName() {
060: return CssConstants.CSS_BORDER_STYLE_PROPERTY;
061: }
062:
063: /** Set the values. This is a bit complicated since the number
064: * of "arguments" in the value determines how we distribute
065: * the children.
066: */
067: public void setValues(CSSEngine eng,
068: ShorthandManager.PropertyHandler ph, LexicalUnit lu,
069: boolean imp) throws DOMException {
070:
071: LexicalUnit first = lu;
072: LexicalUnit second = first.getNextLexicalUnit();
073: if (second == null) {
074: // Only one value specified
075: // 1 value: applies to all four sides
076: ph.property(CssConstants.CSS_BORDER_LEFT_STYLE_PROPERTY,
077: first, imp);
078: ph.property(CssConstants.CSS_BORDER_RIGHT_STYLE_PROPERTY,
079: first, imp);
080: ph.property(CssConstants.CSS_BORDER_TOP_STYLE_PROPERTY,
081: first, imp);
082: ph.property(CssConstants.CSS_BORDER_BOTTOM_STYLE_PROPERTY,
083: first, imp);
084: } else {
085: LexicalUnit third = second.getNextLexicalUnit();
086: if (third == null) {
087: // Only two values specified
088:
089: // 2 values: (1) top & bottom (2) left & right
090: ph.property(CssConstants.CSS_BORDER_TOP_STYLE_PROPERTY,
091: first, imp);
092: ph.property(
093: CssConstants.CSS_BORDER_BOTTOM_STYLE_PROPERTY,
094: first, imp);
095: ph.property(
096: CssConstants.CSS_BORDER_LEFT_STYLE_PROPERTY,
097: second, imp);
098: ph.property(
099: CssConstants.CSS_BORDER_RIGHT_STYLE_PROPERTY,
100: second, imp);
101: } else {
102: LexicalUnit fourth = third.getNextLexicalUnit();
103: if (fourth == null) {
104: // Only three values specified
105:
106: // 3 values: (1) top, (2) left & right, (3) bottom
107: ph.property(
108: CssConstants.CSS_BORDER_TOP_STYLE_PROPERTY,
109: first, imp);
110: ph
111: .property(
112: CssConstants.CSS_BORDER_LEFT_STYLE_PROPERTY,
113: second, imp);
114: ph
115: .property(
116: CssConstants.CSS_BORDER_RIGHT_STYLE_PROPERTY,
117: second, imp);
118: ph
119: .property(
120: CssConstants.CSS_BORDER_BOTTOM_STYLE_PROPERTY,
121: third, imp);
122: } else {
123: // 4 values: (1) top, (2) right, (3) bottom, (4) left
124: ph.property(
125: CssConstants.CSS_BORDER_TOP_STYLE_PROPERTY,
126: first, imp);
127: ph
128: .property(
129: CssConstants.CSS_BORDER_RIGHT_STYLE_PROPERTY,
130: second, imp);
131: ph
132: .property(
133: CssConstants.CSS_BORDER_BOTTOM_STYLE_PROPERTY,
134: third, imp);
135: ph
136: .property(
137: CssConstants.CSS_BORDER_LEFT_STYLE_PROPERTY,
138: fourth, imp);
139: }
140: }
141: }
142: }
143: }
|