chooser
Class BindingChooser

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
                      extended by chooser.BindingChooser
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class BindingChooser
extends BindingPanel

Implementation of the BindingPanel that provides configuring functionality for the keystroke component of key bindings. Methods provide a means of producing predefined, sweeping changes in the display. This defaults to a light blue color scheme with an index indent style.
Though display elements are still accessible, manual changes are not particularly recommended unless automated changes to the appearance (the indentation style and color scheme) are disabled since they may be unexpectedly reverted or clash any alterations made.

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

Nested Class Summary
static class BindingChooser.FrameColorScheme
          Coloring used for the labels and buttons of constructed dialogs.
static class BindingChooser.IndentStyle
          Supported appearances of the indent field, which includes:
NONE- No actions are taken to change the indent field's appearance.
EMPTY- Indent field is set to be invisible (effectively removing it from the display).
SPACER- Blank field that occupies its currently set dimensions.
TYPE- Displays Unicode arrows according to the shortcut's event type (down for KEY_PRESSED, up for KEY_RELEASED, bidirectional for KEY_TYPED, and an 'X' if disabled).
INDEX- Displays the field's index from the top (starting with one).
 
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
BindingChooser()
           
 
Method Summary
 BindingChooser.IndentStyle getIndentStyle()
          Provides the indent style used by the chooser.
 BindingEntry getSelected()
          Provides the currently selected entry if awaiting input.
 boolean isBindingSelected()
          Returns if a binding is currently awaiting input or not.
 BindingAdaptor makeAdaptor()
          Provides a key adaptor that can provide editing functionality for the selected entry.
 BindingEntry makeLabels(BindingChooser.FrameColorScheme colorScheme)
          Provides the labels naming the fields.
 void setColorScheme(Color color, boolean lightened)
          Sets foreground and background of components to a theme centered around a given hue.
 void setColorScheme(Color selectedBackground, Color evenBackground, Color oddBackground, Color foreground, Color selectedForeground)
          Manually sets each attribute of color scheme.
 void setColorSchemeEnabled(boolean enabled)
          Sets if the display should manage its coloring scheme or not.
 void setEditable(boolean editable)
          Sets if the shortcut fields of entries can be selected to provide editing functionality or not.
 void setIndentStyle(BindingChooser.IndentStyle style)
          Sets content display in the indent field of entries.
 void setSelected(BindingEntry entry)
          Sets the shortcut field of an entry to prompt user input.
 void setSelectedText(String message)
          Sets the message of the selected shortcut field when awaiting user input.
static LinkedHashMap<KeyStroke,String> showDialog(Component parent, BindingChooser display, String dialogTitle, boolean showLabels, BindingAdaptor adaptor, BindingChooser.FrameColorScheme frameColoring)
          Displays a dialog allowing the user to redefine the keystroke component of key bindings.
static LinkedHashMap<KeyStroke,String> showDialog(Component parent, Map<KeyStroke,String> bindings)
          Displays a dialog allowing the user to redefine the keystroke component of key bindings.
 void validate()
           
 
Methods inherited from class chooser.BindingPanel
clearBindings, contains, getBinding, getBindingCount, getBindingIndex, getBindingInputMap, getBindingMap, getBindings, putAllBindings, putBinding, putBinding, putBinding, putBinding, removeBinding, removeBinding
 
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
 
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

BindingChooser

public BindingChooser()
Method Detail

showDialog

public static LinkedHashMap<KeyStroke,String> showDialog(Component parent,
                                                         Map<KeyStroke,String> bindings)
Displays a dialog allowing the user to redefine the keystroke component of key bindings. The top has light blue labels describing the fields and the bottom provides an 'OK' and 'Cancel' option. This uses the default color scheme and indent style. If no entries are selected then the enter key is equivalent to pressing 'OK' and escape is the same as 'Cancel'.

Parameters:
parent - frame to which to apply modal property and center within (centers within screen if null)
bindings - initial mapping of keystrokes to their actions
Returns:
redefined mapping of keystrokes to their actions, null if cancel is pressed

showDialog

public static LinkedHashMap<KeyStroke,String> showDialog(Component parent,
                                                         BindingChooser display,
                                                         String dialogTitle,
                                                         boolean showLabels,
                                                         BindingAdaptor adaptor,
                                                         BindingChooser.FrameColorScheme frameColoring)
