org.geotoolkit.gui.swing.image
Class ImagePane

Object
  extended by Component
      extended by Container
          extended by JComponent
              extended by ZoomPane
                  extended by ImagePane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, DeformableViewer

public class ImagePane
extends ZoomPane

A simple image viewer. This widget accepts either rendered or renderable image. Rendered image are displayed immediately, while renderable image will be rendered in a background thread when first requested.

This widget may scale down images for faster rendering. This is convenient for image previews, but should not be used as a "real" (i.e. robust and accurate) renderer.

Since:
2.3
Version:
3.07
Author:
Martin Desruisseaux (IRD, Geomatys)
See Also:
ImageProperties, 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 ZoomPane
DEFAULT_ZOOM, RESET, ROTATE, SCALE_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y, UNIFORM_SCALE, zoom
 
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
ImagePane()
          Constructs an initially empty image pane with a default rendered image size.
ImagePane(Dimension renderedSize)
          Constructs an initially empty image pane with the specified rendered image size.
ImagePane(int renderedSize)
          Constructs an initially empty image pane with the specified rendered image size.
 
Method Summary
 Rectangle2D getArea()
          Returns the image bounds, or null if none.
 int getProgress()
          Returns the current progress, as a percentage between 0 and 100 inclusive.
 String getProgressLabel()
          Returns the current label to display on top of the progress bar.
 boolean isProgressVisible()
          Returns true if the progress bar is visible, or false otherwise.
protected  void paintComponent(Graphics2D graphics)
          Paints the image.
 void reset()
          Resets the default zoom.
 void setError(Throwable error)
          Removes the current image (if any) and paints the stack trace of the given exception instead.
 void setImage(RenderableImage image)
          Sets the source renderable image.
 void setImage(RenderedImage image)
          Sets the source rendered image.
 void setProgress(int percentageDone)
          Sets the progress done, as a percentage between 0 and 100 inclusive.
 void setProgressLabel(String label)
          Sets the label to display on top of the progress bar.
 void setProgressVisible(boolean visible)
          Shows or hide the progress bar.
 
Methods inherited from class ZoomPane
addMouseListener, addZoomChangeListener, buildNavigationMenu, correctApparentPixelPosition, createScrollPane, fireZoomChanged, getDefaultSize, getInsets, getMagnifierBorder, getMagnifierGlass, getMagnifierMenu, getMouseSelectionShape, getPopupMenu, getPreferredArea, getPreferredPixelSize, getScaleFactor, getTransform, getVisibleArea, getZoomableBounds, hasPreferredArea, isMagnifierEnabled, isMagnifierVisible, isPaintingWhileAdjusting, mouseSelectionPerformed, paintComponent, paintMagnifier, printComponent, printComponent, removeZoomChangeListener, repaint, reset, scrollRectToVisible, setMagnifierBorder, setMagnifierEnabled, setMagnifierGlass, setMagnifierVisible, setPaintingWhileAdjusting, setPreferredArea, setResetPolicy, setTransform, setVisibleArea, tieModels, transform, transformPixels, untieModels, updateUI
 
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, 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, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, 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, 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

ImagePane

public ImagePane()
Constructs an initially empty image pane with a default rendered image size.


ImagePane

public ImagePane(int renderedSize)
Constructs an initially empty image pane with the specified rendered image size. The renderedSize argument is the maximum width and height for rendered image. Images greater than this value will be scaled down for faster rendering.

Parameters:
renderedSize - The maximal image width and height.

ImagePane

public ImagePane(Dimension renderedSize)
Constructs an initially empty image pane with the specified rendered image size. The renderedSize argument is the maximum dimension for rendered image. Images greater than this value will be scaled down for faster rendering.

Parameters:
renderedSize - The maximal image dimension before to scale down.
Since:
3.07
Method Detail

setImage

public void setImage(RenderableImage image)
Sets the source renderable image. The given image will be rendered in a background thread when first needed.

Parameters:
image - The image to display, or null if none.

setImage

public void setImage(RenderedImage image)
Sets the source rendered image. If the given image is larger than the size given at construction time, then it will be scaled down when first needed. A null value remove the current image.

Parameters:
image - The image to display, or null if none.

setError

public void setError(Throwable error)
Removes the current image (if any) and paints the stack trace of the given exception instead. This method is invoked when the client code failed to create the image to display, typically because of an IOException.

The error is cleaned when a setImage(...) method is invoked.

Parameters:
error - The error to paint, or null if none.
Since:
3.05

setProgressVisible

public void setProgressVisible(boolean visible)
Shows or hide the progress bar. This method should be invoked with the value true before to invoke setProgress(int), and invoked again with the value false when the operation is completed. This will not be done automatically.

Parameters:
visible - true for showing the progress pane, or false for hiding it.
Since:
3.07

isProgressVisible

public boolean isProgressVisible()
Returns true if the progress bar is visible, or false otherwise. This method returns the last value given to the setProgressVisible(boolean) method, or false if the value has never been set.

Returns:
true if the progress bar is currently visible.
Since:
3.07

setProgressLabel

public void setProgressLabel(String label)
Sets the label to display on top of the progress bar. If this method has never been invoked, then the default value is "Loading..." localized for the current locale.

Parameters:
label - The new label to print on top of the progress bar.
Since:
3.07

getProgressLabel

public String getProgressLabel()
Returns the current label to display on top of the progress bar. This is the last value given to the setProgressLabel(String) method, or "Loading..." localized for the current locale if the value has never been set.

Returns:
The current label to print on top of the progress bar.
Since:
3.07

setProgress

public void setProgress(int percentageDone)
Sets the progress done, as a percentage between 0 and 100 inclusive. This method can be invoked during lengthly operation like reading the image from a file. The lengthly operation is typically run in a background thread, but this method shall be invoked from the Swing thread only.

The setProgressVisible(boolean) method should be invoked before to lengthly operation begin, and when it is finished.

Parameters:
percentageDone - The percentage done as a number between 0 and 100 inclusive.
Since:
3.07

getProgress

public int getProgress()
Returns the current progress, as a percentage between 0 and 100 inclusive. This is the last value given to the setProgress(int) method, or 0 if the value has never been set.

Returns:
The current progress percentage.
Since:
3.07

reset

public void reset()
Resets the default zoom. This method overrides the default implementation in order to keep the y axis in its Java2D direction (y value increasing down), which is the usual direction of most image.

Overrides:
reset in class ZoomPane

getArea

public Rectangle2D getArea()
Returns the image bounds, or null if none. This is used by ZoomPane in order to set the initial zoom.

Specified by:
getArea in class ZoomPane
Returns:
A bounding box for the logical coordinates of all contents that are going to be drawn in this ZoomPane. If this bounding box is unknown, then this method can return null (but this is not recommended).

paintComponent

protected void paintComponent(Graphics2D graphics)
Paints the image. If the image was a RenderableImage, then a RenderedImage will be computed in a background thread when this method is first invoked. If the rendering fails, then the exception stack trace will be painted.

Specified by:
paintComponent in class ZoomPane
Parameters:
graphics - The graphics where to paint this component.


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