org.fife.ui.rtextfilechooser
Class RTextFileChooser

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.fife.ui.ResizableFrameContentPane
                      extended by org.fife.ui.rtextfilechooser.RTextFileChooser
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, FileSelector

public class RTextFileChooser
extends ResizableFrameContentPane
implements java.awt.event.ActionListener, java.beans.PropertyChangeListener, FileSelector

A powerful, flexible text file chooser. Its UI is similar to the Windows LnF JFileChooser, but it is not affected by Look-and-Feel changes. This file chooser has the following features:

This component has many of the features found in JFileChooser and is designed to be a drop-in replacement for opening text files.

Version:
0.7
Author:
Robert Futrell
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int APPROVE_OPTION
           
static int CANCEL_OPTION
           
static int DETAILS_MODE
           
static int DIRECTORIES_ONLY
           
static int ERROR_OPTION
           
static int FILES_AND_DIRECTORIES
           
static int FILES_ONLY
           
static int ICONS_MODE
           
static int LIST_MODE
           
static int OPEN_DIALOG
           
static int SAVE_DIALOG
           
static int STYLE_BOLD
           
static int STYLE_ITALIC
           
static int STYLE_UNDERLINE
           
protected  org.fife.ui.rtextfilechooser.RTextFileChooserView view
          The "view" of the current directory (either list, details or icons).
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
RTextFileChooser()
          Creates a new RTextFileChooser.
RTextFileChooser(boolean showEncodingCombo)
          Creates a new RTextFileChooser.
RTextFileChooser(boolean showEncodingCombo, java.io.File startDirectory)
          Creates a new RTextFileChooser.
RTextFileChooser(java.io.File startDirectory)
          Creates a new RTextFileChooser.
RTextFileChooser(java.lang.String startDirectory)
          Creates a new RTextFileChooser.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Listens for actions in this file dialog.
 void addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)
          Adds a file filter to the filter combo box.
 boolean addToFavorites(java.lang.String dir)
          Adds the specified directory to the user's "favorites" list.
 void approveSelection()
          Called when the user clicks the "Approve" button.
protected  boolean approveSelectionImpl()
          Called at the end of approveSelection(); the file chooser dialog will only close if this method returns true.
 void cancelSelection()
          Called when the user clicks the Cancel button.
 void clearExtensionColorMap()
          Removes all values from the extension-to-color map.
 void clearFavorites()
          Removes all favorites from the "Favorites" list.
protected  javax.swing.JDialog createDialog(java.awt.Window parent)
          Creates a dialog for the given parent frame.
 boolean getAutoCompleteFileNames()
          Returns whether the filename text field auto-completes the next matching filename when the drop-down list is visible.
 javax.swing.filechooser.FileFilter[] getChoosableFileFilters()
          Gets the list of user-choosable file filters.
 java.awt.Color getColorForExtension(java.lang.String extension)
          Returns the color associated with a file type.
 java.io.File getCurrentDirectory()
          Returns the directory this RTextFileChooser is currently in.
 java.util.Map<java.lang.String,java.awt.Color> getCustomColorsMap()
          Returns the map containing all file extensions and the colors used to color the names of files of those types.
 java.lang.String getCustomTitle()
          Returns the custom title to use for this file chooser.
static java.lang.String getDefaultEncoding()
          Returns the default encoding for this operating system.
 java.awt.Color getDefaultFileColor()
          Returns the color used to paint the name of files with unknown type.
 java.lang.String getDescription(java.io.File file)
          Returns the description for the file displayed in the file chooser.
 int getDialogType()
          Returns the last type of dialog displayed.
 java.lang.String getEncoding()
          Returns a string representing the encoding chosen by the user.
 java.lang.String[] getFavorites()
          Returns the "Favorite directories" of this file chooser, as an array of strings.
 javax.swing.filechooser.FileFilter getFileFilter()
          Returns the currently-active file filter.
 int getFileSelectionMode()
          Returns the file selection mode.
 boolean getFileSystemAware()
          Returns whether or not the filename text field is file-system aware.
 javax.swing.filechooser.FileSystemView getFileSystemView()
          Returns the file system view for this file chooser.
 FileTypeInfo getFileTypeInfoFor(java.io.File file)
          Returns the file type info (color) to use when painting the specified file in this file chooser.
 java.awt.Color getHiddenFileColor()
          Returns the color used to paint hidden files if hidden files are being shown.
 void getIcons()
          Creates the icons used by this file chooser.
 java.lang.String getName(java.io.File f)
          Returns the name of the file.
 int getOpenFilesStyle()
          Returns the special styling used when displaying the names of opened files.
 java.io.File getSelectedFile()
          Returns the file selected by the user.
 java.io.File[] getSelectedFiles()
          Returns the files selected by the user.
 boolean getShowHiddenFiles()
          Returns whether hidden files and directories are shown by the file chooser.
 java.lang.String getString(java.lang.String key)
          Returns the localized text for a given key.
 boolean getStyleOpenFiles()
          Returns whether "opened" files should have a special style applied to them when they are displayed in this file chooser (for example, being underlined).
 int getViewMode()
          Returns the view mode.
