org.freehep.application
Class RecentItemTextField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JComboBox
                  extended by org.freehep.application.RecentItemTextField
All Implemented Interfaces:
ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener

public class RecentItemTextField
extends JComboBox

This class is ideal if you want to have a text field for user input but also have a list of recently selected items available to choose from. Some notes on using this class:

It is important to point this out because the KeyEvents, ActionEvents, and ChangeEvents described above are not how a normal combo box will generate them.

Basically, a ChangeEvent is a dual purpose event. One is sent to listeners both when a KeyEvent is generated from the text field, and one is sent when an ItemEvent is generated (which happens when an item is selected from the drop-down list). This means that somebody who wants to know when the actual text showing has changed only needs to implement ChangeListener instead of both ItemListener and KeyListener.

Version:
$Id: RecentItemTextField.java 8584 2006-08-10 23:06:37Z duns $
Author:
Jonas Gifford
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComboBox
JComboBox.AccessibleJComboBox, JComboBox.KeySelectionManager
 
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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder
 
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
RecentItemTextField()
           
RecentItemTextField(String[] dropDownItems, boolean clickDefault)
          Creates a RecentItemTextField with the given list of drop-down items.
RecentItemTextField(String key, int nItems, boolean clickDefault)
          Creates a RecentItemTextField with a dropDown list that will be stored in the user properties object for the Application.
RecentItemTextField(String key, String lengthKey, boolean clickDefault)
          Creates a RecentItemTextField with a dropDown list that will be stored in the user properties object for the Application.
 
Method Summary
 void addActionListener(ActionListener l)
          Adds an the given ActionListener to the text field.
 void addChangeListener(ChangeListener l)
          Change listeners will be notified any time the text visible in the text field changes.
 void addKeyListener(KeyListener kl)
           
protected  void fireItemStateChanged(ItemEvent event)
          This method is protected as an implementation side effect.
 String getKey()
          Getter for property key.
 Dimension getMaximumSize()
          Incorporates the maximum width if it has been set.
 Dimension getMinimumSize()
          Incorporates the minimum width if it has been set.
 int getNumberOfItems()
          Getter for property numberOfItems.
 Dimension getPreferredSize()
          Incorporates the minimum and maximum widths if they have been set.
 String getText()
          Returns the text currently showing in the text field.
 boolean isClickDefault()
          Getter for property clickDefault.
 void requestFocus()
          Requests focus for the text field of the box.
 void saveState()
          If a key was supplied to the constructor, the drop-down list will be updated to include the currently selected item.
 void setClickDefault(boolean clickDefault)
          Setter for property clickDefault.
 void setKey(String key)
          Setter for property key.
 void setMaxWidth(int maxWidth)
          Set the maximum width of the box.
 void setMinWidth(int minWidth)
          Set the minimum width of the box.
 void setNumberOfItems(int numberOfItems)
          Setter for property numberOfItems.
 void setText(String s)
          Sets the text showing in the text field.
static String showInputDialog(Component owner, Object message, String key)
          Show an input dialog, with a record of recent entries.
static String showInputDialog(Component owner, Object message, String title, int messageType, String key)
          Show an input dialog, with a record of recent entries.
 
Methods inherited from class javax.swing.JComboBox
actionPerformed, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setSelectedItem, setUI, showPopup, 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, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, 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, 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

RecentItemTextField

public RecentItemTextField()

RecentItemTextField

public RecentItemTextField(String[] dropDownItems,
                           boolean clickDefault)
Creates a RecentItemTextField with the given list of drop-down items. You are responsible for keeping and providing an updated list.

Parameters:
dropDownItems - the items to show in the drop-down list (can safely be null)
clickDefault - whether the default button should be clicked when Enter is pressed
See Also:
JRootPane.defaultButton

RecentItemTextField

public RecentItemTextField(String key,
                           int nItems,
                           boolean clickDefault)
Creates a RecentItemTextField with a dropDown list that will be stored in the user properties object for the Application. Invoke the saveState() method to have the list be updated to include the selected item.

Parameters:
key - the key that the drop-down items will be stored by
nItems - the maximum number of items that will be stored on the drop-down list
clickDefault - whether the default button should be clicked when Enter is pressed
See Also:
Application.getUserProperties(), JRootPane.defaultButton

