uic.widgets.filechooser
Class FileChooser

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 uic.widgets.filechooser.FileChooserBase
                      extended by uic.widgets.filechooser.FileChooser
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, FileSelectionListener

public class FileChooser
extends FileChooserBase
implements FileSelectionListener

A widget for selecting a file.

Currently only support some KDE settings.. but still needs a lot of improvement

Since:
2.0
Author:
Roy van der Kuil
See Also:
Serialized Form

Nested Class Summary
protected static class FileChooser.BrowseIcon
          Very simple icon based on FileChooser.newFolderIcon.
protected  class FileChooser.FileChooserComboBoxEditor
           
protected  class FileChooser.FileChooserComboBoxModel
           
protected static class FileChooser.FileChooserPreviewPanel
           
protected static class FileChooser.FileFilterListCellRenderer
          Paint the FileFilters description in the filters combobox and list.
protected  class FileChooser.HiddenFilesFileFilter
           
protected  class FileChooser.HistoryMenuItem
          Class that shows the history menu item.
protected  class FileChooser.HistoryPopupMenu
          Class that shows the history popupmenu.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String FILE_ACCEPTED
          Add property listener to FileChooser with FILE_ACCEPTED to keep track of files accepted from FileChooser.
 
Fields inherited from class uic.widgets.filechooser.FileChooserBase
directory, directoryUpButton, directoryUpButtonAction, fileName, fileShortcutsList, filters, newFolderButton, newFolderButtonAction, nextButton, nextButtonAction, optionsButton, optionsButtonAction, previousButton, previousButtonAction, textLabel1, textLabel1_2, textLabel2, viewContent
 
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
protected FileChooser(File defaultDirectory, String instance)
          Constructor.
 
Method Summary
 void directorySelectedSlot()
          A directory has been selected by the navigation bar.
 void directoryUpButtonPressedSlot()
          Go to the parent of the current selected directory.
 void fileAccepted(File selectedFile)
           
 void fileSelectionChanged(File file)
           
protected static File getFile(File f)
          Checks for shortcuts.
static FileChooser getInstance(String instance, File defaultDirectory)
          Return the instance of the FileChooser.
 String getInstanceName()
           
 boolean getMutipleSelection()
           
 File getSelectedFile()
          Return the selected file.
 File[] getSelectedFiles()
          Return the selected files.
 void guiInit()
           
static void main(String[] args)
          Test functionality.
 void newFolderButtonPressedSlot()
          Create a new directory in the current folder.
 void nextButtonPressedSlot()
          Go to the next directory in the history.
 void previousButtonPressedSlot()
          Go to the previous directory in the history.
protected static String replace(String str, String search, String replace)
          Replaces first occurance of search with replace.
static File selectFile(MainWindow parent)
          Convenience method for the selectFile(Window) method.
static File selectFile(MainWindow parent, String instance)
          Convenience method for the selectFile(Window,String) method.
static File selectFile(MainWindow parent, String instance, List fileFilters)
          Convenience method for the selectFile(Window,String,List) method.
static File selectFile(MainWindow parent, String instance, List fileFilters, String windowTitle)
          Convenience method for the selectFile(Window,String,List,String) method.
static File selectFile(MainWindow parent, String instance, List fileFilters, String windowTitle, File defaultDirectory)
          Convenience method for the selectFile(Window,String,List,String,File) method.
static File selectFile(Window parent)
          Show file selection dialog.
static File selectFile(Window parent, String instance)
          Show file selection dialog.
static File selectFile(Window parent, String instance, List fileFilters)
          Show file selection dialog.
static File selectFile(Window parent, String instance, List fileFilters, String windowTitle)
          Show file selection dialog.
static File selectFile(Window parent, String instance, List fileFilters, String windowTitle, File defaultDirectory)
          Show file selection dialog.
static File[] selectFiles(MainWindow parent, String instance, List fileFilters, String windowTitle, File defaultDirectory)
          Convenience method for the selectFiles(Window,String,List,String,File) method.
