01: package abbot.tester;
02:
03: import java.awt.*;
04: import java.util.ArrayList;
05:
06: import javax.swing.JTabbedPane;
07: import javax.swing.plaf.TabbedPaneUI;
08:
09: import abbot.tester.JTabbedPaneLocation.TabNotVisibleException;
10:
11: /** Provides user actions on a JTabbedPane. */
12: public class JTabbedPaneTester extends JComponentTester {
13:
14: /** Return an array of strings that represent the tabs in the pane.
15: */
16: public String[] getTabs(Component comp) {
17: JTabbedPane tp = (JTabbedPane) comp;
18: int count = tp.getTabCount();
19: ArrayList list = new ArrayList(count);
20: for (int i = 0; i < count; i++) {
21: list.add(tp.getTitleAt(i));
22: }
23: return (String[]) list.toArray(new String[count]);
24: }
25:
26: public void actionSelectTab(final Component comp,
27: JTabbedPaneLocation loc) {
28: Point pt;
29: try {
30: pt = loc.getPoint(comp);
31: actionClick(comp, new ComponentLocation(pt));
32: } catch (final TabNotVisibleException e) {
33: // Set the tab directly
34: invokeAndWait(new Runnable() {
35: public void run() {
36: ((JTabbedPane) comp).setSelectedIndex(e.index);
37: }
38: });
39: }
40: }
41:
42: /** Parse the String representation of a JTableLocation into the actual
43: JTableLocation object.
44: */
45: public ComponentLocation parseLocation(String encoded) {
46: return new JTabbedPaneLocation().parse(encoded);
47: }
48:
49: /** Return (in order of preference) the location corresponding to value,
50: * cell, or coordinate.
51: */
52: public ComponentLocation getLocation(Component c, Point p) {
53: JTabbedPane tabs = (JTabbedPane) c;
54: TabbedPaneUI ui = tabs.getUI();
55: int index = ui.tabForCoordinate(tabs, p.x, p.y);
56: if (index != -1) {
57: String name = tabs.getTitleAt(index);
58: return new JTabbedPaneLocation(name);
59: }
60: return new JTabbedPaneLocation(p);
61: }
62: }
|