CADI.Viewer.Display
Class ThumbnailDisplay

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 CADI.Viewer.Display.ThumbnailDisplay
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class ThumbnailDisplay
extends javax.swing.JPanel

This class implements a thumbnail displayer. If the size of thumbnail image is greater than the drawing area size, the thumbnail image is fit to the drawing area size.

Usage example:
  constructor
  setThumbnail
  movePanner

Version:
1.0.1 2008/01/16
Author:
Group on Interactive Coding of Images (GICI)
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
private  java.awt.image.BufferedImage bufferedImage
          Is the thumbnail image.
private  int dx1
          The x coordinate of the first corner of the destination rectangle.
private  int dx2
          The x coordinate of the second corner of the destination rectangle.
private  int dy1
          The y coordinate of the first corner of the destination rectangle.
private  int dy2
          The y coordinate of the second corner of the destination rectangle.
private  int height
          Height of the panel
private  java.awt.Insets insets
          Insets of the panel.
private  java.awt.Rectangle panner
          Are the panner coordinates (origin and size).
private  java.awt.Color pannerColor
          Is the color that will be used to display the panner.
private  javax.swing.JFrame parent
          Reference to the parent window.
private  boolean setThumnailImage
          Indicates whether the thumbnail image is available or not.
private  int sx1
          The x coordinate of the first corner of the source rectangle.
private  int sx2
          The x coordinate of the second corner of the source rectangle.
private  int sy1
          The y coordinate of the first corner of the source rectangle.
private  int sy2
          The y coordinate of the second corner of the source rectangle.
private  int width
          Width of the panel
 
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
ThumbnailDisplay(javax.swing.JFrame parent, int width, int height)
          Constructor.
 
Method Summary
 void clear()
          Clears the thumbnail display.
private  void createAndShowGUI()
          Display the DrawingPanel with BufferedImage on the applet.
private  java.awt.image.BufferedImage createView(java.awt.image.BufferedImage bImage)
          Creates a new view of the raster image that fits to the thumbnail display window.
private  void displayImage()
          Build a BufferedImage from a pixel array.
 java.awt.Dimension getDisplaySize()
          Returns the size of the area where thumbnail is displayed.
 java.awt.Dimension getImageSize()
          Returns the image size.
 java.awt.Dimension getSize()
           
protected  void movePanner(int imgWidth, int imgHeight, int x, int y, int width, int height)
          Moves the panner window on the thumbnail image to the new position and size.
 void paintComponent(java.awt.Graphics g)
           
 void setThumbnail(java.awt.image.BufferedImage bufferedImage)
          Sets a new thumbnail to be displayed.
 
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, 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, 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, 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

parent

private javax.swing.JFrame parent
Reference to the parent window.


width

private int width
Width of the panel


height

private int height
Height of the panel


bufferedImage

private java.awt.image.BufferedImage bufferedImage
Is the thumbnail image.


panner

private java.awt.Rectangle panner
Are the panner coordinates (origin and size).


pannerColor

private final java.awt.Color pannerColor
Is the color that will be used to display the panner.

See Also:
panner

insets

private java.awt.Insets insets
Insets of the panel.


dx1

private int dx1
The x coordinate of the first corner of the destination rectangle.

See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)

dy1

private int dy1
The y coordinate of the first corner of the destination rectangle.

See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)

dx2

private int dx2
The x coordinate of the second corner of the destination rectangle.

See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)

dy2

private int dy2
The y coordinate of the second corner of the destination rectangle.

See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)

sx1

private int sx1
The x coordinate of the first corner of the source rectangle.

See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)

sy1

private int sy1
The y coordinate of the first corner of the source rectangle.

See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)

sx2

private int sx2
The x coordinate of the second corner of the source rectangle.

See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)

sy2

private int sy2
The y coordinate of the second corner of the source rectangle.

See Also:
Graphics.drawImage(java.awt.Image, int, int, int, int, int, int, int, int, java.awt.image.ImageObserver)

setThumnailImage

private boolean setThumnailImage
Indicates whether the thumbnail image is available or not. The image will be available if the setThumbnail(BufferedImage) method has been called.

Constructor Detail

ThumbnailDisplay

public ThumbnailDisplay(javax.swing.JFrame parent,
                        int width,
                        int height)
Constructor.

Parameters:
parent - reference to the parent window.
width - width of the panel
height - height of the panel
Method Detail

setThumbnail

public void setThumbnail(java.awt.image.BufferedImage bufferedImage)
Sets a new thumbnail to be displayed.

Parameters:
bufferedImage - the new thumbnail image.

clear

public void clear()
Clears the thumbnail display.


movePanner

protected void movePanner(int imgWidth,
                          int imgHeight,
                          int x,
                          int y,
                          int width,
                          int height)
Moves the panner window on the thumbnail image to the new position and size.

The coordinates which are passed in this method are referred to the original image. The dimensions of the original image are also passed to the method.

Parameters:
imgWidth - width of the original image
imgHeight - height of the original image
x - x coordinate in the original image
y - y corrdinate in the original image
width - width in the original image
height - height in the original image

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

getSize

public java.awt.Dimension getSize()
Overrides:
getSize in class java.awt.Component

getDisplaySize

public java.awt.Dimension getDisplaySize()
Returns the size of the area where thumbnail is displayed.

Returns:
size of the displayer area.

getImageSize

public java.awt.Dimension getImageSize()
Returns the image size.

Returns:
the size of the image.

createAndShowGUI

private void createAndShowGUI()
Display the DrawingPanel with BufferedImage on the applet.


displayImage

private void displayImage()
Build a BufferedImage from a pixel array.


createView

private java.awt.image.BufferedImage createView(java.awt.image.BufferedImage bImage)
Creates a new view of the raster image that fits to the thumbnail display window. If the image size is greater than the window size, image is scaled to fit the window size keeping the aspect ratio. Otherwise, do nothing.

Parameters:
bImage - image to be scaled.
Returns:
scaled image.


CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) (contact)