01: package abbot.tester;
02:
03: import java.awt.Component;
04:
05: import javax.swing.*;
06:
07: /** Provides access to JPopupMenu contents. No special user actions. */
08: public class JPopupMenuTester extends JComponentTester {
09:
10: /** Return an identifying tag for the popup menu. */
11: public String deriveTag(Component comp) {
12: Component invoker = ((JPopupMenu) comp).getInvoker();
13: return invoker == null ? "Popup menu" : "Popup on "
14: + getTag(invoker);
15: }
16:
17: /** Return the contents of the popup menu as a String array. */
18: public String[] getMenuLabels(Component comp) {
19: JPopupMenu menu = (JPopupMenu) comp;
20: MenuElement[] els = menu.getSubElements();
21: String[] result = new String[els.length];
22: for (int i = 0; i < els.length; i++) {
23: Component mi = els[i].getComponent();
24: if (mi instanceof JMenuItem) {
25: result[i] = ((JMenuItem) mi).getText();
26: } else {
27: result[i] = "-";
28: }
29: }
30: return result;
31: }
32: }
|