01: package abbot.tester;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05: import javax.swing.*;
06:
07: /** Provides user actions on a JSplitPane. */
08: public class JSplitPaneTester extends JComponentTester {
09:
10: /** Set the divider position proportionally. */
11: public void actionMoveDivider(Component c,
12: final double proportionalLocation) {
13: JSplitPane split = (JSplitPane) c;
14: int max = split.getMaximumDividerLocation();
15: int position = (int) (max * proportionalLocation);
16: actionMoveDividerAbsolute(split, position);
17: }
18:
19: /** Set the divider position to an absolute position. */
20: public void actionMoveDividerAbsolute(Component c,
21: final int location) {
22: final JSplitPane split = (JSplitPane) c;
23: int old = split.getDividerLocation();
24: // Move as close as possible, then programmatically set the position
25: if (split.getOrientation() == JSplitPane.VERTICAL_SPLIT) {
26: mouseMove(c, c.getWidth() / 2, old);
27: mousePress(InputEvent.BUTTON1_MASK);
28: mouseMove(c, c.getWidth() / 2, location);
29: mouseRelease();
30: } else {
31: mouseMove(c, old, c.getHeight() / 2);
32: mousePress(InputEvent.BUTTON1_MASK);
33: mouseMove(c, location, c.getHeight() / 2);
34: mouseRelease();
35: }
36: invokeAndWait(c, new Runnable() {
37: public void run() {
38: split.setDividerLocation(location);
39: }
40: });
41: }
42: }
|