ProjectElement owner = step.getOwner();
int range = 0;
- for (Iterator<MenuItem> action = menu.iterator(); action.hasNext();) {
+ for (Iterator<MenuItem> action = _menu.iterator(); action.hasNext();) {
MenuItem item = action.next();
String index = item.getAction(); // Returns the above string ended by the selection number
if (!index.endsWith(number))
package org.splat.wapp;
+
/**
* Abstract class implementing the base services of contextual menu such as popup-menus and tool-bars.
*
* @author Daniel Brunier-Coulin
*/
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import java.util.Vector;
-
-
-public abstract class ContextualMenu {
-
- protected int width;
- protected int height;
- protected HashMap<String,Object> context;
- protected List<ContextualItem> items; // Instead of HashMap for being able to see ContextualMenu objects as Lists
- protected HashMap<String,Integer> indices; // Indices of ContextualItem objects into items
-
- private enum Side { Client, Server }; // Side of action execution
- protected static class ContextualItem {
-// -------------------------------------
- private String myname;
- private ContextualMenu owner;
- private Side execute;
- protected int width = 0;
- protected int height = 0;
- protected String myurl = null;
- protected String myicon = null;
- protected String mylabel = null; // Either menu item name or button tooltip
- protected String confirm = null; // Either menu item confirmation message or button argument
-
- public String getAction () {
- return myurl; // Null if not enabled
- }
- public int getHeight () {
- return height;
- }
- public String getIcon () {
- return myicon;
- }
- public int getWidth () {
- return width;
- }
- public boolean isSeparator () {
- return (mylabel == null && myicon == null);
- }
- public void setAction (String url) { // Enables the item
- myurl = url;
- if (url.endsWith(")")) execute = Side.Client; // JavaScript function
- else execute = Side.Server; // URL
- }
- public Boolean isClientSide () {
- if (myurl != null) return (execute == Side.Client);
- return null;
- }
- public boolean isEnabled () {
- return owner.isEnabled(myname); // Delegation to overridden function
- }
- }
-
-// ==============================================================================================================================
-// Construction
-// ==============================================================================================================================
-
- protected ContextualMenu () {
-// ---------------------------
- context = new HashMap<String,Object>();
- items = new Vector<ContextualItem>();
- indices = new HashMap<String,Integer>();
- }
- protected void addItem (String name, ContextualItem item) {
-// ---------------------------------------------------------
- indices.put(name, items.size());
- items.add(item);
- item.myname = name; // Just for delegating isEnabled
- item.owner = this;
- }
-
-// ==============================================================================================================================
-// Member functions
-// ==============================================================================================================================
-
- public int getHeight () {
-// -----------------------
- return height;
- }
-
- public int getWidth () {
-// ----------------------
- return width;
- }
-
- public boolean isEmpty () {
-// -------------------------
- return (items.size() == 0);
- }
-
- public boolean isEnabled (String name) {
-// --------------------------------------
- return (items.get(indices.get(name)).getAction() != null);
- }
-
- public void resetContext (String name) {
-// --------------------------------------
- this.context.remove(name);
- }
-
- public void setContext (String name, Object context) {
-// ----------------------------------------------------
- this.context.put(name, context);
- }
+import java.util.Map;
+
+public class ContextualMenu {
+
+ protected transient int _width;
+ protected transient int _height;
+ protected transient Map<String, Object> _context;
+ protected transient List<ContextualItem> _items; // Instead of HashMap for being able to see ContextualMenu objects as Lists
+ protected transient Map<String, Integer> _indices; // Indices of ContextualItem objects into items
+
+ private enum Side {
+ Client, Server
+ }; // Side of action execution
+
+ protected static class ContextualItem {
+ private transient String _myname;
+ private transient ContextualMenu _owner;
+ private transient Side _execute;
+ protected transient int _width = 0;
+ protected transient int _height = 0;
+ protected String _action = null;
+ protected transient String _myicon = null;
+ protected transient String _mylabel = null; // Either menu item name or button tooltip
+ protected String _confirm = null; // Either menu item confirmation message or button argument
+
+ public String getAction() {
+ return _action; // Null if not enabled
+ }
+
+ public int getHeight() {
+ return _height;
+ }
+
+ public String getIcon() {
+ return _myicon;
+ }
+
+ public int getWidth() {
+ return _width;
+ }
+
+ public boolean isSeparator() {
+ return (_mylabel == null && _myicon == null);
+ }
+
+ public void setAction(final String url) { // Enables the item
+ _action = url;
+ if (url.endsWith(")")) {
+ _execute = Side.Client; // JavaScript function
+ } else {
+ _execute = Side.Server; // URL
+ }
+ }
+
+ public Boolean isClientSide() {
+ Boolean res = null;
+ if (_action != null) {
+ res = (_execute == Side.Client);
+ }
+ return res;
+ }
+
+ public boolean isEnabled() {
+ return _owner.isEnabled(_myname); // Delegation to overridden function
+ }
+ }
+
+ // ==============================================================================================================================
+ // Construction
+ // ==============================================================================================================================
+
+ protected ContextualMenu() {
+ _context = new HashMap<String, Object>();
+ _items = new ArrayList<ContextualItem>();
+ _indices = new HashMap<String, Integer>();
+ }
+
+ protected void addItem(final String name, final ContextualItem item) {
+ _indices.put(name, _items.size());
+ _items.add(item);
+ item._myname = name; // Just for delegating isEnabled
+ item._owner = this;
+ }
+
+ // ==============================================================================================================================
+ // Member functions
+ // ==============================================================================================================================
+
+ public int getHeight() {
+ return _height;
+ }
+
+ public int getWidth() {
+ return _width;
+ }
+
+ public boolean isEmpty() {
+ return _items.isEmpty();
+ }
+
+ public boolean isEnabled(final String name) {
+ return (_items.get(_indices.get(name)).getAction() != null);
+ }
+
+ public void resetContext(final String name) {
+ this._context.remove(name);
+ }
+
+ public void setContext(final String name, final Object context) {
+ this._context.put(name, context);
+ }
}
\ No newline at end of file
public class Item implements Serializable {
- private String mylabel;
- private String myicon;
- private String myurl;
- private boolean selected = false;
+ private transient final String _mylabel;
+ private transient String _myicon;
+ private transient String _action;
+ private transient boolean _selected = false;
/**
* Serial version ID.
// Construction
// ==============================================================================================================================
- public Item (String label) {
-// -------------------------
- mylabel = label;
- myicon = null;
- myurl = null;
+ public Item (final String label) {
+ _mylabel = label;
+ _myicon = null;
+ _action = null;
}
- public Item (String label, String url) {
-// -------------------------------------
- mylabel = label;
- myicon = null;
- myurl = url;
+ public Item (final String label, final String url) {
+ _mylabel = label;
+ _myicon = null;
+ _action = url;
}
- public Item (String label, String icon, String url) {
-// ---------------------------------------------------
- mylabel = label;
- myicon = icon;
- myurl = url;
+ public Item (final String label, final String icon, final String url) {
+ _mylabel = label;
+ _myicon = icon;
+ _action = url;
}
- public Item action (String url) {
-// -------------------------------
- myurl = url;
+ public Item action (final String url) {
+ _action = url;
return this;
}
- public Item icon (String icon) {
-// ------------------------------
- myicon = icon;
+ public Item icon (final String icon) {
+ _myicon = icon;
return this;
}
// ==============================================================================================================================
public String getAction () {
-// --------------------------
- return myurl; // Null if not enabled
+ return _action; // Null if not enabled
}
public String getIcon () {
-// ------------------------
- return myicon;
+ return _myicon;
}
public String getLabel () {
-// -------------------------
- return mylabel;
+ return _mylabel;
}
public boolean isEnabled () {
-// ---------------------------
- return (myurl != null);
+ return (_action != null);
}
public boolean isSelected () {
-// ----------------------------
- return selected;
+ return _selected;
}
protected void select () {
-// ------------------------
- selected = true;
+ _selected = true;
}
protected void unselect () {
-// --------------------------
- selected = false;
+ _selected = false;
}
}
\ No newline at end of file
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Vector;
/**
- * Base abstract class defining the minimal services for implementing menus.<br/>
- * A menu is an ordered list of named menu-items. Each menu-item is made of:
+ * Base abstract class defining the minimal services for implementing menus.<br/> A menu is an ordered list of named menu-items. Each
+ * menu-item is made of:
* <ul>
* <li>A non localized label (a key into a locale file)</li>
* <li>Optionally, an icon (an image file name)</li>
* <li>A command to be executed when selecting this menu-item</li>
* </ul>
- * On the contrary of PopupMenus, Menus are not contextual, that is, their items are always active, and can keep the user
- * selection.<br/>
- * After its creation, a menu is in Unselected state - the getSelection() method returns null. The user selection is then
- * set (and changed) by the name of its corresponding menu-item, thus making getSelection() returning this name.<br/>
- * <br/>
- * The commands of menu-items are in an application-dependent format. They can be undefined, for example in a demonstration
- * version of the application, making the corresponding menu-items disabled.<br/>
- * <br/>
- * Menus are visible by the application as Lists (from java.util) for allowing their display.
+ * On the contrary of PopupMenus, Menus are not contextual, that is, their items are always active, and can keep the user selection.<br/>
+ * After its creation, a menu is in Unselected state - the getSelection() method returns null. The user selection is then set (and changed)
+ * by the name of its corresponding menu-item, thus making getSelection() returning this name.<br/> <br/> The commands of menu-items are in
+ * an application-dependent format. They can be undefined, for example in a demonstration version of the application, making the
+ * corresponding menu-items disabled.<br/> <br/> Menus are visible by the application as Lists (from java.util) for allowing their display.
*
* @see MenuItem
* @see ContextualMenu
* @author Daniel Brunier-Coulin
*/
-public abstract class Menu {
-
- private String myname;
- private String myscope;
- protected Vector<MenuItem> menu; // For making the menu visible as a list of MenuItems
- protected HashMap<String,Integer> indices; // Indices of MenuItem objects into this menu
- protected HashMap<String,String> disabled; // Actions of disabled item
- protected String selection = null;
-
-// ==============================================================================================================================
-// Constructors
-// ==============================================================================================================================
-
- protected Menu (String name) {
-// ----------------------------
- myname = name;
- myscope = "/";
- menu = new Vector<MenuItem>();
- indices = new HashMap<String,Integer>();
- disabled = new HashMap<String,String>();
- }
- protected Menu (String name, String scope) {
-// ------------------------------------------
- myname = name;
- myscope = "/" + scope;
- menu = new Vector<MenuItem>();
- indices = new HashMap<String,Integer>();
- disabled = new HashMap<String,String>();
- }
-
- /**
- * Initialize the menu.
- */
- protected void init() {
- menu.clear();
- indices.clear();
- disabled.clear();
- }
-// ==============================================================================================================================
-// Member functions
-// ==============================================================================================================================
-/**
- * Adds an item to this menu.
- * @param name the name of the item added to this menu
- * @param item the added item
- */
- public void addItem (String name, MenuItem item) {
-// ------------------------------------------------
- indices.put(name, menu.size());
- menu.add(item);
- }
-/**
- * Returns the list of items of this menu.
- * @return the list of items of this menu.
- */
- public List<MenuItem> asList () {
-// -------------------------------
- return menu;
- }
-/**
- * Disables the menu item of given name.
- * @param name the name of the item
- */
- public void disables (String name) {
-// ----------------------------------
- String action = disabled.get(name);
- MenuItem item = menu.get(indices.get(name));
-
- if (action != null) return; // Item already disabled
- disabled.put(name, item.getAction()); // Saves the current action for latter enabling
- item.action(null);
- }
-/**
- * Enables the menu item of given name, if previously disabled.
- * @param name the name of the item
- */
- public void enables (String name) {
-// ---------------------------------
- String action = disabled.get(name);
- MenuItem item = menu.get(indices.get(name));
-
- if (action == null) return; // Item not previously disabled
- disabled.remove(name);
- item.action(action);
- }
-/**
- * Returns the name of this menu.
- * @return the name of this menu.
- */
- public String getName () {
-// ------------------------
- return myname;
- }
-/**
- * Returns the namespace of this menu.
- * @return the namespace of this menu.
- */
- public String getNamespace () {
-// -----------------------------
- return myscope;
- }
-/**
- * Returns the currently selected item of this menu previously set by selects().
- * @return the currently selected item of this menu.
- */
- public MenuItem getSelectedItem () {
-// ----------------------------------
- return menu.get(indices.get(selection));
- }
-/**
- * Returns the name of the currently selected item of this menu previously set by selects().
- * If no item selected, returns null.
- * @return the name of the currently selected item of this menu.
- */
- public String getSelection () {
-// -----------------------------
- return selection; // May be null
- }
-/**
- * Sets the given menu-item as selected.
- * @param name the name of the selected menu-item.
- */
- public void selects (String name) {
-// ---------------------------------
- Integer newdex = indices.get(name);
-
- if (selection != null) menu.get(indices.get(selection)).unselect();
- if (newdex == null) return;
- menu.get(newdex).select();
- selection = name;
- }
+public class Menu {
+
+ private transient final String _myname;
+ private transient final String _myscope;
+ /**
+ * For making the menu visible as a list of MenuItems.
+ */
+ protected transient Vector<MenuItem> _menu; // RKV: NOPMD: Because of usage of lastElement() method in void
+ // org.splat.wapp.SlidMenu.addSubItem(String name, String label, String icon, String url)
+ /**
+ * Indices of MenuItem objects into this menu.
+ */
+ protected transient Map<String, Integer> _indices;
+ /**
+ * Actions of disabled item.
+ */
+ protected transient Map<String, String> _disabled;
+ protected transient String _selection = null;
+
+ // ==============================================================================================================================
+ // Constructors
+ // ==============================================================================================================================
+
+ protected Menu(final String name) {
+ _myname = name;
+ _myscope = "/";
+ _menu = new Vector<MenuItem>();
+ _indices = new HashMap<String, Integer>();
+ _disabled = new HashMap<String, String>();
+ }
+
+ protected Menu(final String name, final String scope) {
+ _myname = name;
+ _myscope = "/" + scope;
+ _menu = new Vector<MenuItem>();
+ _indices = new HashMap<String, Integer>();
+ _disabled = new HashMap<String, String>();
+ }
+
+ /**
+ * Initialize the menu.
+ */
+ protected void init() {
+ _menu.clear();
+ _indices.clear();
+ _disabled.clear();
+ }
+
+ // ==============================================================================================================================
+ // Member functions
+ // ==============================================================================================================================
+ /**
+ * Adds an item to this menu.
+ *
+ * @param name
+ * the name of the item added to this menu
+ * @param item
+ * the added item
+ */
+ public void addItem(final String name, final MenuItem item) {
+ _indices.put(name, _menu.size());
+ _menu.add(item);
+ }
+
+ /**
+ * Returns the list of items of this menu.
+ *
+ * @return the list of items of this menu.
+ */
+ public List<MenuItem> asList() {
+ return _menu;
+ }
+
+ /**
+ * Disables the menu item of given name.
+ *
+ * @param name
+ * the name of the item
+ */
+ public void disables(final String name) {
+ String action = _disabled.get(name);
+ MenuItem item = _menu.get(_indices.get(name));
+
+ if (action == null) { // Item not previously disabled
+ _disabled.put(name, item.getAction()); // Saves the current action for latter enabling
+ item.action(null);
+ }
+ }
+
+ /**
+ * Enables the menu item of given name, if previously disabled.
+ *
+ * @param name
+ * the name of the item
+ */
+ public void enables(final String name) {
+ String action = _disabled.get(name);
+ MenuItem item = _menu.get(_indices.get(name));
+
+ if (action != null) { // Item already disabled
+ _disabled.remove(name);
+ item.action(action);
+ }
+ }
+
+ /**
+ * Returns the name of this menu.
+ *
+ * @return the name of this menu.
+ */
+ public String getName() {
+ return _myname;
+ }
+
+ /**
+ * Returns the namespace of this menu.
+ *
+ * @return the namespace of this menu.
+ */
+ public String getNamespace() {
+ return _myscope;
+ }
+
+ /**
+ * Returns the currently selected item of this menu previously set by selects().
+ *
+ * @return the currently selected item of this menu.
+ */
+ public MenuItem getSelectedItem() {
+ return _menu.get(_indices.get(_selection));
+ }
+
+ /**
+ * Returns the name of the currently selected item of this menu previously set by selects(). If no item selected, returns null.
+ *
+ * @return the name of the currently selected item of this menu.
+ */
+ public String getSelection() {
+ return _selection; // May be null
+ }
+
+ /**
+ * Sets the given menu-item as selected.
+ *
+ * @param name
+ * the name of the selected menu-item.
+ */
+ public void selects(final String name) {
+ Integer newdex = _indices.get(name);
+
+ if (_selection != null) {
+ _menu.get(_indices.get(_selection)).unselect();
+ }
+ if (newdex != null) {
+ _menu.get(newdex).select();
+ _selection = name;
+ }
+ }
}
\ No newline at end of file
package org.splat.wapp;
-
public class MenuItem extends Item {
- private static final long serialVersionUID = 1002251657309138413L;
+ private static final long serialVersionUID = 1002251657309138413L;
protected static class Group extends MenuItem {
-// ---------------------------------------------
- private boolean open = false;
- /**
- * Serial version ID.
- */
- private static final long serialVersionUID = 8319750643667219000L;
-
- protected Group (String label) { super(label); }
- protected Group (String label, String icon, String url) { super(label, icon, url); }
-
- public boolean isOpen () { return open; }
- public void open () { open = true; }
- }
- protected static class SubItem extends MenuItem {
-// -----------------------------------------------
- /**
- * Serial version ID.
- */
- private static final long serialVersionUID = -4793172296421132566L;
-
- protected SubItem (String label) { super(label); }
- protected SubItem (String label, String icon, String url) { super(label, icon, url); }
- }
-
-// ==============================================================================================================================
-// Construction
-// ==============================================================================================================================
-
- public MenuItem (String label) {
-// ------------------------------
- super(label);
- }
- public MenuItem (String label, String icon, String url) {
-// -------------------------------------------------------
- super(label, url);
- this.icon(icon);
- }
- public MenuItem action (String url) {
-// -----------------------------------
- super.action(url);
- return this;
- }
- public MenuItem icon (String icon) {
-// ----------------------------------
- super.icon(icon);
- return this;
- }
-
-// ==============================================================================================================================
-// Member functions
-// ==============================================================================================================================
-
- public boolean isGroup () {
-// -------------------------
- return (this instanceof Group);
- }
-
- public boolean isOpen () {
-// ------------------------
- return false; // Redefined in the Group subclass
- }
-
- public boolean isSubItem () {
-// ---------------------------
- return (this instanceof SubItem);
- }
+ private transient boolean _open = false;
+ /**
+ * Serial version ID.
+ */
+ private static final long serialVersionUID = 8319750643667219000L;
+
+ protected Group(final String label) {
+ super(label);
+ }
+
+ protected Group(final String label, final String icon, final String url) {
+ super(label, icon, url);
+ }
+
+ @Override
+ public boolean isOpen() {
+ return _open;
+ }
+
+ public void open() {
+ _open = true;
+ }
+ }
+
+ protected static class SubItem extends MenuItem {
+ /**
+ * Serial version ID.
+ */
+ private static final long serialVersionUID = -4793172296421132566L;
+
+ protected SubItem(final String label) {
+ super(label);
+ }
+
+ protected SubItem(final String label, final String icon, final String url) {
+ super(label, icon, url);
+ }
+ }
+
+ // ==============================================================================================================================
+ // Construction
+ // ==============================================================================================================================
+
+ public MenuItem(final String label) {
+ super(label);
+ }
+
+ public MenuItem(final String label, final String icon, final String url) {
+ super(label, url);
+ this.icon(icon);
+ }
+
+ @Override
+ public MenuItem action(final String url) {
+ super.action(url);
+ return this;
+ }
+
+ @Override
+ final public MenuItem icon(final String icon) {
+ super.icon(icon);
+ return this;
+ }
+
+ // ==============================================================================================================================
+ // Member functions
+ // ==============================================================================================================================
+
+ public boolean isGroup() {
+ return (this instanceof Group);
+ }
+
+ public boolean isOpen() {
+ return false; // Redefined in the Group subclass
+ }
+
+ public boolean isSubItem() {
+ return (this instanceof SubItem);
+ }
}
\ No newline at end of file
}
public PopupItem (String label) {
// -------------------------------
- mylabel = label;
- myicon = "image.hold.gif"; // Default icon
+ _mylabel = label;
+ _myicon = "image.hold.gif"; // Default icon
}
// Optional attributes
public PopupItem action (String url) { // Enables the item
}
public PopupItem confirmation (String message) {
// ----------------------------------------------
- confirm = message;
+ _confirm = message;
return this;
}
public PopupItem icon (String icon) {
// -----------------------------------
- myicon = icon;
+ _myicon = icon;
return this;
}
public PopupItem rename (String label) {
// --------------------------------------
- mylabel = label;
+ _mylabel = label;
return this;
}
public String getConfirmationMessage () {
// ---------------------------------------
- return confirm; // Null if does not need any confirmation
+ return _confirm; // Null if does not need any confirmation
}
public String getLabel () {
// ------------------------
- return mylabel; // Null if this is a separator
+ return _mylabel; // Null if this is a separator
}
public boolean needConfirmation () {
// ----------------------------------
- return (confirm != null);
+ return (_confirm != null);
}
}
\ No newline at end of file
public PopupMenu () {
// -------------------
- width = 186; // Includes borders (2px) and shadow (4px)
- height = 2; // Top and bottom border
+ _width = 186; // Includes borders (2px) and shadow (4px)
+ _height = 2; // Top and bottom border
}
// ==============================================================================================================================
public void addItem (String name, PopupItem item) {
// -------------------------------------------------
- item.width = 180;
- item.height = 22; // Height of image.selected.png background image
- this.height += item.height;
+ item._width = 180;
+ item._height = 22; // Height of image.selected.png background image
+ this._height += item._height;
super.addItem(name, item);
}
public void addSeparator () {
// ---------------------------
PopupItem item = new PopupItem();
- item.width = 180;
- item.height = 8;
- this.height += item.height;
+ item._width = 180;
+ item._height = 8;
+ this._height += item._height;
super.addItem("", item);
}
@SuppressWarnings({"rawtypes","unchecked"})
public List<PopupItem> asList () {
// --------------------------------
- return (List)items;
+ return (List)_items;
}
public PopupItem item (String name) {
// -----------------------------------
- return (PopupItem)items.get(indices.get(name));
+ return (PopupItem)_items.get(_indices.get(name));
}
}
\ No newline at end of file
*
* @author Daniel Brunier-Coulin
*/
-abstract public class SlidMenu extends Menu {
+public class SlidMenu extends Menu {
// ==============================================================================================================================
// Constructors
// ==============================================================================================================================
- public SlidMenu (String name) {
+ public SlidMenu (final String name) {
// -----------------------------
super(name);
}
- public SlidMenu (String name, String scope) {
+ public SlidMenu (final String name, final String scope) {
// -------------------------------------------
super(name, scope);
}
// Member functions
// ==============================================================================================================================
- public void addGroup (String name, String label, String icon, String url) {
+ public void addGroup (final String name, final String label, final String icon, final String url) {
// -------------------------------------------------------------------------
this.addItem(name, new MenuItem.Group(label,icon,url) );
}
- public void addItem (String name, String label, String icon, String url) {
+ public void addItem (final String name, final String label, final String icon, final String url) {
// ------------------------------------------------------------------------
this.addItem(name, new MenuItem(label,icon,url) );
}
- public void addSubItem (String name, String label, String icon, String url) {
+ public void addSubItem (final String name, final String label, final String icon, final String url) {
// ---------------------------------------------------------------------------
- MenuItem last = menu.lastElement();
- if (last instanceof Group) ((Group)last).open();
+ MenuItem last = _menu.lastElement();
+ if (last instanceof Group) {
+ ((Group)last).open();
+ }
this.addItem(name, new MenuItem.SubItem(label,icon,url) );
}
protected void clear () {
// -----------------------
- menu.clear();
- indices.clear();
- selection = null;
+ _menu.clear();
+ _indices.clear();
+ _selection = null;
}
}
\ No newline at end of file
package org.splat.wapp;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import java.util.Vector;
+import java.util.Map;
+/**
+ * Tab bar class.
+ */
public class TabBar implements Serializable {
- protected Vector<Item> menu; // For making the menu visible as a list of MenuItems
- protected HashMap<String,Integer> indices; // Indices of MenuItem objects into this menu
- protected HashMap<String,String> disabled; // Actions of disabled item
- protected String selection;
-
/**
* Serial version ID.
*/
private static final long serialVersionUID = 1851786085512439549L;
+ /**
+ * For making the menu visible as a list of MenuItems.
+ */
+ protected transient List<Item> _menu;
+ /**
+ * Indices of MenuItem objects into this menu.
+ */
+ protected transient Map<String,Integer> _indices;
+ /**
+ * Actions of disabled item.
+ */
+ protected transient Map<String,String> _disabled;
+ /**
+ * Selected item id.
+ */
+ protected transient String _selection;
+
// ==============================================================================================================================
// Constructor
// ==============================================================================================================================
+ /**
+ * Empty tab bar constuctor.
+ */
public TabBar () {
-// ----------------
- menu = new Vector<Item>();
- indices = new HashMap<String,Integer>();
- disabled = new HashMap<String,String>();
- selection = null;
+ _menu = new ArrayList<Item>();
+ _indices = new HashMap<String,Integer>();
+ _disabled = new HashMap<String,String>();
+ _selection = null;
}
// ==============================================================================================================================
/**
* Adds an item to this tab-bar.
* @param name the name of the item added to this bar.
- * @param item the added item
+ * @param url the added item url
*/
- public void addItem (String name, String url) {
-// ---------------------------------------------
- indices.put(name, menu.size());
- menu.add( new Item(name, url) );
+ public void addItem (final String name, final String url) {
+ _indices.put(name, _menu.size());
+ _menu.add( new Item(name, url) );
}
/**
* @return the list of items of this bar.
*/
public List<Item> asList () {
-// ---------------------------
- return menu;
+ return _menu;
}
/**
* Disables the item of given name.
* @param name the name of the item.
*/
- public void disables (String name) {
-// ----------------------------------
- String action = disabled.get(name);
- Item item = menu.get(indices.get(name));
-
- if (action != null) return; // Item already disabled
- disabled.put(name, item.getAction()); // Saves the current action for latter enabling
+ public void disables (final String name) {
+ String action = _disabled.get(name);
+ Item item = _menu.get(_indices.get(name));
+
+ if (action != null) {
+ return; // Item already disabled
+ }
+ _disabled.put(name, item.getAction()); // Saves the current action for latter enabling
item.action(null);
}
* Enables the item of given name, if previously disabled.
* @param name the name of the item.
*/
- public void enables (String name) {
-// ---------------------------------
- String action = disabled.get(name);
- Item item = menu.get(indices.get(name));
-
- if (action == null) return; // Item not previously disabled
- disabled.remove(name);
+ public void enables (final String name) {
+ String action = _disabled.get(name);
+ Item item = _menu.get(_indices.get(name));
+
+ if (action == null) {
+ return; // Item not previously disabled
+ }
+ _disabled.remove(name);
item.action(action);
}
* @return the name of the currently selected item of this menu.
*/
public String getSelection () {
-// -----------------------------
- return selection; // May be null
+ return _selection; // May be null
}
/**
* Sets the given menu-item as selected.
* @param name the name of the selected menu-item.
*/
- public void selects (String name) {
-// ---------------------------------
- Integer newdex = indices.get(name);
-
- if (selection != null) menu.get(indices.get(selection)).unselect();
- if (newdex == null) return;
- menu.get(newdex).select();
- selection = name;
+ public void selects (final String name) {
+ Integer newdex = _indices.get(name);
+
+ if (_selection != null) {
+ _menu.get(_indices.get(_selection)).unselect();
+ }
+ if (newdex == null) {
+ return;
+ }
+ _menu.get(newdex).select();
+ _selection = name;
}
}
\ No newline at end of file
public ToolBar (int size) {
// -------------------------
- width = 0;
- height = size;
+ _width = 0;
+ _height = size;
}
// ==============================================================================================================================
public void addTool (String name, ToolButton item) {
// --------------------------------------------------
- item.width = this.height;
- item.height = this.height;
- this.width += item.width;
- if (!this.isEmpty()) width += 6; // Gap between icons
+ item._width = this._height;
+ item._height = this._height;
+ this._width += item._width;
+ if (!this.isEmpty()) _width += 6; // Gap between icons
super.addItem(name, item);
}
public void addSeparator () {
// ---------------------------
- width += 6;
+ _width += 6;
super.addItem("", new ToolButton());
}
@SuppressWarnings({"rawtypes","unchecked"})
public List<ToolButton> asList () {
// ---------------------------------
- return (List)items;
+ return (List)_items;
}
public ToolButton item (String name) {
// ------------------------------------
- return (ToolButton)items.get(indices.get(name));
+ return (ToolButton)_items.get(_indices.get(name));
}
}
\ No newline at end of file
}
public ToolButton (String icon) {
// -------------------------------
- myicon = icon;
+ _myicon = icon;
}
// Optional attributes
public ToolButton action (String url) { // Enables the item
}
public ToolButton argument (String arg) { // In case of tool-bar button only
// ---------------------------------------
- confirm = arg;
+ _confirm = arg;
return this;
}
public ToolButton tooltip (String name) {
// -----------------------------------------
- mylabel = name;
+ _mylabel = name;
return this;
}
public String getArgument () {
// ----------------------------
- return confirm; // Null if does no argument
+ return _confirm; // Null if does no argument
}
public String getTooltip () { // Null if this is a separator
// ---------------------------
- return mylabel;
+ return _mylabel;
}
}
\ No newline at end of file