com.jgoodies.uif.builder
Class MenuBuilder

java.lang.Object
  extended by com.jgoodies.uif.builder.MenuBuilder

public final class MenuBuilder
extends Object

A builder that reduces the effort required to build, configure and fill a JMenu with menu items and separators. Provides several convenience methods that implicitly create extended menu item implementations or implicitly configure items to automatically handle typical platforms differences.

Version:
$Revision: 1.9 $
Author:
Karsten Lentzsch
See Also:
JMenu, Action, ToggleAction, UIFMenuItem, UIFCheckBoxMenuItem, UIFRadioButtonMenuItem, ToolBarBuilder

Constructor Summary
MenuBuilder(JMenu menu)
          Constructs a menu building using the given menu.
MenuBuilder(String label, char mnemonic)
          Constructs menu bar builder.
 
Method Summary
 JMenuItem add(Action action)
          Creates, adds and returns a UIFMenuItem that is configured using the given plain Action.
 JMenuItem add(JMenuItem item)
          Adds the given JMenuItem to this builder's menu.
 UIFMenuItem add(String text)
          Creates a menu item for the specified text, adds it to this builder's menu and returns the new menu item.
 UIFMenuItem add(String text, Icon icon)
          Creates a menu item for the specified text and icon, adds it to this builder's menu and returns the new menu item.
 UIFMenuItem add(String text, Icon icon, int mnemonic)
          Creates a menu item for the specified text and icon, adds it to this builder's menu and returns the new menu item.
 UIFMenuItem add(String text, int mnemonic)
          Creates a menu item for the specified text and icon, adds it to this builder's menu and returns the new menu item.
 UIFCheckBoxMenuItem add(UIFCheckBoxMenuItem item)
          Adds the given UIFRadioButtonMenuItem to this builder's menu.
 UIFMenuItem add(UIFMenuItem item)
          Adds the given UIFMenuItem to this builder's menu.
 UIFRadioButtonMenuItem add(UIFRadioButtonMenuItem item)
          Adds the given UIFRadioButtonMenuItem to this builder's menu.
 void addSeparator()
          Adds a separator to this builder's menu.
 JMenuItem addToggle(ToggleAction toggleAction)
          Creates a radio button or check box menu item for the given ToggleAction, adds it to this builder's menu and returns the new menu item.
static Mode getIconVisibleDefaultMode()
          Returns the default icon mode that is used as initial value of the iconVisibleMode property.
 Mode getIconVisibleMode()
          Returns the current icon mode that determines whether menu items created by createActionComponent(Action) get an icon or not.
 JMenu getMenu()
          Returns the menu that is built by this builder.
static void setIconVisibleDefaultMode(Mode newDefaultMode)
          Sets a new default icon mode that is used as initial value for the iconVisibleMode property.
 void setIconVisibleMode(Mode newMode)
          Sets a new icon mode that determines whether menu items created by createActionComponent(Action) get an icon or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuBuilder

public MenuBuilder(String label,
                   char mnemonic)
Constructs menu bar builder. Implicitly creates a menu with the given label and mnemonic.

Parameters:
label - the label for the built menu
mnemonic - the shortcut for the build menu

MenuBuilder

public MenuBuilder(JMenu menu)
Constructs a menu building using the given menu.

Parameters:
menu - the menu to add items to
Method Detail

getIconVisibleDefaultMode

public static Mode getIconVisibleDefaultMode()
Returns the default icon mode that is used as initial value of the iconVisibleMode property.

Returns:
the current icon mode

setIconVisibleDefaultMode

public static void setIconVisibleDefaultMode(Mode newDefaultMode)
Sets a new default icon mode that is used as initial value for the iconVisibleMode property.

Parameters:
newDefaultMode - the default icon mode to be set

getIconVisibleMode

public Mode getIconVisibleMode()
Returns the current icon mode that determines whether menu items created by createActionComponent(Action) get an icon or not.

Returns:
the current icon mode

setIconVisibleMode

public void setIconVisibleMode(Mode newMode)
Sets a new icon mode that determines whether menu items created by createActionComponent(Action) get an icon or not.

Parameters:
newMode - the icon mode to be set

getMenu

public JMenu getMenu()
Returns the menu that is built by this builder.

Returns:
this builder's menu

add

public UIFMenuItem add(String text)
Creates a menu item for the specified text, adds it to this builder's menu and returns the new menu item.

Parameters:
text - the text for the menu item
Returns:
the new menu item

add

public UIFMenuItem add(String text,
                       Icon icon)
Creates a menu item for the specified text and icon, adds it to this builder's menu and returns the new menu item.

Parameters:
text - the text for the menu item
icon - the icon for the menu item
Returns:
the new menu item

add

public UIFMenuItem add(String text,
                       int mnemonic)
Creates a menu item for the specified text and icon, adds it to this builder's menu and returns the new menu item.

Parameters:
text - the text for the menu item
mnemonic - the mnemonic for the menu item
Returns:
the new menu item

add

public UIFMenuItem add(String text,
                       Icon icon,
                       int mnemonic)
Creates a menu item for the specified text and icon, adds it to this builder's menu and returns the new menu item.

Parameters:
text - the text for the menu item
icon - the icon for the menu item
mnemonic - the mnemonic for the menu item
Returns:
the new menu item

add

public JMenuItem add(Action action)
Creates, adds and returns a UIFMenuItem that is configured using the given plain Action.

Parameters:
action - the Action for the menu item to be added
Returns:
the new menu item
Throws:
NullPointerException - if the action is null
IllegalArgumentException - if the action is an instance of ToggleAction

addToggle

public JMenuItem addToggle(ToggleAction toggleAction)
Creates a radio button or check box menu item for the given ToggleAction, adds it to this builder's menu and returns the new menu item.

Parameters:
toggleAction - the Action for the menu item to be added
Returns:
the new menu item
Throws:
NullPointerException - if the action is null

add

public JMenuItem add(JMenuItem item)
Adds the given JMenuItem to this builder's menu.

Parameters:
item - the menu item to add
Returns:
the added menu item

add

public UIFMenuItem add(UIFMenuItem item)
Adds the given UIFMenuItem to this builder's menu. Sets the item's icon visible mode to this builder's mode.

Parameters:
item - the menu item to add
Returns:
the added menu item

add

public UIFRadioButtonMenuItem add(UIFRadioButtonMenuItem item)
Adds the given UIFRadioButtonMenuItem to this builder's menu. Sets the item's icon visible mode to this builder's mode.

Parameters:
item - the menu item to add
Returns:
the added menu item

add

public UIFCheckBoxMenuItem add(UIFCheckBoxMenuItem item)
Adds the given UIFRadioButtonMenuItem to this builder's menu. Sets the item's icon visible mode to this builder's mode.

Parameters:
item - the menu item to add
Returns:
the added menu item

addSeparator

public void addSeparator()
Adds a separator to this builder's menu.



Copyright © 2000-2008 JGoodies Karsten Lentzsch. All Rights Reserved.