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;
031:
032: import java.awt.Color;
033: import java.awt.Component;
034: import java.io.IOException;
035:
036: import javax.swing.border.Border;
037:
038: import com.jeta.forms.components.border.JETALineBorder;
039: import com.jeta.forms.store.JETAObjectInput;
040: import com.jeta.forms.store.JETAObjectOutput;
041:
042: /**
043: * A <code>LineBorderProperty</code> is used to store the attributes for a
044: * JETALineBorder. This is a type of LineBorder with the added capability of
045: * drawing only specified sides of the border. See:
046: * {@link com.jeta.forms.components.border.JETALineBorder}
047: *
048: * @author Jeff Tassin
049: */
050: public class LineBorderProperty extends BorderProperty {
051: static final long serialVersionUID = -2679973957505795245L;
052:
053: /**
054: * The version for this class
055: */
056: private static final int VERSION = 3;
057:
058: /**
059: * The thickness in pixels of the border
060: */
061: private int m_line_thickness = 1;
062:
063: /**
064: * The color of the border
065: */
066: private ColorProperty m_line_color = new ColorProperty(Color.black);
067:
068: /**
069: * Set to true for a curved border. False for a square border
070: */
071: private boolean m_curved = false;
072:
073: /**
074: * Creates an uninitialized <code>LineBorderProperty</code> instance.
075: */
076: public LineBorderProperty() {
077: }
078:
079: /**
080: * Creates an <code>JETALineBorder</code> instance with the attributes of
081: * this property.
082: *
083: * @return a newly created JETALineBorer instance that can be set on any
084: * Swing component.
085: */
086: public Border createBorder(Component comp) {
087: Border b = new JETALineBorder(new ColorProxy(m_line_color),
088: getLineThickness(), isCurved(), isTopPainted(),
089: isLeftPainted(), isBottomPainted(), isRightPainted());
090: return createTitle(b);
091: }
092:
093: /**
094: * Returns the thickness in pixels of the border.
095: *
096: * @return the thickness of the border
097: */
098: public int getLineThickness() {
099: return m_line_thickness;
100: }
101:
102: /**
103: * Returns the border color.
104: *
105: * @return the border line color
106: */
107: public Color getLineColor() {
108: return m_line_color.getColor();
109: }
110:
111: /**
112: * Returns the border color property.
113: *
114: * @return the border line color property
115: */
116: public ColorProperty getLineColorProperty() {
117: return m_line_color;
118: }
119:
120: /**
121: * Returns true if the corners of this border are rounded.
122: *
123: * @return true if this border is curved
124: */
125: public boolean isCurved() {
126: return m_curved;
127: }
128:
129: /**
130: * Sets the curved attribute for this border
131: *
132: * @param bcurve
133: * if true, sets rounded corners for this border.
134: */
135: public void setCurved(boolean bcurve) {
136: m_curved = bcurve;
137: }
138:
139: /**
140: * Set the thickness of the border
141: */
142: public void setLineThickness(int thickness) {
143: m_line_thickness = thickness;
144: }
145:
146: /**
147: * Set the border line color property
148: */
149: public void setLineColorProperty(ColorProperty c) {
150: m_line_color = c;
151: }
152:
153: /**
154: * Sets this property to that of another LineBorderProperty.
155: *
156: * @param prop
157: * a LineBorderProperty instance
158: */
159: public void setValue(Object prop) {
160: super .setValue(prop);
161: if (prop instanceof LineBorderProperty) {
162: LineBorderProperty bp = (LineBorderProperty) prop;
163: m_line_color.setValue(bp.m_line_color);
164: m_line_thickness = bp.m_line_thickness;
165: m_curved = bp.m_curved;
166: } else {
167: assert (false);
168: }
169: }
170:
171: /**
172: * JETAPersistable Implementation
173: */
174: public void read(JETAObjectInput in) throws ClassNotFoundException,
175: IOException {
176: super .read(in.getSuperClassInput());
177: int version = in.readVersion();
178: m_line_thickness = in.readInt("thickness");
179: Object color = in.readObject("color");
180:
181: if (version > 1) {
182: m_curved = in.readBoolean("curved");
183: }
184:
185: if (color instanceof Color) {
186: m_line_color = new ColorProperty((Color) color);
187: } else {
188: m_line_color = (ColorProperty) color;
189: }
190: }
191:
192: /**
193: * JETAPersistable Implementation
194: */
195: public void write(JETAObjectOutput out) throws IOException {
196: super .write(out.getSuperClassOutput(BorderProperty.class));
197: out.writeVersion(VERSION);
198: out.writeInt("thickness", m_line_thickness);
199: out.writeObject("color", m_line_color);
200: out.writeBoolean("curved", m_curved);
201: }
202:
203: public String toString() {
204: return "LINE";
205: }
206: }
|