001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.editor;
025:
026: import jacareto.system.Environment;
027: import jacareto.toolkit.swing.IntegerTextField;
028: import jacareto.toolkit.swing.LongTextField;
029:
030: import java.awt.Component;
031: import java.awt.GridBagConstraints;
032: import java.awt.GridBagLayout;
033:
034: import javax.swing.JComboBox;
035: import javax.swing.JLabel;
036: import javax.swing.JPanel;
037: import javax.swing.JTextField;
038: import javax.swing.border.EmptyBorder;
039:
040: /**
041: * <p>
042: * An abstract superclass for editors which contain rows of input fields.
043: * </p>
044: *
045: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
046: * @version 1.01
047: */
048: public abstract class InputFieldRowsEditor extends Editor {
049: /** The editor's component. */
050: protected JPanel editorPanel;
051:
052: /** The GridBagConstraints. */
053: protected GridBagConstraints c;
054:
055: /** The number of rows contained in the editor's panel. */
056: private int rowCount;
057:
058: /**
059: * Create a new editor.
060: *
061: * @param env the environment
062: */
063: public InputFieldRowsEditor(Environment env) {
064: super (env);
065:
066: rowCount = 0;
067:
068: // The panel with the text fields
069: editorPanel = new JPanel();
070: editorPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
071: editorPanel.setLayout(new GridBagLayout());
072:
073: // Init the constraints
074: c = new GridBagConstraints();
075: c.ipadx = 5;
076: c.ipady = 5;
077: c.anchor = GridBagConstraints.WEST;
078: }
079:
080: /**
081: * Adds a text field row to the editor's component. The text field is editable by default.
082: *
083: * @param labelText the text of the label
084: * @param length the number of columns of the text field
085: *
086: * @return the text field of that row
087: */
088: protected JTextField addTextFieldRow(String labelText, int length) {
089: c.gridx = 0;
090: c.weightx = 40;
091: c.gridy = rowCount;
092:
093: JLabel label = new JLabel(labelText + ":");
094: editorPanel.add(label, c);
095:
096: c.gridx = 1;
097: c.weightx = 60;
098:
099: JTextField result = new JTextField("", length);
100: editorPanel.add(result, c);
101: label.setLabelFor(result);
102:
103: rowCount++;
104:
105: return result;
106: }
107:
108: /**
109: * Adds an integer text field row to the editor's component. The integer text field is editable
110: * by default.
111: *
112: * @param labelText the text of the label
113: * @param length the number of columns of the text field
114: *
115: * @return the integer text field of that row
116: */
117: protected IntegerTextField addIntegerTextFieldRow(String labelText,
118: int length) {
119: c.gridx = 0;
120: c.weightx = 40;
121: c.gridy = rowCount;
122:
123: JLabel label = new JLabel(labelText + ":");
124: editorPanel.add(label, c);
125:
126: c.gridx = 1;
127: c.weightx = 60;
128:
129: IntegerTextField result = new IntegerTextField(length);
130: editorPanel.add(result, c);
131: label.setLabelFor(result);
132:
133: rowCount++;
134:
135: return result;
136: }
137:
138: /**
139: * Adds a long text field row to the editor's component. The long text field is editable by
140: * default.
141: *
142: * @param labelText the text of the label
143: * @param length the number of columns of the text field
144: *
145: * @return the long text field of that row
146: */
147: protected LongTextField addLongTextFieldRow(String labelText,
148: int length) {
149: c.gridx = 0;
150: c.weightx = 40;
151: c.gridy = rowCount;
152:
153: JLabel label = new JLabel(labelText + ":");
154: editorPanel.add(label, c);
155:
156: c.gridx = 1;
157: c.weightx = 60;
158:
159: LongTextField result = new LongTextField(length);
160: editorPanel.add(result, c);
161: label.setLabelFor(result);
162:
163: rowCount++;
164:
165: return result;
166: }
167:
168: /**
169: * Adds a combobox row to the editor's component.
170: *
171: * @param labelText the text of the label
172: *
173: * @return the combo box of that row
174: */
175: protected JComboBox addComboBoxRow(String labelText) {
176: c.gridx = 0;
177: c.weightx = 40;
178: c.gridy = rowCount;
179:
180: JLabel label = new JLabel(labelText + ":");
181: editorPanel.add(label, c);
182:
183: c.gridx = 1;
184: c.weightx = 60;
185:
186: JComboBox result = new JComboBox();
187: editorPanel.add(result, c);
188: label.setLabelFor(result);
189:
190: rowCount++;
191:
192: return result;
193: }
194:
195: /**
196: * Adds any component editor's component.
197: *
198: * @param component the component
199: *
200: * @return the component
201: */
202: protected Component addComponent(Component component) {
203: c.gridx = 0;
204: c.weightx = 100;
205: c.gridwidth = 2;
206: c.gridy = rowCount;
207:
208: editorPanel.add(component, c);
209: c.gridwidth = 1;
210:
211: rowCount++;
212:
213: return component;
214: }
215:
216: /**
217: * Returns the component of the editor.
218: *
219: * @return the editor component
220: */
221: public Component getComponent() {
222: return editorPanel;
223: }
224:
225: /**
226: * Returns the constraints.
227: *
228: * @return the gridbag constraints.
229: */
230: public GridBagConstraints getConstraints() {
231: return c;
232: }
233: }
|