1 package org.splat.wapp;
3 import java.io.Serializable;
4 import java.util.HashMap;
6 import java.util.Vector;
9 public class TabBar implements Serializable {
11 protected Vector<Item> menu; // For making the menu visible as a list of MenuItems
12 protected HashMap<String,Integer> indices; // Indices of MenuItem objects into this menu
13 protected HashMap<String,String> disabled; // Actions of disabled item
14 protected String selection;
19 private static final long serialVersionUID = 1851786085512439549L;
21 // ==============================================================================================================================
23 // ==============================================================================================================================
27 menu = new Vector<Item>();
28 indices = new HashMap<String,Integer>();
29 disabled = new HashMap<String,String>();
33 // ==============================================================================================================================
35 // ==============================================================================================================================
37 * Adds an item to this tab-bar.
38 * @param name the name of the item added to this bar.
39 * @param item the added item
41 public void addItem (String name, String url) {
42 // ---------------------------------------------
43 indices.put(name, menu.size());
44 menu.add( new Item(name, url) );
48 * Returns the list of items of this tab-bar.
49 * @return the list of items of this bar.
51 public List<Item> asList () {
52 // ---------------------------
57 * Disables the item of given name.
58 * @param name the name of the item.
60 public void disables (String name) {
61 // ----------------------------------
62 String action = disabled.get(name);
63 Item item = menu.get(indices.get(name));
65 if (action != null) return; // Item already disabled
66 disabled.put(name, item.getAction()); // Saves the current action for latter enabling
71 * Enables the item of given name, if previously disabled.
72 * @param name the name of the item.
74 public void enables (String name) {
75 // ---------------------------------
76 String action = disabled.get(name);
77 Item item = menu.get(indices.get(name));
79 if (action == null) return; // Item not previously disabled
80 disabled.remove(name);
85 * Returns the name of the currently selected item of this menu previously set by selects().
86 * If no item selected, returns null.
87 * @return the name of the currently selected item of this menu.
89 public String getSelection () {
90 // -----------------------------
91 return selection; // May be null
95 * Sets the given menu-item as selected.
96 * @param name the name of the selected menu-item.
98 public void selects (String name) {
99 // ---------------------------------
100 Integer newdex = indices.get(name);
102 if (selection != null) menu.get(indices.get(selection)).unselect();
103 if (newdex == null) return;
104 menu.get(newdex).select();