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.apache.batik.css.engine.value.svg.ColorManager;
047: import org.w3c.css.sac.LexicalUnit;
048: import org.w3c.dom.DOMException;
049:
050: /**
051: * Represents the "border" shorthand property for setting
052: * the same width, color, and style for all four borders of a box.
053: *
054: * @author Tor Norbye
055: */
056: public class BorderShorthandManager extends AbstractValueFactory
057: implements ShorthandManager {
058:
059: public String getPropertyName() {
060: return CssConstants.CSS_BORDER_PROPERTY;
061: }
062:
063: public void setValues(CSSEngine eng,
064: ShorthandManager.PropertyHandler ph, LexicalUnit lu,
065: boolean imp) throws DOMException {
066:
067: for (; lu != null; lu = lu.getNextLexicalUnit()) {
068: String first = null;
069: String second = null;
070: String third = null;
071: String fourth = null;
072: switch (lu.getLexicalUnitType()) {
073: /* Inherit isn't allowed is it?
074: case LexicalUnit.SAC_INHERIT:
075: return ValueConstants.INHERIT_VALUE;
076: */
077: case LexicalUnit.SAC_RGBCOLOR:
078: first = CssConstants.CSS_BORDER_TOP_COLOR_PROPERTY;
079: second = CssConstants.CSS_BORDER_LEFT_COLOR_PROPERTY;
080: third = CssConstants.CSS_BORDER_BOTTOM_COLOR_PROPERTY;
081: fourth = CssConstants.CSS_BORDER_RIGHT_COLOR_PROPERTY;
082: break;
083: case LexicalUnit.SAC_EM:
084: case LexicalUnit.SAC_EX:
085: case LexicalUnit.SAC_PIXEL:
086: case LexicalUnit.SAC_CENTIMETER:
087: case LexicalUnit.SAC_MILLIMETER:
088: case LexicalUnit.SAC_INCH:
089: case LexicalUnit.SAC_POINT:
090: case LexicalUnit.SAC_PICA:
091: case LexicalUnit.SAC_INTEGER:
092: //case LexicalUnit.SAC_PERCENTAGE: N/A
093: case LexicalUnit.SAC_REAL:
094: first = CssConstants.CSS_BORDER_TOP_WIDTH_PROPERTY;
095: second = CssConstants.CSS_BORDER_LEFT_WIDTH_PROPERTY;
096: third = CssConstants.CSS_BORDER_BOTTOM_WIDTH_PROPERTY;
097: fourth = CssConstants.CSS_BORDER_RIGHT_WIDTH_PROPERTY;
098: break;
099: case LexicalUnit.SAC_IDENT:
100: case LexicalUnit.SAC_STRING_VALUE:
101: String s = lu.getStringValue().toLowerCase().intern();
102: if (BorderWidthManager.values.get(s) != null) {
103: first = CssConstants.CSS_BORDER_TOP_WIDTH_PROPERTY;
104: second = CssConstants.CSS_BORDER_LEFT_WIDTH_PROPERTY;
105: third = CssConstants.CSS_BORDER_BOTTOM_WIDTH_PROPERTY;
106: fourth = CssConstants.CSS_BORDER_RIGHT_WIDTH_PROPERTY;
107: } else if (BorderStyleManager.values.get(s) != null) {
108: first = CssConstants.CSS_BORDER_TOP_STYLE_PROPERTY;
109: second = CssConstants.CSS_BORDER_LEFT_STYLE_PROPERTY;
110: third = CssConstants.CSS_BORDER_BOTTOM_STYLE_PROPERTY;
111: fourth = CssConstants.CSS_BORDER_RIGHT_STYLE_PROPERTY;
112: } else if (ColorManager.values.get(s) != null) {
113: first = CssConstants.CSS_BORDER_TOP_COLOR_PROPERTY;
114: second = CssConstants.CSS_BORDER_LEFT_COLOR_PROPERTY;
115: third = CssConstants.CSS_BORDER_BOTTOM_COLOR_PROPERTY;
116: fourth = CssConstants.CSS_BORDER_RIGHT_COLOR_PROPERTY;
117: }
118: break;
119: }
120: if (first != null) {
121: ph.property(first, lu, imp);
122: ph.property(second, lu, imp);
123: ph.property(third, lu, imp);
124: ph.property(fourth, lu, imp);
125: }
126: }
127: }
128: }
|