Salome HOME
Addition of a new scenario to a study is fixed. StudyMenu and NewScenarioMenu are...
[tools/siman.git] / Workspace / Siman / src / org / splat / wapp / TabBar.java
1 package org.splat.wapp;
2
3 import java.io.Serializable;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Vector;
7
8
9 public class TabBar implements Serializable {
10
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;
15
16         /**
17          * Serial version ID.
18          */
19         private static final long serialVersionUID = 1851786085512439549L;
20
21 //  ==============================================================================================================================
22 //  Constructor
23 //  ==============================================================================================================================
24
25     public TabBar () {
26 //  ----------------
27       menu      = new Vector<Item>();
28       indices   = new HashMap<String,Integer>();
29       disabled  = new HashMap<String,String>();
30       selection = null;
31     }
32
33 //  ==============================================================================================================================
34 //  Member functions
35 //  ==============================================================================================================================
36 /**
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
40  */
41     public void addItem (String name, String url) {
42 //  ---------------------------------------------
43       indices.put(name, menu.size());
44       menu.add( new Item(name, url) );
45     }
46
47 /**
48  * Returns the list of items of this tab-bar.
49  * @return the list of items of this bar.
50  */
51     public List<Item> asList () {
52 //  ---------------------------
53       return menu;
54     }
55
56 /**
57  * Disables the item of given name.
58  * @param name the name of the item.
59  */
60     public void disables (String name) {
61 //  ----------------------------------
62       String action = disabled.get(name);
63       Item   item   = menu.get(indices.get(name));
64
65       if (action != null) return;             // Item already disabled
66       disabled.put(name, item.getAction());   // Saves the current action for latter enabling
67       item.action(null);
68     }
69
70 /**
71  * Enables the item of given name, if previously disabled.
72  * @param name the name of the item.
73  */
74     public void enables (String name) {
75 //  ---------------------------------
76       String action = disabled.get(name);
77       Item   item   = menu.get(indices.get(name));
78
79       if (action == null) return;             // Item not previously disabled
80       disabled.remove(name);
81       item.action(action);
82     }
83
84 /**
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.
88  */
89     public String getSelection () {
90 //  -----------------------------
91       return selection;        // May be null
92     }
93
94 /**
95  * Sets the given menu-item as selected.
96  * @param name the name of the selected menu-item.
97  */
98     public void selects (String name) {
99 //  ---------------------------------
100       Integer  newdex = indices.get(name);
101
102       if (selection != null) menu.get(indices.get(selection)).unselect();
103       if (newdex    == null) return;
104       menu.get(newdex).select();
105       selection = name;
106     }
107 }