protected  void initializeGUIComponents()
          Initializes the GUI components for the file chooser.
 boolean isMultiSelectionEnabled()
          Returns whether or not multi-selection is enabled.
 boolean isOpenedFile(java.io.File file)
          Returns whether or not a file should be underlined when displayed by a view of this file chooser.
 int loadFavorites(java.io.File file)
          Loads a list of "Favorites" from a file.
 void propertyChange(java.beans.PropertyChangeEvent e)
          Called when a property we're listening to changes.
protected  void refreshEncodingComboBox()
          If the GUI has been initialized, this sets the encoding combo box to display the proper value.
 boolean removeChoosableFileFilter(javax.swing.filechooser.FileFilter f)
          Removes a filter from the list of user choosable file filters.
 void saveFavorites(java.io.File file)
          Saves the list of "Favorites" of this file chooser to a file.
 void savePreferences()
          Saves this file chooser's preferences (colors used for filenames, etc.).
 void setAutoCompleteFileNames(boolean auto)
          Sets whether the filename text field auto-completes the next matching filename when the drop-down list is visible.
 void setColorForExtension(java.lang.String extension, java.awt.Color color)
          Sets the color associated with a file type.
 void setCurrentDirectory(java.io.File dir)
          Sets the directory this RTextFileChooser is currently in.
 void setCurrentDirectory(java.lang.String dir)
          Sets the directory this RTextFileChooser is currently in.
 void setCustomTitle(java.lang.String title)
          Returns the title to use for this file chooser, whether it is an open dialog or a save dialog.
 void setEncoding(java.lang.String encoding)
          Sets the encoding selected by this file chooser.
 void setFileFilter(javax.swing.filechooser.FileFilter filter)
          Sets the current file filter.
protected  void setFileFilterImpl(javax.swing.filechooser.FileFilter filter, boolean cacheIfGUINotRealized)
          Sets the current file filter.
 void setFileSelectionMode(int mode)
          Sets whether the user can select files only, directories only, or both files and directories from this file chooser.
 void setFileSystemAware(boolean aware)
          Sets whether the filename text field is "file system aware."
 void setHiddenFileColor(java.awt.Color color)
          Sets the color used to display hidden files' names.
 void setInfoForExtension(java.lang.String extension, java.awt.Color c)
          Adds a color to associate with a file type.
 void setMultiSelectionEnabled(boolean enabled)
          Sets whether or not multi-selection is enabled.
 void setOpenedFiles(java.io.File[] files)
          Sets the list of files to be underlined if displayed in the file chooser.
 void setOpenFilesStyle(int style)
          Sets the style that "opened" files should have applied to them when they are displayed in this file chooser (for example, being underlined).
 void setSelectedFile(java.io.File file)
          Sets the file selected by the user.
 void setSelectedFiles(java.io.File[] files)
          Sets the files selected by the user.
 void setSelectedFiles(java.util.List<java.io.File> files)
          Sets the files selected by the user.
 void setShowHiddenFiles(boolean show)
          Sets whether hidden files and directories are shown by the file chooser.
 void setStyleOpenFiles(boolean style)
          Sets whether "opened" files should have a special style applied to them when they are displayed in this file chooser (for example, being underlined).
 void setViewMode(int mode)
          Sets the view mode.
protected  void setViewModeImpl(int mode)
          Does the dirty-work of setting the view mode.
protected  int showDialogImpl(java.awt.Window parent, int dialogType)
          Does all of the dirty-work for showOpenDialog and showSaveDialog since much of what they do is the same.
 int showOpenDialog(java.awt.Window parent)
          Displays an "Open" dialog.
 int showSaveDialog(java.awt.Window parent)
          Displays a "Save As" dialog.
 void updateUI()
          Updates any contained components when a Look and Feel change occurs.
 
