FreeHEP API
Version current

org.freehep.util.images
Class ImageHandler

java.lang.Object
  extended byorg.freehep.util.images.ImageHandler

public class ImageHandler
extends Object

A convenience class for handling images. Maintains a cache of images suitable for small icons which may be reused often.

Version:
$Id: ImageHandler.java,v 1.11 2004/05/20 18:27:02 duns Exp $
Author:
Tony Johnson, Cal Loomis
Source Code:
ImageHandler.java

Field Summary
static Cursor brokenCursor
           
static Icon brokenIcon
           
static Image brokenImage
           
 
Constructor Summary
protected ImageHandler()
           
 
Method Summary
static Cursor getBestCursor(String name, Class clazz, int width, int height)
          Create the best cursor by reading from a URL, with hotspot (0,0).
static Cursor getBestCursor(String name, Class clazz, int width, int height, int x, int y)
          Create the best cursor by reading from a URL, with hotspot (x, y).
static Cursor getCursor(String name, Class clazz)
          Convenience routine, equivalent to getCursor(clazz.getResource(name)); As an additional convenience, if the name does not contain an extension (eg .gif) then a list of common extensions will be tried.
static Cursor getCursor(String name, Class clazz, int x, int y)
          Convenience routine, equivalent to getCursor(clazz.getResource(name)); As an additional convenience, if the name does not contain an extension (eg .gif) then a list of common extensions will be tried.
static Cursor getCursor(URL url)
          Create a cursor by reading from a URL, with hotspot (0,0).
static Cursor getCursor(URL url, int x, int y)
          Create a cursor by reading from a URL
static Icon getIcon(String name, Class clazz)
          Convenience routine, equivalent to getIcon(clazz.getResource(name)); As an additional convenience, if the name does not contain an extension (eg .gif) then a list of common extensions will be tried.
static Icon getIcon(URL url)
          Create an Icon by reading from a URL
static Image getImage(String name, Class clazz)
          Convenience routine, equivalent to getImage(clazz.getResource(name)); As an additional convenience, if the name does not contain an extension (eg .gif) then a list of common extensions will be tried.
static Image getImage(URL url)
          Load an image from a URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

brokenImage

public static final Image brokenImage

brokenCursor

public static final Cursor brokenCursor

brokenIcon

public static final Icon brokenIcon
Constructor Detail

ImageHandler

protected ImageHandler()
Method Detail

getImage

public static Image getImage(URL url)
Load an image from a URL. Images are cached for efficiency. If the image cannot be found will return a brokenImage. No exceptions are thrown.

Parameters:
url - The url of the image to load.
Returns:
The image

getBestCursor

public static Cursor getBestCursor(String name,
                                   Class clazz,
                                   int width,
                                   int height)
Create the best cursor by reading from a URL, with hotspot (0,0).


getBestCursor

public static Cursor getBestCursor(String name,
                                   Class clazz,
                                   int width,
                                   int height,
                                   int x,
                                   int y)
Create the best cursor by reading from a URL, with hotspot (x, y). The best width and height are inserted into the URL in the spots with %width and %height. Example: getBestCursor("/org/freehep/swing/images/MyIcon%wx%h.png", 32 32);

Parameters:
name - URL of the cursor
clazz - Class to be used for getting resource
width - suggested width
height - suggested height
x - hotspot
y - hotspot
Returns:
The cursor, the default cursor if custom cursors are not supported or brokenCursor if the cursor cannot be found

getCursor

public static Cursor getCursor(URL url)
Create a cursor by reading from a URL, with hotspot (0,0).

Parameters:
url - The URL to read
Returns:
The cursor, or brokenCursor if the cursor cannot be found

getCursor

public static Cursor getCursor(URL url,
                               int x,
                               int y)
Create a cursor by reading from a URL

Parameters:
url - The URL to read
x - x position of hotspot
y - y position of hotspot
Returns:
The cursor, or brokenCursor if the cursor cannot be found

getIcon

public static Icon getIcon(URL url)
Create an Icon by reading from a URL

Parameters:
url - The URL to read
Returns:
The icon, or brokenIcon if it cannot be loaded

getImage

public static Image getImage(String name,
                             Class clazz)
Convenience routine, equivalent to getImage(clazz.getResource(name)); As an additional convenience, if the name does not contain an extension (eg .gif) then a list of common extensions will be tried.

Parameters:
name - The relative address of the image to load
clazz - The class from which the address is based
Returns:
The image, or brokenImage if no image is found.

getCursor

public static Cursor getCursor(String name,
                               Class clazz)
Convenience routine, equivalent to getCursor(clazz.getResource(name)); As an additional convenience, if the name does not contain an extension (eg .gif) then a list of common extensions will be tried.

Parameters:
name - The relative address of the cursor to load
clazz - The class from which the address is based
Returns:
The cursor, or brokenCursor if no cursor is found.

getCursor

public static Cursor getCursor(String name,
                               Class clazz,
                               int x,
                               int y)
Convenience routine, equivalent to getCursor(clazz.getResource(name)); As an additional convenience, if the name does not contain an extension (eg .gif) then a list of common extensions will be tried.

Parameters:
name - The relative address of the cursor to load
clazz - The class from which the address is based
x - hotspot
y - hotspot
Returns:
The cursor, or brokenCursor if no cursor is found.

getIcon

public static Icon getIcon(String name,
                           Class clazz)
Convenience routine, equivalent to getIcon(clazz.getResource(name)); As an additional convenience, if the name does not contain an extension (eg .gif) then a list of common extensions will be tried.

Parameters:
name - The relative address of the icon to load
clazz - The class from which the address is based
Returns:
The icon, or brokenIcon if no icon is found.

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.