org.fife.ui
Class FSATextField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JTextField
                      extended by org.fife.ui.FSATextField
All Implemented Interfaces:
java.awt.event.ComponentListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.DocumentListener, javax.swing.event.ListSelectionListener, javax.swing.Scrollable, javax.swing.SwingConstants

public class FSATextField
extends javax.swing.JTextField
implements java.awt.event.ComponentListener, javax.swing.event.DocumentListener, javax.swing.event.ListSelectionListener

A "File System-Aware" text field. When the user is typing into this text field, it automagically locates all files that begin with the text typed in, and populates a text field-style list with file choices. This is similar to the text field found in the "Run" dialog in Microsoft Windows.

Version:
0.5
Author:
Robert Futrell
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTextField
javax.swing.JTextField.AccessibleJTextField
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JTextField
notifyAction
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
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 javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FSATextField()
          Creates a new FSATextField that previews both files and directories, and whose current directory is the program's current directory.
FSATextField(boolean directoriesOnly, java.io.File currentDirectory)
          Creates a new FSATextField.
FSATextField(boolean directoriesOnly, java.lang.String currentDirectory)
          Creates a new FSATextField.
FSATextField(int cols)
          Creates a new FSATextField that previews both files and directories, and whose current directory is the program's current directory.
 
Method Summary
 void addItem(java.lang.String item)
          Adds an item to the file list.
 void addNotify()
          
 void changedUpdate(javax.swing.event.DocumentEvent e)
          Called when the text component's document receives a style change.
 void componentHidden(java.awt.event.ComponentEvent e)
          Called when the parent dialog/frame of this text field is hidden.
 void componentMoved(java.awt.event.ComponentEvent e)
          Called when the parent dialog/frame of this text field is moved.
 void componentResized(java.awt.event.ComponentEvent e)
          Called when the parent dialog/frame of this text field is resized.
 void componentShown(java.awt.event.ComponentEvent e)
          Called when the parent dialog/frame of this text field is shown.
 boolean getAutoCompleteFileName()
          Returns whether this text field auto-completes the next matching filename when the drop-down list is visible.
 java.lang.String getCurrentDirectory()
          Returns the current directory for this text field.
 boolean getFileSystemAware()
          Returns whether or not this text field is file-system-aware.
 void hidePopup()
          Hides the popup window, if it is visible.
 void insertUpdate(javax.swing.event.DocumentEvent e)
          Called when text is inserted into this text component.
 boolean isDirectoriesOnly()
          Returns whether or not this text field previews both files and directories or just directories.
 void processFocusEvent(java.awt.event.FocusEvent e)
          Process the focus events of this text field.
 void removeAllItems()
          Removes all items from the file list.
 void removeNotify()
          
 void removeUpdate(javax.swing.event.DocumentEvent e)
          Called when text is removed from the text component's document.
 void setAutoCompleteFileName(boolean auto)
          Sets whether this text field auto-completes the next matching filename when the drop-down list is visible.
 void setCurrentDirectory(java.io.File currentDirectory)
          Sets the current directory for this text field.
 void setCurrentDirectory(java.lang.String currentDirectory)
          Sets the current directory for this text field.
 void setDirectoriesOnly(boolean directoriesOnly)
          Sets whether or not this text field previews both files and directories or just directories.
 void setDocument(javax.swing.text.Document document)
          Sets the document for this text field.
 void setFileSystemAware(boolean aware)
          Toggles whether or not this dialog is file-system-aware.
 void setListCellRenderer(javax.swing.ListCellRenderer renderer)
          Sets the cell renderer for the drop-down file list.
 void setUI(javax.swing.plaf.TextUI ui)
          Overridden so that we always have a document listener on the text field.
 void valueChanged(javax.swing.event.ListSelectionEvent e)
          Called when the user manually selects a popup menu list item with the mouse.
 
Methods inherited from class javax.swing.JTextField
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setFont, setHorizontalAlignment, setScrollOffset
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, updateUI, viewToModel, write
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, 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, 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, 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, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, 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

FSATextField

public FSATextField()
Creates a new FSATextField that previews both files and directories, and whose current directory is the program's current directory.


FSATextField

public FSATextField(int cols)
Creates a new FSATextField that previews both files and directories, and whose current directory is the program's current directory.

Parameters:
cols - The number of columns to display in this text field.

FSATextField

public FSATextField(boolean directoriesOnly,
                    java.io.File currentDirectory)
Creates a new FSATextField.

Parameters:
directoriesOnly - Whether this text field should preview only directories (or both files and directories).
currentDirectory - The directory for which the text field should assume relative filenames are in.

FSATextField

public FSATextField(boolean directoriesOnly,
                    java.lang.String currentDirectory)
Creates a new FSATextField.

Parameters:
directoriesOnly - Whether this text field should preview only directories (or both files and directories).
currentDirectory - The directory for which the text field should assume relative filenames are in.
Method Detail

addItem

public void addItem(java.lang.String item)
Adds an item to the file list.

Parameters:
item - The item to add to the file list.
See Also:
removeAllItems()