Methods inherited from class org.fife.ui.ResizableFrameContentPane
paint
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
Methods inherited from class javax.swing.JComponent
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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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
 
Methods inherited from class java.awt.Container
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, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
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, hide, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LIST_MODE

public static final int LIST_MODE
See Also:
Constant Field Values

DETAILS_MODE

public static final int DETAILS_MODE
See Also:
Constant Field Values

ICONS_MODE

public static final int ICONS_MODE
See Also:
Constant Field Values

APPROVE_OPTION

public static final int APPROVE_OPTION
See Also:
Constant Field Values

CANCEL_OPTION

public static final int CANCEL_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

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

STYLE_BOLD

public static final int STYLE_BOLD
See Also:
Constant Field Values

STYLE_ITALIC

public static final int STYLE_ITALIC
See Also:
Constant Field Values

STYLE_UNDERLINE

public static final int STYLE_UNDERLINE
See Also:
Constant Field Values

view

protected org.fife.ui.rtextfilechooser.RTextFileChooserView view
The "view" of the current directory (either list, details or icons).

Constructor Detail

RTextFileChooser

public RTextFileChooser()
Creates a new RTextFileChooser.


RTextFileChooser

public RTextFileChooser(boolean showEncodingCombo)
Creates a new RTextFileChooser.

Parameters:
showEncodingCombo - Whether the encoding combo box should be visible. This should be true if this is a chooser for text files, and false if it is a chooser for binary files.

RTextFileChooser

public RTextFileChooser(java.lang.String startDirectory)
Creates a new RTextFileChooser.

Parameters:
startDirectory - The directory for the file chooser to "start" in.

RTextFileChooser

public RTextFileChooser(java.io.File startDirectory)
Creates a new RTextFileChooser.

Parameters:
startDirectory - The directory for the file chooser to "start" in.

RTextFileChooser

public RTextFileChooser(boolean showEncodingCombo,
                        java.io.File startDirectory)
Creates a new RTextFileChooser.

Parameters:
showEncodingCombo - Whether the encoding combo box should be visible. This should be true if this is a chooser for text files, and false if it is a chooser for binary files.
startDirectory - The directory for the file chooser to "start" in.
Method Detail

addToFavorites

public boolean addToFavorites(java.lang.String dir)
Adds the specified directory to the user's "favorites" list. This should be an absolute path.

Parameters:
dir - The directory to add to the "favorites" list.
Returns:
Whether the item was added. If this returns false, then the directory specified is already in the "Favorites" list.
Throws:
java.lang.NullPointerException - If dir is null.
See Also:
getFavorites(), clearFavorites(), loadFavorites(File), saveFavorites(File)

initializeGUIComponents

protected void initializeGUIComponents()
Initializes the GUI components for the file chooser. This stuff isn't done in the constructor as it can be time-consuming (actually, Java checking for roots of the file system can be time-consuming). Instead, we put it in this method and defer it until the file chooser is actually displayed, making sure it is only done once. This way the user can pull up the Options dialog and change properties of the file chooser without the GUI having to be initialized.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Listens for actions in this file dialog.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

addChoosableFileFilter

public void addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)
Adds a file filter to the filter combo box.

Parameters:
filter - The file filter to add.
See Also:
removeChoosableFileFilter(javax.swing.filechooser.FileFilter), getChoosableFileFilters()

approveSelection

public void approveSelection()
Called when the user clicks the "Approve" button. You can also call this programmatically. Note that this does NOT necessarily mean the dialog will close; for example, if they have selected a directory and the file selection mode is FILES_ONLY, then the file dialog will simply change to that directory.

Users who wish to subclass this class and provide a means of canceling the dialog closing (such as an "are you sure you wish to overwrite?" message) should override approveSelectionImpl(). That method is called at the end of this one, and the file chooser will only close if that method returns true.


approveSelectionImpl

protected boolean approveSelectionImpl()
Called at the end of approveSelection(); the file chooser dialog will only close if this method returns true. Subclasses can override this method to add things such as an "Are you sure you want to overwrite?" message.

Returns:
Whether to close this file chooser. The default implementation always returns true.

cancelSelection

public void cancelSelection()
Called when the user clicks the Cancel button. You can also call this programatically. Any file selections are nixed and the dialog closes.