RecentItemTextField

public RecentItemTextField(String key,
                           String lengthKey,
                           boolean clickDefault)
Creates a RecentItemTextField with a dropDown list that will be stored in the user properties object for the Application. Invoke the saveState() method to have the list be updated to include the selected item.

Parameters:
key - the key that the drop-down items will be stored by
lengthKey - the key that maps to the maximum number of items that will be stored on the drop-down list
clickDefault - whether the default button should be clicked when Enter is pressed
See Also:
Application.getUserProperties(), JRootPane.defaultButton
Method Detail

addKeyListener

public void addKeyListener(KeyListener kl)
Overrides:
addKeyListener in class Component

saveState

public void saveState()
If a key was supplied to the constructor, the drop-down list will be updated to include the currently selected item.


getText

public String getText()
Returns the text currently showing in the text field.


setText

public void setText(String s)
Sets the text showing in the text field.


addChangeListener

public void addChangeListener(ChangeListener l)
Change listeners will be notified any time the text visible in the text field changes. This is equivalent to having a KeyListener and an ItemListener.

Parameters:
l - the ChangeListener to add

addActionListener

public void addActionListener(ActionListener l)
Adds an the given ActionListener to the text field.

Overrides:
addActionListener in class JComboBox

fireItemStateChanged

protected void fireItemStateChanged(ItemEvent event)
This method is protected as an implementation side effect.

Overrides:
fireItemStateChanged in class JComboBox

requestFocus

public void requestFocus()
Requests focus for the text field of the box.

Overrides:
requestFocus in class JComponent

setMaxWidth

public void setMaxWidth(int maxWidth)
Set the maximum width of the box. The default is used if this method is not called.

Parameters:
maxWidth - give a number in pixels, or -1 to use default

setMinWidth

public void setMinWidth(int minWidth)
Set the minimum width of the box. The default is used if this method is not called.

Parameters:
minWidth - give a number in pixels, or -1 to use default

getMaximumSize

public Dimension getMaximumSize()
Incorporates the maximum width if it has been set.

Overrides:
getMaximumSize in class JComponent
See Also:
setMaxWidth(int)

getMinimumSize

public Dimension getMinimumSize()
Incorporates the minimum width if it has been set.

Overrides:
getMinimumSize in class JComponent
See Also:
setMinWidth(int)

getPreferredSize

public Dimension getPreferredSize()
Incorporates the minimum and maximum widths if they have been set.

Overrides:
getPreferredSize in class JComponent
See Also:
setMinWidth(int), setMaxWidth(int)

showInputDialog

public static String showInputDialog(Component owner,
                                     Object message,
                                     String key)
Show an input dialog, with a record of recent entries.

Parameters:
owner - The dialog owner
message - The message to display
key - The key under which the recent items are stored in the user properties
See Also:
JOptionPane.showInputDialog(Component,Object)

showInputDialog

public static String showInputDialog(Component owner,
                                     Object message,
                                     String title,
                                     int messageType,
                                     String key)
Show an input dialog, with a record of recent entries.

Parameters:
owner - The dialog owner
message - The message to display
title - The dialog title
messageType - The message type
key - The key under which the recent items are stored in the user properties
See Also:
JOptionPane.showInputDialog(Component,Object,String,int)

getKey

public String getKey()
Getter for property key.

Returns:
Value of property key.

setKey

public void setKey(String key)
Setter for property key.

Parameters:
key - New value of property key.

getNumberOfItems

public int getNumberOfItems()
Getter for property numberOfItems.

Returns:
Value of property numberOfItems.

setNumberOfItems

public void setNumberOfItems(int numberOfItems)
Setter for property numberOfItems.

Parameters:
numberOfItems - New value of property numberOfItems.

isClickDefault

public boolean isClickDefault()
Getter for property clickDefault.

Returns:
Value of property clickDefault.

setClickDefault

public void setClickDefault(boolean clickDefault)
Setter for property clickDefault.

Parameters:
clickDefault - New value of property clickDefault.


Copyright © 2000-2006 FreeHEP. All Rights Reserved.