KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > menu > MenuTest


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.core.gui.menu;
19
20 import java.awt.event.ActionEvent JavaDoc;
21
22 import javax.swing.JCheckBoxMenuItem JavaDoc;
23 import javax.swing.JFrame JavaDoc;
24 import javax.swing.JMenuItem JavaDoc;
25 import javax.swing.JRadioButtonMenuItem JavaDoc;
26
27 import org.columba.core.gui.action.AbstractColumbaAction;
28
29 public class MenuTest {
30     private static final String JavaDoc MENUID1 = "menu1";
31
32     private static final String JavaDoc MENUID2 = "menu2";
33
34     private static final String JavaDoc PLACEHOLDER1 = "placeholder1";
35
36     private static final String JavaDoc PLACEHOLDER2 = "placeholder2";
37
38     private ExtendableMenu createMenu() {
39
40         ExtendableMenu menu = new ExtendableMenu(MENUID1, "menu2");
41
42         menu.add(new JMenuItem JavaDoc("test1"));
43         menu.add(new JCheckBoxMenuItem JavaDoc("test2"));
44         menu.addPlaceholder(PLACEHOLDER1);
45         menu.add(new JRadioButtonMenuItem JavaDoc("test4"));
46
47         menu.insert(createAction("sub-test1"), PLACEHOLDER1);
48
49         ExtendableMenu submenu = new ExtendableMenu(MENUID2, "sublabel1");
50
51         submenu.add(createAction("test5"));
52         submenu.addPlaceholder(PLACEHOLDER2);
53         menu.add(submenu);
54
55         submenu.insert(createAction("sub-test2"), PLACEHOLDER2);
56
57         menu.add(createAction("test7"));
58
59         return menu;
60     }
61
62     /**
63      * @param args
64      */

65     public static void main(String JavaDoc[] args) {
66         MenuTest test = new MenuTest();
67
68         ExtendableMenu menu = test.createMenu();
69
70         JFrame JavaDoc frame = new JFrame JavaDoc();
71         frame.setSize(640, 480);
72         ExtendableMenuBar mb = new ExtendableMenuBar();
73         mb.add(menu);
74
75         mb.insertMenuItem(MENUID1, PLACEHOLDER1, new JMenuItem JavaDoc("dynamic item"));
76         mb.insertMenuItem(MENUID2, PLACEHOLDER2, new JMenuItem JavaDoc(
77                 "dynamic subitem 2"));
78
79         frame.setJMenuBar(mb);
80         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
81         frame.setLocationRelativeTo(null);
82         frame.setVisible(true);
83     }
84
85     private TestAction createAction(String JavaDoc str) {
86         return new TestAction(str);
87     }
88
89     class TestAction extends AbstractColumbaAction {
90         public TestAction(String JavaDoc str) {
91             super(null, str);
92         }
93
94         public void actionPerformed(ActionEvent JavaDoc e) {
95             // do nothing
96
}
97     }
98 }
99
Popular Tags