clearExtensionColorMap

public void clearExtensionColorMap()
Removes all values from the extension-to-color map.

See Also:
getColorForExtension(java.lang.String), setColorForExtension(java.lang.String, java.awt.Color)

clearFavorites

public void clearFavorites()
Removes all favorites from the "Favorites" list.

See Also:
addToFavorites(String), getFavorites(), loadFavorites(File), saveFavorites(File)

createDialog

protected javax.swing.JDialog createDialog(java.awt.Window parent)
                                    throws java.awt.HeadlessException
Creates a dialog for the given parent frame.

Parameters:
parent - The window that is to be the parent of the created dialog.
Returns:
The dialog.
Throws:
java.awt.HeadlessException

getAutoCompleteFileNames

public boolean getAutoCompleteFileNames()
Returns whether the filename text field auto-completes the next matching filename when the drop-down list is visible. Note that this property is only honored when this text field is "file system aware".

See Also:
setAutoCompleteFileNames(boolean)

getChoosableFileFilters

public javax.swing.filechooser.FileFilter[] getChoosableFileFilters()
Gets the list of user-choosable file filters.

Returns:
A FileFilter array containing all the choosable file filters.
See Also:
addChoosableFileFilter(javax.swing.filechooser.FileFilter), removeChoosableFileFilter(javax.swing.filechooser.FileFilter)

getColorForExtension

public java.awt.Color getColorForExtension(java.lang.String extension)
Returns the color associated with a file type. This method will take care of the extension's case (i.e., if running on Windows, all file extensions will be compared lower-case to ensure case doesn't matter).

Parameters:
extension - The extension for which to get the associated image.
Returns:
The color associated with this extension, or null if there is none.
See Also:
setColorForExtension(java.lang.String, java.awt.Color), clearExtensionColorMap()

getCurrentDirectory

public final java.io.File getCurrentDirectory()
Returns the directory this RTextFileChooser is currently in.

Returns:
The current directory.
See Also:
setCurrentDirectory(java.io.File)

getCustomColorsMap

public java.util.Map<java.lang.String,java.awt.Color> getCustomColorsMap()
Returns the map containing all file extensions and the colors used to color the names of files of those types. Note that changes to this map will cause changes to the file chooser (it is a shallow copy).

So, for example, with the returned HashMap you can iterate through its keys (the extensions) to get the color used by this file chooser to display files with those extensions.

Returns:
The hash map of file extensions to file information.

getCustomTitle

public java.lang.String getCustomTitle()
Returns the custom title to use for this file chooser.

Returns:
The custom title, or null if default values for "Open" and "Save" dialogs should be used.
See Also:
setCustomTitle(String)

getDefaultEncoding

public static final java.lang.String getDefaultEncoding()
Returns the default encoding for this operating system.

Returns:
The default encoding.

getDefaultFileColor

public java.awt.Color getDefaultFileColor()
Returns the color used to paint the name of files with unknown type.

Returns:
The color used.

getDescription

public java.lang.String getDescription(java.io.File file)
Returns the description for the file displayed in the file chooser.

Parameters:
file - The file for which to get the description.
Returns:
The description.

getDialogType

public int getDialogType()
Returns the last type of dialog displayed.

Returns:
Either OPEN_DIALOG or SAVE_DIALOG.
See Also:
showOpenDialog(Window), showSaveDialog(Window)

getEncoding

public java.lang.String getEncoding()
Returns a string representing the encoding chosen by the user.

Returns:
A string representing the chosen encoding.
See Also:
setEncoding(java.lang.String)

getFavorites

public java.lang.String[] getFavorites()
Returns the "Favorite directories" of this file chooser, as an array of strings. Modifying this array does not modify the favorites used by this file chooser.

Returns:
An array of "favorites". If no favorites are known, a zero-length array is returned.
See Also:
addToFavorites(String), clearFavorites(), loadFavorites(File), saveFavorites(File)

getFileFilter

public javax.swing.filechooser.FileFilter getFileFilter()
Returns the currently-active file filter.

Returns:
The currently active file filter.
See Also:
setFileFilter(javax.swing.filechooser.FileFilter)

getFileSelectionMode

public int getFileSelectionMode()
Returns the file selection mode.

Returns:
One of FILES_ONLY, DIRECTORIES_ONLY, or FILES_AND_DIRECTORIES.
See Also:
setFileSelectionMode(int)

