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-x" shorthand property (where x
052: * can be top, left, right or bottom) for setting
053: * the width, color and style for a particular border side.
054: *
055: * @author Tor Norbye
056: */
057: public class BorderSideShorthandManager extends AbstractValueFactory
058: implements ShorthandManager {
059: private String property;
060: private String width;
061: private String style;
062: private String color;
063:
064: public BorderSideShorthandManager(String property, String width,
065: String style, String color) {
066: this .property = property;
067: this .width = width;
068: this .style = style;
069: this .color = color;
070: }
071:
072: public String getPropertyName() {
073: return property;
074: }
075:
076: public void setValues(CSSEngine eng,
077: ShorthandManager.PropertyHandler ph, LexicalUnit lu,
078: boolean imp) throws DOMException {
079:
080: for (; lu != null; lu = lu.getNextLexicalUnit()) {
081: switch (lu.getLexicalUnitType()) {
082: /* Inherit isn't allowed is it?
083: case LexicalUnit.SAC_INHERIT:
084: return ValueConstants.INHERIT_VALUE;
085: */
086: case LexicalUnit.SAC_RGBCOLOR:
087: ph.property(color, lu, imp);
088: break;
089: case LexicalUnit.SAC_EM:
090: case LexicalUnit.SAC_EX:
091: case LexicalUnit.SAC_PIXEL:
092: case LexicalUnit.SAC_CENTIMETER:
093: case LexicalUnit.SAC_MILLIMETER:
094: case LexicalUnit.SAC_INCH:
095: case LexicalUnit.SAC_POINT:
096: case LexicalUnit.SAC_PICA:
097: case LexicalUnit.SAC_INTEGER:
098: //case LexicalUnit.SAC_PERCENTAGE: N/A
099: case LexicalUnit.SAC_REAL:
100: ph.property(width, lu, imp);
101: break;
102: case LexicalUnit.SAC_IDENT:
103: case LexicalUnit.SAC_STRING_VALUE:
104: String s = lu.getStringValue().toLowerCase().intern();
105: if (BorderWidthManager.values.get(s) != null) {
106: ph.property(width, lu, imp);
107: } else if (BorderStyleManager.values.get(s) != null) {
108: ph.property(style, lu, imp);
109: } else if (ColorManager.values.get(s) != null) {
110: ph.property(color, lu, imp);
111: }
112: break;
113: }
114: }
115: }
116: }
|