Displays a dialog allowing the user to redefine the keystroke component of key bindings. The bottom provides an 'OK' and 'Cancel' option. If no entries are selected then the enter key is equivalent to pressing 'OK' and escape is the same as 'Cancel'. Label and button backgrounds try to match color scheme if set.
Including focusable elements in the display will prevent user input from setting the selected shortcut field. Also note that labels use the default entry size and should be omitted if using content with custom dimensions.

Parameters:
parent - frame to which to apply modal property and center within (centers within screen if null)
display - body of the display, containing current bindings and appearance properties
dialogTitle - title of the displayed dialog
showLabels - if true the top has labels describing the fields, otherwise they are omitted
adaptor - adaptor used to provide configuring functionality
frameColoring - method of determining coloring of labels and buttons
Returns:
redefined mapping of keystrokes to their actions, null if cancel is pressed

setEditable

public void setEditable(boolean editable)
Sets if the shortcut fields of entries can be selected to provide editing functionality or not. If false, any selected entry is deselected.

Parameters:
editable - if true shortcut fields may be selected to have their values changed, otherwise user input and calls to the setSelected method are ignored

setColorSchemeEnabled

public void setColorSchemeEnabled(boolean enabled)
Sets if the display should manage its coloring scheme or not.

Parameters:
enabled - if true then display changes may trigger the recoloring of components according to the current color scheme, otherwise automated recoloring is disabled

setColorScheme

public void setColorScheme(Color color,
                           boolean lightened)
Sets foreground and background of components to a theme centered around a given hue. This effects components in the following ways:
Selected Field (Background)- Given color.
Selected Field (Foreground)- Black unless given color is very dark.
Even Entries (Background)- White if lightened is true, black otherwise.
Odd Entries (Background)- Lightened hue of color if lightened is true, darkened otherwise.
All Entries (Foreground)- Black if lightened is true, white otherwise.
If color schemes are enabled then this will immediately apply the changes to the display.

Parameters:
color - hue considered in setting component colors
lightened - if true backgrounds are bent toward a lighter theme, otherwise they are darker

setColorScheme

public void setColorScheme(Color selectedBackground,
                           Color evenBackground,
                           Color oddBackground,
                           Color foreground,
                           Color selectedForeground)
Manually sets each attribute of color scheme. If color schemes are enabled then this will immediately apply the changes to the display. This will prompt an onUpdate on all entries.

Parameters:
selectedBackground - shortcut field's background color when awaiting user input
evenBackground - background color of entries with an even index (starting with zero)
oddBackground - background color of entries with an odd index (starting with zero)
foreground - text color of entries
selectedForeground - text color of entries awaiting input

getIndentStyle

public BindingChooser.IndentStyle getIndentStyle()
Provides the indent style used by the chooser.

Returns:
type of content in the indent field

setIndentStyle

public void setIndentStyle(BindingChooser.IndentStyle style)
Sets content display in the indent field of entries. This will prompt an onUpdate on all entries unless setting the style to NONE.

Parameters:
style - type of content displayed in entry's indent field

setSelectedText

public void setSelectedText(String message)
Sets the message of the selected shortcut field when awaiting user input. By default this is "Press shortcut...".

Parameters:
message - prompt for user input

isBindingSelected

public boolean isBindingSelected()
Returns if a binding is currently awaiting input or not.

Returns:
true if a binding is awaiting input, false otherwise

getSelected

public BindingEntry getSelected()
Provides the currently selected entry if awaiting input.

Returns:
entry currently awaiting input, if one exists

setSelected

public void setSelected(BindingEntry entry)
Sets the shortcut field of an entry to prompt user input. The next call to doInput sets set its shortcut field and deselects the entry. Any other currently selected entry is deselected. If null, then this simply reverts any selections (leaving no entry selected). The onUpdate method is called whenever an entry is either selected or deselected.

Parameters:
entry - binding entry awaiting input for its shortcut field
Throws:
IllegalArgumentException - if entry is not contained in chooser

makeAdaptor

public BindingAdaptor makeAdaptor()
Provides a key adaptor that can provide editing functionality for the selected entry.

Returns:
binding adaptor configured to this chooser

makeLabels

public BindingEntry makeLabels(BindingChooser.FrameColorScheme colorScheme)
Provides the labels naming the fields. These are based on the settings when constructed and aren't updated when the display changes. Labels use the default entry dimensions.

Parameters:
colorScheme - method of setting background gradient
Returns:
labels used in dialog

validate

public void validate()
Overrides:
validate in class Container