|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--javax.swing.JComponent
|
+--javax.swing.JPanel
|
+--com.vistech.listselect.FileBrowser
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.
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 |
public static final int SORT_BY_DATE
public static final int SORT_BY_ALPHA
protected static int[] sortModes
protected static java.lang.String[] sortModesString
protected int currentSortMode
protected boolean multiSelect
protected java.lang.String[] fileList
protected javax.swing.JTree tree
protected java.lang.String curDir
protected java.lang.String topNode
protected transient java.io.File currentDir
protected char separator
protected javax.swing.JTextField dirField
protected javax.swing.JTextField filterField
protected javax.swing.JButton upButton
protected java.lang.String filterString
protected java.lang.String[] fString
protected javax.swing.JScrollPane treeView
protected int selectionMode
protected java.lang.String[][] fileInfoList
protected java.lang.String[] columnNames
protected javax.swing.JTable fileInfoTable
protected transient java.io.File[] roots
protected javax.swing.JComboBox rootBox
protected javax.swing.JComboBox sortBox
protected javax.swing.JCheckBox multiSelectBox
protected javax.swing.JScrollPane jsp
| Constructor Detail |
public FileBrowser()
| Method Detail |
public void setPath(java.io.File path)
the - path.public java.io.File gePath()
public void setFilterString(java.lang.String filter)
filter - the filter string.public java.lang.String getFilterString()
public void setMultiSelect(boolean multiSelect)
public boolean getMultiSelect()
public void createUI()
protected void handleEvents()
protected void updateFilterString(java.lang.String fStr)
protected javax.swing.JTree createTreeView()
protected javax.swing.JTree newTreeView(java.lang.String curDir)
protected void updateTreeView(java.lang.String curDir)
protected javax.swing.JTable createFileInfoTable()
protected void clickToLoad(javax.swing.JTable tb)
public java.lang.String[] listFilteredFiles(java.lang.String dir,
java.lang.String[] filt)
dir - the current directory.filt - the array containing list of file extendsions.
protected java.lang.String[] filterFileNames(java.io.File[] filelist,
java.lang.String[] fstr)
public static java.lang.String[] listFiles(java.lang.String userDir)
public static boolean isDirectory(java.lang.String file)
public java.lang.String[][] sortFileList(java.lang.String curDir,
java.lang.String[][] flist,
int sortMode)
public void addListSelectListener(ListSelectListener il)
public void removeListSelectListener(ListSelectListener il)
protected void fireListSelectEvent(ListSelectEvent lse)
public static void main(java.lang.String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||