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.KeyboardStateRecordable;
027: import jacareto.struct.StructureElement;
028: import jacareto.system.Environment;
029: import jacareto.system.Language;
030:
031: import java.awt.Component;
032: import java.awt.GridBagConstraints;
033: import java.awt.GridBagLayout;
034: import java.awt.Insets;
035: import java.awt.event.ActionEvent;
036: import java.awt.event.ActionListener;
037:
038: import javax.swing.JCheckBox;
039: import javax.swing.JComboBox;
040: import javax.swing.JPanel;
041:
042: /**
043: * An editor for keyboard state recordables.
044: *
045: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
046: * @version 1.0
047: */
048: public class KeyboardStateRecordableEditor extends Editor {
049: /** The structure element to edit. */
050: private StructureElement element;
051:
052: /** The editor panel. */
053: private JPanel editorPanel;
054:
055: /** Components for the isNumLockOn property. */
056: private JCheckBox numLockCheckBox;
057: private JComboBox numLockComboBox;
058:
059: /** Components for the isScrollLockOn property. */
060: private JCheckBox scrollLockCheckBox;
061: private JComboBox scrollLockComboBox;
062:
063: /** Components for the isCapsLockOn property. */
064: private JCheckBox capsLockCheckBox;
065: private JComboBox capsLockComboBox;
066:
067: /**
068: * Create a new keyboard state recordable editor.
069: *
070: * @param env the environment
071: */
072: public KeyboardStateRecordableEditor(Environment env) {
073: super (env);
074:
075: Language language = getLanguage();
076:
077: editorPanel = new JPanel(new GridBagLayout());
078:
079: GridBagConstraints c = new GridBagConstraints();
080: c.insets = new Insets(5, 5, 5, 5);
081: c.anchor = GridBagConstraints.WEST;
082:
083: // The num lock field
084: numLockCheckBox = new JCheckBox(
085: language
086: .getString("Recordables.KeyboardStateRecordable.NumLock")
087: + ":");
088: numLockCheckBox.addActionListener(new ActionListener() {
089: public void actionPerformed(ActionEvent e) {
090: if (getElement() != null) {
091: ((KeyboardStateRecordable) getElement())
092: .setApplyIsNumLockOn(numLockCheckBox
093: .isSelected());
094: numLockComboBox.setEnabled(numLockCheckBox
095: .isSelected());
096: }
097: }
098: });
099: numLockComboBox = new JComboBox();
100: numLockComboBox.addItem(language.getString("General.On"));
101: numLockComboBox.addItem(language.getString("General.Off"));
102: numLockComboBox.addActionListener(new ActionListener() {
103: public void actionPerformed(ActionEvent e) {
104: if (isUpdateOnChange && (getElement() != null)) {
105: ((KeyboardStateRecordable) getElement())
106: .setIsNumLockOn(numLockComboBox
107: .getSelectedIndex() == 0);
108: }
109: }
110: });
111: c.gridx = 0;
112: c.gridy = 0;
113: editorPanel.add(numLockCheckBox, c);
114: c.gridx = 1;
115: editorPanel.add(numLockComboBox, c);
116:
117: // The scroll lock field
118: scrollLockCheckBox = new JCheckBox(
119: language
120: .getString("Recordables.KeyboardStateRecordable.ScrollLock")
121: + ":");
122: scrollLockCheckBox.addActionListener(new ActionListener() {
123: public void actionPerformed(ActionEvent e) {
124: if (getElement() != null) {
125: ((KeyboardStateRecordable) getElement())
126: .setApplyIsScrollLockOn(scrollLockCheckBox
127: .isSelected());
128: scrollLockComboBox.setEnabled(scrollLockCheckBox
129: .isSelected());
130: }
131: }
132: });
133: scrollLockComboBox = new JComboBox();
134: scrollLockComboBox.addItem(language.getString("General.On"));
135: scrollLockComboBox.addItem(language.getString("General.Off"));
136: scrollLockComboBox.addActionListener(new ActionListener() {
137: public void actionPerformed(ActionEvent e) {
138: if (isUpdateOnChange && (getElement() != null)) {
139: ((KeyboardStateRecordable) getElement())
140: .setIsScrollLockOn(scrollLockComboBox
141: .getSelectedIndex() == 0);
142: }
143: }
144: });
145: c.gridx = 0;
146: c.gridy = 1;
147: editorPanel.add(scrollLockCheckBox, c);
148: c.gridx = 1;
149: editorPanel.add(scrollLockComboBox, c);
150:
151: // The caps lock field
152: capsLockCheckBox = new JCheckBox(
153: language
154: .getString("Recordables.KeyboardStateRecordable.CapsLock")
155: + ":");
156: capsLockCheckBox.addActionListener(new ActionListener() {
157: public void actionPerformed(ActionEvent e) {
158: if (getElement() != null) {
159: ((KeyboardStateRecordable) getElement())
160: .setApplyIsCapsLockOn(capsLockCheckBox
161: .isSelected());
162: capsLockComboBox.setEnabled(capsLockCheckBox
163: .isSelected());
164: }
165: }
166: });
167: capsLockComboBox = new JComboBox();
168: capsLockComboBox.addItem(language.getString("General.On"));
169: capsLockComboBox.addItem(language.getString("General.Off"));
170: capsLockComboBox.addActionListener(new ActionListener() {
171: public void actionPerformed(ActionEvent e) {
172: if (isUpdateOnChange && (getElement() != null)) {
173: ((KeyboardStateRecordable) getElement())
174: .setIsCapsLockOn(capsLockComboBox
175: .getSelectedIndex() == 0);
176: }
177: }
178: });
179: c.gridx = 0;
180: c.gridy = 2;
181: editorPanel.add(capsLockCheckBox, c);
182: c.gridx = 1;
183: editorPanel.add(capsLockComboBox, c);
184: }
185:
186: /**
187: * Returns whether this editor is responsible for a given structure element. This editor is
188: * responsible for keyboard state recordables.
189: *
190: * @param element the structure element
191: *
192: * @return <code>true</code> if <i>element</i> is an window properties recordable and not
193: * <code>null</code>, otherwise <code>false</code>
194: */
195: public boolean handlesElement(StructureElement element) {
196: return (element != null)
197: && (element instanceof KeyboardStateRecordable);
198: }
199:
200: /**
201: * Returns the actual structure element to be edited.
202: *
203: * @return the element
204: */
205: public StructureElement getElement() {
206: return element;
207: }
208:
209: /**
210: * Returns the component for editing the specified structure element.
211: *
212: * @return the editor component
213: */
214: public Component getComponent() {
215: return editorPanel;
216: }
217:
218: /**
219: * Sets the structure element to edit.
220: *
221: * @param element the structure element
222: */
223: public void setElement(StructureElement element) {
224: this .element = element;
225:
226: KeyboardStateRecordable ksRecordable = (KeyboardStateRecordable) element;
227:
228: // numlock components
229: numLockCheckBox.setSelected(ksRecordable.getApplyIsNumLockOn());
230:
231: if (ksRecordable.getIsNumLockOn()) {
232: numLockComboBox.setSelectedIndex(0);
233: } else {
234: numLockComboBox.setSelectedIndex(1);
235: }
236:
237: numLockComboBox.setEnabled(ksRecordable.getApplyIsNumLockOn());
238:
239: // scroll lock components
240: scrollLockCheckBox.setSelected(ksRecordable
241: .getApplyIsScrollLockOn());
242:
243: if (ksRecordable.getIsScrollLockOn()) {
244: scrollLockComboBox.setSelectedIndex(0);
245: } else {
246: scrollLockComboBox.setSelectedIndex(1);
247: }
248:
249: scrollLockComboBox.setEnabled(ksRecordable
250: .getApplyIsScrollLockOn());
251:
252: // caps lock components
253: capsLockCheckBox.setSelected(ksRecordable
254: .getApplyIsCapsLockOn());
255:
256: if (ksRecordable.getIsCapsLockOn()) {
257: capsLockComboBox.setSelectedIndex(0);
258: } else {
259: capsLockComboBox.setSelectedIndex(1);
260: }
261:
262: capsLockComboBox
263: .setEnabled(ksRecordable.getApplyIsCapsLockOn());
264: }
265: }
|