KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > value > css2 > FontStretchManager


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.css2;
19
20 import org.apache.batik.css.engine.CSSEngine;
21 import org.apache.batik.css.engine.CSSStylableElement;
22 import org.apache.batik.css.engine.StyleMap;
23 import org.apache.batik.css.engine.value.IdentifierManager;
24 import org.apache.batik.css.engine.value.StringMap;
25 import org.apache.batik.css.engine.value.Value;
26 import org.apache.batik.css.engine.value.ValueConstants;
27 import org.apache.batik.css.engine.value.ValueManager;
28 import org.apache.batik.util.CSSConstants;
29
30 /**
31  * This class provides a manager for the 'font-stretch' property values.
32  *
33  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
34  * @version $Id: FontStretchManager.java,v 1.8 2005/03/27 08:58:31 cam Exp $
35  */

36 public class FontStretchManager extends IdentifierManager {
37     
38     /**
39      * The identifier values.
40      */

41     protected final static StringMap values = new StringMap();
42     static {
43     values.put(CSSConstants.CSS_ALL_VALUE,
44                    ValueConstants.ALL_VALUE);
45     values.put(CSSConstants.CSS_CONDENSED_VALUE,
46                    ValueConstants.CONDENSED_VALUE);
47     values.put(CSSConstants.CSS_EXPANDED_VALUE,
48                    ValueConstants.EXPANDED_VALUE);
49     values.put(CSSConstants.CSS_EXTRA_CONDENSED_VALUE,
50                    ValueConstants.EXTRA_CONDENSED_VALUE);
51     values.put(CSSConstants.CSS_EXTRA_EXPANDED_VALUE,
52                    ValueConstants.EXTRA_EXPANDED_VALUE);
53     values.put(CSSConstants.CSS_NARROWER_VALUE,
54                    ValueConstants.NARROWER_VALUE);
55     values.put(CSSConstants.CSS_NORMAL_VALUE,
56                    ValueConstants.NORMAL_VALUE);
57     values.put(CSSConstants.CSS_SEMI_CONDENSED_VALUE,
58                    ValueConstants.SEMI_CONDENSED_VALUE);
59     values.put(CSSConstants.CSS_SEMI_EXPANDED_VALUE,
60                    ValueConstants.SEMI_EXPANDED_VALUE);
61     values.put(CSSConstants.CSS_ULTRA_CONDENSED_VALUE,
62                    ValueConstants.ULTRA_CONDENSED_VALUE);
63     values.put(CSSConstants.CSS_ULTRA_EXPANDED_VALUE,
64                    ValueConstants.ULTRA_EXPANDED_VALUE);
65     values.put(CSSConstants.CSS_WIDER_VALUE,
66                    ValueConstants.WIDER_VALUE);
67     }
68
69     /**
70      * Implements {@link
71      * org.apache.batik.css.engine.value.ValueManager#isInheritedProperty()}.
72      */

73     public boolean isInheritedProperty() {
74     return true;
75     }
76
77     /**
78      * Implements {@link
79      * org.apache.batik.css.engine.value.ValueManager#getPropertyName()}.
80      */

81     public String JavaDoc getPropertyName() {
82     return CSSConstants.CSS_FONT_STRETCH_PROPERTY;
83     }
84     
85     /**
86      * Implements {@link
87      * org.apache.batik.css.engine.value.ValueManager#getDefaultValue()}.
88      */

89     public Value getDefaultValue() {
90         return ValueConstants.NORMAL_VALUE;
91     }
92
93     /**
94      * Implements {@link
95      * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
96      */

97     public Value computeValue(CSSStylableElement elt,
98                               String JavaDoc pseudo,
99                               CSSEngine engine,
100                               int idx,
101                               StyleMap sm,
102                               Value value) {
103         if (value == ValueConstants.NARROWER_VALUE) {
104             sm.putParentRelative(idx, true);
105
106             CSSStylableElement p = CSSEngine.getParentCSSStylableElement(elt);
107             if (p == null) {
108                 return ValueConstants.SEMI_CONDENSED_VALUE;
109             }
110             Value v = engine.getComputedStyle(p, pseudo, idx);
111             if (v == ValueConstants.NORMAL_VALUE) {
112                 return ValueConstants.SEMI_CONDENSED_VALUE;
113             }
114             if (v == ValueConstants.CONDENSED_VALUE) {
115                 return ValueConstants.EXTRA_CONDENSED_VALUE;
116             }
117             if (v == ValueConstants.EXPANDED_VALUE) {
118                 return ValueConstants.SEMI_EXPANDED_VALUE;
119             }
120             if (v == ValueConstants.SEMI_EXPANDED_VALUE) {
121                 return ValueConstants.NORMAL_VALUE;
122             }
123             if (v == ValueConstants.SEMI_CONDENSED_VALUE) {
124                 return ValueConstants.CONDENSED_VALUE;
125             }
126             if (v == ValueConstants.EXTRA_CONDENSED_VALUE) {
127                 return ValueConstants.ULTRA_CONDENSED_VALUE;
128             }
129             if (v == ValueConstants.EXTRA_EXPANDED_VALUE) {
130                 return ValueConstants.EXPANDED_VALUE;
131             }
132             if (v == ValueConstants.ULTRA_CONDENSED_VALUE) {
133                 return ValueConstants.ULTRA_CONDENSED_VALUE;
134             }
135             return ValueConstants.EXTRA_EXPANDED_VALUE;
136         } else if (value == ValueConstants.WIDER_VALUE) {
137             sm.putParentRelative(idx, true);
138
139             CSSStylableElement p = CSSEngine.getParentCSSStylableElement(elt);
140             if (p == null) {
141                 return ValueConstants.SEMI_CONDENSED_VALUE;
142             }
143             Value v = engine.getComputedStyle(p, pseudo, idx);
144             if (v == ValueConstants.NORMAL_VALUE) {
145                 return ValueConstants.SEMI_EXPANDED_VALUE;
146             }
147             if (v == ValueConstants.CONDENSED_VALUE) {
148                 return ValueConstants.SEMI_CONDENSED_VALUE;
149             }
150             if (v == ValueConstants.EXPANDED_VALUE) {
151                 return ValueConstants.EXTRA_EXPANDED_VALUE;
152             }
153             if (v == ValueConstants.SEMI_EXPANDED_VALUE) {
154                 return ValueConstants.EXPANDED_VALUE;
155             }
156             if (v == ValueConstants.SEMI_CONDENSED_VALUE) {
157                 return ValueConstants.NORMAL_VALUE;
158             }
159             if (v == ValueConstants.EXTRA_CONDENSED_VALUE) {
160                 return ValueConstants.CONDENSED_VALUE;
161             }
162             if (v == ValueConstants.EXTRA_EXPANDED_VALUE) {
163                 return ValueConstants.ULTRA_EXPANDED_VALUE;
164             }
165             if (v == ValueConstants.ULTRA_CONDENSED_VALUE) {
166                 return ValueConstants.EXTRA_CONDENSED_VALUE;
167             }
168             return ValueConstants.ULTRA_EXPANDED_VALUE;
169         }
170         return value;
171     }
172
173     /**
174      * Implements {@link IdentifierManager#getIdentifiers()}.
175      */

176     public StringMap getIdentifiers() {
177         return values;
178     }
179 }
180
Popular Tags