net.sourceforge.hivegui.component
Class IconTools

java.lang.Object
  extended by net.sourceforge.hivegui.component.IconTools

public class IconTools
extends java.lang.Object

Provides miscellaneous utility functions for handling icons. There is no need to instantiate this class since it only provides static methods.

Author:
Jean-Francois Poilpret

Constructor Summary
protected IconTools()
           
 
Method Summary
static javax.swing.ImageIcon centerIcon(javax.swing.Icon source, int newWidth, int newHeight)
           
static javax.swing.ImageIcon loadIcon(org.apache.hivemind.Resource resource)
          Loads an icon from a HiveMind Resource.
static javax.swing.ImageIcon loadIcon(java.lang.String file)
          Loads an icon from a file name.
static javax.swing.Icon scaleIcon(javax.swing.Icon source, int newSize)
          Scale down an Icon to a new size.
static javax.swing.Icon scaleIcon(java.awt.Image source, int newSize)
          Scale down an Image to a new size.
static java.awt.Image scaleImage(java.awt.Image source, int newSize)
          Scale an Image to a new size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IconTools

protected IconTools()
Method Detail

loadIcon

public static javax.swing.ImageIcon loadIcon(org.apache.hivemind.Resource resource)
Loads an icon from a HiveMind Resource.

Parameters:
resource - HiveMind resource referring to the icon file
Returns:
the image that was loaded from resource

loadIcon

public static javax.swing.ImageIcon loadIcon(java.lang.String file)
Loads an icon from a file name. Works even for files that are located in a JAR file.

It is strongly recommended to always use lowercase names for image files (both in the OS and in the paths used inside the code). File paths must be relatives (else this will not work from within a JAR file).

Parameters:
file - relative path (all in lowercase) to the image file
Returns:
the image that was loaded from file

scaleIcon

public static javax.swing.Icon scaleIcon(javax.swing.Icon source,
                                         int newSize)
Scale down an Icon to a new size. This method is very useful to build a thumbnail for an Icon. The method keeps the aspect ratio of the original Icon.

Parameters:
source - original icon to scale down
newSize - new size to which the icon should be scaled
Returns:
a new icon which is a scaled copy of the source icon

scaleIcon

public static javax.swing.Icon scaleIcon(java.awt.Image source,
                                         int newSize)
Scale down an Image to a new size. This method is very useful to build a thumbnail for an Icon. The method keeps the aspect ratio of the original Icon.

Parameters:
source - original image to scale down
newSize - new size to which the image should be scaled
Returns:
a new icon which is a scaled copy of the source image

scaleImage

public static java.awt.Image scaleImage(java.awt.Image source,
                                        int newSize)
Scale an Image to a new size. The method keeps the aspect ratio of the original Image.

Parameters:
source - original image to scale down
newSize - new size to which the image should be scaled
Returns:
a new image which is a scaled copy of the source image

centerIcon

public static javax.swing.ImageIcon centerIcon(javax.swing.Icon source,
                                               int newWidth,
                                               int newHeight)