Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.plugin.keybindingchooser.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 net.java.sip.communicator.util.swing.TransparentPanel
                      extended by net.java.sip.communicator.plugin.keybindingchooser.chooser.BindingPanel
                          extended by net.java.sip.communicator.plugin.keybindingchooser.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.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.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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
(package private)  void doInput(KeyStroke input)
          Emulates keyboard input, setting the selected entry's shortcut if an entry's currently awaiting input.
 BindingChooser.IndentStyle getIndentStyle()
          Provides the indent style used by the chooser.
static String getReadableConstant(String input)
          Provides a more readable version of constant names.
 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()
          Provides the labels naming the fields.
protected  void onClick(MouseEvent event, BindingEntry entry, BindingEntry.Field field)
          Invoked on click.
protected  void onUpdate(int index, BindingEntry entry, boolean isNew)
          This is called upon: Component reordering (inherited functionality from BindingPanel) Visual changes to the entry Component validation
 void putAllBindings(KeybindingSet set)
          Adds a collection of new key binding mappings to the end of the listing.
 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)
          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 net.java.sip.communicator.plugin.keybindingchooser.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, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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
clone, equals, finalize, 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

putAllBindings

public void putAllBindings(KeybindingSet set)
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:
set - mapping between keystrokes and actions to be added

showDialog

public static LinkedHashMap<KeyStroke,String> showDialog(Component parent,
                                                         BindingChooser display,
                                                         String dialogTitle,
                                                         boolean showLabels,
                                                         BindingAdaptor adaptor)
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
Returns:
redefined mapping of keystrokes to their actions, null if cancel is pressed

onUpdate

protected void onUpdate(int index,
                        BindingEntry entry,
                        boolean isNew)
This is called upon: Component reordering (inherited functionality from BindingPanel) Visual changes to the entry Component validation

Specified by:
onUpdate in class BindingPanel
Parameters:
index - newly assigned index of entry
entry - entry that has been added or shifted
isNew - if true the entry is new to the display, false otherwise

onClick

protected void onClick(MouseEvent event,
                       BindingEntry entry,
                       BindingEntry.Field field)
Invoked on click.

Specified by:
onClick in class BindingPanel
Parameters:
event - fired mouse event that triggered method call
entry - entry on which the click landed
field - field of entry on which the click landed, null if not a recognized field

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

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()
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.

Returns:
labels used in dialog

doInput

void doInput(KeyStroke input)
Emulates keyboard input, setting the selected entry's shortcut if an entry's currently awaiting input.

Parameters:
input - keystroke input for selected entry

validate

public void validate()
Overrides:
validate in class Container

getReadableConstant

public static String getReadableConstant(String input)
Provides a more readable version of constant names. Spaces replace underscores and this changes the input to lowercase except the first letter of each word. For instance, "RARE_CARDS" would become "Rare Cards".

Parameters:
input - string to be converted
Returns:
reader friendly variant of constant name

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.