JavaView® v2.00.008

jv.objectGui
Class PsImage

java.lang.Object
  |
  +--jv.objectGui.PsImage

public class PsImage
extends java.lang.Object

A class for loading and handling images.

Version:
18.01.00, 1.01 revised (kp) Changed superclass from PsObject to java.lang.Object.
02.01.99, 1.00 created (kp).
Author:
Konrad Polthier

Field Summary
protected  java.lang.String m_alternateText
          Alternate text for display if image is missing or unreachable.
protected  boolean m_bDoneLoading
           
protected  int m_currentTrackerID
           
protected  int m_explicitHeight
          New image dimensions after a setSize() call.
protected  boolean m_explicitSize
          This flag notes an explicit resize request.
protected  int m_explicitWidth
          New image dimensions after a setSize() call.
protected  int m_height
          Width and height of the image.
protected  java.awt.Image m_image
          The actual Image.
protected  java.lang.String m_imageString
          The relative path as string of the image.
protected  java.net.URL m_imageUrl
          The absolute URL of the image.
protected static int m_lastTrackerID
          Used by MediaTracker to be sure image is loaded before paint & resize, since you can't find out the size until it is done loading.
protected  java.awt.Component m_parentComponent
          Component necessay for media tracker.
protected  java.awt.MediaTracker m_tracker
          The MediaTracker that can tell if image has been loaded before trying to paint it or resize based on its size.
protected  int m_width
          Width and height of the image.
 
Constructor Summary
PsImage(java.awt.Image anImage, java.lang.String alternateText)
          Create an PsImage using the image specified.
PsImage(java.lang.String imageString)
          Create an PsImage using the image at relative path specified by the string.
PsImage(java.net.URL url)
          Create an PsImage using the image at an absolute URL specified by the string.
 
Method Summary
static java.awt.Image createImageFromPixels(java.awt.Component comp, int[] pixels, int width, int height, int offset, int bufferWidth)
           
 int getHeight()
          Get height of loaded image.
 java.awt.Image getImage()
          Get the image after loading it if not done yet.
static java.awt.Image getImage(java.lang.String imageString)
          Get image relative to codeBase of applet or from file system.
static java.awt.Image getImage(java.net.URL url)
          Get image from absolute URL.
static PsImage getImageFromArchive(java.lang.String imageName, java.lang.String jarArchive)
           
static int[] getPixels(java.awt.Image image)
           
static int[] getPixels(java.awt.Image image, int x, int y, int width, int height, int[] pixels, int off, int scan)
           
 int getWidth()
          Get width of loaded image.
 void init()
          Create MediaTracker.
 boolean loadImage()
          Makes sure that the Image is loaded before returning from this method.
static boolean loadImage(java.awt.Component comp, java.awt.Image image)
          Load image with a media tracker and return when image is loaded or failure occurred.
 void setParentComponent(java.awt.Component comp)
          Set component used for MediaTracker in init() method
 void setSize(int width, int height)
          Resizes the image after loading it if not done yet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_image

protected transient java.awt.Image m_image
The actual Image. Don't specify this directly but pass a fileName or URL to the PsImage constructor.

m_imageUrl

protected java.net.URL m_imageUrl
The absolute URL of the image.

m_imageString

protected java.lang.String m_imageString
The relative path as string of the image.

m_alternateText

protected java.lang.String m_alternateText
Alternate text for display if image is missing or unreachable.

m_width

protected int m_width
Width and height of the image.

m_height

protected int m_height
Width and height of the image.

m_explicitSize

protected boolean m_explicitSize
This flag notes an explicit resize request.

m_explicitWidth

protected int m_explicitWidth
New image dimensions after a setSize() call.

m_explicitHeight

protected int m_explicitHeight
New image dimensions after a setSize() call.

m_tracker

protected java.awt.MediaTracker m_tracker
The MediaTracker that can tell if image has been loaded before trying to paint it or resize based on its size.
See Also:
m_parentComponent

m_parentComponent

protected java.awt.Component m_parentComponent
Component necessay for media tracker. If null, use PsConfig.getFrame().
See Also:
m_tracker, init(), setParentComponent(Component)

m_lastTrackerID

protected static int m_lastTrackerID
Used by MediaTracker to be sure image is loaded before paint & resize, since you can't find out the size until it is done loading.

m_currentTrackerID

protected int m_currentTrackerID

m_bDoneLoading

protected boolean m_bDoneLoading
Constructor Detail

PsImage

public PsImage(java.net.URL url)
Create an PsImage using the image at an absolute URL specified by the string.
Parameters:
url - A String specifying the absolute URL of the image.

PsImage

public PsImage(java.lang.String imageString)
Create an PsImage using the image at relative path specified by the string.
Parameters:
imageString - A String specifying the relative path of the image.

PsImage

public PsImage(java.awt.Image anImage,
               java.lang.String alternateText)
Create an PsImage using the image specified. The other constructors eventually call this one, but you may want to call it directly if you already have an image (e.g. created via createImage).
Parameters:
image - The image
alternateText - Alternate text used if image cannot be retrieved
comp - Component necessay for media tracker
Method Detail

init

public void init()
Create MediaTracker.

setParentComponent

public void setParentComponent(java.awt.Component comp)
Set component used for MediaTracker in init() method

loadImage

public boolean loadImage()
Makes sure that the Image is loaded before returning from this method. Caller of this method may spin off a separate thread to do the loading. On the other hand, postponing the waiting as long as possible is more efficient, since loading can go on in the background.

getWidth

public int getWidth()
Get width of loaded image.

getHeight

public int getHeight()
Get height of loaded image.

getImage

public java.awt.Image getImage()
Get the image after loading it if not done yet.

setSize

public void setSize(int width,
                    int height)
Resizes the image after loading it if not done yet.

getPixels

public static int[] getPixels(java.awt.Image image,
                              int x,
                              int y,
                              int width,
                              int height,
                              int[] pixels,
                              int off,
                              int scan)

getPixels

public static int[] getPixels(java.awt.Image image)

getImageFromArchive

public static PsImage getImageFromArchive(java.lang.String imageName,
                                          java.lang.String jarArchive)

getImage

public static java.awt.Image getImage(java.lang.String imageString)
Get image relative to codeBase of applet or from file system.

getImage

public static java.awt.Image getImage(java.net.URL url)
Get image from absolute URL.

loadImage

public static boolean loadImage(java.awt.Component comp,
                                java.awt.Image image)
Load image with a media tracker and return when image is loaded or failure occurred.

createImageFromPixels

public static java.awt.Image createImageFromPixels(java.awt.Component comp,
                                                   int[] pixels,
                                                   int width,
                                                   int height,
                                                   int offset,
                                                   int bufferWidth)

JavaView® v2.00.008

The software JavaView® is copyright protected. All Rights Reserved.