static File[] selectFiles(Window parent, String instance, List fileFilters, String windowTitle, File defaultDirectory)
          Show file selection dialog.
 void setFileFilters(List filefilters)
          Set the filefilters that can be used in the filechooser.
 void setFilePreview(FilePreviewInterface fpi)
           
 void setMultipleSelection(boolean multipleSelection)
          Sets the filedialog to multiple or single selection.
 void setSelectedFile(File selectedFile)
          Select the current file from the view.
 void setSelectedFiles(File[] selectedFiles)
           
 void shortcutSelectedSlot()
          A shortcut has been selected.
 File[] showFileChooser(Window parent, String windowTitle)
          Deprecated. use showOpenDialog or showSaveDialog
 File[] showFileChooser(Window parent, String windowTitle, String acceptButtonTitle)
          Show a StandardDialog to select files from the current FileChooser instance.
 File[] showOpenDialog(Window parent)
          Show an open dialog from the current filechooser instance.
 File showSaveDialog(Window parent)
          Show a save dialog from the current filechooser instance.
 TranslationInterface translate()
           
protected  void updateByHistory(File historyFile)
           
 
Methods inherited from class uic.widgets.filechooser.FileChooserBase
optionsButtonPressedSlot
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, 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, 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
 
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

FILE_ACCEPTED

public static final String FILE_ACCEPTED
Add property listener to FileChooser with FILE_ACCEPTED to keep track of files accepted from FileChooser. Add a property listener to the FileChooser with the FILE_ACCEPTED key to keep track of files accepted from the FileChooser NOTE: files accepted with the OK button on the standard dialog are NOT fired as a property change

See Also:
Constant Field Values
Constructor Detail

FileChooser

protected FileChooser(File defaultDirectory,
                      String instance)
Constructor. Constructs a new FileChooser

Parameters:
defaultDirectory - the directory to start the filechooser when no last saved exists
instance - name for this FileChooser, so that settings can be made (last directory, etc) per instance, null when no settings need to be restored/saved
Method Detail

guiInit

public void guiInit()
Overrides:
guiInit in class FileChooserBase

selectFile

public static File selectFile(MainWindow parent)
Convenience method for the selectFile(Window) method.


selectFile

public static File selectFile(MainWindow parent,
                              String instance)
Convenience method for the selectFile(Window,String) method.


selectFile

public static File selectFile(MainWindow parent,
                              String instance,
                              List fileFilters)
Convenience method for the selectFile(Window,String,List) method.


selectFile

public static File selectFile(MainWindow parent,
                              String instance,
                              List fileFilters,
                              String windowTitle)
Convenience method for the selectFile(Window,String,List,String) method.


selectFile

public static File selectFile(MainWindow parent,
                              String instance,
                              List fileFilters,
                              String windowTitle,
                              File defaultDirectory)
Convenience method for the selectFile(Window,String,List,String,File) method.


selectFiles

public static File[] selectFiles(MainWindow parent,
                                 String instance,
                                 List fileFilters,
                                 String windowTitle,
                                 File defaultDirectory)
Convenience method for the selectFiles(Window,String,List,String,File) method.


selectFile

public static File selectFile(Window parent)
Show file selection dialog. Show file selection dialog with the default AllFilesFilter Same as calling FileChooser.selectFile(parent, null, null)

Parameters:
parent - the parent that is used to display the filechooser on top of.
Returns:
the selected file or null if none selected

selectFile

public static File selectFile(Window parent,
                              String instance)
Show file selection dialog. Show file selection dialog with the default AllFilesFilter AllFilesFilter Same as calling FileChooser.selectFile(parent, instance, null) Note that fileFilters should contain a file filter for "all files" if this filter should be choosable

Parameters:
parent - the parent that is used to display the filechooser on top of.
instance - the instance of the FileChooser to return. Settings will be stored per instance
Returns:
the selected file or null if none selected

selectFile

public static File selectFile(Window parent,
                              String instance,
                              List fileFilters)
Show file selection dialog. Show file selection dialog with the default AllFilesFilter Same as calling FileChooser.selectFile(parent, fileFilters, instance, null) Note that fileFilters should contain a file filter for "all files" if this filter should be choosable

Parameters:
parent - the parent that is used to display the filechooser on top of.
fileFilters - a collection of AbstractFileFilter objects that is displayed in the filter combobox or null when the default (AllFilesFilter) should be used
instance - the instance of the FileChooser to return. Settings will be stored per instance
Returns:
the selected file or null if none selected

selectFile

public static File selectFile(Window parent,
                              String instance,
                              List fileFilters,
                              String windowTitle)
Show file selection dialog. Show file selection dialog with the default AllFilesFilter Same as calling FileChooser.selectFile(parent, fileFilters, instance, null) Note that fileFilters should contain a file filter for "all files" if this filter should be choosable

Parameters:
parent - the parent that is used to display the filechooser on top of.
fileFilters - a collection of AbstractFileFilter objects that is displayed in the filter combobox or null when the default (AllFilesFilter) should be used
instance - the instance of the FileChooser to return. Settings will be stored per instance
windowTitle - the title of the FileChooser window, when null "Open File" will be used
Returns:
the selected file

selectFile

public static File selectFile(Window parent,
                              String instance,
                              List fileFilters,
                              String windowTitle,
                              File defaultDirectory)
Show file selection dialog. Show file selection dialog with the default AllFilesFilter Same as calling FileChooser.selectFile(parent, fileFilters, instance, null) Note that fileFilters should contain a file filter for "all files" if this filter should be choosable

Parameters:
parent - the parent that is used to display the filechooser on top of.
instance - the instance of the FileChooser to return. Settings will be stored per instance
fileFilters - a collection of AbstractFileFilter objects that is displayed in the filter combobox or null when the default (AllFilesFilter) should be used
windowTitle - the title of the FileChooser window, when null "Open File" will be used
defaultDirectory - the directory to start the filechooser when no last saved exists
Returns:
the selected file

selectFiles

public static File[] selectFiles(Window parent,
                                 String instance,
                                 List fileFilters,
                                 String windowTitle,
                                 File defaultDirectory)
Show file selection dialog. Show file selection dialog with the default AllFilesFilter Same as calling FileChooser.selectFile(parent, fileFilters, instance, null) Note that fileFilters should contain a file filter for "all files" if this filter should be choosable

Parameters:
parent - the parent that is used to display the filechooser on top of.
fileFilters - a collection of AbstractFileFilter objects that is displayed in the filter combobox or null when the default (AllFilesFilter) should be used
instance - the instance of the FileChooser to return. Settings will be stored per instance
windowTitle - the title of the FileChooser window, when null "Open File" will be used
defaultDirectory - the directory to start the filechooser when no last saved exists
Returns:
the selected files

showFileChooser

public File[] showFileChooser(Window parent,
                              String windowTitle)
Deprecated. use showOpenDialog or showSaveDialog


showOpenDialog

public File[] showOpenDialog(Window parent)
Show an open dialog from the current filechooser instance.

Parameters:
parent - the parent window

showSaveDialog

public File showSaveDialog(Window parent)
Show a save dialog from the current filechooser instance.

Parameters:
parent - the parent window
Throws:
IllegalStateException - when multipleselection is on

showFileChooser

public File[] showFileChooser(Window parent,
                              String windowTitle,
                              String acceptButtonTitle)
Show a StandardDialog to select files from the current FileChooser instance. Show a StandardDialog to select files from the current FileChooser instance

Parameters:
parent - the parent window for modal settings
windowTitle - the window title, or ull when a translation of Open file should be used
acceptButtonTitle - the translated version of the accept button (open or save) including the mnemonic, or null for &Open
Returns:
the files selected or an empty array when nothing selected

