KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Enumeration JavaDoc;
21 import java.util.Hashtable JavaDoc;
22
23 import javax.swing.Action JavaDoc;
24 import javax.swing.JMenu JavaDoc;
25 import javax.swing.JMenuItem JavaDoc;
26 import javax.swing.JPopupMenu JavaDoc;
27 import javax.swing.JSeparator JavaDoc;
28
29
30 public class ExtendablePopupMenu extends JPopupMenu JavaDoc {
31
32     private MenuModel model;
33
34     private Hashtable JavaDoc map = new Hashtable JavaDoc();
35
36     private String JavaDoc id;
37
38     public ExtendablePopupMenu(String JavaDoc id, String JavaDoc label) {
39         super(label);
40         this.id = id;
41
42         model = new MenuModel(id);
43
44         map.put(id, this);
45     }
46
47     public ExtendablePopupMenu(String JavaDoc id) {
48         super();
49
50         this.id = id;
51
52         model = new MenuModel(id);
53
54         map.put(id, this);
55     }
56
57     public MenuModel getMenuModel() {
58         return model;
59     }
60
61     /**
62      * @see javax.swing.JPopupMenu#add(javax.swing.Action)
63      */

64     public JMenuItem JavaDoc add(Action JavaDoc action) {
65         model.add(action);
66
67         return super.add(action);
68     }
69
70     /**
71      * @see javax.swing.JPopupMenu#add(javax.swing.JMenuItem)
72      */

73     public JMenuItem JavaDoc add(JMenuItem JavaDoc menuItem) {
74         model.add(menuItem);
75
76         return super.add(menuItem);
77     }
78
79     /**
80      * @see javax.swing.JPopupMenu#addSeparator()
81      */

82     public void addSeparator() {
83         model.addSeparator();
84
85         super.addSeparator();
86     }
87
88     /**
89      * @see javax.swing.JPopupMenu#insert(javax.swing.Action, int)
90      */

91     public void insert(Action JavaDoc action, int pos) {
92         model.insert(action, pos);
93
94         super.insert(action, pos);
95     }
96
97     public void addPlaceholder(String JavaDoc placeholderId) {
98         model.appendPlaceholder(placeholderId);
99     }
100
101     public void insertPlaceholder(String JavaDoc placeholderId, int pos) {
102         model.insertPlaceholder(placeholderId, pos);
103     }
104
105     public void insert(Action JavaDoc action, String JavaDoc placeholderId) {
106         int index = model.insert(action, placeholderId);
107         super.insert(action, index);
108     }
109
110     public void insert(JMenuItem JavaDoc menuItem, String JavaDoc placeholderId) {
111         int index = model.insert(menuItem, placeholderId);
112         super.insert(menuItem, index);
113     }
114
115     public void insertSeparator(String JavaDoc placeholderId) {
116         int index = model.insertSeparator(placeholderId);
117         super.insert(new JSeparator JavaDoc(), index);
118     }
119
120     public void add(ExtendableMenu submenu) {
121
122         map.put(submenu.getId(), submenu);
123
124         model.addSubmenu(submenu.getMenuModel());
125
126         super.add((JMenu JavaDoc) submenu);
127     }
128
129     /**
130      * @return Returns the id.
131      */

132     public String JavaDoc getId() {
133         return id;
134     }
135
136     public Enumeration JavaDoc getSubmenuEnumeration() {
137         return map.elements();
138     }
139 }
140
Popular Tags