01: package abbot.tester;
02:
03: import java.awt.Component;
04: import java.awt.event.KeyEvent;
05: import javax.swing.*;
06: import javax.swing.text.*;
07:
08: import abbot.finder.BasicFinder;
09: import abbot.finder.matchers.ClassMatcher;
10: import abbot.i18n.Strings;
11:
12: /** Provides access to all user actions on a JSpinner. */
13: public class JSpinnerTester extends JComponentTester {
14:
15: /** Increment the JSpinner. */
16: public void actionIncrement(Component c) {
17: actionKeyStroke(c, KeyEvent.VK_UP);
18: }
19:
20: /** Decrement the JSpinner. */
21: public void actionDecrement(Component c) {
22: actionKeyStroke(c, KeyEvent.VK_DOWN);
23: }
24:
25: /** Set the value of the JSpinner, assuming its editor has a
26: JTextComponent under it somewhere.
27: */
28: public void actionSetValue(Component c, String value) {
29: JComponent ed = ((JSpinner) c).getEditor();
30: try {
31: Component tf = BasicFinder.getDefault().find(ed,
32: new ClassMatcher(JTextComponent.class));
33: JTextComponentTester t = new JTextComponentTester();
34: t.actionEnterText(tf, value);
35: t.actionKeyStroke(tf, KeyEvent.VK_ENTER);
36: } catch (Exception e) {
37: String msg = Strings.get("tester.JSpinner.unknown_editor",
38: new String[] { ed.toString() });
39: throw new ActionFailedException(msg);
40: }
41: }
42: }
|