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.replay.ReplayMode;
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.BorderUtilities;
032: import jacareto.toolkit.swing.LongTextField;
033:
034: import java.awt.BorderLayout;
035: import java.awt.Component;
036: import java.awt.FlowLayout;
037: import java.awt.GridLayout;
038: import java.awt.event.ActionEvent;
039: import java.awt.event.ActionListener;
040:
041: import javax.swing.ButtonGroup;
042: import javax.swing.JCheckBox;
043: import javax.swing.JLabel;
044: import javax.swing.JPanel;
045: import javax.swing.JRadioButton;
046: import javax.swing.border.EmptyBorder;
047: import javax.swing.event.DocumentEvent;
048:
049: /**
050: * Editor for configuring the replay mode.
051: *
052: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
053: * @version 1.01
054: */
055: public class ReplayModeEditor extends Editor {
056: /** The editor's component. */
057: protected JPanel editorPanel;
058:
059: /** The element to edit. */
060: private StructureElement element;
061:
062: /** button for realtime */
063: private JRadioButton realtimeButton;
064:
065: /** button for fixed time */
066: private JRadioButton fixedtimeButton;
067:
068: /** The button group for the time mode buttons. */
069: private ButtonGroup timeButtonGroup;
070:
071: /** button for realmouse */
072: private JRadioButton realMouseButton;
073:
074: /** button for pseudo mouse */
075: private JRadioButton pseudoMouseButton;
076:
077: /** button for no mouse mode */
078: private JRadioButton noMouseButton;
079:
080: /** The button group for the mouse mode buttons. */
081: private ButtonGroup mouseModeButtonGroup;
082:
083: /** textfield for the spectime */
084: private LongTextField spectimeField;
085:
086: /** textfield for the fast forward duration */
087: private LongTextField ffwdTimeField;
088:
089: /** textfield for the maximum delay */
090: private LongTextField maxDelayField;
091:
092: /** The mark mode. */
093: private JCheckBox markModeChkBox;
094:
095: /** The safe mode. */
096: private JCheckBox safeModeChkBox;
097:
098: /** Show the record position? */
099: private JCheckBox showPosChkBox;
100:
101: /** Ignore exceptions? */
102: private JCheckBox ignoreExceptionsChkBox;
103:
104: /** Plays mouse sounds? */
105: private JCheckBox playsMouseSoundsChkBox;
106:
107: /** Plays keyboard sounds? */
108: private JCheckBox playsKeyboardSoundsChkBox;
109:
110: /** Component search components. */
111: private JCheckBox timeoutEnabledChkBox;
112: private LongTextField timeoutField;
113: private LongTextField timeStepField;
114:
115: /**
116: * Creates a new replay mode editor.
117: *
118: * @param env the environment
119: */
120: public ReplayModeEditor(Environment env) {
121: super (env);
122: editorPanel = new JPanel();
123:
124: Language language = env.getLanguage();
125:
126: // the time mode components
127: JPanel timePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
128: timePanel.setBorder(BorderUtilities.getTitledBorder(language
129: .getString("Replay.Mode.TimeMode")));
130: realtimeButton = new JRadioButton(language
131: .getString("Replay.Mode.RealTime"));
132: realtimeButton.addActionListener(new ActionListener() {
133: public void actionPerformed(ActionEvent e) {
134: spectimeField.setEnabled(false);
135: markModeChkBox.setEnabled(false);
136:
137: if (isUpdateOnChange && (getElement() != null)) {
138: ((ReplayMode) getElement())
139: .setTimeMode(ReplayMode.REALTIME);
140: }
141: }
142: });
143: fixedtimeButton = new JRadioButton(language
144: .getString("Replay.Mode.FixedTime"));
145: fixedtimeButton.addActionListener(new ActionListener() {
146: public void actionPerformed(ActionEvent e) {
147: spectimeField.setEnabled(true);
148: markModeChkBox.setEnabled(true);
149:
150: if (isUpdateOnChange && (getElement() != null)) {
151: ((ReplayMode) getElement())
152: .setTimeMode(ReplayMode.FIXEDTIME);
153: }
154: }
155: });
156: spectimeField = new LongTextField(5);
157: spectimeField.getDocument().addDocumentListener(
158: new TextValueListener() {
159: public void textValueChanged(DocumentEvent e) {
160: if (isUpdateOnChange && (getElement() != null)) {
161: ((ReplayMode) getElement())
162: .setFixedTimeDelay(spectimeField
163: .getValue());
164: }
165: }
166: });
167:
168: timePanel.add(realtimeButton);
169: timePanel.add(fixedtimeButton);
170: timePanel.add(spectimeField);
171: timePanel.add(new JLabel(language.getString("General.Msec")));
172: timeButtonGroup = new ButtonGroup();
173: timeButtonGroup.add(realtimeButton);
174: timeButtonGroup.add(fixedtimeButton);
175:
176: JPanel mouseModePanel = new JPanel(new FlowLayout(
177: FlowLayout.LEFT));
178: mouseModePanel.setBorder(BorderUtilities
179: .getTitledBorder(language
180: .getString("Replay.Mode.MouseMode")));
181: realMouseButton = new JRadioButton(language
182: .getString("Replay.Mode.RealMouse"));
183: realMouseButton.addActionListener(new ActionListener() {
184: public void actionPerformed(ActionEvent e) {
185: if (isUpdateOnChange && (getElement() != null)) {
186: ((ReplayMode) getElement())
187: .setMouseMode(ReplayMode.REALMOUSE);
188: }
189: }
190: });
191:
192: pseudoMouseButton = new JRadioButton(language
193: .getString("Replay.Mode.PseudoMouse"));
194: pseudoMouseButton.addActionListener(new ActionListener() {
195: public void actionPerformed(ActionEvent e) {
196: if (isUpdateOnChange && (getElement() != null)) {
197: ((ReplayMode) getElement())
198: .setMouseMode(ReplayMode.PSEUDOMOUSE);
199: }
200: }
201: });
202: noMouseButton = new JRadioButton(language
203: .getString("Replay.Mode.NoMouse"));
204: noMouseButton.addActionListener(new ActionListener() {
205: public void actionPerformed(ActionEvent e) {
206: if (isUpdateOnChange && (getElement() != null)) {
207: ((ReplayMode) getElement())
208: .setMouseMode(ReplayMode.NOMOUSE);
209: }
210: }
211: });
212: mouseModePanel.add(realMouseButton);
213: mouseModePanel.add(pseudoMouseButton);
214: mouseModePanel.add(noMouseButton);
215: mouseModeButtonGroup = new ButtonGroup();
216: mouseModeButtonGroup.add(realMouseButton);
217: mouseModeButtonGroup.add(pseudoMouseButton);
218: mouseModeButtonGroup.add(noMouseButton);
219: realMouseButton.setSelected(true);
220:
221: // the feature panel
222: JPanel featPanel = new JPanel();
223: featPanel.setLayout(new GridLayout(3, 2));
224: featPanel.setBorder(BorderUtilities.getTitledBorder(language
225: .getString("Replay.Mode.Options")));
226: markModeChkBox = new JCheckBox(language
227: .getString("Replay.Mode.MarkMode"));
228: markModeChkBox.addActionListener(new ActionListener() {
229: public void actionPerformed(ActionEvent e) {
230: if (isUpdateOnChange && (getElement() != null)) {
231: ((ReplayMode) getElement())
232: .setIsMarkMode(markModeChkBox.isSelected());
233: }
234: }
235: });
236:
237: showPosChkBox = new JCheckBox(language
238: .getString("Replay.Mode.ShowPosition"));
239: showPosChkBox.addActionListener(new ActionListener() {
240: public void actionPerformed(ActionEvent e) {
241: if (isUpdateOnChange && (getElement() != null)) {
242: ((ReplayMode) getElement())
243: .setIsPositionShowing(showPosChkBox
244: .isSelected());
245: }
246: }
247: });
248: ignoreExceptionsChkBox = new JCheckBox(language
249: .getString("Replay.Mode.IgnoreExceptions"));
250: ignoreExceptionsChkBox.addActionListener(new ActionListener() {
251: public void actionPerformed(ActionEvent e) {
252: if (isUpdateOnChange && (getElement() != null)) {
253: ((ReplayMode) getElement())
254: .setIgnoreExceptions(ignoreExceptionsChkBox
255: .isSelected());
256: }
257: }
258: });
259: playsMouseSoundsChkBox = new JCheckBox(language
260: .getString("Replay.Mode.PlaysMouseSounds"));
261: playsMouseSoundsChkBox.addActionListener(new ActionListener() {
262: public void actionPerformed(ActionEvent e) {
263: if (isUpdateOnChange && (getElement() != null)) {
264: ((ReplayMode) getElement())
265: .setPlaysMouseSounds(playsMouseSoundsChkBox
266: .isSelected());
267: }
268: }
269: });
270: playsKeyboardSoundsChkBox = new JCheckBox(language
271: .getString("Replay.Mode.PlaysKeyboardSounds"));
272: playsKeyboardSoundsChkBox
273: .addActionListener(new ActionListener() {
274: public void actionPerformed(ActionEvent e) {
275: if (isUpdateOnChange && (getElement() != null)) {
276: ((ReplayMode) getElement())
277: .setPlaysKeyboardSounds(playsKeyboardSoundsChkBox
278: .isSelected());
279: }
280: }
281: });
282:
283: safeModeChkBox = new JCheckBox(language
284: .getString("Replay.Mode.SafeMode"));
285: safeModeChkBox.addActionListener(new ActionListener() {
286: public void actionPerformed(ActionEvent e) {
287: if (isUpdateOnChange && (getElement() != null)) {
288: ((ReplayMode) getElement())
289: .setIsSafeMode(safeModeChkBox.isSelected());
290: }
291: }
292: });
293:
294: featPanel.add(markModeChkBox);
295: featPanel.add(playsMouseSoundsChkBox);
296: featPanel.add(showPosChkBox);
297: featPanel.add(playsKeyboardSoundsChkBox);
298: featPanel.add(ignoreExceptionsChkBox);
299: featPanel.add(safeModeChkBox);
300:
301: // the ffwd panel
302: JPanel ffwdPanel = new JPanel();
303: ffwdPanel.setLayout(new GridLayout(2, 2));
304: ffwdPanel.setBorder(BorderUtilities.getTitledBorder(language
305: .getString("Replay.Mode.Delays")));
306: ffwdTimeField = new LongTextField(8);
307: ffwdTimeField.getDocument().addDocumentListener(
308: new TextValueListener() {
309: public void textValueChanged(DocumentEvent e) {
310: if (isUpdateOnChange && (getElement() != null)) {
311: ((ReplayMode) getElement())
312: .setFastForwardDelay(ffwdTimeField
313: .getValue());
314: }
315: }
316: });
317: ffwdPanel.add(new JLabel(language
318: .getString("Replay.Mode.FfwdDuration")
319: + ":"));
320: ffwdPanel.add(ffwdTimeField);
321:
322: // the maximum delay
323: maxDelayField = new LongTextField(8);
324: maxDelayField.getDocument().addDocumentListener(
325: new TextValueListener() {
326: public void textValueChanged(DocumentEvent e) {
327: if (isUpdateOnChange && (getElement() != null)) {
328: ((ReplayMode) getElement())
329: .setMaxDelay(maxDelayField
330: .getValue());
331: }
332: }
333: });
334: ffwdPanel.add(new JLabel(language
335: .getString("Replay.Mode.MaxDelay")
336: + ":"));
337: ffwdPanel.add(maxDelayField);
338:
339: // the component search panel
340: JPanel componentSearchPanel = new JPanel();
341: componentSearchPanel.setLayout(new GridLayout(2, 2));
342: componentSearchPanel.setBorder(BorderUtilities
343: .getTitledBorder(language
344: .getString("Replay.Mode.ComponentSearch")));
345:
346: timeoutEnabledChkBox = new JCheckBox(language
347: .getString("Replay.Mode.Timeout")
348: + ":");
349: timeoutEnabledChkBox.addActionListener(new ActionListener() {
350: public void actionPerformed(ActionEvent e) {
351: if (isUpdateOnChange && (getElement() != null)) {
352: ((ReplayMode) getElement())
353: .setComponentSearchTimeoutEnabled(timeoutEnabledChkBox
354: .isSelected());
355: timeoutField.setEnabled(timeoutEnabledChkBox
356: .isSelected());
357: }
358: }
359: });
360: timeoutField = new LongTextField(8);
361: timeoutField.getDocument().addDocumentListener(
362: new TextValueListener() {
363: public void textValueChanged(DocumentEvent e) {
364: if (isUpdateOnChange && (getElement() != null)) {
365: ((ReplayMode) getElement())
366: .setComponentSearchTimeout(timeoutField
367: .getValue());
368: }
369: }
370: });
371:
372: JLabel timeStepFieldLabel = new JLabel(language
373: .getString("Replay.Mode.TimeStep")
374: + ":");
375: timeStepField = new LongTextField(8);
376: timeStepField.getDocument().addDocumentListener(
377: new TextValueListener() {
378: public void textValueChanged(DocumentEvent e) {
379: if (isUpdateOnChange && (getElement() != null)) {
380: ((ReplayMode) getElement())
381: .setComponentSearchStep(timeStepField
382: .getValue());
383: }
384: }
385: });
386:
387: componentSearchPanel.add(timeoutEnabledChkBox);
388: componentSearchPanel.add(timeoutField);
389: componentSearchPanel.add(timeStepFieldLabel);
390: componentSearchPanel.add(timeStepField);
391:
392: JPanel modePanel = new JPanel(new GridLayout(2, 1));
393: modePanel.add(timePanel);
394: modePanel.add(mouseModePanel);
395:
396: JPanel middlePanel = new JPanel(new GridLayout(2, 1));
397: middlePanel.add(featPanel);
398: middlePanel.add(componentSearchPanel);
399:
400: // Putting all together
401: editorPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
402: editorPanel.setLayout(new BorderLayout());
403: editorPanel.add(modePanel, BorderLayout.NORTH);
404: editorPanel.add(middlePanel, BorderLayout.CENTER);
405: editorPanel.add(ffwdPanel, BorderLayout.SOUTH);
406: }
407:
408: /**
409: * Returns whether this editor is responsible for a given structure element. This editor is
410: * responsible for replay modes.
411: *
412: * @param element the structure element
413: *
414: * @return <code>true</code> if <i>element</i> is a pause recordable and not <code>null</code>,
415: * otherwise <code>false</code>
416: */
417: public boolean handlesElement(StructureElement element) {
418: return (element != null) && (element instanceof ReplayMode);
419: }
420:
421: /**
422: * Returns the actual structure element to be edited.
423: *
424: * @return DOCUMENT ME!
425: */
426: public StructureElement getElement() {
427: return element;
428: }
429:
430: /**
431: * Sets the element to edit.
432: *
433: * @param element DOCUMENT ME!
434: */
435: public void setElement(StructureElement element) {
436: this .element = element;
437:
438: ReplayMode replayMode = (ReplayMode) element;
439:
440: switch (replayMode.getTimeMode()) {
441: case ReplayMode.FIXEDTIME:
442: fixedtimeButton.setSelected(true);
443:
444: break;
445:
446: case ReplayMode.REALTIME:
447: default:
448: realtimeButton.setSelected(true);
449:
450: break;
451: }
452:
453: switch (replayMode.getMouseMode()) {
454: case ReplayMode.NOMOUSE:
455: noMouseButton.setSelected(true);
456:
457: break;
458:
459: case ReplayMode.PSEUDOMOUSE:
460: pseudoMouseButton.setSelected(true);
461:
462: break;
463:
464: case ReplayMode.REALMOUSE:
465: default:
466: realMouseButton.setSelected(true);
467:
468: break;
469: }
470:
471: spectimeField.setValue(replayMode.getFixedTimeDelay());
472: spectimeField.setEnabled(fixedtimeButton.isSelected());
473:
474: markModeChkBox.setSelected(replayMode.getIsMarkMode());
475: markModeChkBox.setEnabled(fixedtimeButton.isSelected());
476:
477: ffwdTimeField.setValue(replayMode.getFastForwardDelay());
478:
479: safeModeChkBox.setSelected(replayMode.getIsSafeMode());
480:
481: maxDelayField.setValue(replayMode.getMaxDelay());
482: showPosChkBox.setSelected(replayMode.getIsPositionShowing());
483: ignoreExceptionsChkBox.setSelected(replayMode
484: .getIgnoreExceptions());
485: playsMouseSoundsChkBox.setSelected(replayMode
486: .getPlaysMouseSounds());
487: playsKeyboardSoundsChkBox.setSelected(replayMode
488: .getPlaysKeyboardSounds());
489:
490: timeoutEnabledChkBox.setSelected(replayMode
491: .getComponentSearchTimeoutEnabled());
492: timeoutField.setValue(replayMode.getComponentSearchTimeout());
493: timeoutField.setEnabled(timeoutEnabledChkBox.isSelected());
494: timeStepField.setValue(replayMode.getComponentSearchStep());
495: }
496:
497: /**
498: * Returns the component of the editor.
499: *
500: * @return the editor component
501: */
502: public Component getComponent() {
503: return editorPanel;
504: }
505: }
|