KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > awt > ActionMenu


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20
21 package com.sshtools.ui.awt;
22
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 public class ActionMenu {
29
30     public final static Action SEPARATOR = new AbstractAction("separator") { //$NON-NLS-1$
31
public void actionPerformed(ActionEvent JavaDoc e) {
32         }
33     };
34
35     private int weight;
36     private int mnemonic;
37     private String JavaDoc name;
38     private String JavaDoc displayName;
39     private Vector JavaDoc children;
40     private Vector JavaDoc listeners;
41     private String JavaDoc toolTip;
42
43     private ActionMenu() {
44         // separator
45
}
46
47     public ActionMenu(String JavaDoc name, String JavaDoc displayName, int mnemonic, int weight, String JavaDoc toolTip) {
48         this.name = name;
49         this.displayName = displayName;
50         this.mnemonic = mnemonic;
51         this.weight = weight;
52         this.toolTip = toolTip;
53         children = new Vector JavaDoc();
54     }
55     
56     public String JavaDoc getToolTip() {
57         return toolTip;
58     }
59     
60     public void setToolTip() {
61         this.toolTip = toolTip;
62     }
63
64     public int compareTo(Object JavaDoc o) {
65         double oweight = ((ActionMenu) o).weight;
66         return (weight < oweight ? -1 : (weight == oweight ? 0 : 1));
67     }
68
69     /**
70      * @return Returns the displayName.
71      */

72
73     public String JavaDoc getDisplayName() {
74         return displayName;
75     }
76
77     /**
78      * @param displayName
79      * The displayName to set.
80      */

81
82     public void setDisplayName(String JavaDoc displayName) {
83         this.displayName = displayName;
84     }
85
86     /**
87      * @return Returns the mnemonic.
88      */

89
90     public int getMnemonic() {
91         return mnemonic;
92     }
93
94     /**
95      * @param mnemonic
96      * The mnemonic to set.
97      */

98
99     public void setMnemonic(int mnemonic) {
100         this.mnemonic = mnemonic;
101     }
102
103     /**
104      * @return Returns the name.
105      */

106
107     public String JavaDoc getName() {
108         return name;
109     }
110
111     /**
112      * @param name
113      * The name to set.
114      */

115
116     public void setName(String JavaDoc name) {
117         this.name = name;
118     }
119
120     /**
121      * @return Returns the weight.
122      */

123
124     public int getWeight() {
125         return weight;
126     }
127
128     /**
129      * @param weight
130      * The weight to set.
131      */

132
133     public void setWeight(int weight) {
134         this.weight = weight;
135     }
136
137     /**
138      *
139      */

140     public void addSeparator() {
141         children.addElement(SEPARATOR);
142     }
143
144     /**
145      * @param item
146      */

147     public void add(Action item) {
148         children.addElement(item);
149     }
150
151     /**
152      * @return
153      */

154     public Enumeration JavaDoc children() {
155         return children.elements();
156     }
157
158     /**
159      * @return
160      */

161     public int getChildCount() {
162         return children.size();
163     }
164     
165     public void addActionListener(ActionListener JavaDoc l) {
166         if (listeners == null) {
167             listeners = new Vector JavaDoc();
168         }
169         listeners.addElement(l);
170     }
171
172     public void removeActionListener(ActionListener JavaDoc l) {
173         if (listeners != null) {
174             listeners.removeElement(l);
175         }
176     }
177
178     public boolean action() {
179         ActionEvent JavaDoc evt = null;
180         for (int i = listeners == null ? -1 : listeners.size() - 1; i >= 0; i--) {
181             if (evt == null) {
182                 evt = new ActionEvent JavaDoc(this, 1001, getName());
183             }
184             ((ActionListener JavaDoc) listeners.elementAt(i)).actionPerformed(evt);
185         }
186         return false;
187     }
188
189     /**
190      * @param clicked
191      * @return
192      */

193     public Action getChild(int clicked) {
194         return (Action)children.elementAt(clicked);
195     }
196
197     /**
198      *
199      */

200     public void removeAllChildren() {
201         children.removeAllElements();
202     }
203
204 }
Popular Tags