getFileSystemAware

public boolean getFileSystemAware()
Returns whether or not the filename text field is file-system aware.

Returns:
Whether the filename text field provides possible matches while you are typing in it.
See Also:
setFileSystemAware(boolean)

getFileSystemView

public javax.swing.filechooser.FileSystemView getFileSystemView()
Returns the file system view for this file chooser.

Returns:
The file system view.

getFileTypeInfoFor

public FileTypeInfo getFileTypeInfoFor(java.io.File file)
Returns the file type info (color) to use when painting the specified file in this file chooser.

Parameters:
file - The file.
Returns:
The file's color to use when painting it. The color is the color with which to paint the file's name when it is not "selected" in the view.

getHiddenFileColor

public java.awt.Color getHiddenFileColor()
Returns the color used to paint hidden files if hidden files are being shown.

Returns:
The color used to paint hidden file names.
See Also:
setHiddenFileColor(java.awt.Color)

getIcons

public void getIcons()
Creates the icons used by this file chooser. This method can be called when the user changes the Look and Feel, and icons used in this file chooser will change to reflect the new Look and Feel.


getName

public java.lang.String getName(java.io.File f)
Returns the name of the file.

Parameters:
f - The file for which you want its name.
Returns:
The file's name.

getOpenFilesStyle

public int getOpenFilesStyle()
Returns the special styling used when displaying the names of opened files.

Returns:
The style. This will be one of STYLE_BOLD, STYLE_ITALIC or STYLE_UNDERLINE.
See Also:
setOpenFilesStyle(int), getStyleOpenFiles()

getSelectedFile

public java.io.File getSelectedFile()
Returns the file selected by the user. Note that if the user selected more than one file, only the first file selected is returned.

Specified by:
getSelectedFile in interface FileSelector
Returns:
The file selected by the user.
See Also:
getSelectedFiles(), setSelectedFile(File), setSelectedFiles(File[])

getSelectedFiles

public java.io.File[] getSelectedFiles()
Returns the files selected by the user.

Specified by:
getSelectedFiles in interface FileSelector
Returns:
The files selected by the user.
See Also:
getSelectedFile(), setSelectedFile(java.io.File), setSelectedFiles(java.util.List)

getShowHiddenFiles

public boolean getShowHiddenFiles()
Returns whether hidden files and directories are shown by the file chooser.

Returns:
Whether hidden files are displayed.
See Also:
setShowHiddenFiles(boolean)

getString

public java.lang.String getString(java.lang.String key)
Returns the localized text for a given key.

Parameters:
key - The key.
Returns:
the localized text.

getStyleOpenFiles

public boolean getStyleOpenFiles()
Returns whether "opened" files should have a special style applied to them when they are displayed in this file chooser (for example, being underlined).

Returns:
Whether opened files should have a special style applied to them.
See Also:
setStyleOpenFiles(boolean), setOpenFilesStyle(int)

getViewMode

public int getViewMode()
Returns the view mode.

Returns:
One of LIST_MODE, DETAILS_MODE, or ICONS_MODE.
See Also:
setViewMode(int)

isMultiSelectionEnabled

public final boolean isMultiSelectionEnabled()
Returns whether or not multi-selection is enabled.

Returns:
Whether or not multi-selection is enabled.
See Also:
setMultiSelectionEnabled(boolean)

isOpenedFile

public boolean isOpenedFile(java.io.File file)
Returns whether or not a file should be underlined when displayed by a view of this file chooser.

Parameters:
file - A file.
Returns:
Whether or not file should be underlined by the view.
See Also:
setOpenedFiles(File[])

loadFavorites

public int loadFavorites(java.io.File file)
                  throws java.io.IOException
Loads a list of "Favorites" from a file. This should be a plain text, UTF-8 file, with one favorite (full path) listed per-line. Empty lines and lines starting with the #' character are ignored.

Parameters:
file - The favorites file to load.
Returns:
The number of favorites added.
Throws:
java.io.IOException - If an IO error occurs.
See Also:
addToFavorites(String), clearFavorites(), getFavorites(), saveFavorites(File)

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Called when a property we're listening to changes.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
e - The event.

refreshEncodingComboBox

protected void refreshEncodingComboBox()
If the GUI has been initialized, this sets the encoding combo box to display the proper value.


removeChoosableFileFilter

public boolean removeChoosableFileFilter(javax.swing.filechooser.FileFilter f)
Removes a filter from the list of user choosable file filters.

