com.alee.utils.swing.menu
Class AbstractMenuGenerator

java.lang.Object
  extended by com.alee.utils.swing.menu.AbstractMenuGenerator
Direct Known Subclasses:
PopupMenuGenerator

public abstract class AbstractMenuGenerator
extends java.lang.Object

This is a base generator class for custom menu generators. Menu generators are made to simplify various Swing menues creation.

Author:
Mikle Garin

Field Summary
protected static java.lang.String defaultIconFormat
          Default menu icons format.
protected  java.lang.String extension
          Menu icons format.
protected  UnselectableButtonGroup group
          Buttons grouping.
protected  java.lang.String languagePrefix
          Menu language key prefix.
protected  java.lang.Class nearClass
          Class near which menu icons are placed.
protected  java.lang.String path
          Path to menu icons folder relative to class.
 
Constructor Summary
AbstractMenuGenerator()
           
 
Method Summary
 UnselectableButtonGroup closeGroup()
          Finishes grouping menu items.
 WebCheckBoxMenuItem createCheckBoxItem(java.lang.String icon, java.lang.String text, HotkeyData hotkey, boolean enabled, boolean selected, java.awt.event.ActionListener actionListener)
          Returns newly created checkbox menu item.
 WebMenuItem createItem(java.lang.String icon, java.lang.String text, HotkeyData hotkey, boolean enabled, java.awt.event.ActionListener actionListener)
          Returns newly created menu item.
 WebMenu createMenu(java.lang.String icon, java.lang.String text, boolean enabled, java.awt.event.ActionListener actionListener)
          Returns newly created menu.
 WebRadioButtonMenuItem createRadioButtonItem(java.lang.String icon, java.lang.String text, HotkeyData hotkey, boolean enabled, boolean selected, java.awt.event.ActionListener actionListener)
          Returns newly created radio button menu item.
 java.lang.String getExtension()
          Returns menu icons format.
 javax.swing.ImageIcon getIcon(java.lang.String icon)
          Returns icon for the specified name.
 java.lang.String getLanguageKey(java.lang.String text)
          Returns menu item language key for the specified name.
 java.lang.String getLanguagePrefix()
          Returns menu language key prefix.
 java.lang.Class getNearClass()
          Returns class near which menu icons are placed.
 java.lang.String getPath()
          Returns path to menu icons folder relative to class.
 UnselectableButtonGroup group(javax.swing.AbstractButton button)
          Adds custom button into currently used buttons group.
 UnselectableButtonGroup openGroup()
          Starts grouping menu items.
 UnselectableButtonGroup openGroup(boolean unselectable)
          Starts grouping menu items.
 void setExtension(java.lang.String extension)
          Sets menu icons format.
 void setIconSettings(java.lang.Class nearClass, java.lang.String path, java.lang.String extension)
          Sets menu icons location and format.
 void setLanguagePrefix(java.lang.String prefix)
          Sets menu language key prefix.
 void setNearClass(java.lang.Class nearClass)
          Sets class near which menu icons are placed.
 void setPath(java.lang.String path)
          Sets path to menu icons folder relative to class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultIconFormat

protected static final java.lang.String defaultIconFormat
Default menu icons format.

See Also:
Constant Field Values

nearClass

protected java.lang.Class nearClass
Class near which menu icons are placed.


path

protected java.lang.String path
Path to menu icons folder relative to class.


extension

protected java.lang.String extension
Menu icons format.


languagePrefix

protected java.lang.String languagePrefix
Menu language key prefix.


group

protected UnselectableButtonGroup group
Buttons grouping.

Constructor Detail

AbstractMenuGenerator

public AbstractMenuGenerator()
Method Detail

getNearClass

public java.lang.Class getNearClass()
Returns class near which menu icons are placed.

Returns:
class near which menu icons are placed

setNearClass

public void setNearClass(java.lang.Class nearClass)
Sets class near which menu icons are placed.

Parameters:
nearClass - class near which menu icons are placed

getPath

public java.lang.String getPath()
Returns path to menu icons folder relative to class.

Returns:
path to menu icons folder relative to class

