com.sygem.swing.jdirectorychooser
Class JDirectoryChooser

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended bycom.sygem.swing.jdirectorychooser.JDirectoryChooser
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class JDirectoryChooser
extends javax.swing.JComponent
implements javax.accessibility.Accessible, java.io.Serializable

The JDirectoryChooser represents a simpler way for users to select directories than using the JFileChooser. It more closely resembles a native platform directory chooser.

The chooser also supports the ability to create new directories, and rename those newly created directories.

Title: JDirectoryChooser
Description: A Swing component for selecting directories
Copyright: Copyright (c) 2004
Company: SyGem Software

Version:
1.0b
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
static int APPROVE_OPTION
          Return value if approve (yes, ok) is chosen.
static int CANCEL_OPTION
          Return value if cancel is chosen.
static java.lang.String DIRECTORY_CHANGED_PROPERTY
          Identifies user's directory change.
static int ERROR_OPTION
          Return value if an error occured.
static java.lang.String FILE_SYSTEM_VIEW_CHANGED_PROPERTY
          Says that a different object is being used to find available drives on the system.
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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()
          Constructs a JDirectoryChooser object, using the default FileSystemView.
JDirectoryChooser(java.io.File currentDirectory)
          Constructs a JDirectoryChooser object, using the default FileSystemView but pointing at the given directory.
JDirectoryChooser(java.io.File currentDirectory, javax.swing.filechooser.FileSystemView fsv)
          Constructs a JDirectoryChooser using the given current directory and FileSystemView.
JDirectoryChooser(javax.swing.filechooser.FileSystemView fsv)
          Constructs a JDirectoryChooser object, using the specified FileSystemView.
JDirectoryChooser(java.lang.String currentDirectoryPath)
          Constructs a JDirectoryChooser using the given directory path.
JDirectoryChooser(java.lang.String currentDirectoryPath, javax.swing.filechooser.FileSystemView fsv)
          Constructs a JDirectoryChooser using the given current directory and FileSystemView.
 
Method Summary
 javax.accessibility.AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this JDirectoryChooser.
 char getCancelButtonMnemonic()
          Returns the mnemonic for the "Cancel" button.
 java.lang.String getCancelButtonText()
          Gets the text used for the "Cancel" button
 java.lang.String getCancelButtonToolTipText()
          Gets the tool tip used for the "Cancel" button
 java.io.File getCurrentDirectory()
          Returns the current directory.
 javax.swing.filechooser.FileSystemView getFileSystemView()
          Returns the file system view.
 char getMakeDirectoryButtonMnemonic()
          Gets the mnemonic used for the "Make Directory" button
 java.lang.String getMakeDirectoryButtonText()
          Gets the text used for the "Make Directory" button
 java.lang.String getMakeDirectoryButtonToolTipText()
          Gets the tool tip text from the "Make Directory" button
 java.lang.String getMessageText()
          Gets the message displayed at the top of the directory chooser dialog.
 char getOkButtonMnemonic()
          Returns the mnemonic for the "OK" button.
 java.lang.String getOkButtonText()
          Gets the text used for the "OK" button
 java.lang.String getOkButtonToolTipText()
          Gets the tool tip text from the "OK" button.
 java.lang.String getTitle()
          Gets the window title of the directory chooser dialog.
 void setCancelButtonMnemonic(char cancelButtonMnemonic)
          Sets the mnemonic for the "Cancel" button.
 void setCancelButtonText(java.lang.String cancelButtonText)
          Sets the text used for the "Cancel" button
 void setCancelButtonToolTipText(java.lang.String cancelButtonToolTipText)
          Sets the tool tip text for the "Cancel" button
 void setCurrentDirectory(java.io.File dir)
          Sets the current directory.
 void setFileSystemView(javax.swing.filechooser.FileSystemView fsv)
          Sets the file system view that the JDirectoryChooser uses for accessing and creating file system resources, such as finding the floppy drive and getting a list of root drives.
 void setMakeDirectoryButtonMnemonic(char makeDirectoryButtonMnemonic)
          Sets the mnemonic used for the "Make Directory" button
 void setMakeDirectoryButtonText(java.lang.String makeDirectoryButtonText)
          Sets the text used for the "Make Directory" button
 void setMakeDirectoryButtonToolTipText(java.lang.String makeDirectoryButtonToolTipText)
          Sets the tool tip text for the "Make Directory" button
 void setMessageText(java.lang.String messageText)
          Sets the message used at the top of the directory chooser dialog.
 void setOkButtonMnemonic(char okButtonMnemonic)
          Sets the mnemonic for the "OK" button.
 void setOkButtonText(java.lang.String okButtonText)
          Sets the text for the "OK" button.
 void setOkButtonToolTipText(java.lang.String okButtonToolTipText)
          Sets the tool tip text for the "OK" button.
 void setTitle(java.lang.String title)
          Sets the window title of the directory chooser dialog.
 int showDialog(java.awt.Component parent)
          Pops up the directory chooser dialog.
 void updateUI()
          Resets the UI property to a value from the current look and feel.
 
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, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, 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, 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, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

