jfig.gui
Class ImageHelper

java.lang.Object
  extended byjfig.gui.ImageHelper

public class ImageHelper
extends java.lang.Object

find and load images from files, URLs, Java resources.

ImageHelper: a not-so-simple utility class to load and create images. One typical use is to create backbround images for buffering while the main user interface is still under construction. (This class won't be necessary, except for all those AWT bugs... )


Field Summary
(package private) static java.lang.String appletBaseDirName
           
(package private) static java.net.URL appletCodeBase
           
(package private) static java.lang.String appletServerName
           
(package private) static boolean debug
           
(package private) static ConsoleMessage printer
           
(package private) static java.awt.Component visibleParent
           
 
Constructor Summary
ImageHelper()
           
 
Method Summary
static void checkParentIsVisible()
          Based on experimental evidence, at least older versions of the AWT required that a toplevel component (a Frame) was visible before any of the image creation methods worked.
static java.awt.Image createImage(java.awt.image.ImageProducer producer)
           
static java.awt.Image createImage(int width, int height)
           
static void dbg(java.lang.String msg)
           
static java.awt.Image findImage(java.lang.String type, java.lang.String pathname, java.lang.String imgname)
          A method to find and load images whose name is relative to some base URL/directory/path.
static java.awt.Image findImageFromFile(java.lang.String pathname, java.lang.String imgname)
           
static java.awt.Image findImageFromResource(java.lang.String pathname, java.lang.String imgname)
          Unlike loadResourceImage, this method does not use a MediaTracker to synchronize the loading.
static java.awt.Image findImageFromURL(java.lang.String urlname)
           
static java.awt.Image findImageFromURL(java.lang.String pathname, java.lang.String imgname)
           
static boolean getDebug()
           
static java.awt.Image getFilteredImage(java.awt.Image src, java.awt.image.ImageFilter filter)
           
static java.awt.Image getInvertedImage(java.awt.Image src)
           
static java.awt.Image loadResourceImage(java.lang.String resourcename)
           
static void main(java.lang.String[] argv)
           
static void message(java.lang.String msg)
           
static void setAppletBaseDir(java.lang.String name)
           
static void setAppletServerName(java.lang.String name)
          set the applet server and base directory for later loadResourceImage() calls, e.g.
static void setConsole(ConsoleMessage p)
           
static void setDebug(boolean b)
           
static void setVisibleParent(java.awt.Component parent)
           
static void trace(java.lang.Throwable e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

visibleParent

static java.awt.Component visibleParent

printer

static ConsoleMessage printer

appletServerName

static java.lang.String appletServerName

appletBaseDirName

static java.lang.String appletBaseDirName

appletCodeBase

static java.net.URL appletCodeBase

debug

static boolean debug
Constructor Detail

ImageHelper

public ImageHelper()
Method Detail

setConsole

public static void setConsole(ConsoleMessage p)

message

public static void message(java.lang.String msg)

dbg

public static void dbg(java.lang.String msg)

setDebug

public static void setDebug(boolean b)

getDebug

public static boolean getDebug()

trace

public static void trace(java.lang.Throwable e)

setVisibleParent

public static void setVisibleParent(java.awt.Component parent)

checkParentIsVisible

public static void checkParentIsVisible()
Based on experimental evidence, at least older versions of the AWT required that a toplevel component (a Frame) was visible before any of the image creation methods worked. Therefore, this method simply checks whether 'visibleParent' is non null. If not, a dummy Frame is created and shown() / pack()ed, and afterwards used as the AWT component for image creation.


setAppletServerName

public static void setAppletServerName(java.lang.String name)
set the applet server and base directory for later loadResourceImage() calls, e.g.
 ImageHelper.setAppletServerName( "http://tech-www.informatik.uni-hamburg.de" );
 ImageHelper.setAppletBaseDir( "/applets/hades/classes" );
 Image icon = ImageHelper.loadResourceImage( "/hades/gui/images/icon.gif" );
 


setAppletBaseDir

public static void setAppletBaseDir(java.lang.String name)

loadResourceImage

public static java.awt.Image loadResourceImage(java.lang.String resourcename)

createImage

public static java.awt.Image createImage(int width,
                                         int height)

createImage

public static java.awt.Image createImage(java.awt.image.ImageProducer producer)

findImage

public static java.awt.Image findImage(java.lang.String type,
                                       java.lang.String pathname,
                                       java.lang.String imgname)
A method to find and load images whose name is relative to some base URL/directory/path. Note that relative names are the default for all of xfig's names.

The basic algorithm performed by findImage() is as follows:

findImage() knows about the following filename types:

If the "type" argument is "", findImage() will try all possibilities.


findImageFromURL

public static java.awt.Image findImageFromURL(java.lang.String pathname,
                                              java.lang.String imgname)

findImageFromURL

public static java.awt.Image findImageFromURL(java.lang.String urlname)

findImageFromFile

public static java.awt.Image findImageFromFile(java.lang.String pathname,
                                               java.lang.String imgname)

findImageFromResource

public static java.awt.Image findImageFromResource(java.lang.String pathname,
                                                   java.lang.String imgname)
Unlike loadResourceImage, this method does not use a MediaTracker to synchronize the loading.


getFilteredImage

public static java.awt.Image getFilteredImage(java.awt.Image src,
                                              java.awt.image.ImageFilter filter)

getInvertedImage

public static java.awt.Image getInvertedImage(java.awt.Image src)

main

public static void main(java.lang.String[] argv)