01: package org.uispec4j;
02:
03: import org.uispec4j.utils.UIComponentFactory;
04: import org.uispec4j.xml.EventLogger;
05:
06: import javax.swing.*;
07: import java.awt.event.ActionEvent;
08:
09: public class MenuItemForJMenuTest extends MenuItemTestCase {
10: public void testFactory() throws Exception {
11: checkFactory(new JMenu(), MenuItem.class);
12: }
13:
14: protected MenuItem createLoggingMenuItem(
15: final EventLogger eventLogger) {
16: final Action action = new AbstractAction("item") {
17: public void actionPerformed(ActionEvent e) {
18: eventLogger.log("action");
19: }
20: };
21: JPopupMenu menu = new JPopupMenu();
22: menu.add(action);
23: return createMenuItem(menu);
24: }
25:
26: static private MenuItem createMenuItem(JPopupMenu menu) {
27: return (MenuItem) UIComponentFactory.createUIComponent(menu);
28: }
29:
30: public static class JMenuBuilder implements MenuBuilder {
31: private JMenu jMenu;
32:
33: public JMenuBuilder(String text) {
34: this (new JMenu(text));
35: }
36:
37: public JMenuBuilder(JMenu menu) {
38: this .jMenu = menu;
39: }
40:
41: public MenuBuilder setName(String name) {
42: jMenu.setName(name);
43: return this ;
44: }
45:
46: public MenuBuilder add(String item) {
47: jMenu.add(new JMenuItem(item));
48: return this ;
49: }
50:
51: public MenuBuilder add(Action action) {
52: jMenu.add(new JMenuItem(action));
53: return this ;
54: }
55:
56: public MenuBuilder addSeparator() {
57: jMenu.addSeparator();
58: return this ;
59: }
60:
61: public MenuBuilder setEnabled(boolean enabled) {
62: jMenu.setEnabled(enabled);
63: return this ;
64: }
65:
66: public MenuBuilder startSubMenu(String item) {
67: JMenu sub = new JMenu(item);
68: jMenu.add(sub);
69: return new JMenuBuilder(sub);
70: }
71:
72: public MenuItem getMenuItem() {
73: return new MenuItem(jMenu);
74: }
75: }
76:
77: public MenuItemTestCase.MenuBuilder getBuilder(String text) {
78: return new JMenuBuilder(text);
79: }
80: }
|