swingwtx.swing
Class JFileChooser

java.lang.Object
  extended byswingwt.awt.Component
      extended byswingwt.awt.Container
          extended byswingwtx.swing.JComponent
              extended byswingwtx.swing.JPanel
                  extended byswingwtx.swing.JFileChooser
All Implemented Interfaces:
ImageObserver, MenuContainer

public class JFileChooser
extends JPanel

JFileChooser is now a custom control (like Swing's), however if you only use the showXDialog() methods without calling setAccessory() or setExtensions(), you will get a native platform file chooser dialog instead. You can force native or non-native by creating an instance of JFileChooser and doing [instance].useNative = true/false This hopefully supplies the best of both worlds. FIXME: Does not support multiple file selection or directories in custom mode (works fine for platform native)


Nested Class Summary
 
Nested classes inherited from class swingwtx.swing.JComponent
JComponent.InternalFrameSelectionListener
 
Field Summary
static java.lang.String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY
           
static java.lang.String ACCESSORY_CHANGED_PROPERTY
           
protected  swingwtx.swing.JFileChooser.FileFilterWrapper allFiles
           
static java.lang.String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY
           
static java.lang.String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
           
static java.lang.String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY
           
static int APPROVE_OPTION
           
protected  JPanel buttonPanel
           
static int CANCEL_OPTION
           
static java.lang.String CANCEL_SELECTION
           
protected  JPanel centralPanel
           
static java.lang.String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY
           
static java.lang.String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
           
protected  java.io.File curFile
           
protected  java.io.File[] curFiles
           
protected  java.io.File curPath
           
static int CUSTOM_DIALOG
           
protected  swingwtx.swing.JFileChooser.FileChooserDialog customDialog
           
static java.lang.String DIALOG_TITLE_CHANGED_PROPERTY
           
static java.lang.String DIALOG_TYPE_CHANGED_PROPERTY
           
protected  int dialogReturnValue
           
protected  java.lang.String dialogTitle
           
protected  int dialogType
           
static int DIRECTORIES_ONLY
           
static java.lang.String DIRECTORY_CHANGED_PROPERTY
           
static int ERROR_OPTION
           
protected  JComponent fcAccessory
           
static java.lang.String FILE_FILTER_CHANGED_PROPERTY
           
static java.lang.String FILE_HIDING_CHANGED_PROPERTY
           
static java.lang.String FILE_SELECTION_MODE_CHANGED_PROPERTY
           
static java.lang.String FILE_SYSTEM_VIEW_CHANGED_PROPERTY
           
static java.lang.String FILE_VIEW_CHANGED_PROPERTY
           
protected  java.util.Vector fileFilters
           
protected  JList fileList
           
static int FILES_AND_DIRECTORIES
           
static int FILES_ONLY
           
protected  int fileSelection
           
protected  JComboBox filter
           
protected  java.lang.String[] filterNames
           
protected  java.lang.String[] filters
           
protected  JTextField location
           
protected  JLabel locationLabel
           
static java.lang.String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
           
protected  boolean multiSelect
           
protected  JButton okButton
           
static int OPEN_DIALOG
           
static int SAVE_DIALOG
           
static java.lang.String SELECTED_FILE_CHANGED_PROPERTY
           
static java.lang.String SELECTED_FILES_CHANGED_PROPERTY
           
 boolean useNative
          Whether or not to use native chooser - is set to false if setAccessory() or setExtensions() is called.
 
Fields inherited from class swingwtx.swing.JPanel
opaque, ppeer
 
Fields inherited from class swingwtx.swing.JComponent
accessibleContext, actionMap, ancestorInputMap, border, clientProperties, descendantHasPeer, focusInputMap, internalFrameAdapter, internalFrameParent, propertyChangeListeners, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, windowInputMap
 
Fields inherited from class swingwt.awt.Container
composite, comps, containerListeners, layout, queuedValidateRequest
 
Fields inherited from class swingwt.awt.Component
actionCommand, actionListeners, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, componentListeners, componentName, consumeAvailableHeight, consumeAvailableWidth, focusable, focusListeners, graphicsConfig, inputMethodListeners, isUserSetFont, keyListeners, layoutModifier, LEFT_ALIGNMENT, LOCK, mouseListeners, mouseMotionListeners, mouseWheelListeners, parent, pBackground, pCursor, pDoubleBuffered, peer, pEnabled, pFont, pForeground, pLayoutData, pLocation, pMaxSize, pMinSize, pPrefSize, pSize, pToolTipText, pVisible, RIGHT_ALIGNMENT, swingWTDefaultActionEventAdapter, swingWTEventAdapter, TOP_ALIGNMENT
 
Fields inherited from interface swingwt.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JFileChooser()
          Creates a new instance of JFileChooser
JFileChooser(java.io.File currentDirectory)
           
JFileChooser(java.lang.String currentDirectoryPath)
           
 
Method Summary
 void addChoosableFileFilter(FileFilter f)
           
 void changeToParentDirectory()
           
protected  void checkDriveEntry(java.lang.String path, java.lang.String displayName, JComboBox driveBox)
          Checks if the specified file path exists and if it does, creates a DriveEntry object, wraps the path and description up with it and loads it into the drives combo box for display.
 void ensureFileIsVisible(java.io.File f)
           
protected  void firePropertyChangeEvent(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Sends property change event to all listeners
protected  void forceRelayout()
          Lays out the whole thing - this is really for problems with accessories not resizing.
 JComponent getAccessory()
           
 java.lang.String getApproveButtonText()
           
 java.lang.String getApproveButtonToolTipText()
           
 FileFilter[] getChoosableFileFilters()
           
 boolean getControlButtonsAreShown()
           
 java.io.File getCurrentDirectory()
           
 int getDialogType()
           
 FileFilter getFileFilter()
           
 int getFileSelectionMode()
           
 java.io.File getSelectedFile()
           
 java.io.File[] getSelectedFiles()
           
 java.lang.String getTitle()
           
 boolean isAcceptAllFileFilterUsed()
           
 boolean isDirectorySelectionEnabled()
           
 boolean isFileHidingEnabled()
           
 boolean isFileSelectionEnabled()
           
 boolean isMultiSelectionEnabled()
           
protected  void layoutComponent()
          Lays out native widgets for this component.
 boolean removeChoosableFileFilter(FileFilter f)
           
 void rescanCurrentDirectory()
          Refreshes the on-screen list for the current location
 void resetChoosableFileFilters()
           
 void scanDrives(JComboBox driveBox)
          Scans "drives" according to platform.
 void setAcceptAllFileFilterUsed(boolean b)
           
 void setAccessory(JComponent newAccessory)
           
 void setApproveButtonMnemonic(char mnemonic)
           
 void setApproveButtonMnemonic(int mnemonic)
           
 void setApproveButtonText(java.lang.String approveButtonText)
           
 void setApproveButtonToolTipText(java.lang.String toolTipText)
           
 void setControlButtonsAreShown(boolean b)
           
 void setCurrentDirectory(java.io.File dir)
           
 void setDialogTitle(java.lang.String dialogTitle)
           
 void setDialogType(int dialogType)
           
 void setExtensionFilters(java.lang.String[] extensions, java.lang.String[] names)
          NOT A REAL SWING METHOD - THIS SETS FILTERS FOR THE PLATFORM DIALOGS INSTEAD OF OUR CUSTOM FILECHOOSER.
 void setFileFilter(FileFilter fileFilter)
           
 void setFileHidingEnabled(boolean b)
           
 void setFileSelectionMode(int mode)
           
 void setMultiSelectionEnabled(boolean b)
           
 void setSelectedFile(java.io.File file)
           
 void setSelectedFiles(java.io.File[] selectedFiles)
           
 void setTitle(java.lang.String title)
           
static void setUseLastDirectory(boolean b)
           
protected  int showCustomOpenDialog(Component parent)
           
protected  int showCustomSaveDialog(Component parent)
           
 java.lang.String showDirectorySelectDialog(Component parent, java.lang.String message)
          This is a convenience method to the DirectoryDialog SWT class.
protected  int showNativeOpenDialog(Component parent)
           
protected  int showNativeSaveDialog(Component parent)
           
 int showOpenDialog(Component parent)
          Wrapper routine - calls either showNativeOpenDialog or showCustomOpenDialog depending on options chosen
 int showSaveDialog(Component parent)
           
 java.io.File[] sortFiles(java.io.File[] sort)
          Sorts an array of Java File references into alphabetical order.
 
Methods inherited from class swingwtx.swing.JPanel
calculatePreferredSize, getHeight, getSize, getWidth, setBorder, setSwingWTParent
 
Methods inherited from class swingwtx.swing.JComponent
add, add, add, add, add, addPropertyChangeListener, addPropertyChangeListener, checkInternalFrameChild, dispose, getAccessibleContext, getActionMap, getAutoscrolls, getBorder, getClientProperty, getInputMap, getInsets, getToolTipLocation, getToolTipText, getTopLevelAncestor, getVisibleRect, isDoubleBuffered, isOpaque, isOptimizedDrawingEnabled, isValidateRoot, paint, paintBackground, paintChildren, paintComponent, paintImmediately, paintImmediately, putClientProperty, remove, remove, removePropertyChangeListener, removePropertyChangeListener, repaint, revalidate, scrollRectToVisible, setActionMap, setAutoscrolls, setDoubleBuffered, setInputMap, setMargin, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled
 
Methods inherited from class swingwt.awt.Container
addComponentToLayout, addContainerListener, debug_showContainmentTree, doAdd, doLayout, getComponent, getComponentCount, getComponentOrientation, getComponents, getComposite, getLayout, getMaximumSize, getMinimumSize, getParent, getPreferredSize, invalidate, minimumSize, preferredSize, processContainerEvent, processEvent, queuedValidate, removeAll, removeComponentFromCache, removeContainerListener, setLayout, setLayoutImpl, validate
 
Methods inherited from class swingwt.awt.Component
add, addActionListener, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, componentOnlyDispose, computePreferredSize, contains, contains, createImage, createListenerArrayFromVector, createVolatileImage, dispatchEvent, getActionCommand, getAlignmentX, getAlignmentY, getBackground, getBounds, getCursor, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getListeners, getLocation, getLocationOnScreen, getName, getPeer, getPeerSize, getSize, getSWTPeer, getToolkit, getToolTipText, getTreeLock, getX, getY, grabFocus, hasFocus, hasSetFont, hide, imageUpdate, inside, isEnabled, isFocusable, isMinimumSizeSet, isShowing, isVisible, processActionEvent, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, processTraverseEvent, registerActionEvents, registerComponentEvents, registerEvents, registerExtendedModifyEvents, registerFocusEvents, registerKeyEvents, registerModifyEvents, registerMouseEvents, registerPaintEvents, registerTraversalEvents, remove, removeActionListener, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, repaint, repaint, repaint, requestFocus, setActionCommand, setAlignmentX, setAlignmentY, setBackground, setBounds, setBounds, setCachedProperties, setComponentOrientation, setComponentRemoved, setCursor, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setFont, setForeground, setHeight, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setSize, setSize, setToolTipText, setVisible, setWidth, show, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN_DIALOG

public static final int OPEN_DIALOG
See Also:
Constant Field Values

SAVE_DIALOG

public static final int SAVE_DIALOG
See Also:
Constant Field Values

CUSTOM_DIALOG

public static final int CUSTOM_DIALOG
See Also:
Constant Field Values

CANCEL_OPTION

public static final int CANCEL_OPTION
See Also:
Constant Field Values

CANCEL_SELECTION

public static final java.lang.String CANCEL_SELECTION
See Also:
Constant Field Values

APPROVE_OPTION

public static final int APPROVE_OPTION
See Also:
Constant Field Values

ERROR_OPTION

public static final int ERROR_OPTION
See Also:
Constant Field Values

FILES_ONLY

public static final int FILES_ONLY
See Also:
Constant Field Values

DIRECTORIES_ONLY

public static final int DIRECTORIES_ONLY
See Also:
Constant Field Values

FILES_AND_DIRECTORIES

public static final int FILES_AND_DIRECTORIES
See Also:
Constant Field Values

ACCESSORY_CHANGED_PROPERTY

public static final java.lang.String ACCESSORY_CHANGED_PROPERTY
See Also:
Constant Field Values

ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY

public static final java.lang.String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY
See Also:
Constant Field Values

DIALOG_TITLE_CHANGED_PROPERTY

public static final java.lang.String DIALOG_TITLE_CHANGED_PROPERTY
See Also:
Constant Field Values

DIALOG_TYPE_CHANGED_PROPERTY

public static final java.lang.String DIALOG_TYPE_CHANGED_PROPERTY
See Also:
Constant Field Values

CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY

public static final java.lang.String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY
See Also:
Constant Field Values

FILE_VIEW_CHANGED_PROPERTY

public static final java.lang.String FILE_VIEW_CHANGED_PROPERTY
See Also:
Constant Field Values

FILE_HIDING_CHANGED_PROPERTY

public static final java.lang.String FILE_HIDING_CHANGED_PROPERTY
See Also:
Constant Field Values

FILE_FILTER_CHANGED_PROPERTY

public static final java.lang.String FILE_FILTER_CHANGED_PROPERTY
See Also:
Constant Field Values

FILE_SELECTION_MODE_CHANGED_PROPERTY

public static final java.lang.String FILE_SELECTION_MODE_CHANGED_PROPERTY
See Also:
Constant Field Values

APPROVE_BUTTON_TEXT_CHANGED_PROPERTY

public static final java.lang.String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY
See Also:
Constant Field Values

APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY

public static final java.lang.String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY
See Also:
Constant Field Values

APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY

public static final java.lang.String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY
See Also:
Constant Field Values

CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY

public static final java.lang.String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
See Also:
Constant Field Values

DIRECTORY_CHANGED_PROPERTY

public static final java.lang.String DIRECTORY_CHANGED_PROPERTY
See Also:
Constant Field Values

SELECTED_FILE_CHANGED_PROPERTY

public static final java.lang.String SELECTED_FILE_CHANGED_PROPERTY
See Also:
Constant Field Values

SELECTED_FILES_CHANGED_PROPERTY

public static final java.lang.String SELECTED_FILES_CHANGED_PROPERTY
See Also:
Constant Field Values

MULTI_SELECTION_ENABLED_CHANGED_PROPERTY

public static final java.lang.String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY
See Also:
Constant Field Values

FILE_SYSTEM_VIEW_CHANGED_PROPERTY

public static final java.lang.String FILE_SYSTEM_VIEW_CHANGED_PROPERTY
See Also:
Constant Field Values

dialogType

protected int dialogType

dialogTitle

protected java.lang.String dialogTitle

fileSelection

protected int fileSelection

curPath

protected java.io.File curPath

curFile

protected java.io.File curFile

curFiles

protected java.io.File[] curFiles

multiSelect

protected boolean multiSelect

filters

protected java.lang.String[] filters

filterNames

protected java.lang.String[] filterNames

fileFilters

protected java.util.Vector fileFilters

useNative

public boolean useNative
Whether or not to use native chooser - is set to false if setAccessory() or setExtensions() is called. Since native ones can't support this. If this is embedded in a container as a component, then this value is ignored anyway. It is only relevant for showOpenDialog()/showSaveDialog() You can set this value directly prior to calling a show method to force the component to use either native, or custom dialogs as you wish if you don't want it to intelligently work out what to use.


location

protected JTextField location

filter

protected JComboBox filter

centralPanel

protected JPanel centralPanel

fileList

protected JList fileList

buttonPanel

protected JPanel buttonPanel

locationLabel

protected JLabel locationLabel

okButton

protected JButton okButton

fcAccessory

protected JComponent fcAccessory

customDialog

protected swingwtx.swing.JFileChooser.FileChooserDialog customDialog

dialogReturnValue

protected int dialogReturnValue

allFiles

protected swingwtx.swing.JFileChooser.FileFilterWrapper allFiles
Constructor Detail

JFileChooser

public JFileChooser()
Creates a new instance of JFileChooser


JFileChooser

public JFileChooser(java.lang.String currentDirectoryPath)

JFileChooser

public JFileChooser(java.io.File currentDirectory)
Method Detail

setUseLastDirectory

public static void setUseLastDirectory(boolean b)

getSelectedFile

public java.io.File getSelectedFile()

setSelectedFile

public void setSelectedFile(java.io.File file)

getSelectedFiles

public java.io.File[] getSelectedFiles()

setSelectedFiles

public void setSelectedFiles(java.io.File[] selectedFiles)

getCurrentDirectory

public java.io.File getCurrentDirectory()

setCurrentDirectory

public void setCurrentDirectory(java.io.File dir)

changeToParentDirectory

public void changeToParentDirectory()

scanDrives

public void scanDrives(JComboBox driveBox)
Scans "drives" according to platform. UNIX platforms have / (root), plus the contents of the /mnt directory, along with /cdrom and /cdrom1 if they exist. Win32 machines we scan a: through to z: and any that exist are added to the list. I am well aware that this is a quick and dirty solution that will work for probably 99% of PC owners with Windows and a popular *nix distro (Mandrake, Red Hat, Debian, FreeBSD are fine with this stuff)


checkDriveEntry

protected void checkDriveEntry(java.lang.String path,
                               java.lang.String displayName,
                               JComboBox driveBox)
Checks if the specified file path exists and if it does, creates a DriveEntry object, wraps the path and description up with it and loads it into the drives combo box for display.


rescanCurrentDirectory

public void rescanCurrentDirectory()
Refreshes the on-screen list for the current location


ensureFileIsVisible

public void ensureFileIsVisible(java.io.File f)

getControlButtonsAreShown

public boolean getControlButtonsAreShown()

setControlButtonsAreShown

public void setControlButtonsAreShown(boolean b)

getDialogType

public int getDialogType()

setDialogType

public void setDialogType(int dialogType)

setDialogTitle

public void setDialogTitle(java.lang.String dialogTitle)

setApproveButtonToolTipText

public void setApproveButtonToolTipText(java.lang.String toolTipText)

getApproveButtonToolTipText

public java.lang.String getApproveButtonToolTipText()

setApproveButtonMnemonic

public void setApproveButtonMnemonic(int mnemonic)

setApproveButtonMnemonic

public void setApproveButtonMnemonic(char mnemonic)

setApproveButtonText

public void setApproveButtonText(java.lang.String approveButtonText)

getApproveButtonText

public java.lang.String getApproveButtonText()

getAccessory

public JComponent getAccessory()

setAccessory

public void setAccessory(JComponent newAccessory)

setFileSelectionMode

public void setFileSelectionMode(int mode)

getFileSelectionMode

public int getFileSelectionMode()

isFileSelectionEnabled

public boolean isFileSelectionEnabled()

isDirectorySelectionEnabled

public boolean isDirectorySelectionEnabled()

setMultiSelectionEnabled

public void setMultiSelectionEnabled(boolean b)

isMultiSelectionEnabled

public boolean isMultiSelectionEnabled()

isFileHidingEnabled

public boolean isFileHidingEnabled()

setFileHidingEnabled

public void setFileHidingEnabled(boolean b)

setExtensionFilters

public void setExtensionFilters(java.lang.String[] extensions,
                                java.lang.String[] names)
NOT A REAL SWING METHOD - THIS SETS FILTERS FOR THE PLATFORM DIALOGS INSTEAD OF OUR CUSTOM FILECHOOSER. Because setting Swing-style filters trips use of our custom dialog instead of the platform-native one, you can use this method instead to add filters to the native dialogs.


setFileFilter

public void setFileFilter(FileFilter fileFilter)

getFileFilter

public FileFilter getFileFilter()

getChoosableFileFilters

public FileFilter[] getChoosableFileFilters()

addChoosableFileFilter

public void addChoosableFileFilter(FileFilter f)

removeChoosableFileFilter

public boolean removeChoosableFileFilter(FileFilter f)

resetChoosableFileFilters

public void resetChoosableFileFilters()

isAcceptAllFileFilterUsed

public boolean isAcceptAllFileFilterUsed()

setAcceptAllFileFilterUsed

public void setAcceptAllFileFilterUsed(boolean b)

showOpenDialog

public int showOpenDialog(Component parent)
Wrapper routine - calls either showNativeOpenDialog or showCustomOpenDialog depending on options chosen


showDirectorySelectDialog

public java.lang.String showDirectorySelectDialog(Component parent,
                                                  java.lang.String message)
This is a convenience method to the DirectoryDialog SWT class. I'm sure it can be integrated better into JFileChooser (with the directory selection flag), but one problem is it doesn't allow multi-select. So, here's a simple wrapper for those who need it...

Parameters:
parent -
Returns:
Directory name selected by user. NULL if nothing selected (cancel pressed)

showCustomOpenDialog

protected int showCustomOpenDialog(Component parent)

showNativeOpenDialog

protected int showNativeOpenDialog(Component parent)

showSaveDialog

public int showSaveDialog(Component parent)

showNativeSaveDialog

protected int showNativeSaveDialog(Component parent)

showCustomSaveDialog

protected int showCustomSaveDialog(Component parent)

getTitle

public java.lang.String getTitle()

setTitle

public void setTitle(java.lang.String title)

sortFiles

public java.io.File[] sortFiles(java.io.File[] sort)
Sorts an array of Java File references into alphabetical order.


firePropertyChangeEvent

protected void firePropertyChangeEvent(java.lang.String propertyName,
                                       java.lang.Object oldValue,
                                       java.lang.Object newValue)
Sends property change event to all listeners


forceRelayout

protected void forceRelayout()
Lays out the whole thing - this is really for problems with accessories not resizing.


layoutComponent

protected void layoutComponent()
Lays out native widgets for this component.