JIDE 3.5.15

com.jidesoft.shortcut
Class ShortcutField

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 com.jidesoft.swing.LabeledTextField
                      extended by com.jidesoft.shortcut.ShortcutField
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ShortcutField
extends LabeledTextField

A LabeledTextField that is used to display Shortcut. You can use it to define KeyboardShortcut or MouseShortcut.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jidesoft.swing.LabeledTextField
LabeledTextField.PopupMenuCustomizer
 
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
protected  KeyListener _keyListener
           
protected  MouseListener _mouseListener
           
protected  ChangeEvent changeEvent
           
static int TYPE_KEYBOARD
           
static int TYPE_MOUSE
           
 
Fields inherited from class com.jidesoft.swing.LabeledTextField
_button, _contextMenuKeyStroke, _customizer, _hintLabel, _hintText, _icon, _label, _labelText, _showHintTextWhenFocused, _textField
 
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
ShortcutField()
          Creates a ShortcutField that supports both mouse and keyboard shortcut.
ShortcutField(int allowedType)
          Creates a ShortcutField.
ShortcutField(int allowedType, int type)
          Creates a ShortcutField.
 
Method Summary
 void addChangeListener(ChangeListener l)
          Adds a ChangeListener to the model.
 void addKeyStroke(KeyStroke keyStroke)
          Adds the KeyStroke.
 void clearShortcut()
          Clears the existing Shortcut.
protected  String convertShortcutToString(Shortcut shortcut)
          Converts the Shortcut instance to string to be displayed.
protected  JidePopupMenu createContextMenu()
          Creates a context menu.
protected  KeyboardShortcut createKeyboardShortcut()
          Creates an empty KeyboardShortcut.
protected  MouseShortcut createMouseShortcut()
          Creates an empty MouseShortcut.
protected  void fireStateChanged()
          Runs each ChangeListener's stateChanged method.
 int getAllowedKeystrokes()
          Gets the number of keystrokes allowed in this shortcut.
 int getAllowedType()
          Gets the allowed shortcut type.
 ChangeListener[] getChangeListeners()
          Returns an array of all the ChangeListeners added to this DefaultColorSelectionModel with addChangeListener.
 int getMaximumAllowedKeystrokes()
          Gets the maximum allowed keystrokes in a shortcut.
 Shortcut getShortcut()
          Gets the shortcut.
 int getType()
          Gets the current shortcut type.
 void removeChangeListener(ChangeListener l)
          Removes a ChangeListener from the model.
 void setAllowedKeystrokes(int allowedKeystrokes)
          Sets the number of keystrokes allowed in this shortcut.
 void setAllowedType(int allowedType)
          Sets the allowed shortcut type.
 void setMaximumAllowedKeystrokes(int maximumAllowedKeystrokes)
          Sets the the maximum allowed keystrokes in a shortcut.
 void setType(int type)
          Sets the current shortcut type.
 
Methods inherited from class com.jidesoft.swing.LabeledTextField
calculateContextMenuLocation, createButton, createLabel, createTextField, customizePopupMenu, getBaseline, getButton, getContextMenuKeyStroke, getHintText, getIcon, getLabel, getLabelText, getPopupMenuCustomizer, getText, getTextField, initComponent, initLayout, isShowHintTextWhenFocused, setColumns, setContextMenuKeyStroke, setEnabled, setHintText, setIcon, setLabelText, setPopupMenuCustomizer, setShowHintTextWhenFocused, setText, showContextMenu, updateUI
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
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, 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, 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, validate, 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
 

Field Detail

TYPE_KEYBOARD

public static final int TYPE_KEYBOARD
See Also:
Constant Field Values

TYPE_MOUSE

public static final int TYPE_MOUSE
See Also:
Constant Field Values

_keyListener

protected KeyListener _keyListener

_mouseListener

protected MouseListener _mouseListener

changeEvent

protected transient ChangeEvent changeEvent
Constructor Detail

ShortcutField

public ShortcutField()
Creates a ShortcutField that supports both mouse and keyboard shortcut.


ShortcutField

public ShortcutField(int allowedType)
Creates a ShortcutField.

Parameters:
allowedType - the allowed type. You can use TYPE_MOUSE, TYPE_KEYBOARD or TYPE_MOUSE | TYPE_KEYBOARD if you want to support both.

ShortcutField

public ShortcutField(int allowedType,
                     int type)
Creates a ShortcutField.

