jas2.util.gui
Class JDirectoryChooser
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- jas2.util.gui.JDirectoryChooser
-
- All Implemented Interfaces:
- java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
public class JDirectoryChooser extends javax.swing.JComponentA 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
-
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field and Description static intAPPROVE_OPTIONstatic intCANCEL_OPTION-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor and Description JDirectoryChooser()Create a JDirectoryChooser with the default FileSystemViewJDirectoryChooser(java.io.File currentDirectory)Create a JDirectoryChooser with the default FileSystemViewJDirectoryChooser(java.io.File currentDirectory, javax.swing.filechooser.FileSystemView view)Create a JDirectoryChooserJDirectoryChooser(javax.swing.filechooser.FileSystemView view)Create a JDirectoryChooserJDirectoryChooser(java.lang.String currentDirectory)Create a JDirectoryChooser with the default FileSystemViewJDirectoryChooser(java.lang.String currentDirectory, javax.swing.filechooser.FileSystemView view)Create a JDirectoryChooser
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddNotify()java.lang.StringgetDialogTitle()Gets the string that goes in the FileChooser's titlebarjavax.swing.filechooser.FileFiltergetFileFilter()Get the current file filterintgetFileSelectionMode()Test the file selection modejavax.swing.filechooser.FileViewgetFileView()Returns the current file view.java.io.FilegetSelectedFile()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.booleanisFileHidingEnabled()Test if file hiding is enabledbooleanisMultiSelectionEnabled()Returns true if multi-file selection is enabled.static voidmain(java.lang.String[] argv)voidsetCurrentDirectory(java.io.File dir)Set the directory to which the tree is to openvoidsetDialogTitle(java.lang.String dialogTitle)Sets the string that goes in the FileChooser window's title barvoidsetFileFilter(javax.swing.filechooser.FileFilter fileFilter)Set a filter to control which files are displayed in the treevoidsetFileHidingEnabled(boolean hide)Select whether to show "hidden" files in the treevoidsetFileSelectionMode(int mode)Set the file selection mode.voidsetFileView(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.voidsetMultiSelectionEnabled(boolean enable)Sets the filechooser to allow multiple file selections.intshowDialog(java.awt.Component parent)Popup up a modal dialog containing the JDirectoryChooservoidupdateUI()-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, 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
-
-
-
-
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 setview- 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 setview- 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:
addNotifyin classjavax.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.
-
updateUI
public void updateUI()
- Overrides:
updateUIin classjavax.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)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG