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.record.EventObjectRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.event.TextValueListener;
031: import jacareto.toolkit.swing.IntegerTextField;
032: import jacareto.toolkit.swing.LongTextField;
033:
034: import java.awt.Component;
035: import java.awt.GridBagConstraints;
036: import java.awt.GridBagLayout;
037:
038: import javax.swing.JComboBox;
039: import javax.swing.JLabel;
040: import javax.swing.JPanel;
041: import javax.swing.JTextField;
042: import javax.swing.border.EmptyBorder;
043: import javax.swing.event.DocumentEvent;
044: import javax.swing.*;
045:
046: /**
047: * <p>
048: * An editor which offers some standard methods for adding GUI elements
049: * </p>
050: *
051: * <p>
052: * If a subclass overwrites the method {@link #setElement(StructureElement)}, it should call the
053: * method of its superclass first.
054: * </p>
055: *
056: *
057: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
058: * @version 1.01
059: */
060: public abstract class EnhancedEditor extends Editor {
061: /** The editor's component. */
062: protected JPanel editorPanel;
063:
064: /** The GridBagConstraints. */
065: protected GridBagConstraints c;
066:
067: /** The structure element to edit. */
068: private StructureElement element;
069:
070: /** The number of rows contained in the editor's panel. */
071: private int rowCount;
072:
073: /**
074: * Create a new event object recordable editor.
075: *
076: * @param env the environment
077: */
078: public EnhancedEditor(Environment env) {
079: super (env);
080:
081: Language language = getLanguage();
082: rowCount = 0;
083:
084: // The panel with the text fields
085: editorPanel = new JPanel();
086: editorPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
087: editorPanel.setLayout(new GridBagLayout());
088:
089: // Init the constraints
090: c = new GridBagConstraints();
091: c.ipadx = 5;
092: c.ipady = 5;
093: c.anchor = GridBagConstraints.WEST;
094: }
095:
096: /**
097: * Adds a text field row to the editor's component. The text field is editable by default.
098: *
099: * @param labelText the text of the label
100: * @param length the number of columns of the text field
101: *
102: * @return the text field of that row
103: */
104: protected JTextField addTextFieldRow(String labelText, int length) {
105: c.gridx = 0;
106: c.weightx = 40;
107: c.gridy = rowCount;
108:
109: JLabel label = new JLabel(labelText + ":");
110: editorPanel.add(label, c);
111:
112: c.gridx = 1;
113: c.weightx = 60;
114:
115: JTextField result = new JTextField("", length);
116: editorPanel.add(result, c);
117: label.setLabelFor(result);
118:
119: rowCount++;
120:
121: return result;
122: }
123:
124: /**
125: * Adds an integer text field row to the editor's component. The integer text field is editable
126: * by default.
127: *
128: * @param labelText the text of the label
129: * @param length the number of columns of the text field
130: *
131: * @return the integer text field of that row
132: */
133: protected IntegerTextField addIntegerTextFieldRow(String labelText,
134: int length) {
135: c.gridx = 0;
136: c.weightx = 40;
137: c.gridy = rowCount;
138:
139: JLabel label = new JLabel(labelText + ":");
140: editorPanel.add(label, c);
141:
142: c.gridx = 1;
143: c.weightx = 60;
144:
145: IntegerTextField result = new IntegerTextField(length);
146: editorPanel.add(result, c);
147: label.setLabelFor(result);
148:
149: rowCount++;
150:
151: return result;
152: }
153:
154: /**
155: * Adds a long text field row to the editor's component. The long text field is editable by
156: * default.
157: *
158: * @param labelText the text of the label
159: * @param length the number of columns of the text field
160: *
161: * @return the long text field of that row
162: */
163: protected LongTextField addLongTextFieldRow(String labelText,
164: int length) {
165: c.gridx = 0;
166: c.weightx = 40;
167: c.gridy = rowCount;
168:
169: JLabel label = new JLabel(labelText + ":");
170: editorPanel.add(label, c);
171:
172: c.gridx = 1;
173: c.weightx = 60;
174:
175: LongTextField result = new LongTextField(length);
176: editorPanel.add(result, c);
177: label.setLabelFor(result);
178:
179: rowCount++;
180:
181: return result;
182: }
183:
184: /**
185: * Adds a combobox row to the editor's component.
186: *
187: * @param labelText the text of the label
188: *
189: * @return the combo box of that row
190: */
191: protected JComboBox addComboBoxRow(String labelText) {
192: c.gridx = 0;
193: c.weightx = 40;
194: c.gridy = rowCount;
195:
196: JLabel label = new JLabel(labelText + ":");
197: editorPanel.add(label, c);
198:
199: c.gridx = 1;
200: c.weightx = 60;
201:
202: JComboBox result = new JComboBox();
203: editorPanel.add(result, c);
204: label.setLabelFor(result);
205:
206: rowCount++;
207:
208: return result;
209: }
210:
211: /**
212: * Adds a checkbox row to the editor's component.
213: *
214: * @param labelText the text of the label
215: *
216: * @return the checkbox of that row
217: */
218: protected JCheckBox addCheckBoxRow(String labelText) {
219: c.gridx = 0;
220: c.weightx = 40;
221: c.gridy = rowCount;
222: c.gridwidth = 2;
223:
224: JCheckBox result = new JCheckBox(labelText);
225: editorPanel.add(result, c);
226:
227: rowCount++;
228:
229: return result;
230: }
231:
232: /**
233: * Returns the actual structure element to be edited.
234: *
235: * @return DOCUMENT ME!
236: */
237: public StructureElement getElement() {
238: return element;
239: }
240:
241: /**
242: * Sets the structure element to edit.
243: *
244: * @param element DOCUMENT ME!
245: */
246: public void setElement(StructureElement element) {
247: this .element = element;
248: }
249:
250: /**
251: * Returns the component of the editor.
252: *
253: * @return the editor component
254: */
255: public Component getComponent() {
256: return editorPanel;
257: }
258: }
|