jas.util.gui
Class JDirectoryChooser

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--jas.util.gui.JDirectoryChooser
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class JDirectoryChooser
extends javax.swing.JComponent

A class which allows a user to select directories or files, similar to JFileChooser, except that it display files as a tree, and is better suited to selecting directories than the current file chooser (see java bug id 4239219). TODO: Understand issue with moving mouse between double clicks (seems like MOUSE_PRESSED and MOUSE_RELEASED events are generated, but not MOUSE_CLICKED) See Bug ID 4218549

See Also:
Serialized Form

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
static int APPROVE_OPTION
           
static int CANCEL_OPTION
           
 
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
JDirectoryChooser()
          Create a JDirectoryChooser with the default FileSystemView
JDirectoryChooser(java.io.File currentDirectory)
          Create a JDirectoryChooser with the default FileSystemView
JDirectoryChooser(java.io.File currentDirectory, javax.swing.filechooser.FileSystemView view)
          Create a JDirectoryChooser
JDirectoryChooser(javax.swing.filechooser.FileSystemView view)
          Create a JDirectoryChooser
JDirectoryChooser(java.lang.String currentDirectory)
          Create a JDirectoryChooser with the default FileSystemView
JDirectoryChooser(java.lang.String currentDirectory, javax.swing.filechooser.FileSystemView view)
          Create a JDirectoryChooser
 
Method Summary
 void addNotify()
           
 java.lang.String getDialogTitle()
          Gets the string that goes in the FileChooser's titlebar
 javax.swing.filechooser.FileFilter getFileFilter()
          Get the current file filter
 int getFileSelectionMode()
          Test the file selection mode
 javax.swing.filechooser.FileView getFileView()
          Returns the current file view.
 java.io.File getSelectedFile()
          Returns the currently selected file (or the first selected file if multiple files are selected)
 java.io.File[] getSelectedFiles()
          Returns a list of selected files if the filechooser is set to allow multi-selection.
 boolean isFileHidingEnabled()
          Test if file hiding is enabled
 boolean isMultiSelectionEnabled()
          Returns true if multi-file selection is enabled.
static void main(java.lang.String[] argv)
           
 void setCurrentDirectory(java.io.File dir)
          Set the directory to which the tree is to open
 void setDialogTitle(java.lang.String dialogTitle)
          Sets the string that goes in the FileChooser window's title bar
 void setFileFilter(javax.swing.filechooser.FileFilter fileFilter)
          Set a filter to control which files are displayed in the tree
 void setFileHidingEnabled(boolean hide)
          Select whether to show "hidden" files in the tree
 void setFileSelectionMode(int mode)
          Set the file selection mode.
 void setFileView(javax.swing.filechooser.FileView fileView)
          Sets the file view to used to retrieve UI information, such as the icon that represents a file or the type description of a file.
 void setMultiSelectionEnabled(boolean enable)
          Sets the filechooser to allow multiple file selections.
protected  void setup(javax.swing.filechooser.FileSystemView view)
           
 int showDialog(java.awt.Component parent)
          Popup up a modal dialog containing the JDirectoryChooser
 void updateUI()
           
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, 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, paramString, 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

APPROVE_OPTION

public static int APPROVE_OPTION

CANCEL_OPTION

public static int CANCEL_OPTION
Constructor Detail

JDirectoryChooser

public JDirectoryChooser()
Create a JDirectoryChooser with the default FileSystemView

JDirectoryChooser

public JDirectoryChooser(java.io.File currentDirectory)
Create a JDirectoryChooser with the default FileSystemView
Parameters:
currentDirectory - The directory to which the tree is initially set

JDirectoryChooser

public JDirectoryChooser(java.lang.String currentDirectory)
Create a JDirectoryChooser with the default FileSystemView
Parameters:
currentDirectory - The directory to which the tree is initially set

JDirectoryChooser

public JDirectoryChooser(java.io.File currentDirectory,
                         javax.swing.filechooser.FileSystemView view)
Create a JDirectoryChooser
Parameters:
currentDirectory - The directory to which the tree is initially set
view - The FileSystemView to use

JDirectoryChooser

public JDirectoryChooser(java.lang.String currentDirectory,
                         javax.swing.filechooser.FileSystemView view)
Create a JDirectoryChooser
Parameters:
currentDirectory - The directory to which the tree is initially set
view - The FileSystemView to use

JDirectoryChooser

public JDirectoryChooser(javax.swing.filechooser.FileSystemView view)
Create a JDirectoryChooser
Parameters:
view - The FileSystemView to use
Method Detail

addNotify

public void addNotify()
Overrides:
addNotify in class javax.swing.JComponent

setCurrentDirectory

public void setCurrentDirectory(java.io.File dir)
Set the directory to which the tree is to open

setFileFilter

public void setFileFilter(javax.swing.filechooser.FileFilter fileFilter)
Set a filter to control which files are displayed in the tree

getFileFilter

public javax.swing.filechooser.FileFilter getFileFilter()
Get the current file filter
Returns:
The current FileFilter or null if none set

setFileHidingEnabled

public void setFileHidingEnabled(boolean hide)
Select whether to show "hidden" files in the tree
Parameters:
hide - True if hidden files should not be shown

isFileHidingEnabled

public boolean isFileHidingEnabled()
Test if file hiding is enabled
Returns:
true if file hiding is enabled
See Also:
setFileHidingEnabled(boolean)

setFileSelectionMode

public void setFileSelectionMode(int mode)
Set the file selection mode. Valid modes are
Parameters:
mode - either JFileChooser.DIRECTORIES_ONLY or JFileChooser.FILES_AND_DIRECTORIES (the default)
See Also:
JFileChooser.setFileSelectionMode(int)

getFileSelectionMode

public int getFileSelectionMode()
Test the file selection mode
Returns:
The current file selection mode
See Also:
setFileSelectionMode(int)

setMultiSelectionEnabled

public void setMultiSelectionEnabled(boolean enable)
Sets the filechooser to allow multiple file selections.

isMultiSelectionEnabled

public boolean isMultiSelectionEnabled()
Returns true if multi-file selection is enabled.

getSelectedFile

public java.io.File getSelectedFile()
Returns the currently selected file (or the first selected file if multiple files are selected)

getSelectedFiles

public java.io.File[] getSelectedFiles()
Returns a list of selected files if the filechooser is set to allow multi-selection.

setup

protected void setup(javax.swing.filechooser.FileSystemView view)

updateUI

public void updateUI()
Overrides:
updateUI in class javax.swing.JComponent

showDialog

public int showDialog(java.awt.Component parent)
Popup up a modal dialog containing the JDirectoryChooser
Parameters:
parent - The parent of the dialog box
Returns:
either JFileChooser.CANCEL_OPTION or JFileChooser.APPROVE_OPTION
See Also:
JFileChooser.showDialog(java.awt.Component, java.lang.String)

setDialogTitle

public void setDialogTitle(java.lang.String dialogTitle)
Sets the string that goes in the FileChooser window's title bar

getDialogTitle

public java.lang.String getDialogTitle()
Gets the string that goes in the FileChooser's titlebar

setFileView

public void setFileView(javax.swing.filechooser.FileView fileView)
Sets the file view to used to retrieve UI information, such as the icon that represents a file or the type description of a file.

getFileView

public javax.swing.filechooser.FileView getFileView()
Returns the current file view.

main

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