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.util.Enumeration;
021: import java.util.Hashtable;
022:
023: import javax.swing.Action;
024: import javax.swing.JMenu;
025: import javax.swing.JMenuItem;
026: import javax.swing.JPopupMenu;
027: import javax.swing.JSeparator;
028:
029: public class ExtendablePopupMenu extends JPopupMenu {
030:
031: private MenuModel model;
032:
033: private Hashtable map = new Hashtable();
034:
035: private String id;
036:
037: public ExtendablePopupMenu(String id, String label) {
038: super (label);
039: this .id = id;
040:
041: model = new MenuModel(id);
042:
043: map.put(id, this );
044: }
045:
046: public ExtendablePopupMenu(String id) {
047: super ();
048:
049: this .id = id;
050:
051: model = new MenuModel(id);
052:
053: map.put(id, this );
054: }
055:
056: public MenuModel getMenuModel() {
057: return model;
058: }
059:
060: /**
061: * @see javax.swing.JPopupMenu#add(javax.swing.Action)
062: */
063: public JMenuItem add(Action action) {
064: model.add(action);
065:
066: return super .add(action);
067: }
068:
069: /**
070: * @see javax.swing.JPopupMenu#add(javax.swing.JMenuItem)
071: */
072: public JMenuItem add(JMenuItem menuItem) {
073: model.add(menuItem);
074:
075: return super .add(menuItem);
076: }
077:
078: /**
079: * @see javax.swing.JPopupMenu#addSeparator()
080: */
081: public void addSeparator() {
082: model.addSeparator();
083:
084: super .addSeparator();
085: }
086:
087: /**
088: * @see javax.swing.JPopupMenu#insert(javax.swing.Action, int)
089: */
090: public void insert(Action action, int pos) {
091: model.insert(action, pos);
092:
093: super .insert(action, pos);
094: }
095:
096: public void addPlaceholder(String placeholderId) {
097: model.appendPlaceholder(placeholderId);
098: }
099:
100: public void insertPlaceholder(String placeholderId, int pos) {
101: model.insertPlaceholder(placeholderId, pos);
102: }
103:
104: public void insert(Action action, String placeholderId) {
105: int index = model.insert(action, placeholderId);
106: super .insert(action, index);
107: }
108:
109: public void insert(JMenuItem menuItem, String placeholderId) {
110: int index = model.insert(menuItem, placeholderId);
111: super .insert(menuItem, index);
112: }
113:
114: public void insertSeparator(String placeholderId) {
115: int index = model.insertSeparator(placeholderId);
116: super .insert(new JSeparator(), index);
117: }
118:
119: public void add(ExtendableMenu submenu) {
120:
121: map.put(submenu.getId(), submenu);
122:
123: model.addSubmenu(submenu.getMenuModel());
124:
125: super .add((JMenu) submenu);
126: }
127:
128: /**
129: * @return Returns the id.
130: */
131: public String getId() {
132: return id;
133: }
134:
135: public Enumeration getSubmenuEnumeration() {
136: return map.elements();
137: }
138: }
|