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.components.line;
031:
032: import java.awt.Dimension;
033: import java.util.Iterator;
034:
035: import javax.swing.JComponent;
036:
037: import com.jeta.forms.gui.common.FormUtils;
038: import com.jeta.forms.store.properties.CompoundLineProperty;
039: import com.jeta.forms.store.properties.LineProperty;
040:
041: /**
042: * A component that is one or more lines that can be oriented vertically or
043: * horizontally
044: *
045: * @author Jeff Tassin
046: */
047: public abstract class LineComponent extends JComponent {
048: private boolean m_design_mode = false;
049:
050: /**
051: * A list of LineProperties
052: */
053: private CompoundLineProperty m_prop = new CompoundLineProperty();
054:
055: /**
056: * The preferred size
057: */
058: private Dimension m_pref_size;
059:
060: /**
061: * ctor
062: */
063: public LineComponent() {
064: m_prop.addLine(new LineProperty());
065: m_design_mode = FormUtils.isDesignMode();
066: }
067:
068: /**
069: * @return the definition for this line
070: */
071: public CompoundLineProperty getLineDefinition() {
072: return m_prop;
073: }
074:
075: /**
076: * @return the position for this line
077: */
078: public int getPosition() {
079: return m_prop.getPosition();
080: }
081:
082: /**
083: * @return the preferred size for this component
084: */
085: public Dimension getPreferredSize() {
086: if (m_pref_size == null) {
087: if (isHorizontal()) {
088: int width = 0;
089: int height = 0;
090:
091: if (m_prop != null) {
092: height = getThickness();
093: }
094:
095: if (width == 0)
096: width = 10;
097: if (height == 0)
098: height = 1;
099: m_pref_size = new Dimension(width, height);
100: } else {
101: int width = 0;
102: int height = 0;
103:
104: if (m_prop != null) {
105: width = getThickness();
106: }
107: if (width == 0)
108: width = 1;
109: if (height == 0)
110: height = 10;
111: m_pref_size = new Dimension(width, height);
112:
113: }
114: }
115: return m_pref_size;
116: }
117:
118: /**
119: * @return the total thickness for this line. This is the total of all lines
120: * in the compound line property
121: */
122: public int getThickness() {
123: int t = 0;
124: Iterator iter = iterator();
125: while (iter.hasNext()) {
126: LineProperty prop = (LineProperty) iter.next();
127: t += prop.getThickness();
128: }
129: return t;
130: }
131:
132: boolean isDesignMode() {
133: return m_design_mode;
134: }
135:
136: /**
137: * @return true if this line is oriented horizontally
138: */
139: public abstract boolean isHorizontal();
140:
141: /**
142: * @return an iterator to the lines (LineProperty objects)in this compound
143: * border
144: */
145: public Iterator iterator() {
146: return m_prop.iterator();
147: }
148:
149: /**
150: * Sets the definition for this line
151: */
152: public void setLineDefinition(CompoundLineProperty prop) {
153: m_prop = prop;
154: m_pref_size = null;
155: revalidate();
156: repaint();
157: }
158:
159: /**
160: * Sets the definition for this line
161: */
162: public void setLineDefinitionEx(LineProperty prop) {
163: setLineDefinition(new CompoundLineProperty(prop));
164: }
165:
166: /**
167: * Prints this component state to the console
168: */
169: public void print() {
170: System.out.println("LineComponent.....................");
171: m_prop.print();
172: }
173:
174: /**
175: * @return the position for this line
176: */
177: public void setPosition(int pos) {
178: m_prop.setPosition(pos);
179: }
180:
181: }
|