From: rkv Date: Wed, 7 Nov 2012 15:27:17 +0000 (+0000) Subject: Modifications to respect PMD rules. X-Git-Tag: Root_Delivery1_2012_12_06~88 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6d0775649db16e00427fb4461fa6c138d63c152a;p=tools%2Fsiman.git Modifications to respect PMD rules. --- diff --git a/Workspace/Siman/src/org/splat/simer/StudyMenu.java b/Workspace/Siman/src/org/splat/simer/StudyMenu.java index b54f4c7..022b957 100644 --- a/Workspace/Siman/src/org/splat/simer/StudyMenu.java +++ b/Workspace/Siman/src/org/splat/simer/StudyMenu.java @@ -218,7 +218,7 @@ public class StudyMenu extends SlidMenu { ProjectElement owner = step.getOwner(); int range = 0; - for (Iterator action = menu.iterator(); action.hasNext();) { + for (Iterator 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)) diff --git a/Workspace/Siman/src/org/splat/wapp/ContextualMenu.java b/Workspace/Siman/src/org/splat/wapp/ContextualMenu.java index bd67eff..a32b858 100644 --- a/Workspace/Siman/src/org/splat/wapp/ContextualMenu.java +++ b/Workspace/Siman/src/org/splat/wapp/ContextualMenu.java @@ -1,4 +1,5 @@ package org.splat.wapp; + /** * Abstract class implementing the base services of contextual menu such as popup-menus and tool-bars. * @@ -6,110 +7,118 @@ package org.splat.wapp; * @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 context; - protected List items; // Instead of HashMap for being able to see ContextualMenu objects as Lists - protected HashMap 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(); - items = new Vector(); - indices = new HashMap(); - } - 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 _context; + protected transient List _items; // Instead of HashMap for being able to see ContextualMenu objects as Lists + protected transient Map _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(); + _items = new ArrayList(); + _indices = new HashMap(); + } + + 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 diff --git a/Workspace/Siman/src/org/splat/wapp/Item.java b/Workspace/Siman/src/org/splat/wapp/Item.java index e68dc43..8d3aa28 100644 --- a/Workspace/Siman/src/org/splat/wapp/Item.java +++ b/Workspace/Siman/src/org/splat/wapp/Item.java @@ -5,10 +5,10 @@ import java.io.Serializable; 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. @@ -19,32 +19,27 @@ public class Item implements Serializable { // 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; } @@ -53,37 +48,30 @@ public class Item implements Serializable { // ============================================================================================================================== 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 diff --git a/Workspace/Siman/src/org/splat/wapp/Menu.java b/Workspace/Siman/src/org/splat/wapp/Menu.java index d8b25ba..40a4f1c 100644 --- a/Workspace/Siman/src/org/splat/wapp/Menu.java +++ b/Workspace/Siman/src/org/splat/wapp/Menu.java @@ -2,159 +2,183 @@ package org.splat.wapp; 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.
- * 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.
A menu is an ordered list of named menu-items. Each + * menu-item is made of: *
    *
  • A non localized label (a key into a locale file)
  • *
  • Optionally, an icon (an image file name)
  • *
  • A command to be executed when selecting this menu-item
  • *
- * On the contrary of PopupMenus, Menus are not contextual, that is, their items are always active, and can keep the user - * selection.
- * 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.
- *
- * 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.
- *
- * 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.
+ * 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.

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.

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 menu; // For making the menu visible as a list of MenuItems - protected HashMap indices; // Indices of MenuItem objects into this menu - protected HashMap disabled; // Actions of disabled item - protected String selection = null; - -// ============================================================================================================================== -// Constructors -// ============================================================================================================================== - - protected Menu (String name) { -// ---------------------------- - myname = name; - myscope = "/"; - menu = new Vector(); - indices = new HashMap(); - disabled = new HashMap(); - } - protected Menu (String name, String scope) { -// ------------------------------------------ - myname = name; - myscope = "/" + scope; - menu = new Vector(); - indices = new HashMap(); - disabled = new HashMap(); - } - - /** - * 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 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 _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 _indices; + /** + * Actions of disabled item. + */ + protected transient Map _disabled; + protected transient String _selection = null; + + // ============================================================================================================================== + // Constructors + // ============================================================================================================================== + + protected Menu(final String name) { + _myname = name; + _myscope = "/"; + _menu = new Vector(); + _indices = new HashMap(); + _disabled = new HashMap(); + } + + protected Menu(final String name, final String scope) { + _myname = name; + _myscope = "/" + scope; + _menu = new Vector(); + _indices = new HashMap(); + _disabled = new HashMap(); + } + + /** + * 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 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 diff --git a/Workspace/Siman/src/org/splat/wapp/MenuItem.java b/Workspace/Siman/src/org/splat/wapp/MenuItem.java index fafbac5..a9625cc 100644 --- a/Workspace/Siman/src/org/splat/wapp/MenuItem.java +++ b/Workspace/Siman/src/org/splat/wapp/MenuItem.java @@ -1,75 +1,87 @@ 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 diff --git a/Workspace/Siman/src/org/splat/wapp/PopupItem.java b/Workspace/Siman/src/org/splat/wapp/PopupItem.java index e4312dd..3696519 100644 --- a/Workspace/Siman/src/org/splat/wapp/PopupItem.java +++ b/Workspace/Siman/src/org/splat/wapp/PopupItem.java @@ -13,8 +13,8 @@ public class PopupItem extends ContextualMenu.ContextualItem { } 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 @@ -24,17 +24,17 @@ public class PopupItem extends ContextualMenu.ContextualItem { } 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; } @@ -44,14 +44,14 @@ public class PopupItem extends ContextualMenu.ContextualItem { 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 diff --git a/Workspace/Siman/src/org/splat/wapp/PopupMenu.java b/Workspace/Siman/src/org/splat/wapp/PopupMenu.java index 32a080c..2a7934a 100644 --- a/Workspace/Siman/src/org/splat/wapp/PopupMenu.java +++ b/Workspace/Siman/src/org/splat/wapp/PopupMenu.java @@ -11,8 +11,8 @@ public class PopupMenu extends ContextualMenu { 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 } // ============================================================================================================================== @@ -21,29 +21,29 @@ public class PopupMenu extends ContextualMenu { 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 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 diff --git a/Workspace/Siman/src/org/splat/wapp/SlidMenu.java b/Workspace/Siman/src/org/splat/wapp/SlidMenu.java index b60738b..1075b1e 100644 --- a/Workspace/Siman/src/org/splat/wapp/SlidMenu.java +++ b/Workspace/Siman/src/org/splat/wapp/SlidMenu.java @@ -22,17 +22,17 @@ import org.splat.wapp.MenuItem.Group; * * @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); } @@ -41,20 +41,22 @@ abstract public class SlidMenu extends Menu { // 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) ); } @@ -65,8 +67,8 @@ abstract public class SlidMenu extends Menu { protected void clear () { // ----------------------- - menu.clear(); - indices.clear(); - selection = null; + _menu.clear(); + _indices.clear(); + _selection = null; } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/wapp/TabBar.java b/Workspace/Siman/src/org/splat/wapp/TabBar.java index 0698691..8759a9b 100644 --- a/Workspace/Siman/src/org/splat/wapp/TabBar.java +++ b/Workspace/Siman/src/org/splat/wapp/TabBar.java @@ -1,33 +1,51 @@ 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 menu; // For making the menu visible as a list of MenuItems - protected HashMap indices; // Indices of MenuItem objects into this menu - protected HashMap 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 _menu; + /** + * Indices of MenuItem objects into this menu. + */ + protected transient Map _indices; + /** + * Actions of disabled item. + */ + protected transient Map _disabled; + /** + * Selected item id. + */ + protected transient String _selection; + // ============================================================================================================================== // Constructor // ============================================================================================================================== + /** + * Empty tab bar constuctor. + */ public TabBar () { -// ---------------- - menu = new Vector(); - indices = new HashMap(); - disabled = new HashMap(); - selection = null; + _menu = new ArrayList(); + _indices = new HashMap(); + _disabled = new HashMap(); + _selection = null; } // ============================================================================================================================== @@ -36,12 +54,11 @@ public class TabBar implements Serializable { /** * 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) ); } /** @@ -49,21 +66,21 @@ public class TabBar implements Serializable { * @return the list of items of this bar. */ public List 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); } @@ -71,13 +88,14 @@ public class TabBar implements Serializable { * 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); } @@ -87,21 +105,23 @@ public class TabBar implements Serializable { * @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 diff --git a/Workspace/Siman/src/org/splat/wapp/ToolBar.java b/Workspace/Siman/src/org/splat/wapp/ToolBar.java index f9f7c2f..3f962cb 100644 --- a/Workspace/Siman/src/org/splat/wapp/ToolBar.java +++ b/Workspace/Siman/src/org/splat/wapp/ToolBar.java @@ -11,8 +11,8 @@ public class ToolBar extends ContextualMenu { public ToolBar (int size) { // ------------------------- - width = 0; - height = size; + _width = 0; + _height = size; } // ============================================================================================================================== @@ -36,27 +36,27 @@ public class ToolBar extends ContextualMenu { 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 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 diff --git a/Workspace/Siman/src/org/splat/wapp/ToolButton.java b/Workspace/Siman/src/org/splat/wapp/ToolButton.java index d70be8f..b6b00a7 100644 --- a/Workspace/Siman/src/org/splat/wapp/ToolButton.java +++ b/Workspace/Siman/src/org/splat/wapp/ToolButton.java @@ -13,7 +13,7 @@ public class ToolButton extends ContextualMenu.ContextualItem { } public ToolButton (String icon) { // ------------------------------- - myicon = icon; + _myicon = icon; } // Optional attributes public ToolButton action (String url) { // Enables the item @@ -23,12 +23,12 @@ public class ToolButton extends ContextualMenu.ContextualItem { } 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; } @@ -38,10 +38,10 @@ public class ToolButton extends ContextualMenu.ContextualItem { 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