becker.robots.icons
Class CompositeIcon

java.lang.Object
  extended by becker.robots.icons.Icon
      extended by becker.robots.icons.CompositeIcon
Direct Known Subclasses:
AnimatedIcon, IntersectionIcon, StreetlightIcon

public class CompositeIcon
extends Icon

A CompositeIcon is composed of two or more icons which, taken together, form the desired icon. An example is StreetlightIcon which composes one icon for the streetlight's post with another for the light.

Author:
Byron Weber Becker

Field Summary
 
Fields inherited from class becker.robots.icons.Icon
transparent
 
Constructor Summary
CompositeIcon(Icon[] icons)
          Construct a new CompositeIcon out of an array of icons.
CompositeIcon(Icon background, Icon foreground)
          Construct a new CompositeIcon out of two icons.
 
Method Summary
protected  void applyTransforms(Graphics2D g2, int width, int height, double rotation, double relSize)
          Apply translations, scaling and rotation to g2 in preparation for rendering the image.
 Icon componentIcon(int index)
          Obtain a reference to one of the component icons, perhaps so it can be modified.
 Color getColor()
          Returns null.
 boolean hasChanged()
          Has this icon changed since it was last rendered?
protected  void markChanged()
          Mark this icon as changed so it is rendered again.
 int numComponents()
          Determine the number of component icons in this composite icon.
protected  void renderImage(Graphics2D g2, int width, int height)
          Override either this method or Icon.paintIcon(java.awt.Graphics) to specify how the icon looks.
 void setColor(Color c)
          Has no effect.
 
Methods inherited from class becker.robots.icons.Icon
getImage, getLabel, getRotation, getSize, getTransparency, paintIcon, setLabel, setSize, setTransparency
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeIcon

public CompositeIcon(Icon background,
                     Icon foreground)
Construct a new CompositeIcon out of two icons.

Parameters:
background - the icon to draw in the background.
foreground - the icon to draw in front of the background.

CompositeIcon

public CompositeIcon(Icon[] icons)
Construct a new CompositeIcon out of an array of icons. The Icon at icons[0] will be displayed first, then icons[1], and so on.

Parameters:
icons - the icons which compose this composite icon. icons.length >= 1
Method Detail

renderImage

protected void renderImage(Graphics2D g2,
                           int width,
                           int height)
Description copied from class: Icon
Override either this method or Icon.paintIcon(java.awt.Graphics) to specify how the icon looks. For this method, the upper left corner of the icon has coordinates (0,0). The width and height are both 1.0.

Overrides:
renderImage in class Icon
Parameters:
g2 - the graphics context where the icon should be drawn.
width - the number of pixels wide the image will be
height - the number of pixels high the image will be

applyTransforms

protected void applyTransforms(Graphics2D g2,
                               int width,
                               int height,
                               double rotation,
                               double relSize)
Description copied from class: Icon
Apply translations, scaling and rotation to g2 in preparation for rendering the image. The standard transformations are:
    g2.translate(width/2.0, height/2.0);
    g2.scale(width*this.relSize, height*this.relSize);
    g2.rotate(rotation);
    g2.translate( - 0.5,  - 0.5);
    g2.setStroke(new BasicStroke(1.0F / width));
 

Overrides:
applyTransforms in class Icon
Parameters:
g2 - The graphics context to apply transformations to
width - the width (in pixels) of the icon
height - the height (in pixels) of the icon
rotation - the rotation of the icon, in radians
relSize - the relative size (0.0 < relSize <= 1.0) of the icon

markChanged

protected void markChanged()
Description copied from class: Icon
Mark this icon as changed so it is rendered again.

Overrides:
markChanged in class Icon

hasChanged

public boolean hasChanged()
Description copied from class: Icon
Has this icon changed since it was last rendered?

Overrides:
hasChanged in class Icon
Returns:
true if this icon has changed since it was last rendered; false otherwise

componentIcon

public Icon componentIcon(int index)
Obtain a reference to one of the component icons, perhaps so it can be modified.

Parameters:
index - which component icon to return. 0 <= index < this.numComponents().

numComponents

public int numComponents()
Determine the number of component icons in this composite icon.

Returns:
the number of component icons

getColor

public Color getColor()
Returns null. To get the color of a composite icon, get the color of one of the components:
Color c = compositeIcon.componentIcon(0).getColor();

Overrides:
getColor in class Icon
Returns:
this icon's current color.

setColor

public void setColor(Color c)
Has no effect. To set the color of a composite icon, set the color of one of the components:
Color c = compositeIcon.componentIcon(0).setColor(newColor);

Overrides:
setColor in class Icon
Parameters:
c - The new color.