edu.cmu.sun.components
Class ImageComponent

java.lang.Object
  extended by Component3D
      extended by edu.cmu.sun.components.ImageComponent

public class ImageComponent
extends Component3D

A Component3D object that replaces the ImagePanel Shape3D that LG3D provides. This panel is alligned upper-left-front. Much od the code in this class is taken from ImagePanel in LG3D. However, this class also CACHES acess to the images. This means that every time you create an image panel the system does not have to hit the disk. This dramatically speeds up the placing of many duplicate images in the scenegraph. At the moment, there is no way to clear the image cache, or remoive a loaded image from the cache. In the future, perhaps we could use a Factory object to create ImageComponents. The Factory could be responsible for caching image loads.

Author:
Braden kowitz

Field Summary
(package private)  float alpha
          TODO: change this to a constant somewhere.
(package private) static java.util.Map<java.lang.String,SimpleAppearance> appearances
          A map from the filename string and the SimpleAppearance that contains the texture.
(package private)  boolean shiny
          Field that is passed directly to the ImagePanel compoennt
 
Constructor Summary
ImageComponent(java.lang.String imagePath, float width, float height)
          Create a new ImageComponent for an image file.
 
Method Summary
private  SimpleAppearance getAppearance(java.lang.String textureFilePath)
          Returns the appearance for a panel, with the provided texture.
private  Geometry getGeometry(float width, float height)
          returns the geometry of a simple panel for the image component to be drawn on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

appearances

static java.util.Map<java.lang.String,SimpleAppearance> appearances
A map from the filename string and the SimpleAppearance that contains the texture. This is where we keep the image cache, so the next time an ImageComponent needs an image file as a texture, we take the appearance from this field.


shiny

boolean shiny
Field that is passed directly to the ImagePanel compoennt


alpha

float alpha
TODO: change this to a constant somewhere.

Constructor Detail

ImageComponent

public ImageComponent(java.lang.String imagePath,
                      float width,
                      float height)
Create a new ImageComponent for an image file. It will be upper-left aligned. The image will be stretched over the size of the panel, so it is important that the ImageComponent be given the correct width and height proportions of the image to avoid distortion.

Parameters:
imagePath - file path to the image
width - width of resulting panel (in meters)
height - height of resulting panel (in meters)
Method Detail

getGeometry

private Geometry getGeometry(float width,
                             float height)
returns the geometry of a simple panel for the image component to be drawn on.


getAppearance

private SimpleAppearance getAppearance(java.lang.String textureFilePath)
Returns the appearance for a panel, with the provided texture. This function also stores and retreives appearances from a cache. So, it does not read an image from disk twice.

Parameters:
textureFilePath - path to the texture file
Returns:
an appearance for the panel, if an error occours, returns an empty panel.