KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > properties > CommonTextDecoration


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 /* $Id: CommonTextDecoration.java 474225 2006-11-13 10:08:19Z jeremias $ */
19
20 package org.apache.fop.fo.properties;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 import java.awt.Color JavaDoc;
26
27 import org.apache.fop.apps.FOUserAgent;
28 import org.apache.fop.fo.Constants;
29 import org.apache.fop.fo.PropertyList;
30 import org.apache.fop.fo.expr.PropertyException;
31
32 /**
33  * Stores all information concerning text-decoration.
34  */

35 public class CommonTextDecoration {
36
37     //using a bit-mask here
38
private static final int UNDERLINE = 1;
39     private static final int OVERLINE = 2;
40     private static final int LINE_THROUGH = 4;
41     private static final int BLINK = 8;
42     
43     private int decoration;
44     private Color JavaDoc underColor;
45     private Color JavaDoc overColor;
46     private Color JavaDoc throughColor;
47     
48     /**
49      * Creates a new CommonTextDecoration object with default values.
50      */

51     public CommonTextDecoration() {
52     }
53     
54     /**
55      * Creates a CommonTextDecoration object from a property list.
56      * @param pList the property list to build the object for
57      * @return a CommonTextDecoration object or null if the obj would only have default values
58      * @throws PropertyException if there's a problem while processing the property
59      */

60     public static CommonTextDecoration createFromPropertyList(PropertyList pList)
61                 throws PropertyException {
62         return calcTextDecoration(pList);
63     }
64     
65     private static CommonTextDecoration calcTextDecoration(PropertyList pList)
66                 throws PropertyException {
67         CommonTextDecoration deco = null;
68         PropertyList parentList = pList.getParentPropertyList();
69         if (parentList != null) {
70             //Parent is checked first
71
deco = calcTextDecoration(parentList);
72         }
73         //For rules, see XSL 1.0, chapters 5.5.6 and 7.16.4
74
Property textDecoProp = pList.getExplicit(Constants.PR_TEXT_DECORATION);
75         if (textDecoProp != null) {
76             List JavaDoc list = textDecoProp.getList();
77             Iterator JavaDoc i = list.iterator();
78             while (i.hasNext()) {
79                 Property prop = (Property)i.next();
80                 int propEnum = prop.getEnum();
81                 FOUserAgent ua = (pList == null)
82                         ? null
83                         : (pList.getFObj() == null ? null : pList.getFObj().getUserAgent());
84                 if (propEnum == Constants.EN_NONE) {
85                     if (deco != null) {
86                         deco.decoration = 0;
87                     }
88                     return deco;
89                 } else if (propEnum == Constants.EN_UNDERLINE) {
90                     if (deco == null) {
91                         deco = new CommonTextDecoration();
92                     }
93                     deco.decoration |= UNDERLINE;
94                     deco.underColor = pList.get(Constants.PR_COLOR).getColor(ua);
95                 } else if (propEnum == Constants.EN_NO_UNDERLINE) {
96                     if (deco != null) {
97                         deco.decoration &= OVERLINE | LINE_THROUGH | BLINK;
98                         deco.underColor = pList.get(Constants.PR_COLOR).getColor(ua);
99                     }
100                 } else if (propEnum == Constants.EN_OVERLINE) {
101                     if (deco == null) {
102                         deco = new CommonTextDecoration();
103                     }
104                     deco.decoration |= OVERLINE;
105                     deco.overColor = pList.get(Constants.PR_COLOR).getColor(ua);
106                 } else if (propEnum == Constants.EN_NO_OVERLINE) {
107                     if (deco != null) {
108                         deco.decoration &= UNDERLINE | LINE_THROUGH | BLINK;
109                         deco.overColor = pList.get(Constants.PR_COLOR).getColor(ua);
110                     }
111                 } else if (propEnum == Constants.EN_LINE_THROUGH) {
112                     if (deco == null) {
113                         deco = new CommonTextDecoration();
114                     }
115                     deco.decoration |= LINE_THROUGH;
116                     deco.throughColor = pList.get(Constants.PR_COLOR).getColor(ua);
117                 } else if (propEnum == Constants.EN_NO_LINE_THROUGH) {
118                     if (deco != null) {
119                         deco.decoration &= UNDERLINE | OVERLINE | BLINK;
120                         deco.throughColor = pList.get(Constants.PR_COLOR).getColor(ua);
121                     }
122                 } else if (propEnum == Constants.EN_BLINK) {
123                     if (deco == null) {
124                         deco = new CommonTextDecoration();
125                     }
126                     deco.decoration |= BLINK;
127                 } else if (propEnum == Constants.EN_NO_BLINK) {
128                     if (deco != null) {
129                         deco.decoration &= UNDERLINE | OVERLINE | LINE_THROUGH;
130                     }
131                 } else {
132                     throw new PropertyException("Illegal value encountered: " + prop.getString());
133                 }
134             }
135         }
136         return deco;
137     }
138     
139     /** @return true if underline is active */
140     public boolean hasUnderline() {
141         return (this.decoration & UNDERLINE) != 0;
142     }
143
144     /** @return true if overline is active */
145     public boolean hasOverline() {
146         return (this.decoration & OVERLINE) != 0;
147     }
148
149     /** @return true if line-through is active */
150     public boolean hasLineThrough() {
151         return (this.decoration & LINE_THROUGH) != 0;
152     }
153
154     /** @return true if blink is active */
155     public boolean isBlinking() {
156         return (this.decoration & BLINK) != 0;
157     }
158     
159     /** @return the color of the underline mark */
160     public Color JavaDoc getUnderlineColor() {
161         return this.underColor;
162     }
163     
164     /** @return the color of the overline mark */
165     public Color JavaDoc getOverlineColor() {
166         return this.overColor;
167     }
168
169     /** @return the color of the line-through mark */
170     public Color JavaDoc getLineThroughColor() {
171         return this.throughColor;
172     }
173
174 }
175
Popular Tags