public class FileDialog
extends javax.swing.JFileChooser
javax.swing.JFileChooser.AccessibleJFileChooser
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
context |
private static java.lang.String |
DEFAULT_CONTEXT |
private boolean |
fileShouldExist |
private boolean |
isCurDirSet |
private static javax.swing.filechooser.FileFilter |
lastChosenFilter |
private boolean |
modifyDir |
private java.awt.Component |
owner |
static java.lang.String |
PREFS |
private static java.util.HashMap<java.lang.String,java.io.File> |
recentDirs |
private static java.util.prefs.Preferences |
recentPathPreferences |
ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY, accessibleContext, ACCESSORY_CHANGED_PROPERTY, APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY, APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY, APPROVE_OPTION, APPROVE_SELECTION, CANCEL_OPTION, CANCEL_SELECTION, CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY, CUSTOM_DIALOG, DIALOG_TITLE_CHANGED_PROPERTY, DIALOG_TYPE_CHANGED_PROPERTY, DIRECTORIES_ONLY, DIRECTORY_CHANGED_PROPERTY, ERROR_OPTION, FILE_FILTER_CHANGED_PROPERTY, FILE_HIDING_CHANGED_PROPERTY, FILE_SELECTION_MODE_CHANGED_PROPERTY, FILE_SYSTEM_VIEW_CHANGED_PROPERTY, FILE_VIEW_CHANGED_PROPERTY, FILES_AND_DIRECTORIES, FILES_ONLY, MULTI_SELECTION_ENABLED_CHANGED_PROPERTY, OPEN_DIALOG, SAVE_DIALOG, SELECTED_FILE_CHANGED_PROPERTY, SELECTED_FILES_CHANGED_PROPERTY
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
FileDialog() |
FileDialog(boolean isSaveDialog,
java.lang.String filters,
java.lang.String title) |
FileDialog(int dialogType,
java.lang.String filters,
java.lang.String title) |
Modifier and Type | Method and Description |
---|---|
FileDialog |
addFilters(java.lang.String filterSpecSet)
Adds a set of filter-specs to the list of file filters for the FileChooser.
|
void |
approveSelection() |
FileDialog |
clearFilters()
Clear any existing filters.
|
private void |
filterChanged(java.beans.PropertyChangeEvent evt) |
private javax.swing.filechooser.FileFilter |
findMatchingFilter(java.io.File f) |
java.lang.String |
getContext() |
static java.io.File |
getDefaultDir() |
java.lang.String |
getDefaultExtension() |
private static java.util.prefs.Preferences |
getDefaultPreferenceStorage() |
static java.lang.String |
getFileName(boolean forSave,
java.awt.Component parent,
java.lang.String title,
java.lang.String defaultPath,
java.lang.String filters,
java.lang.String context) |
static java.lang.String |
getFileName(boolean forSave,
java.awt.Component parent,
java.lang.String title,
java.lang.String defaultPath,
java.lang.String filters,
java.lang.String context,
boolean disableDirChange,
java.lang.String defaultExtension) |
boolean |
getFileShouldExist() |
static javax.swing.filechooser.FileFilter |
getLastChosenFilter() |
static java.lang.String |
getOpenName(java.lang.String filters) |
static java.lang.String |
getOpenName(java.lang.String filters,
java.lang.String defaultPath) |
static java.lang.String |
getOpenName(java.lang.String filters,
java.lang.String defaultPath,
java.lang.String title,
java.lang.String context,
java.awt.Component parent) |
java.awt.Component |
getOwner() |
static java.io.File |
getRecentDir(java.lang.String context) |
static java.io.File |
getRecentDir(java.lang.String context,
boolean mustExist) |
static java.io.File |
getRecentDir(java.lang.String context,
boolean mustExist,
java.io.File defaultIfNotSet) |
static java.io.File |
getRecentDirOrDefault(java.lang.String context,
boolean mustExist) |
static java.lang.String |
getSaveName(java.lang.String filters) |
static java.lang.String |
getSaveName(java.lang.String filters,
java.lang.String defaultPath) |
static java.lang.String |
getSaveName(java.lang.String filters,
java.lang.String defaultPath,
java.lang.String title,
java.lang.String context,
java.awt.Component parent) |
static java.lang.String |
getSaveName(java.lang.String filters,
java.lang.String defaultPath,
java.lang.String title,
java.lang.String context,
java.awt.Component parent,
java.lang.String defaultExtension) |
java.io.File |
getSelectedFile()
Returns the selected file.
|
static void |
loadRecentPaths() |
static void |
loadRecentPaths(java.util.prefs.Preferences storage) |
boolean |
modifyDir()
Gets the property 'modifyDir', which affects whether the user's actions (i.e.
|
boolean |
passesFilter(java.io.File f) |
static void |
saveRecentPaths() |
static void |
saveRecentPaths(java.util.prefs.Preferences storage) |
FileDialog |
setButtonText(java.lang.String text)
Set the text that appears on the accept (OK) button.
|
FileDialog |
setContext(java.lang.String context)
Set the context for default startup folder.
|
static void |
setDefaultDir(java.io.File dir) |
FileDialog |
setDefaultFile(java.io.File f) |
FileDialog |
setDefaultFile(java.lang.String path) |
void |
setFileShouldExist(boolean fileShouldExist) |
FileDialog |
setFilterFromExt(java.lang.String findExt) |
FileDialog |
setFilterFromFile(java.io.File f) |
FileDialog |
setFilterIndex(int filterIndex) |
FileDialog |
setModifyDir(boolean modifyDir)
Sets the property 'modifyDir', which affects whether the user's actions (i.e.
|
void |
setOwner(java.awt.Component owner) |
static void |
setRecentDir(java.lang.String context,
java.io.File value) |
static void |
setRecentDir(java.lang.String context,
java.lang.String value) |
FileDialog |
setStartDir(java.io.File dir) |
FileDialog |
setStartDir(java.lang.String path) |
java.io.File |
showFileDialog(java.awt.Component parent)
Show the File Chooser and return the selected file path, if successful, or null if the user
cancels.
|
accept, addActionListener, addChoosableFileFilter, cancelSelection, changeToParentDirectory, createDialog, ensureFileIsVisible, fireActionPerformed, getAcceptAllFileFilter, getAccessibleContext, getAccessory, getActionListeners, getApproveButtonMnemonic, getApproveButtonText, getApproveButtonToolTipText, getChoosableFileFilters, getControlButtonsAreShown, getCurrentDirectory, getDescription, getDialogTitle, getDialogType, getDragEnabled, getFileFilter, getFileSelectionMode, getFileSystemView, getFileView, getIcon, getName, getSelectedFiles, getTypeDescription, getUI, getUIClassID, isAcceptAllFileFilterUsed, isDirectorySelectionEnabled, isFileHidingEnabled, isFileSelectionEnabled, isMultiSelectionEnabled, isTraversable, paramString, removeActionListener, removeChoosableFileFilter, rescanCurrentDirectory, resetChoosableFileFilters, setAcceptAllFileFilterUsed, setAccessory, setApproveButtonMnemonic, setApproveButtonMnemonic, setApproveButtonText, setApproveButtonToolTipText, setControlButtonsAreShown, setCurrentDirectory, setDialogTitle, setDialogType, setDragEnabled, setFileFilter, setFileHidingEnabled, setFileSelectionMode, setFileSystemView, setFileView, setMultiSelectionEnabled, setSelectedFile, setSelectedFiles, setup, showDialog, showOpenDialog, showSaveDialog, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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
private java.lang.String context
private static final java.lang.String DEFAULT_CONTEXT
private boolean fileShouldExist
private boolean isCurDirSet
private static javax.swing.filechooser.FileFilter lastChosenFilter
private boolean modifyDir
private java.awt.Component owner
public static final java.lang.String PREFS
private static java.util.HashMap<java.lang.String,java.io.File> recentDirs
private static java.util.prefs.Preferences recentPathPreferences
public FileDialog()
public FileDialog(boolean isSaveDialog, java.lang.String filters, java.lang.String title)
public FileDialog(int dialogType, java.lang.String filters, java.lang.String title)
public FileDialog addFilters(java.lang.String filterSpecSet)
|
) and one or more
File Extensions, separated by semi-colons (;
). I.e.: Description|ext1[;ext2...]
Both the description and at least one extension are required and cannot be blank.
A "set" of filter-specs consists of one or more filter-specs separated by a bar. E.g.:
filter-spec_1[|filter-spec_2...]
i.e. Description|ext1_1[;ext1_2...]|Description2|ext2_1[;ext2_2...]
A blank filter-spec is allowed and will simply be ignored. So the following will result in
the addition of exactly two filters (despite the empty file-specs at the start, middle and end).
${ code |Description|ext1;ext2||Description2|ext1;ext2| }
However the following filter-spec set would raise an error, because the list of extensions is effectively blank.
(the ext1... would be interpreted as the start of the second filter-spec).
${ code Description||ext1;ext2 }
As a special case, the filter-specs "*" or "*|*" are both interpreted as the accept-all-files filter, i.e.
"All Files (*.*)"filterSpecSet
- public void approveSelection()
approveSelection
in class javax.swing.JFileChooser
public FileDialog clearFilters()
JFileChooser.setAcceptAllFileFilterUsed(boolean)
with the value false would be more efficient
than clearing all filters.private void filterChanged(java.beans.PropertyChangeEvent evt)
private javax.swing.filechooser.FileFilter findMatchingFilter(java.io.File f)
public java.lang.String getContext()
public static java.io.File getDefaultDir()
public java.lang.String getDefaultExtension()
private static java.util.prefs.Preferences getDefaultPreferenceStorage()
public static java.lang.String getFileName(boolean forSave, java.awt.Component parent, java.lang.String title, java.lang.String defaultPath, java.lang.String filters, java.lang.String context)
public static java.lang.String getFileName(boolean forSave, java.awt.Component parent, java.lang.String title, java.lang.String defaultPath, java.lang.String filters, java.lang.String context, boolean disableDirChange, java.lang.String defaultExtension)
public boolean getFileShouldExist()
public static javax.swing.filechooser.FileFilter getLastChosenFilter()
public static java.lang.String getOpenName(java.lang.String filters)
public static java.lang.String getOpenName(java.lang.String filters, java.lang.String defaultPath)
public static java.lang.String getOpenName(java.lang.String filters, java.lang.String defaultPath, java.lang.String title, java.lang.String context, java.awt.Component parent)
public java.awt.Component getOwner()
public static java.io.File getRecentDir(java.lang.String context)
public static java.io.File getRecentDir(java.lang.String context, boolean mustExist)
public static java.io.File getRecentDir(java.lang.String context, boolean mustExist, java.io.File defaultIfNotSet)
public static java.io.File getRecentDirOrDefault(java.lang.String context, boolean mustExist)
public static java.lang.String getSaveName(java.lang.String filters)
public static java.lang.String getSaveName(java.lang.String filters, java.lang.String defaultPath)
public static java.lang.String getSaveName(java.lang.String filters, java.lang.String defaultPath, java.lang.String title, java.lang.String context, java.awt.Component parent)
public static java.lang.String getSaveName(java.lang.String filters, java.lang.String defaultPath, java.lang.String title, java.lang.String context, java.awt.Component parent, java.lang.String defaultExtension)
public java.io.File getSelectedFile()
setSelectedFile
or by a user action, such as
either typing the filename into the UI or selecting the
file from a list in the UI.getSelectedFile
in class javax.swing.JFileChooser
JFileChooser.setSelectedFile(java.io.File)
public static void loadRecentPaths()
public static void loadRecentPaths(java.util.prefs.Preferences storage)
public boolean modifyDir()
public boolean passesFilter(java.io.File f)
public static void saveRecentPaths()
public static void saveRecentPaths(java.util.prefs.Preferences storage)
public FileDialog setButtonText(java.lang.String text)
text
- The text to display on the button.public FileDialog setContext(java.lang.String context)
context
- public static void setDefaultDir(java.io.File dir)
public FileDialog setDefaultFile(java.io.File f)
public FileDialog setDefaultFile(java.lang.String path)
public void setFileShouldExist(boolean fileShouldExist)
public FileDialog setFilterFromExt(java.lang.String findExt)
public FileDialog setFilterFromFile(java.io.File f)
public FileDialog setFilterIndex(int filterIndex)
public FileDialog setModifyDir(boolean modifyDir)
modifyDir
- Set to True if the users actions should affect the recent directory stored for the current
context. Set to false if the system's recent directories should not be affected.public void setOwner(java.awt.Component owner)
public static void setRecentDir(java.lang.String context, java.io.File value)
public static void setRecentDir(java.lang.String context, java.lang.String value)
public FileDialog setStartDir(java.io.File dir)
public FileDialog setStartDir(java.lang.String path)
public java.io.File showFileDialog(java.awt.Component parent)