net.lucidviews.util.gui.swing
Class JImage

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by net.lucidviews.util.gui.swing.JImage
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, DimensionImageObserver.Listener

public class JImage
extends JComponent
implements DimensionImageObserver.Listener

A UI component that displays an image.
To display an image in a GUI, simply create an new instance of JImage specifying an Image or the location of a file containing an image:

 Image logoImage = Toolkit.getDefaultToolkit.createImage( "./icons/logo.gif" );

 JImage logoPane = new JImage( logoImage, new Dimension( 80, 50 ) );
 JImage localPicture = new JImage( "C:/MyPictures/Photo.jpg", JImage.MAINTAIN_SIZE );
 JImage remotePicture = new JImage( new URL( "http://www.mysite.com/Photo.jpg" ), JImage.SHRINK_TO_AREA_MAINTAIN_ASPECT );

 JPanel contentPane = ...;
 contentPane.add( logoPane );
 contentPane.add( localPicture );
 contentPane.add( remotePicture );

The functionality required to load a file from a local file or remote URL is encapsulated in this class. The image data will load in the background and the UI component will be refreshed once the image has fully loaded.

You can change the image displayed at any time by calling one of the setImage methods.
If you intend to change the image frequently (e.g. switch between two images) it is recommended you load those images in your client module to ensure the Image objects persist in memory. Using the setImage( filename ) method will cause each image to load on every call to setImage. Holding the Image object in memory and calling setImage( Image ) will ensure the image is loaded just once and provide a smoother display.

Since:
1.0
Version:
$Revision: 1.5 $
Author:
Stephen Battey
See Also:
Image, Toolkit.createImage(java.lang.String), Serialized Form

Nested Class Summary
 
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
protected  Image _displayImage
          The image that gets displayed (a re-sized copy of _image)
protected  Point _displayPosition
          The pixel position of the top-right corner of the image relative to the top-right corner of the available area.
protected  int _displayScaling
          The algorithm used to scale the original image to the displayed (re-sized) image.
protected  Dimension _displaySetting
          The algorithm used to determine the size of the displayed image based upon the available area in which to display it.
protected  Dimension _displaySize
          The size of the rendered image.
protected  Image _image
          The image to be displayed.
protected  Dimension _imageSize
          The (original) size of the image.
