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.WindowEventRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030: import jacareto.toolkit.event.TextValueListener;
031:
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034: import java.awt.event.WindowEvent;
035:
036: import javax.swing.JComboBox;
037: import javax.swing.JTextField;
038: import javax.swing.event.DocumentEvent;
039:
040: /**
041: * An editor for window event recordables.
042: *
043: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
044: * @version 1.0
045: */
046: public class WindowEventRecordableEditor extends
047: ComponentEventRecordableEditor {
048: /** The combo box for the event type (=id). */
049: private JComboBox typeBox;
050:
051: /** The text field for the window title. */
052: private JTextField titleField;
053:
054: /**
055: * Create a new window event recordable editor.
056: *
057: * @param env the environment
058: */
059: public WindowEventRecordableEditor(Environment env) {
060: super (env);
061:
062: Language language = getLanguage();
063:
064: // The title of the window
065: // The when field.
066: titleField = addTextFieldRow(language
067: .getString("Events.WindowEvent.Title"), 20);
068: titleField.getDocument().addDocumentListener(
069: new TextValueListener() {
070: public void textValueChanged(DocumentEvent e) {
071: if (isUpdateOnChange && (getElement() != null)) {
072: ((WindowEventRecordable) getElement())
073: .setWindowTitle(titleField
074: .getText());
075: }
076: }
077: });
078:
079: // The type box
080: typeBox = addComboBoxRow(language
081: .getString("Events.WindowEvent.Type"));
082: typeBox.addItem(language
083: .getString("Events.WindowEvent.Activated"));
084: typeBox
085: .addItem(language
086: .getString("Events.WindowEvent.Closed"));
087: typeBox.addItem(language
088: .getString("Events.WindowEvent.Closing"));
089: typeBox.addItem(language
090: .getString("Events.WindowEvent.Deactivated"));
091: typeBox.addItem(language
092: .getString("Events.WindowEvent.Deiconified"));
093: typeBox.addItem(language
094: .getString("Events.WindowEvent.Iconified"));
095: typeBox
096: .addItem(language
097: .getString("Events.WindowEvent.Opened"));
098: typeBox.addActionListener(new ActionListener() {
099: public void actionPerformed(ActionEvent e) {
100: WindowEventRecordable wRecordable = (WindowEventRecordable) getElement();
101:
102: if (isUpdateOnChange && (wRecordable != null)) {
103: switch (typeBox.getSelectedIndex()) {
104: case 0:
105: wRecordable.setID(WindowEvent.WINDOW_ACTIVATED);
106:
107: break;
108:
109: case 1:
110: wRecordable.setID(WindowEvent.WINDOW_CLOSED);
111:
112: break;
113:
114: case 2:
115: wRecordable.setID(WindowEvent.WINDOW_CLOSING);
116:
117: break;
118:
119: case 3:
120: wRecordable
121: .setID(WindowEvent.WINDOW_DEACTIVATED);
122:
123: break;
124:
125: case 4:
126: wRecordable
127: .setID(WindowEvent.WINDOW_DEICONIFIED);
128:
129: break;
130:
131: case 5:
132: wRecordable.setID(WindowEvent.WINDOW_ICONIFIED);
133:
134: break;
135:
136: case 6:
137: wRecordable.setID(WindowEvent.WINDOW_OPENED);
138:
139: break;
140: }
141: }
142: }
143: });
144: }
145:
146: /**
147: * Returns whether this editor is responsible for a given structure element. This editor is
148: * responsible for all window event recordables.
149: *
150: * @param element the structure element
151: *
152: * @return <code>true</code> if <i>element</i> is an window event recordable and not
153: * <code>null</code>, otherwise <code>false</code>
154: */
155: public boolean handlesElement(StructureElement element) {
156: return (element != null)
157: && (element instanceof WindowEventRecordable);
158: }
159:
160: /**
161: * Sets the element to edit.
162: *
163: * @param element DOCUMENT ME!
164: */
165: public void setElement(StructureElement element) {
166: super .setElement(element);
167:
168: WindowEventRecordable wRecordable = (WindowEventRecordable) element;
169: titleField.setText(wRecordable.getWindowTitle());
170:
171: switch (wRecordable.getID()) {
172: case WindowEvent.WINDOW_ACTIVATED:
173: typeBox.setSelectedIndex(0);
174:
175: break;
176:
177: case WindowEvent.WINDOW_CLOSED:
178: typeBox.setSelectedIndex(1);
179:
180: break;
181:
182: case WindowEvent.WINDOW_CLOSING:
183: typeBox.setSelectedIndex(2);
184:
185: break;
186:
187: case WindowEvent.WINDOW_DEACTIVATED:
188: typeBox.setSelectedIndex(3);
189:
190: break;
191:
192: case WindowEvent.WINDOW_DEICONIFIED:
193: typeBox.setSelectedIndex(4);
194:
195: break;
196:
197: case WindowEvent.WINDOW_ICONIFIED:
198: typeBox.setSelectedIndex(5);
199:
200: break;
201:
202: case WindowEvent.WINDOW_OPENED:
203: typeBox.setSelectedIndex(6);
204:
205: break;
206: }
207: }
208: }
|