org.geotoolkit.gui.swing.image
Class ImageFileProperties

Object
  extended by Component
      extended by Container
          extended by JComponent
              extended by ImageProperties
                  extended by ImageFileProperties
All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Dialog
Direct Known Subclasses:
CoverageFileProperties

public class ImageFileProperties
extends ImageProperties
implements PropertyChangeListener

A panel showing the properties of an image file. This is different than ImageProperties, which shows the properties of a RenderedImage. The panel contains the following tabs:

All setImage methods defined in this class may be slow because they involve I/O operations. It is recommended to invoke them from an other thread than the Swing thread.


Using this component together with a FileChooser
This component can be registered to a JFileChooser for listening to change events. When the file selection change, the propertyChange(PropertyChangeEvent) method is automatically invoked. The default implementation invokes in turn setImage(File) in a background thread. This allows this ImageFileProperties to be updated automatically when the user selection changed. Example:

ImageFileChooser chooser = new ImageFileChooser("png");
ImageFileProperties properties = new ImageFileProperties();
chooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, properties);
//
// Add the FileChooser and ImageFileProperties to some panel with the layout constraints
// of your choice. The example below uses BorderLayout in such a way that, when resizing
// the panel, only the properties pane is resized.
//
JPanel panel = new JPanel(new BorderLayout());
panel.add(this, BorderLayout.WEST);
panel.add(properties, BorderLayout.CENTER);

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

Nested Class Summary
 
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 ImageProperties
viewer
 
Fields inherited from class 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 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
ImageFileProperties()
          Creates a new instance of ImageFileProperties with no image.
ImageFileProperties(File file)
          Creates a new instance of ImageFileProperties initialized to the given file.
 
Method Summary
 Dimension getPreferredThumbnailSize()
          Returns the preferred size of the thumbnail.
 void propertyChange(PropertyChangeEvent event)
          Invoked when the state of a JFileChooser (or any other component at caller choice) changed.
 void setImage(File file)
          Sets the specified file as the source of metadata and thumbnails.
 void setImage(ImageReader reader)
          Sets the specified image reader as the source of metadata and thumbnails.
 void setImage(ImageReader reader, int imageIndex)
          Sets the specified image reader as the source of metadata and thumbnails, reading the information at the given image index.
 void setImageInput(Object input)
          Sets the specified image input as the source of metadata and thumbnails.
 void setImageLater(Object input)
          Reads the metadata and thumbnails from the given image input in a background thread.
 void setPreferredThumbnailSize(Dimension size)
          Sets the preferred size of the thumbnail.
static void show(File image)
          Shows the properties for the specified image file in a frame.
 
Methods inherited from class ImageProperties
commitEdit, setImage, setImage, setImage, show, showDialog
 
Methods inherited from class JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, updateUI
 
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

ImageFileProperties

public ImageFileProperties()
Creates a new instance of ImageFileProperties with no image. One of setImage(...) methods must be invoked in order to set the properties source.


ImageFileProperties

public ImageFileProperties(File file)
                    throws IOException
Creates a new instance of ImageFileProperties initialized to the given file.

Parameters:
file - The image file.
Throws:
IOException - If the file is not found, or no suitable image reader is found for the given file, or if an error occurred while reading the metadata or the thumbnails.
Method Detail

setImage

public void setImage(ImageReader reader,
                     int imageIndex)
              throws IOException
Sets the specified image reader as the source of metadata and thumbnails, reading the information at the given image index. The information are extracted immediately and no reference to the given image reader is retained.

Resources management
This method does not close the Image Input Stream (if any). It is caller responsibility to dispose reader resources (including closing the input stream) after this method call, if desired.

Thread safety
This method can be invoked from any thread. Actually it is recommended to invoke it from an other thread than the Swing one.

Parameters:
reader - The image reader from which to read the informations.
imageIndex - The index of the image to read (usually 0).
Throws:
IOException - If an error occurred while reading the metadata or the thumbnails.
Since:
3.07

setImage

public void setImage(ImageReader reader)
              throws IOException
Sets the specified image reader as the source of metadata and thumbnails. The information are extracted immediately and no reference to the given image reader is retained.

The default implementation delegates to setImage(ImageReader, int) with an image index of 0. Subclasses should override this method if they want to choose automatically an image index depending on the format and the input.

Thread safety
This method can be invoked from any thread. Actually it is recommended to invoke it from an other thread than the Swing one.

Parameters:
reader - The image reader from which to read the informations.
Throws:
IOException - If an error occurred while reading the metadata or the thumbnails.

setImage

public void setImage(File file)
              throws IOException
Sets the specified file as the source of metadata and thumbnails. This is the method which is invoked in a background thread when a JFileChooser is associated to this widget as described in the class javadoc. The default implementation delegates to setImageInput(Object), but subclasses can override if they want to perform additional processing.

Thread safety
This method can be invoked from any thread. Actually it is recommended to invoke it from an other thread than the Swing one.

Parameters:
file - The image file.
Throws:
IOException - If the file is not found, or no suitable image reader is found for the given file, or if an error occurred while reading the metadata or the thumbnails.

setImageInput

public void setImageInput(Object input)
                   throws IOException
Sets the specified image input as the source of metadata and thumbnails. This method gets or creates an ImageReader for the given input as below:

  • If the given input is an instance of ImageReader, then it is used directly. Note that this method does not close the image input stream after usage, as specified by setImage(ImageReader, int).
  • Otherwise this method creates a temporary image readerĀ for the given input, passes it to setImage(ImageReader), then disposes the resources (reader and input stream).
  • Then, this method delegates to setImage(ImageReader).

    Thread safety
    This method can be invoked from any thread. Actually it is recommended to invoke it from an other thread than the Swing one.

    Parameters:
    input - The image input.
    Throws:
    IOException - If the file is not found, or no suitable image reader is found for the given input, or if an error occurred while reading the metadata or the thumbnails.

    setImageLater

    public void setImageLater(Object input)
    Reads the metadata and thumbnails from the given image input in a background thread. This method delegates to the setImage(File) method if the given input is a file, or to setImageInput(Object) otherwise, from a background thread. If the operation fails, then the IOException is painted in the quicklook area.

    NOTE: This method must be invoked from the Swing thread.

    Parameters:
    input - The image input, or null if none.
    Since:
    3.12

    getPreferredThumbnailSize

    public Dimension getPreferredThumbnailSize()
    Returns the preferred size of the thumbnail. If a file contains more than one thumbnail, then the one having the closest size to this value will be selected.

    Returns:
    The preferred thumbnail size.

    setPreferredThumbnailSize

    public void setPreferredThumbnailSize(Dimension size)
    Sets the preferred size of the thumbnail.

    Parameters:
    size - The new preferred thumbnail size.

    propertyChange

    public void propertyChange(PropertyChangeEvent event)
    Invoked when the state of a JFileChooser (or any other component at caller choice) changed. If the event property name is "SelectedFileChangedProperty", then this method invokes setImage(File) in a background thread.

    This method is invoked automatically when this ImageFileProperties is registered to a JFileChooser as an PropertyChangeListener. It can be invoked from the Swing thread only.

    Specified by:
    propertyChange in interface PropertyChangeListener
    Parameters:
    event - The property change event.

    show

    @Debug
    public static void show(File image)
    Shows the properties for the specified image file in a frame. This convenience method is mostly a helper for debugging purpose.

    Parameters:
    image - The image to display in a frame.


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