001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.core.gui.menu;
019:
020: import java.awt.event.ActionEvent;
021:
022: import javax.swing.JCheckBoxMenuItem;
023: import javax.swing.JFrame;
024: import javax.swing.JMenuItem;
025: import javax.swing.JRadioButtonMenuItem;
026:
027: import org.columba.core.gui.action.AbstractColumbaAction;
028:
029: public class MenuTest {
030: private static final String MENUID1 = "menu1";
031:
032: private static final String MENUID2 = "menu2";
033:
034: private static final String PLACEHOLDER1 = "placeholder1";
035:
036: private static final String PLACEHOLDER2 = "placeholder2";
037:
038: private ExtendableMenu createMenu() {
039:
040: ExtendableMenu menu = new ExtendableMenu(MENUID1, "menu2");
041:
042: menu.add(new JMenuItem("test1"));
043: menu.add(new JCheckBoxMenuItem("test2"));
044: menu.addPlaceholder(PLACEHOLDER1);
045: menu.add(new JRadioButtonMenuItem("test4"));
046:
047: menu.insert(createAction("sub-test1"), PLACEHOLDER1);
048:
049: ExtendableMenu submenu = new ExtendableMenu(MENUID2,
050: "sublabel1");
051:
052: submenu.add(createAction("test5"));
053: submenu.addPlaceholder(PLACEHOLDER2);
054: menu.add(submenu);
055:
056: submenu.insert(createAction("sub-test2"), PLACEHOLDER2);
057:
058: menu.add(createAction("test7"));
059:
060: return menu;
061: }
062:
063: /**
064: * @param args
065: */
066: public static void main(String[] args) {
067: MenuTest test = new MenuTest();
068:
069: ExtendableMenu menu = test.createMenu();
070:
071: JFrame frame = new JFrame();
072: frame.setSize(640, 480);
073: ExtendableMenuBar mb = new ExtendableMenuBar();
074: mb.add(menu);
075:
076: mb.insertMenuItem(MENUID1, PLACEHOLDER1, new JMenuItem(
077: "dynamic item"));
078: mb.insertMenuItem(MENUID2, PLACEHOLDER2, new JMenuItem(
079: "dynamic subitem 2"));
080:
081: frame.setJMenuBar(mb);
082: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
083: frame.setLocationRelativeTo(null);
084: frame.setVisible(true);
085: }
086:
087: private TestAction createAction(String str) {
088: return new TestAction(str);
089: }
090:
091: class TestAction extends AbstractColumbaAction {
092: public TestAction(String str) {
093: super (null, str);
094: }
095:
096: public void actionPerformed(ActionEvent e) {
097: // do nothing
098: }
099: }
100: }
|