com.sun.electric.tool.user.menus
Class EMenuItem

java.lang.Object
  extended by com.sun.electric.tool.user.menus.EMenuItem
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener
Direct Known Subclasses:
EMenu, EMenuItem.CheckBox, ToolBar.EToolBarButton

public abstract class EMenuItem
extends java.lang.Object
implements java.awt.event.ActionListener

Generic Electric menu item. It generates real menu buttons and tool buttons with shared state.


Nested Class Summary
static class EMenuItem.CheckBox
          A subclass of EMenuItem to represent toggle button.
 
Field Summary
static EMenuItem[] NULL_ARRAY
           
static EMenuItem SEPARATOR
          A constant to represent separator in menus.
 
Constructor Summary
EMenuItem(java.lang.String text)
           
EMenuItem(java.lang.String text, char acceleratorChar)
           
EMenuItem(java.lang.String text, javax.swing.KeyStroke accelerator)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Invoked when an action occurs.
protected  javax.swing.JMenuItem createMenuItem()
          Creates fresh GUI instance of this generic EMenuItem.
 java.lang.String getDescription()
          Get a string description of the menu item.
 char getMnemonicChar()
          Method to return the ALT character that will invoke this menu item.
 java.lang.String getText()
          Returns hort text description of this EMenuElement.
 java.lang.String getToolTipText()
           
 boolean isEnabled()
          Returns enable state of this generic EMenuItem.
 boolean isSelected()
          Returns selection state of this generic EMenuItem.
protected  void registerItem()
          Register this menu item in EMenuBar.
protected  void registerUpdatable()
          Register this item as updatable ( dimmed items or chec box/radio buttons
static void repeatLastCommand()
          Repeat the last Command
abstract  void run()
          Abstract method which executes command.
static javax.swing.KeyStroke shortcut(int keyCode)
          Determines which modifier key is the appropriate accelerator key for menu shortcuts.
static javax.swing.KeyStroke[] shortcut(int[] keyCode)
          Determines which modifier key is the appropriate accelerator key for menu shortcuts.
 java.lang.String toString()
           
protected  void updateButtons()
          Updates GUI buttons after change of state of generic button.
protected  void updateMenuItem(javax.swing.JMenuItem item)
          Updates appearance of menu item instance before popping up.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL_ARRAY

public static final EMenuItem[] NULL_ARRAY

SEPARATOR

public static final EMenuItem SEPARATOR
A constant to represent separator in menus.

Constructor Detail

EMenuItem

public EMenuItem(java.lang.String text,
                 javax.swing.KeyStroke accelerator)
Parameters:
text - the menu item's displayed text. An "_" in the string indicates the location of the "mnemonic" key for that entry.
accelerator - the shortcut key, or null if none specified.

EMenuItem

public EMenuItem(java.lang.String text)
Parameters:
text - the menu item's displayed text. An "_" in the string indicates the location of the "mnemonic" key for that entry.

EMenuItem

public EMenuItem(java.lang.String text,
                 char acceleratorChar)
Parameters:
text - the menu item's displayed text. An "_" in the string indicates the location of the "mnemonic" key for that entry.
acceleratorChar - the shortcut char.
Method Detail

shortcut

public static javax.swing.KeyStroke[] shortcut(int[] keyCode)
Determines which modifier key is the appropriate accelerator key for menu shortcuts.

Parameters:
keyCode - key code without modifier.
Returns:
key stroke whih approptiate modified

shortcut

public static javax.swing.KeyStroke shortcut(int keyCode)
Determines which modifier key is the appropriate accelerator key for menu shortcuts.

Parameters:
keyCode - key code without modifier.
Returns:
key stroke whih approptiate modified

repeatLastCommand

public static void repeatLastCommand()
Repeat the last Command


getText

public java.lang.String getText()
Returns hort text description of this EMenuElement.


getToolTipText

public java.lang.String getToolTipText()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getDescription

public java.lang.String getDescription()
Get a string description of the menu item. Takes the form

Menu | SubMenu | SubMenu | item

Returns:
a string of the description.

registerItem

protected void registerItem()
Register this menu item in EMenuBar.


registerUpdatable

protected void registerUpdatable()
Register this item as updatable ( dimmed items or chec box/radio buttons


createMenuItem

protected javax.swing.JMenuItem createMenuItem()
Creates fresh GUI instance of this generic EMenuItem. Override in subclasses.

Returns:
GUI instance

updateMenuItem

protected void updateMenuItem(javax.swing.JMenuItem item)
Updates appearance of menu item instance before popping up.

Parameters:
item - item to update.

isEnabled

public boolean isEnabled()
Returns enable state of this generic EMenuItem. Override in subclasses.

Returns:
true is this generic EMenuItem is enabled.

isSelected

public boolean isSelected()
Returns selection state of this generic EMenuItem. Override in subclasses.

Returns:
true is this generic EMenuItem is selected.

getMnemonicChar

public char getMnemonicChar()
Method to return the ALT character that will invoke this menu item.

Returns:
the character (0 if none).

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Invoked when an action occurs. It can be envoked form menu button, tool bar button or shortcut key.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

run

public abstract void run()
Abstract method which executes command.


updateButtons

protected void updateButtons()
Updates GUI buttons after change of state of generic button. Override in subclasses.