KickJava   Java API By Example, From Geeks To Geeks.

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


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: ColorTypeProperty.java 377045 2006-02-11 20:23:47Z jeremias $ */
19
20 package org.apache.fop.fo.properties;
21
22 import java.awt.Color JavaDoc;
23
24 import org.apache.fop.apps.FOUserAgent;
25 import org.apache.fop.fo.FObj;
26 import org.apache.fop.fo.PropertyList;
27 import org.apache.fop.fo.expr.PropertyException;
28 import org.apache.fop.util.ColorUtil;
29
30 /**
31  * Superclass for properties that wrap Color values
32  */

33 public class ColorProperty extends Property {
34     
35     /**
36      * The color represented by this property.
37      */

38     protected final Color JavaDoc color;
39
40     
41     /**
42      * Inner class for creating instances of ColorTypeProperty
43      */

44     public static class Maker extends PropertyMaker {
45
46         /**
47          * @param propId the id of the property for which a Maker should be created
48          */

49         public Maker(int propId) {
50             super(propId);
51         }
52
53         /**
54          * Return a ColorProperty object based on the passed Property object.
55          * This method is called if the Property object built by the parser
56          * isn't the right type for this property.
57          *
58          * @param p
59          * The Property object return by the expression parser
60          * @param propertyList
61          * The PropertyList object being built for this FO.
62          * @param fo
63          * The parent FO for the FO whose property is being made.
64          * @return A Property of the correct type or null if the parsed value
65          * can't be converted to the correct type.
66          * @throws PropertyException
67          * for invalid or inconsistent FO input
68          * @see org.apache.fop.fo.properties.PropertyMaker#convertProperty(
69          * org.apache.fop.fo.properties.Property,
70          * org.apache.fop.fo.PropertyList, org.apache.fop.fo.FObj)
71          */

72         public Property convertProperty(Property p,
73                                         PropertyList propertyList, FObj fo)
74                     throws PropertyException {
75             if (p instanceof ColorProperty) {
76                 return p;
77             }
78             FObj fobj = (fo == null ? propertyList.getFObj() : fo);
79             FOUserAgent ua = (fobj == null ? null : fobj.getUserAgent());
80             Color JavaDoc val = p.getColor(ua);
81             if (val != null) {
82                 return new ColorProperty(val);
83             }
84             return convertPropertyDatatype(p, propertyList, fo);
85         }
86
87     }
88
89     /**
90      * Set the color given a particular String. For a full List of supported
91      * values please see ColorUtil.
92      *
93      * @param foUserAgent FOP user agent
94      * @param value RGB value as String to be parsed
95      * @throws PropertyException if the value can't be parsed
96      * @see ColorUtil#parseColorString(String)
97      */

98     public ColorProperty(FOUserAgent foUserAgent, String JavaDoc value) throws PropertyException {
99         this.color = ColorUtil.parseColorString(foUserAgent, value);
100     }
101
102     /**
103      * Create a new ColorProperty with a given color.
104      *
105      * @param value the color to use.
106      */

107     public ColorProperty(Color JavaDoc value) {
108         this.color = value;
109     }
110     
111     /**
112      * Returns an AWT instance of this color
113      * @param foUserAgent FOP user agent
114      * @return float the AWT color represented by this ColorType instance
115      */

116     public Color JavaDoc getColor(FOUserAgent foUserAgent) {
117         return color;
118     }
119
120     /**
121      * @see java.lang.Object#toString()
122      */

123     public String JavaDoc toString() {
124         return ColorUtil.colorToString(color);
125     }
126
127     /**
128      * Can't convert to any other types
129      * @return this.colorType
130      */

131     public ColorProperty getColorProperty() {
132         return this;
133     }
134
135     /**
136      * @return this.colorType cast as an Object
137      */

138     public Object JavaDoc getObject() {
139         return this;
140     }
141 }
142
143
Popular Tags