org.jrabbit.base.graphics.misc
Class IconLoader

java.lang.Object
  extended by org.jrabbit.base.graphics.misc.IconLoader

public class IconLoader
extends java.lang.Object

A convenience class for loading icons from images. Icons loaded from this class are formatted to fit within the required dimension (16x16, 32x32, or 128x128). If the source image is larger than the target dimension, it is shrunk down to the minimum size that will fit. If it is smaller, then it is only scaled up if the new scale can be a per-pixel linear scale (i.e., x2, x3, x4, etc). In both cases, the image's width/height ratio is kept the same as the source image.

Author:
Chris Molini

Constructor Summary
IconLoader()
           
 
Method Summary
static java.nio.ByteBuffer convertToByteBuffer(java.awt.image.BufferedImage image)
          Converts a BufferedImage into a ByteBuffer of pixel data.
private static double getIconRatio(java.awt.image.BufferedImage src, java.awt.image.BufferedImage icon)
          Gets the width/height ratio of the icon.
static java.nio.ByteBuffer[] load(Loader loader)
          Loads an icon in ByteBuffer form.
static java.nio.ByteBuffer[] load(java.lang.String filepath)
          Loads an icon in ByteBuffer form.
private static java.nio.ByteBuffer loadInstance(java.awt.image.BufferedImage image, int dimension)
          Copies the supplied image into a square icon at the indicated size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IconLoader

public IconLoader()
Method Detail

load

public static java.nio.ByteBuffer[] load(java.lang.String filepath)
Loads an icon in ByteBuffer form.

Parameters:
filepath - The location of the Image to use as an icon.
Returns:
An array of ByteBuffers containing the pixel data for the icon in varying sizes.

load

public static java.nio.ByteBuffer[] load(Loader loader)
Loads an icon in ByteBuffer form.

Parameters:
loader - A Loader pointing to the image.
Returns:
An array of ByteBuffers containing the pixel data for the icon in various sizes (as recommended by the OS).

loadInstance

private static java.nio.ByteBuffer loadInstance(java.awt.image.BufferedImage image,
                                                int dimension)
Copies the supplied image into a square icon at the indicated size.

Parameters:
image - The image to place onto the icon.
dimension - The desired size of the icon.
Returns:
A ByteBuffer of pixel data at the indicated size.

getIconRatio

private static double getIconRatio(java.awt.image.BufferedImage src,
                                   java.awt.image.BufferedImage icon)
Gets the width/height ratio of the icon. This is meant to simplify scaling the icon to a new dimension.

Parameters:
src - The base image that will be placed onto the icon.
icon - The icon that will have the image placed on it.
Returns:
The amount to scale the source image to fit it onto the icon appropriately.

convertToByteBuffer

public static java.nio.ByteBuffer convertToByteBuffer(java.awt.image.BufferedImage image)
Converts a BufferedImage into a ByteBuffer of pixel data.

Parameters:
image - The image to convert.
Returns:
A ByteBuffer that contains the pixel data of the supplied image.