APPROVE_OPTION

public static final int APPROVE_OPTION
Return value if approve (yes, ok) is chosen.

See Also:
Constant Field Values

CANCEL_OPTION

public static final int CANCEL_OPTION
Return value if cancel is chosen.

See Also:
Constant Field Values

DIRECTORY_CHANGED_PROPERTY

public static final java.lang.String DIRECTORY_CHANGED_PROPERTY
Identifies user's directory change.

See Also:
Constant Field Values

ERROR_OPTION

public static final int ERROR_OPTION
Return value if an error occured.

See Also:
Constant Field Values

FILE_SYSTEM_VIEW_CHANGED_PROPERTY

public static final java.lang.String FILE_SYSTEM_VIEW_CHANGED_PROPERTY
Says that a different object is being used to find available drives on the system.

See Also:
Constant Field Values
Constructor Detail

JDirectoryChooser

public JDirectoryChooser()
Constructs a JDirectoryChooser object, using the default FileSystemView. The initial directory will be the root of your system.


JDirectoryChooser

public JDirectoryChooser(java.io.File currentDirectory)
Constructs a JDirectoryChooser object, using the default FileSystemView but pointing at the given directory. Assuming the directory exists, the path to it will be fully opened. If it does not exist, the path will be opened as far as is possible.

Parameters:
currentDirectory - A file representing the initial directory for the chooser

JDirectoryChooser

public JDirectoryChooser(java.io.File currentDirectory,
                         javax.swing.filechooser.FileSystemView fsv)
Constructs a JDirectoryChooser using the given current directory and FileSystemView. Assuming the directory exists, the path to it will be fully opened. If it does not exist, the path will be opened as far as is possible.

Parameters:
currentDirectory - A file representing the initial directory for the chooser
fsv - The FileSystemView object to use for the chooser

JDirectoryChooser

public JDirectoryChooser(javax.swing.filechooser.FileSystemView fsv)
Constructs a JDirectoryChooser object, using the specified FileSystemView. The initial directory will be the root of your system.

Parameters:
fsv - The FileSystemView object to use for the chooser

JDirectoryChooser

public JDirectoryChooser(java.lang.String currentDirectoryPath)
Constructs a JDirectoryChooser using the given directory path. Assuming the directory exists, the path to it will be fully opened. If it does not exist, the path will be opened as far as is possible.

Parameters:
currentDirectoryPath - The initial directory to open

JDirectoryChooser

public JDirectoryChooser(java.lang.String currentDirectoryPath,
                         javax.swing.filechooser.FileSystemView fsv)
Constructs a JDirectoryChooser using the given current directory and FileSystemView. Assuming the directory exists, the path to it will be fully opened. If it does not exist, the path will be opened as far as is possible.

Parameters:
currentDirectoryPath - The initial directory to open
fsv - FileSystemView
Method Detail

getAccessibleContext

public javax.accessibility.AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JDirectoryChooser. For file choosers, the AccessibleContext takes the form of an AccessibleJDirectoryChooser. A new AccessibleJDirectoryChooser instance is created if necessary.

Specified by:
getAccessibleContext in interface javax.accessibility.Accessible
Returns:
an AccessibleJDirectoryChooser that serves as the AccessibleContext of this JDirectoryChooser

getCancelButtonMnemonic

public char getCancelButtonMnemonic()
Returns the mnemonic for the "Cancel" button.

Returns:
The button mnemonic

getCancelButtonText

public java.lang.String getCancelButtonText()
Gets the text used for the "Cancel" button

Returns:
The button text

getCancelButtonToolTipText

public java.lang.String getCancelButtonToolTipText()
Gets the tool tip used for the "Cancel" button

Returns:
The tool tip

getCurrentDirectory

public java.io.File getCurrentDirectory()
Returns the current directory.

Returns:
the current directory
See Also:
setCurrentDirectory(java.io.File)

getFileSystemView

public javax.swing.filechooser.FileSystemView getFileSystemView()
Returns the file system view.

Returns:
the FileSystemView object
See Also:
setFileSystemView(javax.swing.filechooser.FileSystemView)

getMakeDirectoryButtonMnemonic

public char getMakeDirectoryButtonMnemonic()
Gets the mnemonic used for the "Make Directory" button

Returns:
The button mnemonic

getMakeDirectoryButtonText