Returns:
true if the file filter was removed.
See Also:
addChoosableFileFilter(javax.swing.filechooser.FileFilter), getChoosableFileFilters()

saveFavorites

public void saveFavorites(java.io.File file)
                   throws java.io.IOException
Saves the list of "Favorites" of this file chooser to a file. The format of the file is the same as that specified in the description of loadFavorites(File). If there are no Favorites for this file chooser, an empty file is created.

Parameters:
file - The file to write to. If it already exists, it will be overwritten.
Throws:
java.io.IOException - If an IO error occurs writing the file.
See Also:
addToFavorites(String), clearFavorites(), getFavorites(), loadFavorites(File)

savePreferences

public void savePreferences()
Saves this file chooser's preferences (colors used for filenames, etc.). A program should call this method when shutting down if it wishes for its file chooser to have the same properties the next time the application is started.


setAutoCompleteFileNames

public void setAutoCompleteFileNames(boolean auto)
Sets whether the filename text field auto-completes the next matching filename when the drop-down list is visible. Note that this property is only honored when this text field is "file system aware".

Parameters:
auto - Whether the next matching filename is auto-inserted.
See Also:
getAutoCompleteFileNames()

setColorForExtension

public void setColorForExtension(java.lang.String extension,
                                 java.awt.Color color)
Sets the color associated with a file type. This method will take care of the extension's case (i.e., if running on Windows, all file extensions will be compared lower-case to ensure case doesn't matter).

Parameters:
extension - The extension for which to set the associated color.
color - The new color to associate with this extension. A value of null makes the default color used.
See Also:
getColorForExtension(java.lang.String), clearExtensionColorMap()

setCurrentDirectory

public void setCurrentDirectory(java.io.File dir)
Sets the directory this RTextFileChooser is currently in.

Parameters:
dir - The new current directory. If this value isn't a valid directory, The user's home directory is used.
See Also:
getCurrentDirectory()

setCurrentDirectory

public void setCurrentDirectory(java.lang.String dir)
Sets the directory this RTextFileChooser is currently in.

Parameters:
dir - The new current directory. If this value isn't a valid directory, The user's home directory is used.
See Also:
getCurrentDirectory()

setCustomTitle

public void setCustomTitle(java.lang.String title)
Returns the title to use for this file chooser, whether it is an open dialog or a save dialog.

Parameters:
title - The new title. If this is null, a default title will be used appropriately (e.g. a localized version of "Open" or "Save").
See Also:
getCustomTitle()

setEncoding

public void setEncoding(java.lang.String encoding)
Sets the encoding selected by this file chooser.

Parameters:
encoding - The desired encoding. If this value is invalid or not supported by this OS, a system default is used.
See Also:
getEncoding()

setFileFilter

public void setFileFilter(javax.swing.filechooser.FileFilter filter)
Sets the current file filter. The file filter is used by the file chooser to filter out files from the user's view.

Parameters:
filter - The new current file filter to use. If this is null, the "all files" filter is selected.
See Also:
getFileFilter()

setFileFilterImpl

protected void setFileFilterImpl(javax.swing.filechooser.FileFilter filter,
                                 boolean cacheIfGUINotRealized)
Sets the current file filter. The file filter is used by the file chooser to filter out files from the user's view.

Parameters:
filter - The new current file filter to use. If this is null, the "all files" filter is selected.
cacheIfGUINotRealized - If the GUI isn't created, whether or not the selected file filter should be set to this filter when it is created. This parameter is here because addChoosableFileFilter calls this method, but that method should not change the selected file filter.
See Also:
getFileFilter()

setFileSelectionMode

public void setFileSelectionMode(int mode)
Sets whether the user can select files only, directories only, or both files and directories from this file chooser.

Parameters:
mode - One of FILES_ONLY, DIRECTORIES_ONLY, or FILES_AND_DIRECTORIES.
See Also:
getFileSelectionMode()

setFileSystemAware

public void setFileSystemAware(boolean aware)
Sets whether the filename text field is "file system aware."

Parameters:
aware - Whether the filename text field will be helpful and provide possible filename matches while you are typing in it. This feature can be disabled for slow networks.
See Also:
getFileSystemAware()

setHiddenFileColor

public void setHiddenFileColor(java.awt.Color color)
Sets the color used to display hidden files' names.

