Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.jext.misc
Class FindAccessory  view FindAccessory download FindAccessory.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byorg.jext.misc.FindAccessory
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, FindProgressCallback, java.awt.image.ImageObserver, java.awt.MenuContainer, java.lang.Runnable, java.io.Serializable

public class FindAccessory
extends javax.swing.JPanel
implements java.lang.Runnable, java.awt.event.ActionListener, FindProgressCallback

A threaded file search accessory for JFileChooser.

Presents JFileChooser users with a tabbed panel interface for specifying file search criteria including (1) search by name, (2) search by date of modification, and (3) search by file content. Finded are performed "in the background" with found files displayed dynamically as they are found. Only one search can be active at a time. FindResults are displayed in a scrolling list within a results tab panel.

Findes are performed asynchronously so the user can continue browsing the file system. The user may stop the search at any time. Accepting or cancelling the file chooser or closing the dialog window will automatically stop a search in progress.

The starting folder of the search (the search base) is displayed at the top of the accessory panel. The search base dsiplay will not change while a search is running. Thes search base display will change to reflect the current directory of JFileChooser when a search is not running.

Changing the search options does not affect a search in progress.

Version:
1.0, 2000/01/19

Nested Class Summary
(package private)  class FindAccessory.FindAction
          Convenience class for adding action objects to the control panel.
(package private)  class FindAccessory.FindControls
          Find controls panel displays default action components for starting and stopping a search.
(package private)  class FindAccessory.FindResults
          Appears as a special pane within the FindOptions tabbed panel.
(package private)  class FindAccessory.FindTabs
          Contains a collecton of search options displayed as tabbed panes and at least one pane for displaying the search results.
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String ACCESSORY_NAME
          Label for this accessory.
static java.lang.String ACTION_START
          Find start action name
static java.lang.String ACTION_STOP
          Find stop action name
protected  FindAccessory.FindAction actionStart
           
protected  FindAccessory.FindAction actionStop
           
protected  javax.swing.JFileChooser chooser
          Parent JFileChooser component
protected  FindAccessory.FindControls controlPanel
          Find controls with progress display
static int DEFAULT_MAX_SEARCH_HITS
          Default max number of found items.
protected  boolean killFind
          Set to true to stop current search
protected  int matches
          Number of items found by current/last search
protected  int maxMatches
          Max number of found items to prevent overloading the results list.
protected  FindAccessory.FindTabs searchTabs
          Find options with results list
protected  java.lang.Thread searchThread
          This version of FindAccesory supports only one active search thread
protected  int total
          Number of items inspected by current/last search
 
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.Container
 
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
FindAccessory()
          Construct a search panel with start and stop actions, option panes and a results list pane that can display up to DEFAULT_MAX_SEARCH_HITS items.
FindAccessory(javax.swing.JFileChooser parent)
          Construct a search panel with start and stop actions and "attach" it to the specified JFileChooser component.
FindAccessory(javax.swing.JFileChooser c, int max)
          Construct a search panel with start and stop actions and "attach" it to the specified JFileChooser component.
 
Method Summary
protected  boolean accept(java.io.File file, FindFilter[] filters)
           
 void action(java.lang.String command)
          Invoked by FindAction objects to start and stop searches.
 void actionPerformed(java.awt.event.ActionEvent e)
          Called by JFileChooser when the user provokes an action like "cancel" or "open".
 int getMaxFindHits()
          Returns maximum capacity of results list.
 void goTo(java.io.File f)
          Set parent's current directory to the parent folder of the specified file and select the specified file.
 boolean isRunning()
           
protected  FindFilter[] newFind()
          Begins a new search by resetting the total and matches progress variables and retrieves the search filter array from the options panel.
 void quit()
          Stop the current search and unregister in preparation for parent shutdown.
protected  void register(javax.swing.JFileChooser c)
          Add this component to the specified JFileChooser's list of property change listeners and action listeners.
 boolean reportProgress(FindFilter filter, java.io.File file, long current, long total)
          Called by FindFilter to report progress of a search.
 void run()
          Find thread
protected  void runFind(java.io.File base, FindFilter[] filters)
          Recursive search beginning at folder base for files and folders matching each filter in the filters array.
 void setMaxFindHits(int max)
          Sets maximum capacity of the results list.
 void startThread()
          Start a search.
 void stop()
          Stop the active search.
protected  void unregister(javax.swing.JFileChooser c)
          Remove this component from the specified JFileChooser's list of property change listeners and action listeners.
