com.sun.electric.tool.user.ui
Class KeyBindings

java.lang.Object
  extended by com.sun.electric.tool.user.ui.KeyBindings
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class KeyBindings
extends java.lang.Object
implements java.awt.event.ActionListener

The KeyBindings object holds information about an action's key bindings. There can be 0 or more default bindings which are set by the program. There can be 0 or more user defined bindings which are stored as preferences by the KeyBindingManager. Finally, there is a set of action listeners that get activated when the action occurs.

The action can also be disabled/enabled.


Constructor Summary
KeyBindings(java.lang.String actionDesc)
          Constructs a new KeyBinding.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Perform all registered actions
 void addActionListener(java.awt.event.ActionListener a)
          Add an action listener.
 void addDefaultKeyBinding(javax.swing.KeyStroke prefixStroke, javax.swing.KeyStroke stroke)
          Add a one or two-stroke key binding to the default bindings list
 void addDefaultKeyBinding(KeyStrokePair k)
          Add a key stroke pair to the default bindings list
 void addKeyBinding(javax.swing.KeyStroke prefixStroke, javax.swing.KeyStroke stroke)
          Add a one or two-stroke key binding.
 void addKeyBinding(KeyStrokePair k)
          Add a key stroke pair
 void addKeyBindings(java.lang.String str)
          Add key bindings.
 java.lang.String bindingsToString()
          Convert key bindings to a string
 void clearKeyBindings()
          Clear all active bindings
 java.lang.String describe()
           
 java.lang.String getActionDesc()
          Get the action description that describes this key binding
 java.util.Iterator getActionListeners()
          Get an iterator over the actionListeners
 java.util.Iterator<KeyStrokePair> getDefaultKeyStrokePairs()
          Get an iterator over the default key stroke pairs
 boolean getEnabled()
           
 java.util.Iterator<KeyStrokePair> getKeyStrokePairs()
          Get an iterator over the user key stroke pairs
 boolean getUsingDefaultKeys()
           
 void removeActionListener(java.awt.event.ActionListener a)
          Remove an action listener
 void removeKeyBinding(KeyStrokePair k)
          Removes a key binding
 void setEnabled(boolean b)
           
 void setEventSource(java.lang.Object source)
          Set the object that will used as the "source" when the actions in this KeyBindings object are activated.
 void setUsingDefaultKeys(boolean b)
          Set the value of usingDefaultKeys.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyBindings

public KeyBindings(java.lang.String actionDesc)
Constructs a new KeyBinding.

Parameters:
actionDesc - description of the key binding to show to the user
Method Detail

addKeyBinding

public void addKeyBinding(javax.swing.KeyStroke prefixStroke,
                          javax.swing.KeyStroke stroke)
Add a one or two-stroke key binding.

Parameters:
prefixStroke - optional prefix stroke. may be null
stroke - required stroke

addKeyBinding

public void addKeyBinding(KeyStrokePair k)
Add a key stroke pair

Parameters:
k - the key stroke pair

addKeyBindings

public void addKeyBindings(java.lang.String str)
Add key bindings. The string can be a list of KeyStrokePairs.toString(), delimited by KeyBindings.sep.

Parameters:
str - string representing a list of key stroke pairs.

removeKeyBinding

public void removeKeyBinding(KeyStrokePair k)
Removes a key binding

Parameters:
k - the key stroke pair to remove

addDefaultKeyBinding

public void addDefaultKeyBinding(javax.swing.KeyStroke prefixStroke,
                                 javax.swing.KeyStroke stroke)
Add a one or two-stroke key binding to the default bindings list

Parameters:
prefixStroke - optional prefix stroke. may be null
stroke - required stroke

addDefaultKeyBinding

public void addDefaultKeyBinding(KeyStrokePair k)
Add a key stroke pair to the default bindings list

Parameters:
k - the key stroke pair

clearKeyBindings

public void clearKeyBindings()
Clear all active bindings


addActionListener

public void addActionListener(java.awt.event.ActionListener a)
Add an action listener.

Parameters:
a - the action listener to add

removeActionListener

public void removeActionListener(java.awt.event.ActionListener a)
Remove an action listener


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Perform all registered actions

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - the ActionEvent

bindingsToString

public java.lang.String bindingsToString()
Convert key bindings to a string


describe

public java.lang.String describe()

getActionDesc

public java.lang.String getActionDesc()
Get the action description that describes this key binding


getActionListeners

public java.util.Iterator getActionListeners()
Get an iterator over the actionListeners


getKeyStrokePairs

public java.util.Iterator<KeyStrokePair> getKeyStrokePairs()
Get an iterator over the user key stroke pairs


getDefaultKeyStrokePairs

public java.util.Iterator<KeyStrokePair> getDefaultKeyStrokePairs()
Get an iterator over the default key stroke pairs


setEventSource

public void setEventSource(java.lang.Object source)
Set the object that will used as the "source" when the actions in this KeyBindings object are activated. This is useful for faking the source of the event, in the case where the actionListeners may be sensitive to that value. (Event.getSource() value).

Parameters:
source - the object to be set as the source of the event passed to the actionListeners on activation.

setUsingDefaultKeys

public void setUsingDefaultKeys(boolean b)
Set the value of usingDefaultKeys. This is a flag used by the KeyBindingManager to keep track of which set of key bindings is active for this KeyBindings object (i.e. the user-modified set or the default set).

Parameters:
b - true if using default keys, false otherwise

getUsingDefaultKeys

public boolean getUsingDefaultKeys()

setEnabled

public void setEnabled(boolean b)

getEnabled

public boolean getEnabled()