Salome HOME
SIMAN Eclipse workspace first version
[tools/siman.git] / Workspace / Siman / src / org / splat / wapp / SlidMenu.java
1 package org.splat.wapp;
2
3 import org.splat.wapp.MenuItem.Group;
4
5 /**
6  * Abstract subclass implementing the base services of two levels menus.
7  * SlidMenus are supposed (but not necessarily) behaving as follows:
8  * <ul>
9  * <li>Only one first-level menu-item is open at a time</li>
10  * <li>When selecting a closed first-level item, the actual open one, if exist, is closed before opening the new selected one,
11  * making first-level items "sliding"</li>
12  * </ul>
13  * The SlidMenu is implemented as an ordered flat list of named menu-items of type first-level, so called Group,
14  * and second-level, or SubItem (these both latter are subclasses of MenuItem). SubItems must follow in the list the Group
15  * to which they belong. A first-level item can also be empty (not containing any SubItem), so simply called Item.<br/>
16  * <br/>
17  * As such, a SlidMenu is built by calling, in the appropriate order, addItem(), addGroup() and addSubItem(). As any menu,
18  * after its creation, a SlidMenu is in Unselected state. The user selection is then set (and changed) by the name of its
19  * corresponding menu-item through the selects() function.<br/>
20  * One additional function, clear(), allows concrete subclasses of this abstract class to empty the menu before
21  * rebuilding it following a user selection in the implementation of the overridden selects() function.
22  * 
23  * @author Daniel Brunier-Coulin
24  */
25 abstract public class SlidMenu extends Menu {
26
27 //  ==============================================================================================================================
28 //  Constructors
29 //  ==============================================================================================================================
30
31     public SlidMenu (String name) {
32 //  -----------------------------
33       super(name);
34     }
35     public SlidMenu (String name, String scope) {
36 //  -------------------------------------------
37       super(name, scope);
38     }
39
40 //  ==============================================================================================================================
41 //  Member functions
42 //  ==============================================================================================================================
43
44     public void addGroup (String name, String label, String icon, String url) {
45 //  -------------------------------------------------------------------------
46       this.addItem(name, new MenuItem.Group(label,icon,url) );
47     }
48
49     public void addItem (String name, String label, String icon, String url) {
50 //  ------------------------------------------------------------------------
51       this.addItem(name, new MenuItem(label,icon,url) );
52     }
53
54     public void addSubItem (String name, String label, String icon, String url) {
55 //  ---------------------------------------------------------------------------
56       MenuItem  last = menu.lastElement();
57       if (last instanceof Group) ((Group)last).open();
58
59       this.addItem(name, new MenuItem.SubItem(label,icon,url) );
60     }
61
62 //  ==============================================================================================================================
63 //  Protected services
64 //  ==============================================================================================================================
65
66     protected void clear () {
67 //  -----------------------
68       menu.clear();
69       indices.clear();
70       selection = null;
71     }
72 }