org.geotoolkit.gui.swing.image
Class ImageFileChooser

Object
  extended by Component
      extended by Container
          extended by JComponent
              extended by JFileChooser
                  extended by ImageFileChooser
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ImageFileChooser
extends JFileChooser

A file chooser for images. Compared to the standard JFileChooser, this class provides the following additional functionalities:

This class should typically be used as below (replace "showOpenDialog" by "showSaveDialog" for saving an image instead than loading it):

ImageFileChooser chooser = new ImageFileChooser("png", true);
if (chooser.showOpenDialog(parent) == ImageFileChooser.APPROVE_OPTION) {
    File selected = chooser.getSelectedFile();
}

Since:
3.00
Version:
3.08
Author:
Martin Desruisseaux (Geomatys)
See Also:
ImageFileProperties, Serialized Form
Module:
display/geotk-widgets-swing (download)    View source code for this class

Nested Class Summary
 
Nested classes/interfaces inherited from class JFileChooser
JFileChooser.AccessibleJFileChooser
 
Nested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class JFileChooser
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
 
Fields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ImageFileChooser(String defaultFormat)
          Creates a new file chooser having the user's default directory as the initial directory.
ImageFileChooser(String defaultFormat, boolean showProperties)
          Creates a new file chooser, optionally with an ImageFileProperties pane to be shown.
 
Method Summary
protected  JDialog createDialog(Component parent)
          Creates and returns a new dialog wrapping this ImageFileChooser, optionally with its ImageFileProperties pane.
 ImageReaderWriterSpi getCurrentProvider()
          Returns the image reader/writer provider for the currently selected file filter.
 ImageFileProperties getPropertiesPane()
          Returns the pane showing the properties of the selected file, or null if none.
 File getSelectedFile()
          Returns the selected file.
 File[] getSelectedFiles()
          Returns the selected file.
 boolean isListFileFilterUsed()
          Returns true if this ImageFileChooser should proposes a filter for list of files.
 void resetChoosableFileFilters()
          Resets the choosable file filter list to its starting state.
 void setDialogType(int mode)
          Sets whatever this dialog is going to be used for reading or writing images.
 void setListFileFilterUsed(boolean enabled)
          Sets whatever this ImageFileChooser should proposes a filter for list of files.
 void setPropertiesPane(ImageFileProperties properties)
          Sets the pane showing the properties of the selected file, which can be null for hiding the pane.
 
Methods inherited from class JFileChooser
accept, addActionListener, addChoosableFileFilter, approveSelection, cancelSelection, changeToParentDirectory, ensureFileIsVisible, fireActionPerformed, getAcceptAllFileFilter, getAccessibleContext, getAccessory, getActionListeners, getApproveButtonMnemonic, getApproveButtonText, getApproveButtonToolTipText, getChoosableFileFilters, getControlButtonsAreShown, getCurrentDirectory, getDescription, getDialogTitle, getDialogType, getDragEnabled, getFileFilter, getFileSelectionMode, getFileSystemView, getFileView, getIcon, getName, getTypeDescription, getUI, getUIClassID, isAcceptAllFileFilterUsed, isDirectorySelectionEnabled, isFileHidingEnabled, isFileSelectionEnabled, isMultiSelectionEnabled, isTraversable, paramString, removeActionListener, removeChoosableFileFilter, rescanCurrentDirectory, setAcceptAllFileFilterUsed, setAccessory, setApproveButtonMnemonic, setApproveButtonMnemonic, setApproveButtonText, setApproveButtonToolTipText, setControlButtonsAreShown, setCurrentDirectory, setDialogTitle, setDragEnabled, setFileFilter, setFileHidingEnabled, setFileSelectionMode, setFileSystemView, setFileView, setMultiSelectionEnabled, setSelectedFile, setSelectedFiles, setup, showDialog, showOpenDialog, showSaveDialog, updateUI
 
Methods inherited from class 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, 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 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 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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ImageFileChooser

public ImageFileChooser(String defaultFormat)
Creates a new file chooser having the user's default directory as the initial directory. This default depends on the operating system. It is typically the "My Documents" folder on Windows, and the user's home directory on Unix.

The setDialogType(int) method will be invoked implicitly by the showOpenDialog and showSaveDialog methods. If those methods are not going to be invoked, then callers should invoke setDialogType(int) explicitly after construction in order to add file filters appropriate for the kind of operation (open or save) to be performed.

Parameters:
defaultFormat - The default format to be initially selected, or null for proposing all formats. If non-null, it should be an Image I/O format name like "png" or "jpeg".

ImageFileChooser