addNotify

public void addNotify()

Overrides:
addNotify in class javax.swing.JComponent

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent e)
Called when the text component's document receives a style change. Since it is a plain document, this is never called.

Specified by:
changedUpdate in interface javax.swing.event.DocumentListener

componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
Called when the parent dialog/frame of this text field is hidden. This should not be overridden.

Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
Called when the parent dialog/frame of this text field is moved. This should not be overridden.

Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Called when the parent dialog/frame of this text field is resized. This should not be overridden.

Specified by:
componentResized in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
Called when the parent dialog/frame of this text field is shown. This should not be overridden.

Specified by:
componentShown in interface java.awt.event.ComponentListener

getAutoCompleteFileName

public boolean getAutoCompleteFileName()
Returns whether this text field auto-completes the next matching filename when the drop-down list is visible. Note that this property is only honored when this text field is "file system aware".

Returns:
Whether the next matching filename is auto-inserted.
See Also:
setAutoCompleteFileName(boolean)

getCurrentDirectory

public java.lang.String getCurrentDirectory()
Returns the current directory for this text field.

Returns:
The current directory.
See Also:
setCurrentDirectory(java.io.File)

getFileSystemAware

public boolean getFileSystemAware()
Returns whether or not this text field is file-system-aware. If it is, then the drop-down list expands to display all matching files and directories as the user types.

Returns:
Whether or not this text field is file-system aware.
See Also:
setFileSystemAware(boolean)

hidePopup

public void hidePopup()
Hides the popup window, if it is visible. This can be used to programmatically hide the popup window.


insertUpdate

public void insertUpdate(javax.swing.event.DocumentEvent e)
Called when text is inserted into this text component.

Specified by:
insertUpdate in interface javax.swing.event.DocumentListener

isDirectoriesOnly

public boolean isDirectoriesOnly()
Returns whether or not this text field previews both files and directories or just directories.

Returns:
Whether or not this text field shows only directories.
See Also:
setDirectoriesOnly(boolean)

processFocusEvent

public void processFocusEvent(java.awt.event.FocusEvent e)
Process the focus events of this text field. This is overridden so we can hide the drop-down file list if the text field loses focus.

Overrides:
processFocusEvent in class java.awt.Component
Parameters:
e - The focus event fired by this text field.

removeAllItems

public void removeAllItems()
Removes all items from the file list.

See Also:
addItem(java.lang.String)

removeNotify

public void removeNotify()

Overrides:
removeNotify in class javax.swing.text.JTextComponent

removeUpdate

public void removeUpdate(javax.swing.event.DocumentEvent e)
Called when text is removed from the text component's document.

Specified by:
removeUpdate in interface javax.swing.event.DocumentListener

setAutoCompleteFileName

public void setAutoCompleteFileName(boolean auto)
Sets whether this text field auto-completes the next matching filename when the drop-down list is visible. Note that this property is only honored when this text field is "file system aware".

Parameters:
auto - Whether the next matching filename is auto-inserted.
See Also:
getAutoCompleteFileName()

setCurrentDirectory

public void setCurrentDirectory(java.io.File currentDirectory)
Sets the current directory for this text field. The current directory is the directory in which the text field assumes typed relative files reside in.

Parameters:
currentDirectory - The new "current directory" for this combo box. This value should be an absolute pathname.
See Also:
getCurrentDirectory()

setCurrentDirectory

public void setCurrentDirectory(java.lang.String currentDirectory)
Sets the current directory for this text field. The current directory is the directory in which the text field assumes typed relative files reside in.

Parameters:
currentDirectory - The new "current directory" for this combo box. This value should be an absolute pathname.
See Also:
getCurrentDirectory()

setDirectoriesOnly

public void setDirectoriesOnly(boolean directoriesOnly)
Sets whether or not this text field previews both files and directories or just directories.

Parameters:
directoriesOnly - Whether or not to preview only directories.
See Also:
isDirectoriesOnly()

setDocument

public void setDocument(javax.swing.text.Document document)
Sets the document for this text field. This is overridden so we can add a document listener to it.

Overrides:
setDocument in class javax.swing.JTextField

setFileSystemAware

public void setFileSystemAware(boolean aware)
Toggles whether or not this dialog is file-system-aware. This property should be set to false when programmatically inserting text into the text field; otherwise, it has a bad habit of stealing the focus from the currently focused component, etc.

Parameters:
aware - Whether or not this text field should be file-system aware.
See Also:
getFileSystemAware()

setListCellRenderer

public void setListCellRenderer(javax.swing.ListCellRenderer renderer)
Sets the cell renderer for the drop-down file list.

Parameters:
renderer - The cell renderer to use.

setUI

public void setUI(javax.swing.plaf.TextUI ui)
Overridden so that we always have a document listener on the text field.

Overrides:
setUI in class javax.swing.text.JTextComponent

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent e)
Called when the user manually selects a popup menu list item with the mouse. This synchronizes the text field's text value with the selected list item.

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener
Parameters:
e - The event.