KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2004 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
19 package org.apache.batik.css.engine.value.svg12;
20
21 import org.apache.batik.css.engine.CSSEngine;
22 import org.apache.batik.css.engine.CSSStylableElement;
23 import org.apache.batik.css.engine.StyleMap;
24 import org.apache.batik.css.engine.value.LengthManager;
25 import org.apache.batik.css.engine.value.FloatValue;
26 import org.apache.batik.css.engine.value.svg12.SVG12ValueConstants;
27 import org.apache.batik.css.engine.value.Value;
28 import org.apache.batik.css.engine.value.ValueManager;
29 import org.apache.batik.util.SVG12CSSConstants;
30
31 import org.w3c.css.sac.LexicalUnit;
32 import org.w3c.dom.css.CSSPrimitiveValue;
33 import org.w3c.dom.css.CSSValue;
34 import org.w3c.dom.DOMException JavaDoc;
35
36 /**
37  * This class provides a factory for the 'margin-*' properties values.
38  *
39  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
40  * @version $Id: LineHeightManager.java,v 1.2 2005/03/27 08:58:31 cam Exp $
41  */

42 public class LineHeightManager extends LengthManager {
43
44     public LineHeightManager() { }
45     
46     /**
47      * Implements {@link ValueManager#isInheritedProperty()}.
48      */

49     public boolean isInheritedProperty() {
50     return true;
51     }
52
53     /**
54      * Implements {@link ValueManager#getPropertyName()}.
55      */

56     public String JavaDoc getPropertyName() {
57     return SVG12CSSConstants.CSS_LINE_HEIGHT_PROPERTY;
58     }
59     
60     /**
61      * Implements {@link ValueManager#getDefaultValue()}.
62      */

63     public Value getDefaultValue() {
64         return SVG12ValueConstants.NORMAL_VALUE;
65     }
66
67     /**
68      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
69      */

70     public Value createValue(LexicalUnit lu, CSSEngine engine)
71         throws DOMException JavaDoc {
72
73         switch (lu.getLexicalUnitType()) {
74         case LexicalUnit.SAC_INHERIT:
75             return SVG12ValueConstants.INHERIT_VALUE;
76         case LexicalUnit.SAC_IDENT: {
77             String JavaDoc s = lu.getStringValue().toLowerCase();
78             if (SVG12CSSConstants.CSS_NORMAL_VALUE.equals(s))
79                 return SVG12ValueConstants.NORMAL_VALUE;
80             throw createInvalidIdentifierDOMException(lu.getStringValue());
81         }
82         default:
83             return super.createValue(lu, engine);
84         }
85     }
86
87
88     /**
89      * Indicates the orientation of the property associated with
90      * this manager.
91      */

92     protected int getOrientation() {
93         // Not really used.
94
return VERTICAL_ORIENTATION;
95     }
96
97
98     /**
99      * Implements {@link
100      * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
101      */

102     public Value computeValue(CSSStylableElement elt,
103                               String JavaDoc pseudo,
104                               CSSEngine engine,
105                               int idx,
106                               StyleMap sm,
107                               Value value) {
108         if (value.getCssValueType() != CSSValue.CSS_PRIMITIVE_VALUE)
109             return value;
110
111         switch (value.getPrimitiveType()) {
112         case CSSPrimitiveValue.CSS_NUMBER:
113             return new LineHeightValue(CSSPrimitiveValue.CSS_NUMBER,
114                                        value.getFloatValue(), true);
115
116         case CSSPrimitiveValue.CSS_PERCENTAGE: {
117             float v = value.getFloatValue();
118             int fsidx = engine.getFontSizeIndex();
119             float fs = engine.getComputedStyle
120                 (elt, pseudo, fsidx).getFloatValue();
121             return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, v * fs*.01f);
122         }
123
124         default:
125             return super.computeValue(elt, pseudo, engine, idx, sm, value);
126         }
127     }
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
Popular Tags