ObjectComponent
Container
Window
Dialog
JDialog
GFFileChooser
public class GFFileChooser
This Swing class enables file name selection in a manner similar to JFileChooser, but with some additional features.
| * | will match any number of characters |
| + | will match one or more characters |
| ? | will match any single character |
| \ | flags the next character to be taken literally. |
By default, the filter will be "*", giving all files in the current directory. The user is able to change the filter, eg. to "*.txt" or "Fred?". The filter feature will not work or be displayed on systems earlier than Java 1.4 which lack the Pattern class, though this will not cause loading this class to fail.
By default, "hidden" files and directories will not be listed. If all names are wanted, there is a check-box to request the hidden files.
showDialog methods. The parameters to showDialog
determine how the selector will behave, so a single dialog can be used
for different purposes by choosing the appropriate parameters each time
it is displayed. The selector can be used to select only filenames,
only directory names, only existing names, or any names including ones
that may not already exist.
The single-parameter showDialog method will allow anything to
be selected, including files that do not yet exist, which might possibly
be in a new directory which must first be created.
In the two-parameter showDialog method, the second parameter
indicates whether or not the chosen name must exist on the file system.
In the three-parameter method, the third parameter allows the programmer to impose the requirement whether it is a file or a directory that is being chosen. When directory selection is wanted, the names of files in the directory are shown but they cannot be selected. An explicit click on the accept button is required, and the directory name at the top of the window will be returned to the program.
The intent of the design is that, wherever possible, selection will be based on a single click.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class Dialog |
|---|
Dialog.ModalExclusionType, Dialog.ModalityType |
| Nested classes/interfaces inherited from class Component |
|---|
Component.BaselineResizeBehavior |
| Field Summary |
|---|
| Fields inherited from class Dialog |
|---|
DEFAULT_MODALITY_TYPE |
| Fields inherited from class Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface WindowConstants |
|---|
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE |
| Fields inherited from interface ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
GFFileChooser(JFrame owner)
Simple constructor for the file chooser. |
|
GFFileChooser(JFrame owner,
String dir)
Constructor for the file chooser, allowing the initial directory to be given. |
|
| Method Summary | |
|---|---|
void |
actionPerformed(ActionEvent e)
Event handler for buttons and text-fields. |
void |
caretUpdate(CaretEvent e)
Event handler for the name filter. |
File |
getFile()
Return a File object representing the file name chosen. |
String |
getFilter()
Return the filter string that the user has given. |
String |
getName()
Return the full file name chosen. |
String |
getShortName()
Return the short form of the file name chosen, without directory prefixes. |
void |
itemStateChanged(ItemEvent e)
Event handler for the checkboxes, eg for hidden name display. |
static void |
main(String[] args)
Simple demonstration to test the interface. |
void |
setCurrentDirectory(File dir)
Set the current directory prior to displaying the chooser. |
void |
setFile(File selected)
Set the initial name of the selected file. |
void |
setFilter(String text)
Set the filter string which limits which files can be selected. |
boolean |
showDialog(String approveButtonText)
Display the file selection dialog, allowing any file name, existing or otherwise to be typed or selected. |
boolean |
showDialog(String approveButtonText,
boolean fileMustExist)
Display the file selection dialog, with a parameter controlling whether the selected name must already exist on the file system. |
boolean |
showDialog(String approveButtonText,
boolean dirMustExist,
boolean dirSelection)
Display the file selection dialog, with a parameter controlling whether the name chosen must already exist on the file system, and another parameter determining whether it is a file or a directory that is being selected. |
void |
valueChanged(ListSelectionEvent e)
Event handler for the lists. |
| Methods inherited from class JDialog |
|---|
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update |
| Methods inherited from class Dialog |
|---|
addNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setModalityType, setResizable, setTitle, setUndecorated, setVisible, show, toBack |
| Methods inherited from class Window |
|---|
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, toFront |
| Methods inherited from class Container |
|---|
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate |
| Methods inherited from class Component |
|---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle |
| Methods inherited from class Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public GFFileChooser(JFrame owner)
public GFFileChooser(JFrame owner,
String dir)
dir - The initial directory to be shown when the file
chooseer is first displayed.| Method Detail |
|---|
public void actionPerformed(ActionEvent e)
actionPerformed in interface ActionListenerpublic void valueChanged(ListSelectionEvent e)
valueChanged in interface ListSelectionListenerpublic void caretUpdate(CaretEvent e)
caretUpdate in interface CaretListenerpublic void itemStateChanged(ItemEvent e)
itemStateChanged in interface ItemListenerpublic boolean showDialog(String approveButtonText)
approveButtonText - The text to display on the Accept button.
public boolean showDialog(String approveButtonText,
boolean fileMustExist)
approveButtonText - The text to display on the Accept button.fileMustExist - If true, only existing files can be selected,
and new directories cannot be created. Selection of a
file will complete on the button press in the file list.
public boolean showDialog(String approveButtonText,
boolean dirMustExist,
boolean dirSelection)
approveButtonText - The text to display on the Accept button.dirMustExist - If true, only existing directories can be selected,
and new directories cannot be created.dirSelection - If true, the purpose of the selector is to
choose a directory name.
public String getFilter()
public void setFilter(String text)
public String getName()
getName in class Componentpublic String getShortName()
public File getFile()
public void setCurrentDirectory(File dir)
public void setFile(File selected)
public static void main(String[] args)