dip.misc
Class XJFileChooser

java.lang.Object
  extended bydip.misc.XJFileChooser

public class XJFileChooser
extends java.lang.Object

A simplified and extended JFileChooser for single-file (only!) selections. It is also cached, so that it displays faster.

SimpleFileFilter support is integrated, so that file extensions are automatically appended (unless "all files" is selected).

Futhermore, if saving a file, checking is done to determine if a file will be overwritten; if so, a confirmation dialog is displayed.


Method Summary
 void addFileFilter(SimpleFileFilter filter)
          Adds a SimpleFileFilter to the list of available file filters.
 java.io.File display(java.awt.Component parent, java.lang.String title, java.lang.String acceptButtonText, int type, int mode)
          Display the file chooser, with the given title and Accept button text.
 java.io.File displayOpen(java.awt.Component parent)
          The typical "Open" dialog.
 java.io.File displayOpen(java.awt.Component parent, java.lang.String title)
          The typical "Open" dialog.
 java.io.File displaySave(java.awt.Component parent)
          The typical "Save" dialog.
 java.io.File displaySave(java.awt.Component parent, java.lang.String title)
          The typical "Save" dialog.
 java.io.File displaySaveAs(java.awt.Component parent)
          The typical "Save As" dialog.
 java.io.File displaySelectDir(java.awt.Component parent, java.lang.String title)
          Display a filechooser that only allows the selection of a single directory.
static void dispose()
          Disposes the in-use XJFileChooser.
static XJFileChooser getXJFileChooser()
          Gets the XJFileChooser (only one exists -- this must be enforced by you!).
static void init()
          Can be used to initialize the XJFileChooser when called to provide faster response later
 void setCurrentDirectory(java.io.File file)
          Set the current directory.
 void setFileFilter(SimpleFileFilter filter)
          Sets the default file filter.
 void setSelectedFile(java.io.File file)
          Sets the suggested file name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

init

public static void init()
Can be used to initialize the XJFileChooser when called to provide faster response later


getXJFileChooser

public static XJFileChooser getXJFileChooser()
Gets the XJFileChooser (only one exists -- this must be enforced by you!).

The file filters are reset when this is called, which means that (usually) only the AcceptAll file filter (which is not a SimpleFileFilter) remains.


dispose

public static void dispose()
Disposes the in-use XJFileChooser. This should ALWAYS be called after a display() method has been called. The number of dispose() and getXJFileChooser() methods should be balanced.


addFileFilter

public void addFileFilter(SimpleFileFilter filter)
Adds a SimpleFileFilter to the list of available file filters.


setFileFilter

public void setFileFilter(SimpleFileFilter filter)
Sets the default file filter. If null, sets the 'accept all' file filter.


setCurrentDirectory

public void setCurrentDirectory(java.io.File file)
Set the current directory. May be set to null ('home' directory)


setSelectedFile

public void setSelectedFile(java.io.File file)
Sets the suggested file name. By default, no file name is suggested.


display

public java.io.File display(java.awt.Component parent,
                            java.lang.String title,
                            java.lang.String acceptButtonText,
                            int type,
                            int mode)
Display the file chooser, with the given title and Accept button text. No file filters are added. The type (JFileChooser.OPEN_DIALOG or SAVE_DIALOG) must be specified. If the acceptButtonText and/or title is null, the default button text (for OPEN_DIALOG or SAVE_DIALOG) and/or title is used.

Returns:
the selected File, or null

displayOpen

public java.io.File displayOpen(java.awt.Component parent)
The typical "Open" dialog. No filters are added.

Returns:
the selected File, or null

displayOpen

public java.io.File displayOpen(java.awt.Component parent,
                                java.lang.String title)
The typical "Open" dialog. No filters are added. A title may be specified.

Returns:
the selected File, or null

displaySave

public java.io.File displaySave(java.awt.Component parent)
The typical "Save" dialog. No filters are added.

Returns:
the selected File, or null

displaySave

public java.io.File displaySave(java.awt.Component parent,
                                java.lang.String title)
The typical "Save" dialog. No filters are added. A different title may be specified.

Returns:
the selected File, or null

displaySaveAs

public java.io.File displaySaveAs(java.awt.Component parent)
The typical "Save As" dialog. No filters are added.

Returns:
the selected File, or null

displaySelectDir

public java.io.File displaySelectDir(java.awt.Component parent,
                                     java.lang.String title)
Display a filechooser that only allows the selection of a single directory.

Returns:
the selected directory, or null


Copyright 2002-2004 Zachary DelProposto / jDip Development Team. All Rights Reserved.