Groovy Documentation

com.wordpress.tipsforjava.swing
[Java] Class ThumbnailIcon

java.lang.Object
  javax.swing.ImageIcon
      com.wordpress.tipsforjava.swing.StretchIcon
          com.wordpress.tipsforjava.swing.ShrinkIcon
              com.wordpress.tipsforjava.swing.ThumbnailIcon

public class ThumbnailIcon
extends ShrinkIcon

@(#)ThumbnailIcon.java 1.0 04/12/12


Field Summary
static int COMPUTED

The constant for setting the width, height, default width or default height to be computed from the other dimension in a way that maintains the aspect ratio of the contained image.

static int DEFAULT

The constant for setting the width and/or height to use the default for the class.

private static int defaultHeight

private static int defaultWidth

private int thumbHeight

private int thumbWidth

 
Fields inherited from class StretchIcon
proportionate
 
Constructor Summary
ThumbnailIcon(byte[] imageData)

Creates a ThumbnailIcon from an array of bytes.

ThumbnailIcon(byte[] imageData, String description)

Creates a ThumbnailIcon from an array of bytes.

ThumbnailIcon(Image image)

Creates a ThumbnailIcon from the image.

ThumbnailIcon(Image image, String description)

Creates a ThumbnailIcon from the image.

ThumbnailIcon(String filename)

Creates a ThumbnailIcon from the specified file.

ThumbnailIcon(String filename, String description)

Creates a ThumbnailIcon from the specified file.

ThumbnailIcon(URL location)

Creates a ThumbnailIcon from the specified URL.

ThumbnailIcon(URL location, String description)

Creates a ThumbnailIcon from the specified URL.

 
Method Summary
static int getDefaultHeight()

Gets the default height of all ThumbnailIcons.

static int getDefaultWidth()

Gets the default width of all ThumbnailIcons.

int getIconHeight()

Gets the height of the icon.

int getIconWidth()

Gets the width of the icon.

int getThumbHeight()

Returns the height that has been set, or DEFAULT.

int getThumbWidth()

Returns the width that has been set, or DEFAULT.

BufferedImage getThumbnail()

Convenience method to obtain the icon's image at the size at which it is displayed.

static void setDefaultSize(int width, int height)

Sets the default size of all ThumbnailIcons.

void setThumbHeight(int height)

Sets the height of an individual ThumbnailIcon.

void setThumbWidth(int width)

Sets the width of an individual ThumbnailIcon.

 
Methods inherited from class ShrinkIcon
paintIcon
 
Methods inherited from class StretchIcon
getIconHeight, getIconWidth, paintIcon
 
Methods inherited from class ImageIcon
toString, getDescription, getAccessibleContext, getIconWidth, getIconHeight, setDescription, getImage, paintIcon, getImageLoadStatus, setImage, setImageObserver, getImageObserver, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll
 

Field Detail

COMPUTED

public static final int COMPUTED
The constant for setting the width, height, default width or default height to be computed from the other dimension in a way that maintains the aspect ratio of the contained image.

If both the width and height evaluate to COMPUTED, the image will be displayed at its natural size, essentially mimicking the behavior of ImageIcon.


DEFAULT

public static final int DEFAULT
The constant for setting the width and/or height to use the default for the class.


defaultHeight

private static int defaultHeight


defaultWidth

private static int defaultWidth


thumbHeight

private int thumbHeight


thumbWidth

private int thumbWidth


 
Constructor Detail

ThumbnailIcon

public ThumbnailIcon(byte[] imageData)
Creates a ThumbnailIcon from an array of bytes.
Parameters:
imageData - an array of pixels in an image format supported by the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
See Also:
ImageIcon#ImageIcon(byte[])#ImageIcon(byte[])


ThumbnailIcon

public ThumbnailIcon(byte[] imageData, String description)
Creates a ThumbnailIcon from an array of bytes.
Parameters:
imageData - an array of pixels in an image format supported by the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
description - a brief textual description of the image
See Also:
ImageIcon#ImageIcon(byte[], java.lang.String)


ThumbnailIcon

public ThumbnailIcon(Image image)
Creates a ThumbnailIcon from the image.
Parameters:
image - the image
See Also:
ImageIcon#ImageIcon(java.awt.Image)


ThumbnailIcon

public ThumbnailIcon(Image image, String description)
Creates a ThumbnailIcon from the image.
Parameters:
image - the image
description - a brief textual description of the image
See Also:
ImageIcon#ImageIcon(java.awt.Image, java.lang.String)


ThumbnailIcon

public ThumbnailIcon(String filename)
Creates a ThumbnailIcon from the specified file.
Parameters:
filename - a String specifying a filename or path
See Also:
ImageIcon#ImageIcon(java.lang.String)


ThumbnailIcon

public ThumbnailIcon(String filename, String description)
Creates a ThumbnailIcon from the specified file.
Parameters:
filename - a String specifying a filename or path
description - a brief textual description of the image
See Also:
ImageIcon#ImageIcon(java.lang.String, java.lang.String)


ThumbnailIcon

public ThumbnailIcon(URL location)
Creates a ThumbnailIcon from the specified URL.
Parameters:
location - the URL for the image
See Also:
ImageIcon#ImageIcon(java.net.URL)


ThumbnailIcon

public ThumbnailIcon(URL location, String description)
Creates a ThumbnailIcon from the specified URL.
Parameters:
location - the URL for the image
description - a brief textual description of the image
See Also:
ImageIcon#ImageIcon(java.net.URL, java.lang.String)


 
Method Detail

getDefaultHeight

public static int getDefaultHeight()
Gets the default height of all ThumbnailIcons. A return value of zero indicates that the default height will be computed from the default width so as to maintain the aspect ratio of the contained image.
Returns:
The default width for all ThumbnailIcons


getDefaultWidth

public static int getDefaultWidth()
Gets the default width of all ThumbnailIcons. A return value of zero indicates that the default width will be computed from the default height so as to maintain the aspect ratio of the contained image.
Returns:
The default width for all ThumbnailIcons


getIconHeight

@Override
public int getIconHeight()
Gets the height of the icon.
Returns:
The height in pixels of this icon


getIconWidth

@Override
public int getIconWidth()
Gets the width of the icon.
Returns:
The width in pixels of this icon


getThumbHeight

public int getThumbHeight()
Returns the height that has been set, or DEFAULT. Note that this is not the same value as that returned by getIconHeight().
Returns:
the set height, or DEFAULT if none has been set.


getThumbWidth

public int getThumbWidth()
Returns the width that has been set, or DEFAULT. Note that this is not the same value as that returned by getIconWidth().
Returns:
the set width, or DEFAULT if none has been set.


getThumbnail

public BufferedImage getThumbnail()
Convenience method to obtain the icon's image at the size at which it is displayed. Note that a thumbnail obtained from an animated image will not itself be animated.
Returns:
The thumbnail image.


setDefaultSize

public static void setDefaultSize(int width, int height)
Sets the default size of all ThumbnailIcons.

If either the width or height is zero it will be computed from the other dimension, according to the aspect ratio of each ThumbnaiIcon's contained image. Setting the default width to zero may be useful for a horizontal layout of components that display a ThumbnailIcon; correspondingly, a default height of zero can be useful in a vertical layout.

If both width and height are zero, a ThumbnailIcon that respects the default width and height will be sized to its contained image, essentially mimicking the behavior of ImageIcon.

Parameters:
width - The default width to set.
height - The default height to set.


setThumbHeight

public void setThumbHeight(int height)
Sets the height of an individual ThumbnailIcon.

Set the height to DEFAULT to use the default height for the class, or set it to COMPUTED for the height to be computed form the width, maintaining the aspect ratio of the contained image.

If both the width and height evaluate to COMPUTED, the image will be displayed at its natural size, essentially mimicking the behavior of ImageIcon.

Setting a value less than DEFAULT is not permitted.

Parameters:
height - The height to set


setThumbWidth

public void setThumbWidth(int width)
Sets the width of an individual ThumbnailIcon.

Set the width to DEFAULT to use the default width for the class, or set it to COMPUTED for the width to be computed form the height, maintaining the aspect ratio of the contained image.

If both the width and height evaluate to COMPUTED, the image will be displayed at its natural size, essentially mimicking the behavior of ImageIcon.

Setting a value less than DEFAULT is not permitted.

Parameters:
width - The width to set


 

Groovy Documentation