001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.css.engine.value.svg12;
020:
021: import org.apache.batik.css.engine.CSSEngine;
022: import org.apache.batik.css.engine.value.AbstractValueFactory;
023: import org.apache.batik.css.engine.value.ShorthandManager;
024: import org.apache.batik.css.engine.value.ValueManager;
025: import org.apache.batik.util.SVG12CSSConstants;
026: import org.w3c.css.sac.LexicalUnit;
027: import org.w3c.dom.DOMException;
028:
029: /**
030: * This class represents an object which provide support for the
031: * 'margin' shorthand property.
032: *
033: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
034: * @version $Id: MarginShorthandManager.java 475685 2006-11-16 11:16:05Z cam $
035: */
036: public class MarginShorthandManager extends AbstractValueFactory
037: implements ShorthandManager {
038:
039: public MarginShorthandManager() {
040: }
041:
042: /**
043: * Implements {@link ValueManager#getPropertyName()}.
044: */
045: public String getPropertyName() {
046: return SVG12CSSConstants.CSS_MARGIN_PROPERTY;
047: }
048:
049: /**
050: * Implements {@link ShorthandManager#isAnimatableProperty()}.
051: */
052: public boolean isAnimatableProperty() {
053: return true;
054: }
055:
056: /**
057: * Implements {@link ShorthandManager#isAdditiveProperty()}.
058: */
059: public boolean isAdditiveProperty() {
060: return false;
061: }
062:
063: /**
064: * Implements {@link ShorthandManager#setValues(CSSEngine,ShorthandManager.PropertyHandler,LexicalUnit,boolean)}.
065: */
066: public void setValues(CSSEngine eng,
067: ShorthandManager.PropertyHandler ph, LexicalUnit lu,
068: boolean imp) throws DOMException {
069: if (lu.getLexicalUnitType() == LexicalUnit.SAC_INHERIT)
070: return;
071:
072: LexicalUnit[] lus = new LexicalUnit[4];
073: int cnt = 0;
074: while (lu != null) {
075: if (cnt == 4)
076: throw createInvalidLexicalUnitDOMException(lu
077: .getLexicalUnitType());
078: lus[cnt++] = lu;
079: lu = lu.getNextLexicalUnit();
080: }
081: switch (cnt) {
082: case 1:
083: lus[3] = lus[2] = lus[1] = lus[0];
084: break;
085: case 2:
086: lus[2] = lus[0];
087: lus[3] = lus[1];
088: break;
089: case 3:
090: lus[3] = lus[1];
091: break;
092: default:
093: }
094:
095: ph.property(SVG12CSSConstants.CSS_MARGIN_TOP_PROPERTY, lus[0],
096: imp);
097: ph.property(SVG12CSSConstants.CSS_MARGIN_RIGHT_PROPERTY,
098: lus[1], imp);
099: ph.property(SVG12CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY,
100: lus[2], imp);
101: ph.property(SVG12CSSConstants.CSS_MARGIN_LEFT_PROPERTY, lus[3],
102: imp);
103: }
104: }
|