KickJava   Java API By Example, From Geeks To Geeks.

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


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.Component JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 import javax.swing.Action JavaDoc;
25 import javax.swing.JMenuItem JavaDoc;
26
27 /**
28  * Menu element.
29  *
30  * @author fdietz
31  */

32 public class MenuElement implements IMenuElement {
33
34     private int type;
35
36     private Action JavaDoc action;
37
38     private String JavaDoc placeholderId;
39
40     private String JavaDoc menuId;
41
42     private String JavaDoc menuLabel;
43
44     private IMenuElement parent;
45
46     private JMenuItem JavaDoc menuItem;
47     
48     private Component JavaDoc component;
49
50     private Vector JavaDoc children = new Vector JavaDoc();
51
52     public MenuElement(int type) {
53         this.type = type;
54     }
55
56     public boolean isSeparator() {
57         return type == TYPE_SEPARATOR ? true : false;
58     }
59
60     public boolean isAction() {
61         return type == TYPE_ACTION ? true : false;
62     }
63
64     public boolean isPlaceholder() {
65         return type == TYPE_PLACEHOLDER ? true : false;
66     }
67
68     public boolean isMenu() {
69         return type == TYPE_MENU ? true : false;
70     }
71
72     public boolean isComponent() {
73         return type == TYPE_MENUITEM ? true : false;
74     }
75
76     /**
77      * @return Returns the action.
78      */

79     public Action JavaDoc getAction() {
80         return action;
81     }
82
83     /**
84      * @return Returns the placeholderId.
85      */

86     public String JavaDoc getPlaceholderId() {
87         return placeholderId;
88     }
89
90     public IMenuElement getParent() {
91         return parent;
92     }
93
94     public Enumeration JavaDoc getChildren() {
95         return children.elements();
96     }
97
98     public void add(IMenuElement child) {
99         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 JavaDoc getMenuId() {
119         return menuId;
120     }
121
122     /**
123      * @param menuId
124      * The menuId to set.
125      */

126     public void setMenuId(String JavaDoc menuId) {
127         this.menuId = menuId;
128     }
129
130     /**
131      * @param action
132      * The action to set.
133      */

134     public void setAction(Action JavaDoc action) {
135         this.action = action;
136     }
137
138     /**
139      * @param placeholderId
140      * The placeholderId to set.
141      */

142     public void setPlaceholderId(String JavaDoc placeholderId) {
143         this.placeholderId = placeholderId;
144     }
145
146     /**
147      * @return Returns the menuLabel.
148      */

149     public String JavaDoc getMenuLabel() {
150         return menuLabel;
151     }
152
153     /**
154      * @param menuLabel
155      * The menuLabel to set.
156      */

157     public void setMenuLabel(String JavaDoc 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 JavaDoc toString() {
172         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
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 JavaDoc getMenuItem() {
186         return menuItem;
187     }
188
189     /**
190      * @param component
191      * The component to set.
192      */

193     public void setMenuItem(JMenuItem JavaDoc menuItem) {
194         this.menuItem = menuItem;
195     }
196
197     public Component JavaDoc getComponent() {
198         return component;
199     }
200
201     /**
202      * @param component The component to set.
203      */

204     public void setComponent(Component JavaDoc component) {
205         this.component = component;
206     }
207
208 }
209
Popular Tags