public java.lang.String getMakeDirectoryButtonText()
Gets the text used for the "Make Directory" button

Returns:
The button text

getMakeDirectoryButtonToolTipText

public java.lang.String getMakeDirectoryButtonToolTipText()
Gets the tool tip text from the "Make Directory" button

Returns:
The tool tip text

getMessageText

public java.lang.String getMessageText()
Gets the message displayed at the top of the directory chooser dialog.

Returns:
The message text

getOkButtonMnemonic

public char getOkButtonMnemonic()
Returns the mnemonic for the "OK" button.

Returns:
a char representing the mnemonic

getOkButtonText

public java.lang.String getOkButtonText()
Gets the text used for the "OK" button

Returns:
The button text

getOkButtonToolTipText

public java.lang.String getOkButtonToolTipText()
Gets the tool tip text from the "OK" button.

Returns:
The tool tip text

getTitle

public java.lang.String getTitle()
Gets the window title of the directory chooser dialog.

Returns:
The dialog title

setCancelButtonMnemonic

public void setCancelButtonMnemonic(char cancelButtonMnemonic)
Sets the mnemonic for the "Cancel" button.

Parameters:
cancelButtonMnemonic - a char

setCancelButtonText

public void setCancelButtonText(java.lang.String cancelButtonText)
Sets the text used for the "Cancel" button

Parameters:
cancelButtonText - The new button text

setCancelButtonToolTipText

public void setCancelButtonToolTipText(java.lang.String cancelButtonToolTipText)
Sets the tool tip text for the "Cancel" button

Parameters:
cancelButtonToolTipText - The new tool tip

setCurrentDirectory

public void setCurrentDirectory(java.io.File dir)
Sets the current directory. Passing in null performs no action on the JDirectoryChooser. If the file passed in as currentDirectory is not a directory, the parent of the file will be used as the currentDirectory. If the parent is not traversable, then it will walk up the parent tree until it finds a traversable directory, or hits the root of the file system.

Parameters:
dir - the current directory to point to
See Also:
getCurrentDirectory()

setFileSystemView

public void setFileSystemView(javax.swing.filechooser.FileSystemView fsv)
Sets the file system view that the JDirectoryChooser uses for accessing and creating file system resources, such as finding the floppy drive and getting a list of root drives.

Parameters:
fsv - the new FileSystemView
See Also:
FileSystemView

setMakeDirectoryButtonMnemonic

public void setMakeDirectoryButtonMnemonic(char makeDirectoryButtonMnemonic)
Sets the mnemonic used for the "Make Directory" button

Parameters:
makeDirectoryButtonMnemonic - The new mnemonic

setMakeDirectoryButtonText

public void setMakeDirectoryButtonText(java.lang.String makeDirectoryButtonText)
Sets the text used for the "Make Directory" button

Parameters:
makeDirectoryButtonText - The new button text

setMakeDirectoryButtonToolTipText

public void setMakeDirectoryButtonToolTipText(java.lang.String makeDirectoryButtonToolTipText)
Sets the tool tip text for the "Make Directory" button

Parameters:
makeDirectoryButtonToolTipText - The new tool tip

setMessageText

public void setMessageText(java.lang.String messageText)
Sets the message used at the top of the directory chooser dialog.

Parameters:
messageText - The new message

setOkButtonMnemonic

public void setOkButtonMnemonic(char okButtonMnemonic)
Sets the mnemonic for the "OK" button.

Parameters:
okButtonMnemonic - a char

setOkButtonText

public void setOkButtonText(java.lang.String okButtonText)
Sets the text for the "OK" button.

Parameters:
okButtonText - The new button text

setOkButtonToolTipText

public void setOkButtonToolTipText(java.lang.String okButtonToolTipText)
Sets the tool tip text for the "OK" button.

Parameters:
okButtonToolTipText - The new tool tip text

setTitle

public void setTitle(java.lang.String title)
Sets the window title of the directory chooser dialog.

Parameters:
title - The new title for the dialog

showDialog

public int showDialog(java.awt.Component parent)
Pops up the directory chooser dialog. Note that the text that appears in the buttons can be set by the user.

Parameters:
parent - the parent component of the dialog, can be null;
Returns:
the return state of the file chooser on popdown:
  • JDirectoryChooser.CANCEL_OPTION
  • JDirectoryChooser.APPROVE_OPTION
  • JDirectoryChooser.ERROR_OPTION if an error occurs or the dialog is dismissed
Throws:
java.awt.HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
See Also:
GraphicsEnvironment.isHeadless()

updateUI

public void updateUI()
Resets the UI property to a value from the current look and feel.

See Also:
JComponent.updateUI()


Copyright © 2004 SyGem Software. All Rights Reserved.