001: /*
002: * Copyright (c) 2004 JETA Software, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without modification,
005: * are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JETA Software nor the names of its contributors may
015: * be used to endorse or promote products derived from this software without
016: * specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
021: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
022: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
023: * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
024: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
025: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026: * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: */
029:
030: package com.jeta.forms.store.properties.effects;
031:
032: import java.awt.Color;
033: import java.io.IOException;
034:
035: import com.jeta.forms.gui.beans.JETABean;
036: import com.jeta.forms.gui.effects.Paintable;
037: import com.jeta.forms.gui.effects.Painter;
038: import com.jeta.forms.gui.effects.SolidPainter;
039: import com.jeta.forms.store.JETAObjectInput;
040: import com.jeta.forms.store.JETAObjectOutput;
041: import com.jeta.forms.store.properties.ColorProperty;
042: import com.jeta.forms.store.properties.JETAProperty;
043: import com.jeta.open.i18n.I18N;
044:
045: /**
046: * Property for storing settings for a solid color fill effect. See
047: * {@link com.jeta.forms.gui.effects.SolidPainter}
048: *
049: * @author Jeff Tassin
050: */
051: public class SolidProperty extends JETAProperty implements PaintSupport {
052: static final long serialVersionUID = -846608124012768052L;
053:
054: /**
055: * The version for this class
056: */
057: public static final int VERSION = 2;
058:
059: /**
060: * The color for the solid.
061: */
062: private ColorProperty m_color_prop = new ColorProperty();
063:
064: /**
065: * A cached painter object
066: */
067: private transient SolidPainter m_painter;
068:
069: /**
070: * Creates an uninitialized <code>SolidProperty</code> instance
071: */
072: public SolidProperty() {
073:
074: }
075:
076: /**
077: * PaintSupport implementation. Creates a painter that renders a solid
078: * background.
079: */
080: public Painter createPainter() {
081: if (m_painter == null)
082: m_painter = new SolidPainter(this );
083:
084: return m_painter;
085: }
086:
087: /**
088: * Returns the fill color.
089: *
090: * @return the fill color
091: */
092: public Color getColor() {
093: return m_color_prop.getColor();
094: }
095:
096: /**
097: * Returns the fill color property
098: *
099: * @return the fill color property
100: */
101: public ColorProperty getColorProperty() {
102: return m_color_prop;
103: }
104:
105: /**
106: * Sets the fill color property.
107: *
108: * @param c
109: * the fill color property
110: */
111: public void setColorProperty(ColorProperty c) {
112: m_color_prop.setValue(c);
113: }
114:
115: /**
116: * Sets this property to that of SolidProperty
117: *
118: * @param prop
119: * a SolidProperty instance
120: */
121: public void setValue(Object prop) {
122: if (prop instanceof SolidProperty) {
123: SolidProperty sp = (SolidProperty) prop;
124: m_color_prop.setValue(sp.m_color_prop);
125: m_painter = null;
126: } else {
127: assert (false);
128: }
129: }
130:
131: /**
132: * Updates the bean. Gets the underlying Java bean component associated with
133: * this property and if that component implements the Paintable interface,
134: * sets the background painter.
135: */
136: public void updateBean(JETABean jbean) {
137: SolidPainter painter = (SolidPainter) createPainter();
138: if (jbean != null) {
139: java.awt.Component comp = jbean.getDelegate();
140: if (comp instanceof Paintable) {
141: ((Paintable) comp).setBackgroundPainter(painter);
142: }
143: }
144: }
145:
146: /**
147: * @return a string representation of this proprety
148: */
149: public String toString() {
150: return I18N.getLocalizedMessage("Solid");
151: }
152:
153: /**
154: * Externalizable Implementation
155: */
156: public void read(JETAObjectInput in) throws ClassNotFoundException,
157: IOException {
158: super .read(in.getSuperClassInput());
159: int version = in.readVersion();
160: if (version == 1) {
161: Color c = (Color) in.readObject("color");
162: m_color_prop.setColorKey(ColorProperty.CONSTANT_COLOR);
163: m_color_prop.setConstantColor(c);
164: } else {
165: m_color_prop = (ColorProperty) in.readObject("color");
166: }
167: }
168:
169: /**
170: * Externalizable Implementation
171: */
172: public void write(JETAObjectOutput out) throws IOException {
173: super .write(out.getSuperClassOutput(JETAProperty.class));
174: out.writeVersion(VERSION);
175: out.writeObject("color", m_color_prop);
176:
177: }
178:
179: }
|