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.Component;
033: import java.io.IOException;
034:
035: import javax.swing.border.Border;
036: import javax.swing.border.EmptyBorder;
037:
038: import com.jeta.forms.store.JETAObjectInput;
039: import com.jeta.forms.store.JETAObjectOutput;
040:
041: /**
042: * An <code>EmptyBorderProperty</code> represents an empty border for a
043: * component. An empty border is used to add padding around the top, left,
044: * bottom, or right sides of a component. See:
045: * {@link javax.swing.border.EmptyBorder}
046: *
047: * @author Jeff Tassin
048: */
049: public class EmptyBorderProperty extends BorderProperty {
050: static final long serialVersionUID = 6035977997403297375L;
051:
052: public static final int VERSION = 1;
053:
054: /**
055: * The padding in pixels for the sides of this border.
056: */
057: private int m_top;
058: private int m_left;
059: private int m_bottom;
060: private int m_right;
061:
062: /**
063: * Creates an <code>EmptyBorderProperty</code> instance with no padding
064: * values.
065: */
066: public EmptyBorderProperty() {
067:
068: }
069:
070: /**
071: * Creates an <code>EmptyBorderProperty</code> instance with the specified
072: * padding values.
073: *
074: * @param top
075: * the padding in pixels for the top of this border.
076: * @param left
077: * the padding in pixels for the left side of this border.
078: * @param bottom
079: * the padding in pixels for the bottom of this border.
080: * @param right
081: * the padding in pixels for the right side of this border.
082: */
083: public EmptyBorderProperty(int top, int left, int bottom, int right) {
084:
085: m_top = top;
086: m_left = left;
087: m_bottom = bottom;
088: m_right = right;
089: }
090:
091: /**
092: * Creates an <code>EmptyBorder</code> instance with the padding values
093: * specified by this property.
094: *
095: * @return a newly created EmptyBorder instance that can be set on any Swing
096: * component.
097: */
098: public Border createBorder(Component comp) {
099: Border b = new EmptyBorder(getTop(), getLeft(), getBottom(),
100: getRight());
101: return createTitle(b);
102: }
103:
104: /**
105: * Returns the top padding in pixels for this border.
106: *
107: * @return the top padding in pixels
108: */
109: public int getTop() {
110: return m_top;
111: }
112:
113: /**
114: * Returns the left padding in pixels for this border.
115: *
116: * @return the left padding in pixels.
117: */
118: public int getLeft() {
119: return m_left;
120: }
121:
122: /**
123: * Returns the bottom padding in pixels for this border.
124: *
125: * @return the bottom padding in pixels.
126: */
127: public int getBottom() {
128: return m_bottom;
129: }
130:
131: /**
132: * Returns the right padding in pixels for this border.
133: *
134: * @return the right padding in pixels
135: */
136: public int getRight() {
137: return m_right;
138: }
139:
140: /**
141: * Sets this property to that of another <code>EmptyBorderProperty</code>.
142: *
143: * @param prop
144: * the property
145: */
146: public void setValue(Object prop) {
147: super .setValue(prop);
148: if (prop instanceof EmptyBorderProperty) {
149: EmptyBorderProperty bp = (EmptyBorderProperty) prop;
150: m_top = bp.m_top;
151: m_left = bp.m_left;
152: m_bottom = bp.m_bottom;
153: m_right = bp.m_right;
154: } else {
155: assert (false);
156: }
157: }
158:
159: /**
160: * JETAPersistable Implementation
161: */
162: public void read(JETAObjectInput in) throws ClassNotFoundException,
163: IOException {
164: super .read(in.getSuperClassInput());
165: int version = in.readVersion();
166: m_top = in.readInt("top");
167: m_left = in.readInt("left");
168: m_bottom = in.readInt("bottom");
169: m_right = in.readInt("right");
170: }
171:
172: /**
173: * JETAPersistable Implementation
174: */
175: public void write(JETAObjectOutput out) throws IOException {
176: super .write(out.getSuperClassOutput(BorderProperty.class));
177: out.writeVersion(VERSION);
178: out.writeInt("top", m_top);
179: out.writeInt("left", m_left);
180: out.writeInt("bottom", m_bottom);
181: out.writeInt("right", m_right);
182: }
183:
184: public String toString() {
185: return "EMPTY";
186: }
187: }
|