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.BevelBorder;
037: import javax.swing.border.Border;
038:
039: import com.jeta.forms.store.JETAObjectInput;
040: import com.jeta.forms.store.JETAObjectOutput;
041:
042: /**
043: * A <code>BevelBorderProperty</code> stores the attributes for a Swing bevel
044: * border.
045: *
046: * @author Jeff Tassin
047: */
048: public class BevelBorderProperty extends BorderProperty {
049: static final long serialVersionUID = -9171261099090722557L;
050:
051: public static final int VERSION = 2;
052:
053: /**
054: * The type of bevel: BevelBorder.RAISED, LOWERED
055: */
056: private int m_type;
057:
058: /**
059: * The colors for the border.
060: */
061: private ColorProperty m_highlightOuter = new ColorProperty(
062: ColorProperty.DEFAULT_COLOR);
063:
064: private ColorProperty m_highlightInner = new ColorProperty(
065: ColorProperty.DEFAULT_COLOR);
066:
067: private ColorProperty m_shadowOuter = new ColorProperty(
068: ColorProperty.DEFAULT_COLOR);
069:
070: private ColorProperty m_shadowInner = new ColorProperty(
071: ColorProperty.DEFAULT_COLOR);
072:
073: /**
074: * Creates a raised <code>BevelBorderProperty</code> instance.
075: */
076: public BevelBorderProperty() {
077: setBorder(new BevelBorder(BevelBorder.RAISED));
078: }
079:
080: /**
081: * Creates a <code>BevelBorderProperty</code> instance with the specified
082: * bevel type.
083: *
084: * @param bevelType
085: * the type of bevel for the border. Either BevelBorder.RAISED or
086: * BevelBorder.LOWERED.
087: */
088: public BevelBorderProperty(int bevelType) {
089: setBorder(new BevelBorder(bevelType));
090: }
091:
092: /**
093: * BorderProperty.createBorder specialization. Creates a BevelBorder
094: * instance based on the values in this BorderProperty instance.
095: *
096: * @return a BevelBorder instance based on the values in this BorderProperty
097: * instance.
098: */
099: public Border createBorder(Component comp) {
100: Color h_outer = null;
101: Color h_inner = null;
102: Color s_outer = null;
103: Color s_inner = null;
104:
105: ColorProperty cprop = getHighlightOuterColorProperty();
106: if (cprop != null
107: && !cprop.getColorKey().equals(
108: ColorProperty.DEFAULT_COLOR)
109: && cprop.getColor() != null) {
110: h_outer = new ColorProxy(cprop);
111: }
112:
113: cprop = getHighlightInnerColorProperty();
114: if (cprop != null
115: && !cprop.getColorKey().equals(
116: ColorProperty.DEFAULT_COLOR)
117: && cprop.getColor() != null) {
118: h_inner = new ColorProxy(cprop);
119: }
120:
121: cprop = getShadowOuterColorProperty();
122: if (cprop != null
123: && !cprop.getColorKey().equals(
124: ColorProperty.DEFAULT_COLOR)
125: && cprop.getColor() != null) {
126: s_outer = new ColorProxy(cprop);
127: }
128:
129: cprop = getShadowInnerColorProperty();
130: if (cprop != null
131: && !cprop.getColorKey().equals(
132: ColorProperty.DEFAULT_COLOR)
133: && cprop.getColor() != null) {
134: s_inner = new ColorProxy(cprop);
135: }
136:
137: Border b = new BevelBorder(getBevelType(), h_outer, h_inner,
138: s_outer, s_inner);
139: return createTitle(b);
140: }
141:
142: /**
143: * Returns the bevel type for this border. Either BevelBorder.RAISED or
144: * BevelBorder.LOWERED.
145: *
146: * @return the bevel type for this border.
147: */
148: public int getBevelType() {
149: return m_type;
150: }
151:
152: /**
153: * Returns the highlight outer color for the border.
154: *
155: * @return the highlight outer color for the border.
156: */
157: public Color getHighlightOuterColor() {
158: return m_highlightOuter.getColor();
159: }
160:
161: /**
162: * Returns the highlight inner color for the border.
163: *
164: * @return the highlight inner color for the border.
165: */
166: public Color getHighlightInnerColor() {
167: return m_highlightInner.getColor();
168: }
169:
170: /**
171: * Returns the shadow inner color for the border.
172: *
173: * @return the shadow inner color for the border.
174: */
175: public Color getShadowInnerColor() {
176: return m_shadowInner.getColor();
177: }
178:
179: /**
180: * Returns the shadow outer color for the border.
181: *
182: * @return the shadow outer color for the border.
183: */
184: public Color getShadowOuterColor() {
185: return m_shadowOuter.getColor();
186: }
187:
188: /**
189: * Returns the highlight outer ColorProperty for the border.
190: *
191: * @return the highlight outer ColorProperty for the border.
192: */
193: public ColorProperty getHighlightOuterColorProperty() {
194: return m_highlightOuter;
195: }
196:
197: /**
198: * Returns the highlight inner ColorProperty for the border.
199: *
200: * @return the highlight inner ColorProperty for the border.
201: */
202: public ColorProperty getHighlightInnerColorProperty() {
203: return m_highlightInner;
204: }
205:
206: /**
207: * Returns the shadow inner ColorProperty for the border.
208: *
209: * @return the shadow inner ColorProperty for the border.
210: */
211: public ColorProperty getShadowInnerColorProperty() {
212: return m_shadowInner;
213: }
214:
215: /**
216: * Returns the shadow outer ColorProperty for the border.
217: *
218: * @return the shadow outer ColorProperty for the border.
219: */
220: public ColorProperty getShadowOuterColorProperty() {
221: return m_shadowOuter;
222: }
223:
224: /**
225: * Sets the attributes of this property to those of the given bevel border
226: * instance.
227: *
228: * @param bb
229: * the bevel border instance
230: */
231: private void setBorder(BevelBorder bb) {
232: m_type = bb.getBevelType();
233: }
234:
235: /**
236: * Sets the bevel border type.
237: *
238: * @param type
239: * the type of border: BevelBorder.RAISED or BevelBorder.LOWERED.
240: */
241: public void setBevelType(int type) {
242: m_type = type;
243: }
244:
245: /**
246: * Sets the highlight outer ColorProperty for the border.
247: *
248: * @param c
249: * the highlight outer ColorProperty for the border.
250: */
251: public void setHighlightOuterColorProperty(ColorProperty c) {
252: m_highlightOuter = c;
253: }
254:
255: /**
256: * Sets the highlight inner ColorProperty for the border.
257: *
258: * @param c
259: * the highlight inner ColorProperty for the border.
260: */
261: public void setHighlightInnerColorProperty(ColorProperty c) {
262: m_highlightInner = c;
263: }
264:
265: /**
266: * Sets the shadow inner ColorProperty for the border.
267: *
268: * @param c
269: * the shadow inner ColorProperty for the border.
270: */
271: public void setShadowInnerColorProperty(ColorProperty c) {
272: m_shadowInner = c;
273: }
274:
275: /**
276: * Sets the shadow outer ColorProperty for the border.
277: *
278: * @param c
279: * the shadow outer ColorProperty for the border.
280: */
281: public void setShadowOuterColorProperty(ColorProperty c) {
282: m_shadowOuter = c;
283: }
284:
285: /**
286: * Sets this border property to that of another bevel border property.
287: *
288: * @param prop
289: * the value to set. This should be a BevelBorderPropery
290: * instance.
291: */
292: public void setValue(Object prop) {
293: super .setValue(prop);
294: if (prop instanceof BevelBorderProperty) {
295: BevelBorderProperty bp = (BevelBorderProperty) prop;
296: m_type = bp.m_type;
297: m_highlightOuter.setValue(bp.m_highlightOuter);
298: m_highlightInner.setValue(bp.m_highlightInner);
299: m_shadowOuter.setValue(bp.m_shadowOuter);
300: m_shadowInner.setValue(bp.m_shadowInner);
301: } else {
302: assert (false);
303: }
304: }
305:
306: /**
307: * JETAPersistable Implementation
308: */
309: public void read(JETAObjectInput in) throws ClassNotFoundException,
310: IOException {
311: super .read(in.getSuperClassInput());
312: int version = in.readVersion();
313: m_type = in.readInt("type");
314:
315: if (version == 1) {
316: m_highlightOuter.setConstantColor((Color) in
317: .readObject("highlightouter"));
318: m_highlightInner.setConstantColor((Color) in
319: .readObject("highlightinner"));
320: m_shadowOuter.setConstantColor((Color) in
321: .readObject("shadowouter"));
322: m_shadowInner.setConstantColor((Color) in
323: .readObject("shadowinner"));
324: } else {
325: m_highlightOuter = (ColorProperty) in
326: .readObject("highlightouter");
327: m_highlightInner = (ColorProperty) in
328: .readObject("ightlightinner");
329: m_shadowOuter = (ColorProperty) in
330: .readObject("shadowouter");
331: m_shadowInner = (ColorProperty) in
332: .readObject("shadowinner");
333: }
334: }
335:
336: /**
337: * JETAPersistable Implementation
338: */
339: public void write(JETAObjectOutput out) throws IOException {
340: super .write(out.getSuperClassOutput(BorderProperty.class));
341: out.writeVersion(VERSION);
342: out.writeInt("type", m_type);
343: out.writeObject("highlightouter", m_highlightOuter);
344: out.writeObject("highlightinner", m_highlightInner);
345: out.writeObject("shadowouter", m_shadowOuter);
346: out.writeObject("shadowinner", m_shadowInner);
347: }
348:
349: public String toString() {
350: return "BEVEL";
351: }
352: }
|