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.Component;
021: import java.util.Enumeration;
022: import java.util.Vector;
023:
024: import javax.swing.Action;
025: import javax.swing.JMenuItem;
026:
027: /**
028: * Menu element.
029: *
030: * @author fdietz
031: */
032: public class MenuElement implements IMenuElement {
033:
034: private int type;
035:
036: private Action action;
037:
038: private String placeholderId;
039:
040: private String menuId;
041:
042: private String menuLabel;
043:
044: private IMenuElement parent;
045:
046: private JMenuItem menuItem;
047:
048: private Component component;
049:
050: private Vector children = new Vector();
051:
052: public MenuElement(int type) {
053: this .type = type;
054: }
055:
056: public boolean isSeparator() {
057: return type == TYPE_SEPARATOR ? true : false;
058: }
059:
060: public boolean isAction() {
061: return type == TYPE_ACTION ? true : false;
062: }
063:
064: public boolean isPlaceholder() {
065: return type == TYPE_PLACEHOLDER ? true : false;
066: }
067:
068: public boolean isMenu() {
069: return type == TYPE_MENU ? true : false;
070: }
071:
072: public boolean isComponent() {
073: return type == TYPE_MENUITEM ? true : false;
074: }
075:
076: /**
077: * @return Returns the action.
078: */
079: public Action getAction() {
080: return action;
081: }
082:
083: /**
084: * @return Returns the placeholderId.
085: */
086: public String getPlaceholderId() {
087: return placeholderId;
088: }
089:
090: public IMenuElement getParent() {
091: return parent;
092: }
093:
094: public Enumeration getChildren() {
095: return children.elements();
096: }
097:
098: public void add(IMenuElement child) {
099: child.setParent(this );
100: children.add(child);
101: }
102:
103: public void setParent(IMenuElement parent) {
104: this .parent = parent;
105: }
106:
107: public void remove(IMenuElement child) {
108: children.remove(child);
109: }
110:
111: public void remove(int index) {
112: children.remove(index);
113: }
114:
115: /**
116: * @return Returns the menuId.
117: */
118: public String getMenuId() {
119: return menuId;
120: }
121:
122: /**
123: * @param menuId
124: * The menuId to set.
125: */
126: public void setMenuId(String menuId) {
127: this .menuId = menuId;
128: }
129:
130: /**
131: * @param action
132: * The action to set.
133: */
134: public void setAction(Action action) {
135: this .action = action;
136: }
137:
138: /**
139: * @param placeholderId
140: * The placeholderId to set.
141: */
142: public void setPlaceholderId(String placeholderId) {
143: this .placeholderId = placeholderId;
144: }
145:
146: /**
147: * @return Returns the menuLabel.
148: */
149: public String getMenuLabel() {
150: return menuLabel;
151: }
152:
153: /**
154: * @param menuLabel
155: * The menuLabel to set.
156: */
157: public void setMenuLabel(String menuLabel) {
158: this .menuLabel = menuLabel;
159: }
160:
161: public int indexOf(IMenuElement child) {
162: return children.indexOf(child);
163: }
164:
165: public void insert(IMenuElement child, int position) {
166: child.setParent(this );
167:
168: children.insertElementAt(child, position);
169: }
170:
171: public String toString() {
172: StringBuffer buf = new StringBuffer();
173: if (menuId != null)
174: buf.append(menuId);
175: if (placeholderId != null)
176: buf.append(placeholderId);
177: if (action != null)
178: buf.append(action.toString());
179:
180: buf.append(" type=" + type);
181:
182: return buf.toString();
183: }
184:
185: public JMenuItem getMenuItem() {
186: return menuItem;
187: }
188:
189: /**
190: * @param component
191: * The component to set.
192: */
193: public void setMenuItem(JMenuItem menuItem) {
194: this .menuItem = menuItem;
195: }
196:
197: public Component getComponent() {
198: return component;
199: }
200:
201: /**
202: * @param component The component to set.
203: */
204: public void setComponent(Component component) {
205: this.component = component;
206: }
207:
208: }
|