protected  boolean _paintRequested
          Flag set when the paint method is called and reset once the image has been successfully painted (i.e.
protected  float _xAlignment
          Horizontal alignment of the image within the available space (0.0: left; 1.0: right).
protected  float _yAlignment
          Vertical alignment of the image within the available space (0.0: top; 1.0: bottom)
static Dimension FIT_TO_AREA
           
static Dimension FIT_TO_AREA_MAINTAIN_ASPECT
           
static Dimension MAINTAIN_SIZE
           
static Dimension SHRINK_TO_AREA_MAINTAIN_ASPECT
           
protected static String[] SUPPORTED_IMAGE_EXTNS
          A list of file extensions supported by the Java Image renderer.
protected static Dimension UNDEFINED_SIZE
          Special value used to indicate the image size has not been set.
protected static Insets ZERO_INSET
          An Insets object that defines no border.
 
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
JImage()
          Create a component that displays an image, but leave the image undefined.
JImage(Image image, Dimension size)
          Create a component that displays an image.
JImage(Image image, Dimension size, int scalingAlgorithm)
          Create a GUI component that displays an image, using the given scaling algorithm, whenever necessary, to adjust the size of the image to fit the available space.
JImage(String filename, Dimension size)
          Create a component that displays an image taken from a given file.
JImage(String filename, Dimension size, int scalingAlgorithm)
          Create a GUI component that displays an image taken from a given file, using the given scaling algorithm, whenever necessary, to adjust the size of the image to fit the available space.
 
Method Summary
protected  Dimension computeDisplaySize(int imageWidth, int imageHeight)
          Compute the dimension of the scaled image.
 Insets getBorderInsets()
          Returns an Insets model that describes the location of the inner edge of the border around this image component.
 Image getImage()
          Get the Image object that represents the image being displayed in this component.
static boolean isSupportedImage(File file)
          Checks if a file is an image of a known format.
static boolean isSupportedImage(String fileName)
          Checks if a file is an image of a known format.
 void paint(Graphics g)
           
 void setBounds(int x, int y, int width, int height)
           
protected  void setDisplaySize(Dimension size)
          Called to set the dimension of the image that is displayed in the component.
 void setImage(byte[] imageData, Dimension size)
          Set the image to be displayed in this component.
 void setImage(byte[] imageData, Dimension size, boolean repaintNow)
          Set the image to be displayed in this component.
 void setImage(byte[] imageData, Dimension size, int scalingAlgorithm)
          Set the image to be displayed in this component.
 void setImage(byte[] imageData, Dimension size, int scalingAlgorithm, boolean repaintNow)
          Set the image to be displayed in this component.
 void setImage(Image image, Dimension size)
          Set the image to be displayed in this component.
 void setImage(Image image, Dimension size, boolean repaintNow)
          Set the image to be displayed in this component.
 void setImage(Image image, Dimension size, int scalingAlgorithm)
          Set the image to be displayed in this component.
 void setImage(Image image, Dimension size, int scalingAlgorithm, boolean repaintNow)
          Set the image to be displayed in this component.
 void setImage(String filename, Dimension size)
          Set the image to be displayed in this component.
 void setImage(String filename, Dimension size, boolean repaintNow)
          Set the image to be displayed in this component.
 void setImage(String filename, Dimension size, int scalingAlgorithm)
          Set the image to be displayed in this component.
 void setImage(String filename, Dimension size, int scalingAlgorithm, boolean repaintNow)
          Set the image to be displayed in this component.
 void setImage(URL imageURL, Dimension size)
          Set the image to be displayed in this component.
 void setImage(URL imageURL, Dimension size, boolean repaintNow)
          Set the image to be displayed in this component.
 void setImage(URL imageURL, Dimension size, int scalingAlgorithm)
          Set the image to be displayed in this component.
 void setImage(URL imageURL, Dimension size, int scalingAlgorithm, boolean repaintNow)
          Set the image to be displayed in this component.
 void setImageAlignment(float xAlignment, float yAlignment)
          Set the alignment of the image within the available space.
 void setImageDimension(int imgWidth, int imgHeight)
          Set the size of the original image.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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 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, 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

MAINTAIN_SIZE

public static final Dimension MAINTAIN_SIZE

FIT_TO_AREA

public static final Dimension FIT_TO_AREA

FIT_TO_AREA_MAINTAIN_ASPECT

public static final Dimension FIT_TO_AREA_MAINTAIN_ASPECT

SHRINK_TO_AREA_MAINTAIN_ASPECT

public static final Dimension SHRINK_TO_AREA_MAINTAIN_ASPECT

SUPPORTED_IMAGE_EXTNS

protected static final String[] SUPPORTED_IMAGE_EXTNS
A list of file extensions supported by the Java Image renderer.


UNDEFINED_SIZE

protected static final Dimension UNDEFINED_SIZE
Special value used to indicate the image size has not been set.


ZERO_INSET

protected static final Insets ZERO_INSET
An Insets object that defines no border.


_image

protected Image _image
The image to be displayed.


_imageSize

protected Dimension _imageSize
The (original) size of the image.


_displaySetting

protected Dimension _displaySetting
The algorithm used to determine the size of the displayed image based upon the available area in which to display it.


_displaySize

protected Dimension _displaySize
The size of the rendered image.


_displayScaling

protected int _displayScaling
The algorithm used to scale the original image to the displayed (re-sized) image. The algorthim can be changed to improve quality or performance.


_xAlignment

protected float _xAlignment
Horizontal alignment of the image within the available space (0.0: left; 1.0: right).


_yAlignment

protected float _yAlignment
Vertical alignment of the image within the available space (0.0: top; 1.0: bottom)


_displayImage

protected Image _displayImage
The image that gets displayed (a re-sized copy of _image)


_displayPosition

protected Point _displayPosition
The pixel position of the top-right corner of the image relative to the top-right corner of the available area.


_paintRequested

protected boolean _paintRequested
Flag set when the paint method is called and reset once the image has been successfully painted (i.e. flag is on if the image needs repainting).

Constructor Detail

JImage

public JImage()
Create a component that displays an image, but leave the image undefined.
The component will remain blank until the image has been set with a call to the setImage method.


JImage

public JImage(Image image,
              Dimension size)
Create a component that displays an image.

Parameters:
image - the image to display
size - either an absolute value or one of the constants exported by JImage
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT

JImage

public JImage(String filename,
              Dimension size)
Create a component that displays an image taken from a given file.

Parameters:
filename - the name of the file that stores the image; the file must be in one of the supported formats (JPG or GIF)
size - either an absolute value or one of the constants exported by JImage
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT

JImage

public JImage(Image image,
              Dimension size,
              int scalingAlgorithm)
Create a GUI component that displays an image, using the given scaling algorithm, whenever necessary, to adjust the size of the image to fit the available space.

Parameters:
image - the image to display
size - either an absolute value or one of the constants exported by JImage
scalingAlgorithm - flags to indicate the type of algorithm to use for image re-scaling
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT, Image.SCALE_DEFAULT, Image.SCALE_FAST, Image.SCALE_SMOOTH, Image.SCALE_REPLICATE, Image.SCALE_AREA_AVERAGING

JImage

public JImage(String filename,
              Dimension size,
              int scalingAlgorithm)
Create a GUI component that displays an image taken from a given file, using the given scaling algorithm, whenever necessary, to adjust the size of the image to fit the available space.

Parameters:
filename - the name of the file that stores the image; the file must be in one of the supported formats (JPG or GIF)
size - either an absolute value or one of the constants exported by JImage
scalingAlgorithm - flags to indicate the type of algorithm to use for image re-scaling
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT, Image.SCALE_DEFAULT, Image.SCALE_FAST, Image.SCALE_SMOOTH, Image.SCALE_REPLICATE, Image.SCALE_AREA_AVERAGING
Method Detail

setImageAlignment

public void setImageAlignment(float xAlignment,
                              float yAlignment)
Set the alignment of the image within the available space.
The alignment will affect the position of the image after it has been scaled to fit the available area. If any excess space remains (due to the difference in ratio aspect between the image and available area) then the alignment setting will cause the image to be aligned to one of the edges or in the centre.

Parameters:
xAlignment - horizontal alignment (0.0: left; 1.0: right)
yAlignment - vertical alignment (0.0: top; 1.0: bottom)

getImage

public Image getImage()
Get the Image object that represents the image being displayed in this component.

Returns:
the image being displayed or null if the image has not been set

setImage

public void setImage(Image image,
                     Dimension size)
Set the image to be displayed in this component.
This component will be repainted as soon as the image has loaded to ensure the new image is rendered.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.

Parameters:
image - the image to be displayed
size - either an absolute value or one of the constants exported by JImage
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT

setImage

public void setImage(String filename,
                     Dimension size)
Set the image to be displayed in this component.
This component will be repainted as soon as the image has loaded to ensure the new image is rendered.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.

Parameters:
filename - the name of the file that stores the image; the file must be in one of the supported formats (JPG or GIF)
size - either an absolute value or one of the constants exported by JImage
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT

setImage

public void setImage(URL imageURL,
                     Dimension size)
Set the image to be displayed in this component.
This component will be repainted as soon as the image has loaded to ensure the new image is rendered.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.

Parameters:
imageURL - the URL of the file that stores the image; the file must be in one of the supported formats (JPG or GIF)
size - either an absolute value or one of the constants exported by JImage
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT

setImage

public void setImage(byte[] imageData,
                     Dimension size)
Set the image to be displayed in this component.
This component will be repainted to ensure the new image is rendered.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.

Parameters:
imageData - the binary data of the image to be displayed
size - either an absolute value or one of the constants exported by JImage
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT

setImage

public void setImage(Image image,
                     Dimension size,
                     boolean repaintNow)
Set the image to be displayed in this component.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.

Parameters:
image - the image to be displayed
size - either an absolute value or one of the constants exported by JImage
repaintNow - indicates if the component should be refreshed to ensure the new image is rendered
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT

setImage

public void setImage(String filename,
                     Dimension size,
                     boolean repaintNow)
Set the image to be displayed in this component.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.

Parameters:
filename - the name of the file that stores the image; the file must be in one of the supported formats (JPG or GIF)
size - either an absolute value or one of the constants exported by JImage
repaintNow - indicates if the component should be refreshed to ensure the new image is rendered
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT

setImage

public void setImage(URL imageURL,
                     Dimension size,
                     boolean repaintNow)
Set the image to be displayed in this component.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.

Parameters:
imageURL - the URL of the file that stores the image; the file must be in one of the supported formats (JPG or GIF)
size - either an absolute value or one of the constants exported by JImage
repaintNow - indicates if the component should be refreshed to ensure the new image is rendered
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT

setImage

public void setImage(byte[] imageData,
                     Dimension size,
                     boolean repaintNow)
Set the image to be displayed in this component.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.

Parameters:
imageData - the binary data of the image to be displayed
size - either an absolute value or one of the constants exported by JImage
repaintNow - indicates if the component should be refreshed to ensure the new image is rendered
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT

setImage

public void setImage(Image image,
                     Dimension size,
                     int scalingAlgorithm)
Set the image to be displayed in this component.
This component will be repainted as soon as the image has loaded to ensure the new image is rendered.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.
If the image needs to be re-sized to fit into the available space (or to a specific, absolute size) then the scalingAlgorithm (suggested by the bitmap of constants exported by the java.awt.Image class) will be used.

Parameters:
image - the image to be displayed
size - either an absolute value or one of the constants exported by JImage
scalingAlgorithm - flags to indicate the type of algorithm to use for image re-scaling
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT, Image.SCALE_DEFAULT, Image.SCALE_FAST, Image.SCALE_SMOOTH, Image.SCALE_REPLICATE, Image.SCALE_AREA_AVERAGING

setImage

public void setImage(String filename,
                     Dimension size,
                     int scalingAlgorithm)
Set the image to be displayed in this component.
This component will be repainted as soon as the image has loaded to ensure the new image is rendered.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.
If the image needs to be re-sized to fit into the available space (or to a specific, absolute size) then the scalingAlgorithm (suggested by the bitmap of constants exported by the java.awt.Image class) will be used.

Parameters:
filename - the name of the file that stores the image; the file must be in one of the supported formats (JPG or GIF)
size - either an absolute value or one of the constants exported by JImage
scalingAlgorithm - flags to indicate the type of algorithm to use for image re-scaling
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT, Image.SCALE_DEFAULT, Image.SCALE_FAST, Image.SCALE_SMOOTH, Image.SCALE_REPLICATE, Image.SCALE_AREA_AVERAGING

setImage

public void setImage(URL imageURL,
                     Dimension size,
                     int scalingAlgorithm)
Set the image to be displayed in this component.
This component will be repainted as soon as the image has loaded to ensure the new image is rendered.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.
If the image needs to be re-sized to fit into the available space (or to a specific, absolute size) then the scalingAlgorithm (suggested by the bitmap of constants exported by the java.awt.Image class) will be used.

Parameters:
imageURL - the URL of the file that stores the image; the file must be in one of the supported formats (JPG or GIF)
size - either an absolute value or one of the constants exported by JImage
scalingAlgorithm - flags to indicate the type of algorithm to use for image re-scaling
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT, Image.SCALE_DEFAULT, Image.SCALE_FAST, Image.SCALE_SMOOTH, Image.SCALE_REPLICATE, Image.SCALE_AREA_AVERAGING

setImage

public void setImage(byte[] imageData,
                     Dimension size,
                     int scalingAlgorithm)
Set the image to be displayed in this component.
This component will be repainted to ensure the new image is rendered.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.
If the image needs to be re-sized to fit into the available space (or to a specific, absolute size) then the scalingAlgorithm (suggested by the bitmap of constants exported by the java.awt.Image class) will be used.

Parameters:
imageData - the binary data of the image to be displayed
size - either an absolute value or one of the constants exported by JImage
scalingAlgorithm - flags to indicate the type of algorithm to use for image re-scaling
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT, Image.SCALE_DEFAULT, Image.SCALE_FAST, Image.SCALE_SMOOTH, Image.SCALE_REPLICATE, Image.SCALE_AREA_AVERAGING

setImage

public void setImage(Image image,
                     Dimension size,
                     int scalingAlgorithm,
                     boolean repaintNow)
Set the image to be displayed in this component.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.
If the image needs to be re-sized to fit into the available space (or to a specific, absolute size) then the scalingAlgorithm (suggested by the bitmap of constants exported by the java.awt.Image class) will be used.

Parameters:
image - the image to be displayed
size - either an absolute value or one of the constants exported by JImage
scalingAlgorithm - flags to indicate the type of algorithm to use for image re-scaling
repaintNow - indicates if the component should be refreshed to ensure the new image is rendered
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT, Image.SCALE_DEFAULT, Image.SCALE_FAST, Image.SCALE_SMOOTH, Image.SCALE_REPLICATE, Image.SCALE_AREA_AVERAGING

setImage

public void setImage(String filename,
                     Dimension size,
                     int scalingAlgorithm,
                     boolean repaintNow)
Set the image to be displayed in this component.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.
If the image needs to be re-sized to fit into the available space (or to a specific, absolute size) then the scalingAlgorithm (suggested by the bitmap of constants exported by the java.awt.Image class) will be used.

Parameters:
filename - the name of the file that stores the image; the file must be in one of the supported formats (JPG or GIF)
size - either an absolute value or one of the constants exported by JImage
scalingAlgorithm - flags to indicate the type of algorithm to use for image re-scaling
repaintNow - indicates if the component should be refreshed to ensure the new image is rendered
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT, Image.SCALE_DEFAULT, Image.SCALE_FAST, Image.SCALE_SMOOTH, Image.SCALE_REPLICATE, Image.SCALE_AREA_AVERAGING

setImage

public void setImage(URL imageURL,
                     Dimension size,
                     int scalingAlgorithm,
                     boolean repaintNow)
Set the image to be displayed in this component.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.
If the image needs to be re-sized to fit into the available space (or to a specific, absolute size) then the scalingAlgorithm (suggested by the bitmap of constants exported by the java.awt.Image class) will be used.

Parameters:
imageURL - the URL of the file that stores the image; the file must be in one of the supported formats (JPG or GIF)
size - either an absolute value or one of the constants exported by JImage
scalingAlgorithm - flags to indicate the type of algorithm to use for image re-scaling
repaintNow - indicates if the component should be refreshed to ensure the new image is rendered
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT, Image.SCALE_DEFAULT, Image.SCALE_FAST, Image.SCALE_SMOOTH, Image.SCALE_REPLICATE, Image.SCALE_AREA_AVERAGING

setImage

public void setImage(byte[] imageData,
                     Dimension size,
                     int scalingAlgorithm,
                     boolean repaintNow)
Set the image to be displayed in this component.
The image will be rendered at the size specified or, if size is set to one of the constants exported by this class, then the image will be re-sized taking into account the space available for the image.
If the image needs to be re-sized to fit into the available space (or to a specific, absolute size) then the scalingAlgorithm (suggested by the bitmap of constants exported by the java.awt.Image class) will be used.

Parameters:
imageData - the binary data of the image to be displayed
size - either an absolute value or one of the constants exported by JImage
scalingAlgorithm - flags to indicate the type of algorithm to use for image re-scaling
repaintNow - indicates if the component should be refreshed to ensure the new image is rendered
See Also:
MAINTAIN_SIZE, FIT_TO_AREA, FIT_TO_AREA_MAINTAIN_ASPECT, SHRINK_TO_AREA_MAINTAIN_ASPECT, Image.SCALE_DEFAULT, Image.SCALE_FAST, Image.SCALE_SMOOTH, Image.SCALE_REPLICATE, Image.SCALE_AREA_AVERAGING

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Overrides:
setBounds in class Component

computeDisplaySize

protected Dimension computeDisplaySize(int imageWidth,
                                       int imageHeight)
Compute the dimension of the scaled image.
This method will use the size of the original image and the size of the available area to compute the size of the displayed image. The original dimension will be stretched or squeezed to fit the available space according to the display setting.

Parameters:
imageWidth - the width of the original image
imageHeight - the height of the original image
Returns:
the dimension of the image when it is displayed
See Also:
_displaySetting

setImageDimension

public void setImageDimension(int imgWidth,
                              int imgHeight)
Set the size of the original image.
This method is called by the image observer that is monitoring the loading of the image object. This ensures the size is correct, as defined from the image file.

Specified by:
setImageDimension in interface DimensionImageObserver.Listener
Parameters:
imgWidth - the width of the image to be displayed
imgHeight - the height of the image to be displayed

setDisplaySize

protected void setDisplaySize(Dimension size)
Called to set the dimension of the image that is displayed in the component.
Unlike the dimension passed to the setImage method, this size must be an absolute dimension value (NOT one of the special constants exported by this class).

Parameters:
size - the size of the image when it is rendered

getBorderInsets

public Insets getBorderInsets()
Returns an Insets model that describes the location of the inner edge of the border around this image component.

Returns:
the border insets for this component

paint

public void paint(Graphics g)
Overrides:
paint in class JComponent

isSupportedImage

public static boolean isSupportedImage(File file)
Checks if a file is an image of a known format.
This is done by looking at the file's extension.

Parameters:
file - the file to be tested
Returns:
true if the file has an known & supported extension

isSupportedImage

public static boolean isSupportedImage(String fileName)
Checks if a file is an image of a known format.
This is done by looking at the file's extension.

Parameters:
fileName - the name of the file to be tested
Returns:
true if the file has an known & supported extension