protected  void updateProgress()
          Display progress of running search.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, 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, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, 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, processMouseEvent, 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, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ACCESSORY_NAME

public static final java.lang.String ACCESSORY_NAME
Label for this accessory.


DEFAULT_MAX_SEARCH_HITS

public static final int DEFAULT_MAX_SEARCH_HITS
Default max number of found items. Prevents overloading results list.

See Also:
Constant Field Values

ACTION_START

public static final java.lang.String ACTION_START
Find start action name


ACTION_STOP

public static final java.lang.String ACTION_STOP
Find stop action name


chooser

protected javax.swing.JFileChooser chooser
Parent JFileChooser component


actionStart

protected FindAccessory.FindAction actionStart

actionStop

protected FindAccessory.FindAction actionStop

searchThread

protected java.lang.Thread searchThread
This version of FindAccesory supports only one active search thread


killFind

protected boolean killFind
Set to true to stop current search


searchTabs

protected FindAccessory.FindTabs searchTabs
Find options with results list


controlPanel

protected FindAccessory.FindControls controlPanel
Find controls with progress display


total

protected int total
Number of items inspected by current/last search


matches

protected int matches
Number of items found by current/last search


maxMatches

protected int maxMatches
Max number of found items to prevent overloading the results list.

Constructor Detail

FindAccessory

public FindAccessory()
Construct a search panel with start and stop actions, option panes and a results list pane that can display up to DEFAULT_MAX_SEARCH_HITS items.


FindAccessory

public FindAccessory(javax.swing.JFileChooser parent)
Construct a search panel with start and stop actions and "attach" it to the specified JFileChooser component. Calls register() to establish FindAccessory as a PropertyChangeListener of JFileChooser.


FindAccessory

public FindAccessory(javax.swing.JFileChooser c,
                     int max)
Construct a search panel with start and stop actions and "attach" it to the specified JFileChooser component. Calls register() to establish FindAccessory as a PropertyChangeListener of JFileChooser. Sets maximum number of found items to limit the load in the results list.

Method Detail

setMaxFindHits

public void setMaxFindHits(int max)
Sets maximum capacity of the results list. Find stops when max number of items found.


getMaxFindHits

public int getMaxFindHits()
Returns maximum capacity of results list.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Called by JFileChooser when the user provokes an action like "cancel" or "open". Listens for APPROVE_SELECTION and CANCEL_SELECTION action and stops the current search, if there is one.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

goTo

public void goTo(java.io.File f)
Set parent's current directory to the parent folder of the specified file and select the specified file. This method is invoked when the user double clicks on an item in the results list.


startThread

public void startThread()
Start a search. The path display will show the starting folder of the search. Finds are recursive and will span the entire folder hierarchy below the base folder. The user may continue to browse with JFileChooser.


stop

public void stop()
Stop the active search.


isRunning

public boolean isRunning()

run

public void run()
Find thread

Specified by:
run in interface java.lang.Runnable

runFind

protected void runFind(java.io.File base,
                       FindFilter[] filters)
                throws java.lang.InterruptedException
Recursive search beginning at folder base for files and folders matching each filter in the filters array. To interrupt set killFind to true. Also stops when number of search hits (matches) equals maxMatches.

Note: Convert this to a nonrecursive search algorithm on systems where stack space might be limited and/or the search hierarchy might be very deep.


accept

protected boolean accept(java.io.File file,
                         FindFilter[] filters)

reportProgress

public boolean reportProgress(FindFilter filter,
                              java.io.File file,
                              long current,
                              long total)
Called by FindFilter to report progress of a search. Purely a voluntary report. This really should be implemented as a property change listener. Percentage completion = (current/total)*100.

Specified by:
reportProgress in interface FindProgressCallback

newFind

protected FindFilter[] newFind()
Begins a new search by resetting the total and matches progress variables and retrieves the search filter array from the options panel. Each tab in the options panel is responsible for generating a FindFilter based on its current settings.


updateProgress

protected void updateProgress()
Display progress of running search.


register

protected void register(javax.swing.JFileChooser c)
Add this component to the specified JFileChooser's list of property change listeners and action listeners.


unregister

protected void unregister(javax.swing.JFileChooser c)
Remove this component from the specified JFileChooser's list of property change listeners and action listeners.


quit

public void quit()
Stop the current search and unregister in preparation for parent shutdown.


action

public void action(java.lang.String command)
Invoked by FindAction objects to start and stop searches.