KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > value > svg12 > MarginShorthandManager


1 /*
2
3    Copyright 2002-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.css.engine.value.svg12;
19
20 import org.apache.batik.css.engine.CSSEngine;
21 import org.apache.batik.css.engine.value.AbstractValueFactory;
22 import org.apache.batik.css.engine.value.ShorthandManager;
23 import org.apache.batik.css.engine.value.ValueManager;
24 import org.apache.batik.util.SVG12CSSConstants;
25 import org.w3c.css.sac.LexicalUnit;
26 import org.w3c.dom.DOMException JavaDoc;
27
28 /**
29  * This class represents an object which provide support for the
30  * 'margin' shorthand property.
31  *
32  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
33  * @version $Id: MarginShorthandManager.java,v 1.3 2005/03/27 08:58:31 cam Exp $
34  */

35 public class MarginShorthandManager
36     extends AbstractValueFactory
37     implements ShorthandManager {
38
39     public MarginShorthandManager() { }
40     
41     /**
42      * Implements {@link ValueManager#getPropertyName()}.
43      */

44     public String JavaDoc getPropertyName() {
45     return SVG12CSSConstants.CSS_MARGIN_PROPERTY;
46     }
47     
48     /**
49      * Implements {@link ShorthandManager#setValues(CSSEngine,ShorthandManager.PropertyHandler,LexicalUnit,boolean)}.
50      */

51     public void setValues(CSSEngine eng,
52                           ShorthandManager.PropertyHandler ph,
53                           LexicalUnit lu,
54                           boolean imp)
55         throws DOMException JavaDoc {
56         if (lu.getLexicalUnitType() == LexicalUnit.SAC_INHERIT)
57             return;
58
59         LexicalUnit []lus = new LexicalUnit[4];
60         int cnt=0;
61         while (lu != null) {
62             if (cnt == 4)
63                 throw createInvalidLexicalUnitDOMException
64                     (lu.getLexicalUnitType());
65             lus[cnt++] = lu;
66             lu = lu.getNextLexicalUnit();
67         }
68         switch (cnt) {
69         case 1: lus[3] = lus[2] = lus[1] = lus[0]; break;
70         case 2: lus[2] = lus[0]; lus[3] = lus[1]; break;
71         case 3: lus[3] = lus[1]; break;
72         default:
73         }
74
75         ph.property(SVG12CSSConstants.CSS_MARGIN_TOP_PROPERTY, lus[0], imp);
76         ph.property(SVG12CSSConstants.CSS_MARGIN_RIGHT_PROPERTY, lus[1], imp);
77         ph.property(SVG12CSSConstants.CSS_MARGIN_BOTTOM_PROPERTY, lus[2], imp);
78         ph.property(SVG12CSSConstants.CSS_MARGIN_LEFT_PROPERTY, lus[3], imp);
79     }
80 }
81
Popular Tags