setPath

public void setPath(java.lang.String path)
Sets path to menu icons folder relative to class.

Parameters:
path - path to menu icons folder relative to class

getExtension

public java.lang.String getExtension()
Returns menu icons format.

Returns:
menu icons format

setExtension

public void setExtension(java.lang.String extension)
Sets menu icons format.

Parameters:
extension - menu icons format

setIconSettings

public void setIconSettings(java.lang.Class nearClass,
                            java.lang.String path,
                            java.lang.String extension)
Sets menu icons location and format.

Parameters:
nearClass - class near which menu icons are placed
path - path to menu icons folder relative to class
extension - menu icons format

getLanguagePrefix

public java.lang.String getLanguagePrefix()
Returns menu language key prefix.

Returns:
menu language key prefix

setLanguagePrefix

public void setLanguagePrefix(java.lang.String prefix)
Sets menu language key prefix.

Parameters:
prefix - menu language key prefix

getLanguageKey

public java.lang.String getLanguageKey(java.lang.String text)
Returns menu item language key for the specified name.

Parameters:
text - menu item name or text
Returns:
menu item language key for the specified name

createItem

public WebMenuItem createItem(java.lang.String icon,
                              java.lang.String text,
                              HotkeyData hotkey,
                              boolean enabled,
                              java.awt.event.ActionListener actionListener)
Returns newly created menu item.

Parameters:
icon - menu item icon
text - menu item text
hotkey - menu item accelerator
enabled - whether menu item is enabled or not
actionListener - menu item action listener
Returns:
newly created menu item

createCheckBoxItem

public WebCheckBoxMenuItem createCheckBoxItem(java.lang.String icon,
                                              java.lang.String text,
                                              HotkeyData hotkey,
                                              boolean enabled,
                                              boolean selected,
                                              java.awt.event.ActionListener actionListener)
Returns newly created checkbox menu item.

Parameters:
icon - checkbox menu item icon
text - checkbox menu item text
hotkey - checkbox menu item accelerator
enabled - whether checkbox menu item is enabled or not
selected - whether checkbox menu item is selected or not
actionListener - checkbox menu item action listener
Returns:
newly created checkbox menu item

createRadioButtonItem

public WebRadioButtonMenuItem createRadioButtonItem(java.lang.String icon,
                                                    java.lang.String text,
                                                    HotkeyData hotkey,
                                                    boolean enabled,
                                                    boolean selected,
                                                    java.awt.event.ActionListener actionListener)
Returns newly created radio button menu item.

Parameters:
icon - radio button menu item icon
text - radio button menu item text
hotkey - radio button menu item accelerator
enabled - whether radio button menu item is enabled or not
selected - whether radio button menu item is selected or not
actionListener - radio button menu item action listener
Returns:
newly created radio button menu item

createMenu

public WebMenu createMenu(java.lang.String icon,
                          java.lang.String text,
                          boolean enabled,
                          java.awt.event.ActionListener actionListener)
Returns newly created menu.

Parameters:
icon - menu icon
text - menu text
enabled - whether menu is enabled or not
actionListener - menu action listener
Returns:
newly created menu

openGroup

public UnselectableButtonGroup openGroup()
Starts grouping menu items. All items created after this call and before closeGroup() call will get grouped.

Returns:
buttons group used for grouping

openGroup

public UnselectableButtonGroup openGroup(boolean unselectable)
Starts grouping menu items. All items created after this call and before closeGroup() call will get grouped.

Parameters:
unselectable - whether items should be unselectable or not
Returns:
buttons group used for grouping

group

public UnselectableButtonGroup group(javax.swing.AbstractButton button)
Adds custom button into currently used buttons group.

Parameters:
button - custom button to add into buttons group
Returns:
buttons group used for grouping

closeGroup

public UnselectableButtonGroup closeGroup()
Finishes grouping menu items.

Returns:
buttons group used for grouping

getIcon

public javax.swing.ImageIcon getIcon(java.lang.String icon)
Returns icon for the specified name.

Parameters:
icon - icon name
Returns:
icon for the specified name