Salome HOME
Fix of "Remove this version" menu item. Also Logger is replaced by AppLogger.
[tools/siman.git] / Workspace / Siman / src / org / splat / wapp / PopupMenu.java
1 package org.splat.wapp;
2
3 import java.util.List;
4
5 /**
6  * Base popup menu class.
7  */
8 public class PopupMenu extends ContextualMenu {
9
10         // ==============================================================================================================================
11         // Constructor
12         // ==============================================================================================================================
13
14         /**
15          * Default constructor.
16          */
17         public PopupMenu() {
18                 super();
19                 _width = 186; // Includes borders (2px) and shadow (4px)
20                 _height = 2; // Top and bottom border
21         }
22
23         // ==============================================================================================================================
24         // Member functions
25         // ==============================================================================================================================
26
27         /**
28          * Add a menu item.
29          * 
30          * @param name
31          *            the item name
32          * @param item
33          *            the item to add
34          */
35         public void addItem(final String name, final PopupItem item) {
36                 item._width = 180;
37                 item._height = 22; // Height of image.selected.png background image
38                 this._height += item._height;
39                 super.addItem(name, item);
40         }
41
42         /**
43          * Insert an items separator into the menu.
44          */
45         public void addSeparator() {
46                 PopupItem item = new PopupItem();
47                 item._width = 180;
48                 item._height = 8;
49                 this._height += item._height;
50                 super.addItem("", item);
51         }
52
53         /**
54          * Get the menu as a list of menu items.
55          * 
56          * @return the list of menu items
57          */
58         @SuppressWarnings(Constants.UNCHECKED)
59         public List<PopupItem> asList() {
60                 return (List) _items;
61         }
62
63         /**
64          * Get menu item by name.
65          * 
66          * @param name
67          *            the menu item name
68          * @return the menu item
69          */
70         public PopupItem item(final String name) {
71                 return (PopupItem) _items.get(_indices.get(name));
72         }
73
74         /**
75          * Check if this menu contains the given item.
76          * 
77          * @param name
78          *            the item name
79          * @return true if this menu contains the given item.
80          */
81         public boolean hasItem(final String name) {
82                 return _indices.containsKey(name);
83         }
84 }