Parameters:
color - The new color to use for the names of hidden files.
Throws:
java.lang.NullPointerException - If color is null.
See Also:
getHiddenFileColor()

setInfoForExtension

public void setInfoForExtension(java.lang.String extension,
                                java.awt.Color c)
Adds a color to associate with a file type. This method will take care of the extension's case (i.e., if running on Windows, all file extensions will be compared lower-case to ensure case doesn't matter).

Parameters:
extension - The extension to associate an image and color with.
c - The color to associate with this extension.

setMultiSelectionEnabled

public void setMultiSelectionEnabled(boolean enabled)
Sets whether or not multi-selection is enabled.

Parameters:
enabled - Whether or not multi-selection is to be enabled.
See Also:
isMultiSelectionEnabled()

setOpenedFiles

public void setOpenedFiles(java.io.File[] files)
Sets the list of files to be underlined if displayed in the file chooser. This is useful if, for example, you wish to underline the files that are currently already open in a text editor.

Parameters:
files - The files to underline. Note that they need not all reside in the same directory. To clear all underlined files, pass null in for this value.
See Also:
isOpenedFile(File)

setOpenFilesStyle

public void setOpenFilesStyle(int style)
Sets the style that "opened" files should have applied to them when they are displayed in this file chooser (for example, being underlined).

Parameters:
style - The style to apply. If this is invalid, STYLE_UNDERLINE is used.
See Also:
getOpenFilesStyle(), setStyleOpenFiles(boolean)

setSelectedFile

public void setSelectedFile(java.io.File file)
Sets the file selected by the user.

Parameters:
file - The file selected by the user.
See Also:
getSelectedFile(), getSelectedFiles(), setSelectedFiles(java.util.List)

setSelectedFiles

public void setSelectedFiles(java.util.List<java.io.File> files)
Sets the files selected by the user.

Parameters:
files - The files selected by the user.
See Also:
getSelectedFile(), getSelectedFiles(), setSelectedFile(java.io.File)

setSelectedFiles

public void setSelectedFiles(java.io.File[] files)
Sets the files selected by the user.

Parameters:
files - The files selected by the user.
See Also:
getSelectedFile(), getSelectedFiles(), setSelectedFile(java.io.File)

setShowHiddenFiles

public void setShowHiddenFiles(boolean show)
Sets whether hidden files and directories are shown by the file chooser.

Parameters:
show - Whether to show hidden files.
See Also:
getShowHiddenFiles()

setStyleOpenFiles

public void setStyleOpenFiles(boolean style)
Sets whether "opened" files should have a special style applied to them when they are displayed in this file chooser (for example, being underlined).

Parameters:
style - Whether opened files should have a style applied.
See Also:
getStyleOpenFiles(), setOpenFilesStyle(int)

setViewMode

public void setViewMode(int mode)
Sets the view mode.

Parameters:
mode - One of LIST_MODE, DETAILS_MODE, or ICONS_MODE.
See Also:
getViewMode()

setViewModeImpl

protected void setViewModeImpl(int mode)
Does the dirty-work of setting the view mode. This method does not check whether the mode to which you're setting the file chooser is already the "current mode." It is used by internal methods to force a view mode change.

Parameters:
mode - The new view mode.

showDialogImpl

protected int showDialogImpl(java.awt.Window parent,
                             int dialogType)
Does all of the dirty-work for showOpenDialog and showSaveDialog since much of what they do is the same.

Parameters:
parent - The parent of this open/save dialog.
dialogType - Either OPEN_DIALOG or SAVE_DIALOG.

showOpenDialog

public int showOpenDialog(java.awt.Window parent)
Displays an "Open" dialog.

Parameters:
parent - The window or dialog that owns this file chooser dialog.
Returns:
One of APPROVE_OPTION, CANCEL_OPTION, or ERROR_OPTION.

showSaveDialog

public int showSaveDialog(java.awt.Window parent)
Displays a "Save As" dialog.

Parameters:
parent - The window or dialog that owns this file chooser dialog.
Returns:
One of APPROVE_OPTION, CANCEL_OPTION, or ERROR_OPTION.

updateUI

public void updateUI()
Updates any contained components when a Look and Feel change occurs. Note that this is NOT overriding a superclass's updateUI method, as JDialog doesn't have one. Rather, this method should be explicitly called whenever a LnF change occurs to ensure that the popup menu gets its UI updated.

Overrides:
updateUI in class javax.swing.JPanel