com.vistech.listselect
Class FileBrowser

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--com.vistech.listselect.FileBrowser
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class FileBrowser
extends javax.swing.JPanel

The FileBrowser Class is a JavaBean that creates a embeddable panel to browse local directories. It uses the JTree component to navigate through the file folders and uses JTable to list the files in a directory. When a file is selected, it constructs a ListSelectEvent object with selected filename and the path and sends it to the registered listeners. The receiver of this event can extract this info and use it to load that file, for instance, an Image. Here is an example:

       FileBrowser flBrowser = new FileBrowser();
       flbrowser.addListSelectListener (
            new ListSelectListener() {
                public void load(ListSelectEvent e){
                   File currentDir = e.getPath();
                   String[] flist = e.getFileList();
                    String path =
                    (currentDir !=null)? currentDir.toString()+File.separator+flist[0]:flist[0];
                   if(flist != null) loadImage(path);
                 }
             }

        );
 
Note that the list select event is a custom event defined in the com.vistech.events package. If you are using the Visualization Framework, you can easily connect image loading beans such as ImageLoaderJAI to the FileBrowser bean.

Version:
2.0, 21 Jan 2001
Author:
Lawrence Rodrigues
See Also:
ListSelectListener, ListSelectEvent, Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  java.lang.String[] columnNames
           
protected  java.lang.String curDir
           
protected  java.io.File currentDir
           
protected  int currentSortMode
           
protected  javax.swing.JTextField dirField
           
protected  java.lang.String[][] fileInfoList
           
protected  javax.swing.JTable fileInfoTable
           
protected  java.lang.String[] fileList
           
protected  javax.swing.JTextField filterField
           
protected  java.lang.String filterString
           
protected  java.lang.String[] fString
           
protected  javax.swing.JScrollPane jsp
           
protected  boolean multiSelect
           
protected  javax.swing.JCheckBox multiSelectBox
           
protected  javax.swing.JComboBox rootBox
           
protected  java.io.File[] roots
           
protected  int selectionMode
           
protected  char separator
           
static int SORT_BY_ALPHA
           
static int SORT_BY_DATE
           
protected  javax.swing.JComboBox sortBox
           
protected static int[] sortModes
           
protected static java.lang.String[] sortModesString
           
protected  java.lang.String topNode
           
protected  javax.swing.JTree tree
           
protected  javax.swing.JScrollPane treeView
           
protected  javax.swing.JButton upButton
           
 
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
FileBrowser()
          FileBrowser constructor.
 
Method Summary
 void addListSelectListener(ListSelectListener il)
           
protected  void clickToLoad(javax.swing.JTable tb)
           
protected  javax.swing.JTable createFileInfoTable()
           
protected  javax.swing.JTree createTreeView()
           
 void createUI()
          Creates the UI components and lays them out
protected  java.lang.String[] filterFileNames(java.io.File[] filelist, java.lang.String[] fstr)
           
protected  void fireListSelectEvent(ListSelectEvent lse)
           
 java.io.File gePath()
           
 java.lang.String getFilterString()
           
 boolean getMultiSelect()
           
protected  void handleEvents()
           
static boolean isDirectory(java.lang.String file)
           
static java.lang.String[] listFiles(java.lang.String userDir)
           
 java.lang.String[] listFilteredFiles(java.lang.String dir, java.lang.String[] filt)
          Lists the filtered files
static void main(java.lang.String[] args)
           
protected  javax.swing.JTree newTreeView(java.lang.String curDir)
           
 void removeListSelectListener(ListSelectListener il)
           
 void setFilterString(java.lang.String filter)
          Sets the filter string.
 void setMultiSelect(boolean multiSelect)
           
 void setPath(java.io.File path)
          Sets the path
 java.lang.String[][] sortFileList(java.lang.String curDir, java.lang.String[][] flist, int sortMode)
           
protected  void updateFilterString(java.lang.String fStr)
           
protected  void updateTreeView(java.lang.String curDir)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, 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, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SORT_BY_DATE

public static final int SORT_BY_DATE

SORT_BY_ALPHA

public static final int SORT_BY_ALPHA

sortModes

protected static int[] sortModes

sortModesString

protected static java.lang.String[] sortModesString

currentSortMode

protected int currentSortMode

multiSelect

protected boolean multiSelect

fileList

protected java.lang.String[] fileList

tree

protected javax.swing.JTree tree

curDir

protected java.lang.String curDir

topNode

protected java.lang.String topNode

currentDir

protected transient java.io.File currentDir

separator

protected char separator

dirField

protected javax.swing.JTextField dirField

filterField

protected javax.swing.JTextField filterField

upButton

protected javax.swing.JButton upButton

filterString

protected java.lang.String filterString

fString

protected java.lang.String[] fString

treeView

protected javax.swing.JScrollPane treeView

selectionMode

protected int selectionMode

fileInfoList

protected java.lang.String[][] fileInfoList

columnNames

protected java.lang.String[] columnNames

fileInfoTable

protected javax.swing.JTable fileInfoTable

roots

protected transient java.io.File[] roots

rootBox

protected javax.swing.JComboBox rootBox

sortBox

protected javax.swing.JComboBox sortBox

multiSelectBox

protected javax.swing.JCheckBox multiSelectBox

jsp

protected javax.swing.JScrollPane jsp
Constructor Detail

FileBrowser

public FileBrowser()
FileBrowser constructor.
Method Detail

setPath

public void setPath(java.io.File path)
Sets the path
Parameters:
the - path.

gePath

public java.io.File gePath()
Returns:
the current directory

setFilterString

public void setFilterString(java.lang.String filter)
Sets the filter string.
Parameters:
filter - the filter string.

getFilterString

public java.lang.String getFilterString()
Returns:
the filter string.

setMultiSelect

public void setMultiSelect(boolean multiSelect)

getMultiSelect

public boolean getMultiSelect()

createUI

public void createUI()
Creates the UI components and lays them out

handleEvents

protected void handleEvents()

updateFilterString

protected void updateFilterString(java.lang.String fStr)

createTreeView

protected javax.swing.JTree createTreeView()

newTreeView

protected javax.swing.JTree newTreeView(java.lang.String curDir)

updateTreeView

protected void updateTreeView(java.lang.String curDir)

createFileInfoTable

protected javax.swing.JTable createFileInfoTable()

clickToLoad

protected void clickToLoad(javax.swing.JTable tb)

listFilteredFiles

public java.lang.String[] listFilteredFiles(java.lang.String dir,
                                            java.lang.String[] filt)
Lists the filtered files
Parameters:
dir - the current directory.
filt - the array containing list of file extendsions.
Returns:
the array containing the list of files.

filterFileNames

protected java.lang.String[] filterFileNames(java.io.File[] filelist,
                                             java.lang.String[] fstr)

listFiles

public static java.lang.String[] listFiles(java.lang.String userDir)

isDirectory

public static boolean isDirectory(java.lang.String file)

sortFileList

public java.lang.String[][] sortFileList(java.lang.String curDir,
                                         java.lang.String[][] flist,
                                         int sortMode)

addListSelectListener

public void addListSelectListener(ListSelectListener il)

removeListSelectListener

public void removeListSelectListener(ListSelectListener il)

fireListSelectEvent

protected void fireListSelectEvent(ListSelectEvent lse)

main

public static void main(java.lang.String[] args)