KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > Menu


1 /*
2   Copyright (C) 2002 Laurent Martelli.
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.aspects.gui;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 public class Menu {
26     /** The TOP menu's position */
27     public static final String JavaDoc TOP = "TOP";
28     /** The BOTTOM menu's position */
29     public static final String JavaDoc BOTTOM = "BOTTOM";
30     /** The LEFT menu's position */
31     public static final String JavaDoc LEFT = "LEFT";
32     /** The RIGHT menu's position */
33     public static final String JavaDoc RIGHT = "RIGHT";
34    
35     // key -> [ callback | Menu | null ]
36
HashMap JavaDoc map = new HashMap JavaDoc();
37     // item order
38
Vector JavaDoc keys = new Vector JavaDoc();
39     // icon
40
String JavaDoc icon;
41
42     /**
43      * Sets the icon of the menu. */

44     public void setIcon(String JavaDoc icon) {
45         this.icon = icon;
46     }
47     /**
48      * Gets the menu icon. */

49     public String JavaDoc getIcon() {
50         return icon;
51     }
52     String JavaDoc position = null;
53     /**
54      * Gets the menu position. */

55     public String JavaDoc getPosition() {
56         return position;
57     }
58     /**
59      * Sets the menu position. */

60     public void setPosition(String JavaDoc position) {
61         this.position = position;
62     }
63     /**
64      * Gets an action or sub-menu from its name. */

65     public Object JavaDoc get(String JavaDoc key) {
66         return map.get(key);
67     }
68     /**
69      * Adds an action or sub-menu. */

70     public void put(String JavaDoc key, Object JavaDoc value) {
71         if (!map.containsKey(key))
72             keys.add(key);
73         map.put(key,value);
74     }
75     /**
76      * Gets the contents of this menu. */

77     public List JavaDoc getKeys() {
78         return keys;
79     }
80     /**
81      * Returns true if this menu contains a given element. */

82     public boolean containsKey(String JavaDoc key) {
83         return map.containsKey(key);
84     }
85     /**
86      * Adds a separator in this menu. */

87     public void addSeparator() {
88         keys.add(null);
89     }
90     /**
91      * Returns the items count. */

92     public int size() {
93         return keys.size();
94     }
95 }
96
Popular Tags