getInstance

public static FileChooser getInstance(String instance,
                                      File defaultDirectory)
Return the instance of the FileChooser. Return the instance of the FileChooser

Parameters:
instance - the name of the instance to return, or null when no instance settings requ red
defaultDirectory - the directory to start by default, or null when the default user d rectory should be de defualt
Returns:
the filechooser instance or a new instance when no match was found NOTE: that the settings like FileFilters, FilePreview, multiple selection is reset

getInstanceName

public String getInstanceName()

setFileFilters

public void setFileFilters(List filefilters)
Set the filefilters that can be used in the filechooser. Set the filefilters that can be used in the filechooser. This must include an AllFiles file filter if this should be selectable

Parameters:
filefilters - collection of AbstractFileFilter objects

setFilePreview

public void setFilePreview(FilePreviewInterface fpi)

setMultipleSelection

public void setMultipleSelection(boolean multipleSelection)
Sets the filedialog to multiple or single selection. Sets the filedialog to multiple when parameter true is provided or single selection when false is provided

Parameters:
multipleSelection - true when multiple selection allowed

getMutipleSelection

public boolean getMutipleSelection()

fileAccepted

public void fileAccepted(File selectedFile)
Specified by:
fileAccepted in interface FileSelectionListener

fileSelectionChanged

public void fileSelectionChanged(File file)
Specified by:
fileSelectionChanged in interface FileSelectionListener

setSelectedFile

public void setSelectedFile(File selectedFile)
Select the current file from the view. Called on selection change in the view

Specified by:
setSelectedFile in interface FileSelectionListener

setSelectedFiles

public void setSelectedFiles(File[] selectedFiles)
Specified by:
setSelectedFiles in interface FileSelectionListener

shortcutSelectedSlot

public void shortcutSelectedSlot()
A shortcut has been selected. A shortcut has been selected update the navigation bar, which calls directorySelectedSlot


directorySelectedSlot

public void directorySelectedSlot()
A directory has been selected by the navigation bar.


directoryUpButtonPressedSlot

public void directoryUpButtonPressedSlot()
Go to the parent of the current selected directory.

Overrides:
directoryUpButtonPressedSlot in class FileChooserBase

nextButtonPressedSlot

public void nextButtonPressedSlot()
Go to the next directory in the history.

Overrides:
nextButtonPressedSlot in class FileChooserBase

previousButtonPressedSlot

public void previousButtonPressedSlot()
Go to the previous directory in the history.

Overrides:
previousButtonPressedSlot in class FileChooserBase

updateByHistory

protected void updateByHistory(File historyFile)

getFile

protected static File getFile(File f)
Checks for shortcuts. If it is a shortcut return the destination.. otherwise return the file


newFolderButtonPressedSlot

public void newFolderButtonPressedSlot()
Create a new directory in the current folder. Show a dialog in which the user can enter the new directory name When OK pressed and the folder/file does not exists Create a new directory and go there

Overrides:
newFolderButtonPressedSlot in class FileChooserBase

getSelectedFile

public File getSelectedFile()
Return the selected file. Return the selected file Or null when nothing selected

Returns:
the seleted file or null when nothing selected

getSelectedFiles

public File[] getSelectedFiles()
Return the selected files. Return the selected files Or an empty array when nothing selected

Returns:
the seleted files or an empty array when nothing selected

translate

public TranslationInterface translate()
Overrides:
translate in class FileChooserBase

replace

protected static String replace(String str,
                                String search,
                                String replace)
Replaces first occurance of search with replace. Replaces first occurance of search with replace

Parameters:
str - the string to search on
search - the string to search for
replace - the string to replace search with
Returns:
string with first occurance of search replaced with replace

main

public static void main(String[] args)
                 throws Exception
Test functionality. Show the file browser

Throws:
Exception


Copyright © 2002-2004 Thomas Zander Available under the Free Apache licence