📄 jfilechooser.java
字号:
public boolean isAcceptAllFileFilterUsed() { return isAcceptAll; } /** * Sets the flag that controls whether or not the 'accept all' file filter * is included in the list of filters, and sends a * {@link PropertyChangeEvent} (with the property name * {@link #ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY}) to all registered * listeners. * * @param b the new value of the flag. */ public void setAcceptAllFileFilterUsed(boolean b) { if (isAcceptAll != b) { isAcceptAll = b; firePropertyChange(ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY, ! isAcceptAll, isAcceptAll); } } /** * Returns the accessory component for the file chooser. The default * value is <code>null</code>. * * @return The accessory component (possibly <code>null</code>). * * @see #setAccessory(JComponent) */ public JComponent getAccessory() { return accessory; } /** * Sets the accessory component for the file chooser and sends a * {@link PropertyChangeEvent} to all registered listeners. The property * name is {@link #ACCESSORY_CHANGED_PROPERTY}. * * @param newAccessory the accessory component. */ public void setAccessory(JComponent newAccessory) { if (accessory != newAccessory) { JComponent old = accessory; accessory = newAccessory; firePropertyChange(ACCESSORY_CHANGED_PROPERTY, old, accessory); } } /** * Sets the file selection mode and sends a {@link PropertyChangeEvent} * to all registered listeners. The property name is * {@link #FILE_SELECTION_MODE_CHANGED_PROPERTY}. * * @param mode the mode ({@link #FILES_ONLY}, {@link #DIRECTORIES_ONLY} or * {@link #FILES_AND_DIRECTORIES}). * * @throws IllegalArgumentException if the mode is invalid. */ public void setFileSelectionMode(int mode) { if (mode != FILES_ONLY && mode != DIRECTORIES_ONLY && mode != FILES_AND_DIRECTORIES) throw new IllegalArgumentException("Choose a correct file selection mode."); if (fileSelectionMode != mode) { int old = fileSelectionMode; fileSelectionMode = mode; firePropertyChange(FILE_SELECTION_MODE_CHANGED_PROPERTY, old, fileSelectionMode); } } /** * Returns the file selection mode, one of: {@link #FILES_ONLY}, * {@link #DIRECTORIES_ONLY} or {@link #FILES_AND_DIRECTORIES}. The * default is {@link #FILES_ONLY}. * * @return The file selection mode. * * @see #setFileSelectionMode(int) */ public int getFileSelectionMode() { return fileSelectionMode; } /** * Returns <code>true</code> if file selection is enabled, and * <code>false</code> otherwise. File selection is enabled when the * file selection mode is {@link #FILES_ONLY} or * {@link #FILES_AND_DIRECTORIES}. * * @return <code>true</code> if file selection is enabled. * * @see #getFileSelectionMode() */ public boolean isFileSelectionEnabled() { return (fileSelectionMode == FILES_ONLY || fileSelectionMode == FILES_AND_DIRECTORIES); } /** * Returns <code>true</code> if directory selection is enabled, and * <code>false</code> otherwise. Directory selection is enabled when the * file selection mode is {@link #DIRECTORIES_ONLY} or * {@link #FILES_AND_DIRECTORIES}. * * @return <code>true</code> if file selection is enabled. * * @see #getFileSelectionMode() */ public boolean isDirectorySelectionEnabled() { return (fileSelectionMode == DIRECTORIES_ONLY || fileSelectionMode == FILES_AND_DIRECTORIES); } /** * Sets the flag that controls whether multiple selections are allowed in * this filechooser and sends a {@link PropertyChangeEvent} (with the * property name {@link #MULTI_SELECTION_ENABLED_CHANGED_PROPERTY}) to all * registered listeners. * * @param b the new value of the flag. */ public void setMultiSelectionEnabled(boolean b) { if (multiSelection != b) { multiSelection = b; firePropertyChange(MULTI_SELECTION_ENABLED_CHANGED_PROPERTY, ! multiSelection, multiSelection); } } /** * Returns <code>true</code> if multiple selections are allowed within this * file chooser, and <code>false</code> otherwise. * * @return A boolean. * * @see #setMultiSelectionEnabled(boolean) */ public boolean isMultiSelectionEnabled() { return multiSelection; } /** * Returns <code>true</code> if hidden files are to be hidden, and * <code>false</code> otherwise. * * @return A boolean. * * @see #setFileHidingEnabled(boolean) */ public boolean isFileHidingEnabled() { return fileHiding; } /** * Sets the flag that controls whether or not hidden files are displayed, * and sends a {@link PropertyChangeEvent} (with the property name * {@link #FILE_HIDING_CHANGED_PROPERTY}) to all registered listeners. * * @param b the new value of the flag. */ public void setFileHidingEnabled(boolean b) { if (fileHiding != b) { fileHiding = b; firePropertyChange(FILE_HIDING_CHANGED_PROPERTY, ! fileHiding, fileHiding); } } /** * Sets the file filter and sends a {@link PropertyChangeEvent} (with the * property name {@link #FILE_FILTER_CHANGED_PROPERTY}) to all registered * listeners. * * @param filter the filter. */ public void setFileFilter(FileFilter filter) { if (currentFilter != filter) { FileFilter old = currentFilter; currentFilter = filter; firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, old, currentFilter); } } /** * Returns the file filter. * * @return The file filter. * * @see #setFileFilter(FileFilter) */ public FileFilter getFileFilter() { return currentFilter; } /** * Sets a custom {@link FileView} for the file chooser and sends a * {@link PropertyChangeEvent} to all registered listeners. The property * name is {@link #FILE_VIEW_CHANGED_PROPERTY}. * * @param fileView the file view (<code>null</code> permitted). * * @see #getFileView() */ public void setFileView(FileView fileView) { if (fv != fileView) { FileView old = fv; fv = fileView; firePropertyChange(FILE_VIEW_CHANGED_PROPERTY, old, fv); } } /** * Returns the custom {@link FileView} for the file chooser. * * @return The file view (possibly <code>null</code>). */ public FileView getFileView() { return fv; } /** * Returns the name of the file, generated by the current (or default) * {@link FileView}. * * @param f the file. * * @return The file name. */ public String getName(File f) { String name = null; if (fv != null) name = fv.getName(f); if (name == null) name = getUI().getFileView(this).getName(f); return name; } /** * Returns the description of the file, generated by the current (or default) * {@link FileView}. * * @param f the file. * * @return The file description. */ public String getDescription(File f) { String result = null; if (fv != null) result = fv.getDescription(f); if (result == null) result = getUI().getFileView(this).getDescription(f); return result; } /** * Returns the type description for the file, generated by the current (or * default) {@link FileView}. * * @param f the file. * * @return The file type description. */ public String getTypeDescription(File f) { String result = null; if (fv != null) result = getFileView().getTypeDescription(f); if (result == null) result = getUI().getFileView(this).getTypeDescription(f); return result; } /** * Returns the icon provided by the current (or default) {@link FileView}. * * @param f the file. * * @return An icon representing the file. */ public Icon getIcon(File f) { Icon result = null; if (fv != null) result = fv.getIcon(f); if (result == null) result = getUI().getFileView(this).getIcon(f); return result; } /** * Returns <code>true</code> if the file is traversable, and * <code>false</code> otherwise. * * @param f the file or directory. * * @return A boolean. */ public boolean isTraversable(File f) { return getFileSystemView().isTraversable(f).booleanValue(); } /** * Returns <code>true</code> if the file is accepted by the current * file filter. * * @param f the file. * * @return A boolean. */ public boolean accept(File f) { if (f == null) return false; return getFileFilter().accept(f); } /** * Sets the file system view for the file chooser and sends a * {@link PropertyChangeEvent} to all registered listeners. * * @param fsv the file system view. */ public void setFileSystemView(FileSystemView fsv) { if (this.fsv != fsv) { FileSystemView old = this.fsv; this.fsv = fsv; firePropertyChange(FILE_SYSTEM_VIEW_CHANGED_PROPERTY, old, this.fsv); } } /** * Returns the file system view being used by this file chooser. * * @return The file system view. * * @see #setFileSystemView(FileSystemView) */ public FileSystemView getFileSystemView() { return fsv; } /** * Approves the selection. An {@link ActionEvent} is sent to all registered * listeners. */ public void approveSelection() { retval = APPROVE_OPTION; fireActionPerformed(APPROVE_SELECTION); } /** * Cancels the selection. An {@link ActionEvent} is sent to all registered * listeners. */ public void cancelSelection() { retval = CANCEL_OPTION; fireActionPerformed(CANCEL_SELECTION); } /** * Adds an {@link ActionListener} to the file chooser. * * @param l the listener. */ public void addActionListener(ActionListener l) { listenerList.add(ActionListener.class, l); } /** * Removes an {@link ActionListener} from this file chooser. * * @param l the listener. */ public void removeActionListener(ActionListener l) { try { listenerList.remove(ActionListener.class, l); } catch (IllegalArgumentException e) { e.printStackTrace(); } } /** * Returns the action listeners registered with this file chooser. * * @return An array of listeners. */ public ActionListener[] getActionListeners() { return (ActionListener[]) getListeners(ActionListener.class); } /** * Sends an @link {ActionEvent} to all registered listeners. * * @param command the action command. */ protected void fireActionPerformed(String command) { ActionListener[] list = getActionListeners(); ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, command); for (int i = 0; i < list.length; i++) list[i].actionPerformed(event); } /** * Installs the UI delegate for the current look and feel. */ public void updateUI() { setUI((FileChooserUI) UIManager.getUI(this)); revalidate(); } /** * Returns the UI delegate class identifier. * * @return <code>FileChooserUI</code>. */ public String getUIClassID() { return "FileChooserUI"; } /** * Returns the UI delegate for the component. * * @return The UI delegate. */ public FileChooserUI getUI() { return (FileChooserUI) ui; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ protected String paramString() { return "JFileChooser"; } /** * Returns the accessible context. * * @return The accessible context. */ public AccessibleContext getAccessibleContext() { return new AccessibleJFileChooser(); } /** * Accessibility support for JFileChooser */ protected class AccessibleJFileChooser extends JComponent.AccessibleJComponent { protected AccessibleJFileChooser() { // Nothing to do here. } public AccessibleRole getAccessibleRole() { return AccessibleRole.FILE_CHOOSER; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -