1 package org.splat.wapp;
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.HashMap;
13 public class TabBar implements Serializable {
18 private static final long serialVersionUID = 1851786085512439549L;
21 * For making the menu visible as a list of MenuItems.
23 protected transient List<Item> _menu;
25 * Indices of MenuItem objects into this menu.
27 protected transient Map<String,Integer> _indices;
29 * Actions of disabled item.
31 protected transient Map<String,String> _disabled;
35 protected transient String _selection;
37 // ==============================================================================================================================
39 // ==============================================================================================================================
42 * Empty tab bar constuctor.
45 _menu = new ArrayList<Item>();
46 _indices = new HashMap<String,Integer>();
47 _disabled = new HashMap<String,String>();
51 // ==============================================================================================================================
53 // ==============================================================================================================================
55 * Adds an item to this tab-bar.
56 * @param name the name of the item added to this bar.
57 * @param url the added item url
59 public void addItem (final String name, final String url) {
60 _indices.put(name, _menu.size());
61 _menu.add( new Item(name, url) );
65 * Returns the list of items of this tab-bar.
66 * @return the list of items of this bar.
68 public List<Item> asList () {
73 * Disables the item of given name.
74 * @param name the name of the item.
76 public void disables (final String name) {
77 String action = _disabled.get(name);
78 Item item = _menu.get(_indices.get(name));
81 return; // Item already disabled
83 _disabled.put(name, item.getAction()); // Saves the current action for latter enabling
88 * Enables the item of given name, if previously disabled.
89 * @param name the name of the item.
91 public void enables (final String name) {
92 String action = _disabled.get(name);
93 Item item = _menu.get(_indices.get(name));
96 return; // Item not previously disabled
98 _disabled.remove(name);
103 * Returns the name of the currently selected item of this menu previously set by selects().
104 * If no item selected, returns null.
105 * @return the name of the currently selected item of this menu.
107 public String getSelection () {
108 return _selection; // May be null
112 * Sets the given menu-item as selected.
113 * @param name the name of the selected menu-item.
115 public void selects (final String name) {
116 Integer newdex = _indices.get(name);
118 if (_selection != null) {
119 _menu.get(_indices.get(_selection)).unselect();
121 if (newdex == null) {
124 _menu.get(newdex).select();