Parameters:
allowedType - the allowed type. You can use TYPE_MOUSE, TYPE_KEYBOARD or TYPE_MOUSE | TYPE_KEYBOARD if you want to support both.
type - the selected type. It could be either TYPE_MOUSE or TYPE_KEYBOARD. Please make sure you use the type that is allowed. Otherwise you will get IllegalArgumentException.
Throws:
IllegalArgumentException - if type is not allowed.
Method Detail

getType

public int getType()
Gets the current shortcut type. It could be either TYPE_KEYBOARD or TYPE_MOUSE.

Returns:
the current shortcut type.

setType

public void setType(int type)
Sets the current shortcut type. It could be either TYPE_KEYBOARD or TYPE_MOUSE.

Parameters:
type - the new shortcut type.

getAllowedType

public int getAllowedType()
Gets the allowed shortcut type.

Returns:
the allowed shortcut type.

setAllowedType

public void setAllowedType(int allowedType)
Sets the allowed shortcut type. It could be TYPE_KEYBOARD, TYPE_MOUSE, or both using TYPE_KEYBOARD | TYPE_MOUSE.

Parameters:
allowedType - the allowed shortcut type. It could be either TYPE_MOUSE or TYPE_KEYBOARD. Please make sure you use the type that is allowed. Otherwise you will get IllegalArgumentException.
Throws:
IllegalArgumentException - if type is not allowed.

getMaximumAllowedKeystrokes

public int getMaximumAllowedKeystrokes()
Gets the maximum allowed keystrokes in a shortcut.

Returns:
the maximum allowed keystrokes in a shortcut.

setMaximumAllowedKeystrokes

public void setMaximumAllowedKeystrokes(int maximumAllowedKeystrokes)
Sets the the maximum allowed keystrokes in a shortcut. It is used to define a shortcut that has a number of keystrokes. The valid values are from 1 to 3. We will reset to 1 or 3 if the value is out of the range. If the value is 2 or 3, the context menu will show menu items to allow you to decide the number of keystrokes for this shortcut. If the value is 1, we will hide these menu items since there is no need to let user choose.

Parameters:
maximumAllowedKeystrokes - the maximum allowed keystrokes.

getAllowedKeystrokes

public int getAllowedKeystrokes()
Gets the number of keystrokes allowed in this shortcut.

Returns:
the number of keystrokes allowed in this shortcut.

setAllowedKeystrokes

public void setAllowedKeystrokes(int allowedKeystrokes)
Sets the number of keystrokes allowed in this shortcut.

Parameters:
allowedKeystrokes - the new number of keystrokes allowed in this shortcut. The number must be no greater than getMaximumAllowedKeystrokes().

createContextMenu

protected JidePopupMenu createContextMenu()
Description copied from class: LabeledTextField
Creates a context menu. The context menu will be shown when user clicks on the label.

Overrides:
createContextMenu in class LabeledTextField
Returns:
a context menu.

addKeyStroke

public void addKeyStroke(KeyStroke keyStroke)
Adds the KeyStroke. Since the ShortcutField supports several KeyStrokes, that's why there is addKeystroke method. If the number of KeyStrokes exceeds the getMaximumAllowedKeystrokes(), it will clear all existing KeyStrokes and add this new one. Otherwise it will append this new KeyStroke at the end. If you want this KeyStroke to be the only one in the ShortcutField, you can use clearShortcut() first, then call this addKeyStroke.

Parameters:
keyStroke - the KeyStroke to be added.

createKeyboardShortcut

protected KeyboardShortcut createKeyboardShortcut()
Creates an empty KeyboardShortcut.

Returns:
an empty KeyboardShortcut.

createMouseShortcut

protected MouseShortcut createMouseShortcut()
Creates an empty MouseShortcut.

Returns:
an empty MouseShortcut.

convertShortcutToString

protected String convertShortcutToString(Shortcut shortcut)
Converts the Shortcut instance to string to be displayed.

Parameters:
shortcut - the Shortcut instance
Returns:
the string to represent the Shortcut.

clearShortcut

public void clearShortcut()
Clears the existing Shortcut.


getShortcut

public Shortcut getShortcut()
Gets the shortcut.

Returns:
the shortcut.

addChangeListener

public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the model.

Parameters:
l - the ChangeListener to be added

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the model.

Parameters:
l - the ChangeListener to be removed

getChangeListeners

public ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListeners added to this DefaultColorSelectionModel with addChangeListener.

Returns:
all of the ChangeListeners added, or an empty array if no listeners have been added

fireStateChanged

protected void fireStateChanged()
Runs each ChangeListener's stateChanged method.

See Also:
EventListenerList

JIDE 3.5.15