chooser
Class BindingPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by chooser.BindingPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
BindingChooser

public abstract class BindingPanel
extends JPanel

Panel containing a listing of current keybinding mappings. This contains methods that can be overwritten to provide easy editing functionality and display logic. Note that this does not support the manual addition or removal of BindingEntry components. However this is designed to tolerate the changing of entry visibility (including individual fields) and the manual addition and removal of extra components either to this panel or its BindingEntries.
This represents a mapping of keystrokes to strings, and hence duplicate shortcuts aren't supported. An exception is made in the case of disabled shortcuts, but to keep mappings unique duplicate actions among disabled entries are not permitted.

Version:
September 1, 2007
Author:
Damian Johnson (atagar1@gmail.com)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
BindingPanel()
           
 
Method Summary
 void clearBindings()
          Removes all bindings from the panel.
 boolean contains(KeyStroke shortcut)
          Returns if a keystroke is in the panel's current contents.
 BindingEntry getBinding(int index)
          Provides a binding at a particular index.
 int getBindingCount()
          Provides number of key bindings currently present.
 int getBindingIndex(BindingEntry entry)
          Provides the index of a particular entry.
 InputMap getBindingInputMap()
          Provides an input map associating keystrokes to actions according to the contents of the display.
 LinkedHashMap<KeyStroke,String> getBindingMap()
          Provides the mapping between keystrokes and actions represented by the contents of the display.
 ArrayList<BindingEntry> getBindings()
          Provides listing of the current keybinding entries.
 void putAllBindings(Map<KeyStroke,String> bindings)
          Adds a collection of new key binding mappings to the end of the listing.
 boolean putBinding(BindingEntry newEntry, int index)
          Adds a new key binding mapping to a particular index of the listing.
 boolean putBinding(int keyCode, int modifier, String action)
          Adds a new key binding mapping to the end of the listing.
 boolean putBinding(KeyStroke shortcut, String action)
          Adds a new key binding mapping to the end of the listing.
 boolean putBinding(KeyStroke shortcut, String action, int index)
          Adds a new key binding mapping to a particular index of the listing.
 boolean removeBinding(BindingEntry entry)
          Removes a particular binding from the contents.
 BindingEntry removeBinding(int index)
          Removes the binding at a particular index of the listing.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BindingPanel

public BindingPanel()
Method Detail

putBinding

public boolean putBinding(int keyCode,
                          int modifier,
                          String action)
Adds a new key binding mapping to the end of the listing. If this already contains the shortcut then the previous entry is replaced instead (not triggering the onUpdate method). Disabled shortcuts trigger replacement on duplicate actions instead. This uses the normal parameters used to generate key stokes, such as:
 bindingPanel.putBinding('Y', 0, "Confirm Selection");
 bindingPanel.putBinding(KeyEvent.VK_DELETE, KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK, "Kill Process");
 

Parameters:
keyCode - key code of keystroke component of mapping
modifier - modifiers of keystroke component of mapping
action - string component of mapping
Returns:
true if contents did not already include shortcut

putBinding

public boolean putBinding(KeyStroke shortcut,
                          String action)
Adds a new key binding mapping to the end of the listing. If this already contains the shortcut then the previous entry is replaced instead (not triggering the onUpdate method). Disabled shortcuts trigger replacement on duplicate actions instead.

Parameters:
shortcut - keystroke component of mapping
action - string component of mapping
Returns:
true if contents did not already include shortcut

putBinding

public boolean putBinding(KeyStroke shortcut,
                          String action,
                          int index)
Adds a new key binding mapping to a particular index of the listing. If this already contains the shortcut then the previous entry is replaced instead (not triggering the onUpdate method). Disabled shortcuts trigger replacement on duplicate actions instead.

Parameters:
shortcut - keystroke component of mapping
action - string component of mapping
index - location in which to insert mapping
Returns:
true if contents did not already include shortcut
Throws:
IndexOutOfBoundsException - if index is out of range (index < 0 || index > getBindingCount()).

putBinding

public boolean putBinding(BindingEntry newEntry,
                          int index)
Adds a new key binding mapping to a particular index of the listing. If this already contains the shortcut then the previous entry is replaced instead (not triggering the onUpdate method). Disabled shortcuts trigger replacement on duplicate actions instead.

Parameters:
newEntry - entry to add to contents
index - location in which to insert mapping
Returns:
true if contents did not already include shortcut
Throws:
IndexOutOfBoundsException - if index is out of range (index < 0 || index > getBindingCount()).

putAllBindings

public void putAllBindings(Map<KeyStroke,String> bindings)
Adds a collection of new key binding mappings to the end of the listing. If any shortcuts are already contained then the previous entries are replaced (not triggering the onUpdate method). Disabled shortcuts trigger replacement on duplicate actions instead.

Parameters:
bindings - mapping between keystrokes and actions to be added

removeBinding

public boolean removeBinding(BindingEntry entry)
Removes a particular binding from the contents.

Parameters:
entry - binding to be removed
Returns:
true if binding was in the contents, false otherwise

removeBinding

public BindingEntry removeBinding(int index)
Removes the binding at a particular index of the listing.

Parameters:
index - from which to remove entry
Returns:
the entry that was removed from the contents
Throws:
IndexOutOfBoundsException - if index is out of range (index < 0 || index > getBindingCount()).

clearBindings

public void clearBindings()
Removes all bindings from the panel.


contains

public boolean contains(KeyStroke shortcut)
Returns if a keystroke is in the panel's current contents. This provides a preemptive means of checking if adding a non-disabled shortcut would cause a replacement.

Parameters:
shortcut - keystroke to be checked against contents
Returns:
true if contents includes the shortcut, false otherwise

getBindingCount

public int getBindingCount()
Provides number of key bindings currently present.

Returns:
number of key bindings in the display

getBindingIndex

public int getBindingIndex(BindingEntry entry)
Provides the index of a particular entry.

Parameters:
entry - entry for which the index should be returned
Returns:
entry index, -1 if not found

getBinding

public BindingEntry getBinding(int index)
Provides a binding at a particular index.

Parameters:
index - index from which to retrieve binding.
Returns:
the entry at the specified position in this list

getBindings

public ArrayList<BindingEntry> getBindings()
Provides listing of the current keybinding entries.

Returns:
list of current entry contents

getBindingMap

public LinkedHashMap<KeyStroke,String> getBindingMap()
Provides the mapping between keystrokes and actions represented by the contents of the display. Disabled entries aren't included in the mapping.

Returns:
mapping between contained keystrokes and their associated actions

getBindingInputMap

public InputMap getBindingInputMap()
Provides an input map associating keystrokes to actions according to the contents of the display. Disabled entries aren't included in the mapping.

Returns:
input mapping between contained keystrokes and their associated actions