public ImageFileChooser(String defaultFormat,
                        boolean showProperties)
Creates a new file chooser, optionally with an ImageFileProperties pane to be shown. If showProperties is true, then the properties pane will be visible when the showDialog method or one of its variants is invoked. The properties pane is not visible otherwise; see setPropertiesPane(ImageFileProperties) for more information.

Parameters:
defaultFormat - The default format to be initially selected, or null for all.
showProperties - true for creating an ImageFileProperties. The default value is false.
Since:
3.05
Method Detail

isListFileFilterUsed

public boolean isListFileFilterUsed()
Returns true if this ImageFileChooser should proposes a filter for list of files. A "list of files" is a file with .txt, .lst or .csv extension which contains the actual list of images to select, which may be spread over many directories.

By default this method returns false.

Returns:
true if this chooser should proposes the selection of .txt, .lst or .csv files that contain a list of image files.
See Also:
JFileChooser.isAcceptAllFileFilterUsed()

setListFileFilterUsed

public void setListFileFilterUsed(boolean enabled)
Sets whatever this ImageFileChooser should proposes a filter for list of files.

Parameters:
enabled - true if this chooser should proposes the selection of .txt, .lst or .csv files that contain a list of image files.
See Also:
JFileChooser.setAcceptAllFileFilterUsed(boolean)

resetChoosableFileFilters

public void resetChoosableFileFilters()
Resets the choosable file filter list to its starting state.

Overrides:
resetChoosableFileFilters in class JFileChooser

getPropertiesPane

public ImageFileProperties getPropertiesPane()
Returns the pane showing the properties of the selected file, or null if none. This is different than the accessory pane provided by JFileChooser in that this pane is located at the right side of the chooser, because it is too big for fitting in the accessory area of the file chooser.

Returns:
The current pane showing image properties, or null if none.
Since:
3.05
See Also:
JFileChooser.getAccessory()

setPropertiesPane

public void setPropertiesPane(ImageFileProperties properties)
Sets the pane showing the properties of the selected file, which can be null for hiding the pane. This method automatically unregister the old pane (if any) from the list of property change listeners, and register the new pane (if non null) instead.

The properties pane is shown when one of the showDialog method variants is invoked. If those methods are not going to be used for showing this file chooser, then the caller shall adds the ImageFileProperties pane himself in his own pane.

Parameters:
properties - The new pane showing image properties, or null if none.
Since:
3.05
See Also:
JFileChooser.setAccessory(JComponent)

setDialogType

public void setDialogType(int mode)
Sets whatever this dialog is going to be used for reading or writing images. This method resets the file filters to all image formats registered in IIORegistry. Only formats available for reading or writing (depending on the value of the mode argument) will be listed.

Overrides:
setDialogType in class JFileChooser
Parameters:
mode - OPEN_DIALOG for a chooser to be used for reading images, or SAVE_DIALOG for a chooser to be used for writing images.

getSelectedFile

public File getSelectedFile()
Returns the selected file. If the user has selected a file which contains a list of images (as proposed if setListFileFilterUsed(true) has been invoked), then this method returns the list file itself, not its content since this method can only returns a single file.

Overrides:
getSelectedFile in class JFileChooser

getSelectedFiles

public File[] getSelectedFiles()
Returns the selected file. If the user has selected a file which contains a list of images (as proposed if setListFileFilterUsed(true) has been invoked), then this method opens that file using the platform encoding and returns its content. If an I/O error occurred while reading that file, then its content is not included in the returned array.

Overrides:
getSelectedFiles in class JFileChooser
Returns:
The list of selected files, including the content of text files that are list of images.

getCurrentProvider

public ImageReaderWriterSpi getCurrentProvider()
Returns the image reader/writer provider for the currently selected file filter. If the dialog type has been set to OPEN_DIALOG, then this method returns either null or an instance of ImageReaderSpi. Otherwise if the dialog type has been set to SAVE_DIALOG, then this method returns either null or an instance of ImageWriterSpi.

Returns:
The image reader/writer provider for the currently selected file filter, or null if the current file filter is unknown to this method.

createDialog

protected JDialog createDialog(Component parent)
                        throws HeadlessException
Creates and returns a new dialog wrapping this ImageFileChooser, optionally with its ImageFileProperties pane. This method is invoked automatically by the showDialog methods and is overridden for adding the optional properties pane, if presents.

Overrides:
createDialog in class JFileChooser
Parameters:
parent - he parent component of the dialog, or null.
Returns:
A dialog containing this file chooser, and optionally a properties pane.
Throws:
HeadlessException - If the graphics environment is headlesss.
Since:
3.05


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.