001    /*
002      Copyright (C) 2002 Laurent Martelli.
003    
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful,
010      but WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012      GNU Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public
015      License along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017      USA */
018    
019    package org.objectweb.jac.aspects.gui;
020    
021    import java.util.HashMap;
022    import java.util.List;
023    import java.util.Vector;
024    
025    public class Menu {
026        /** The TOP menu's position */
027        public static final String TOP = "TOP";
028        /** The BOTTOM menu's position */
029        public static final String BOTTOM = "BOTTOM";
030        /** The LEFT menu's position */
031        public static final String LEFT = "LEFT";
032        /** The RIGHT menu's position */
033        public static final String RIGHT = "RIGHT";
034       
035        // key -> [ callback | Menu | null ]
036        HashMap map = new HashMap();
037        // item order
038        Vector keys = new Vector();
039        // icon
040        String icon;
041    
042        /**
043         * Sets the icon of the menu. */
044        public void setIcon(String icon) {
045            this.icon = icon;
046        }
047        /**
048         * Gets the menu icon. */
049        public String getIcon() {
050            return icon;
051        }
052        String position = null;
053        /**
054         * Gets the menu position. */
055        public String getPosition() {
056            return position;
057        }
058        /**
059         * Sets the menu position. */
060        public void setPosition(String position) {
061            this.position = position;
062        }
063        /**
064         * Gets an action or sub-menu from its name. */
065        public Object get(String key) {
066            return map.get(key);
067        }
068        /**
069         * Adds an action or sub-menu. */
070        public void put(String key, Object value) {
071            if (!map.containsKey(key))
072                keys.add(key);
073            map.put(key,value);
074        }
075        /**
076         * Gets the contents of this menu. */
077        public List getKeys() {
078            return keys;
079        }
080        /**
081         * Returns true if this menu contains a given element. */ 
082        public boolean containsKey(String key) {
083            return map.containsKey(key);
084        }
085        /**
086         * Adds a separator in this menu. */
087        public void addSeparator() {
088            keys.add(null);
089        }
090        /**
091         * Returns the items count. */
092        public int size() {
093            return keys.size();
094        }
095    }