becker.robots.icons
Class ShapeIcon

java.lang.Object
  extended by becker.robots.icons.Icon
      extended by becker.robots.icons.ShapeIcon
All Implemented Interfaces:
IColor
Direct Known Subclasses:
CircleIcon, RobotIcon, WallIcon

public class ShapeIcon
extends Icon
implements IColor

A ShapeIcon provides an easy means to make an icon of a particular shape and color.

The easiest example is

  private Icon icon = new ShapeIcon(
               new Rectangle2D.Double(0.0, 0.0, 1.0, 1.0)), Color.blue);

You'll need to import the following:

import becker.robots.icons.*;
  import java.awt.geom.Rectangle2D;
  import java.awt.Color;
A RobotIcon is defined as
  public class RobotIcon extends ShapeIcon
  {
     public RobotIcon(Color color)
     {  this(color, 0.8);
     }

     public RobotIcon(Color color, double relativeSize)
     {  super(RobotIcon.shape, color, relativeSize);
     }

     private static GeneralPath shape;

     static
     {  shape = new GeneralPath();
        shape.moveTo(0.5F, 0.0F);
        shape.lineTo(0.0F, 1.0F);
        shape.lineTo(0.5F, 0.7F);
        shape.lineTo(1.0F, 1.0F);
        shape.closePath();

     }
  }
The static block initializes the shape instance variable before it is used in the constructor. The same shape is used for each RobotIcon instance.

Author:
Byron Weber Becker

Field Summary
 
Fields inherited from class becker.robots.icons.Icon
transparent
 
Constructor Summary
ShapeIcon(Shape aShape, Color aColor)
          Construct a new icon with the given shape and color.
ShapeIcon(Shape aShape, Color aColor, double relativeSize)
          Construct a new icon with the given shape and color.
 
Method Summary
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.
 
Methods inherited from class becker.robots.icons.Icon
applyTransforms, getColor, getImage, getLabel, getRotation, getSize, getTransparency, hasChanged, markChanged, paintIcon, setColor, setLabel, setSize, setTransparency
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface becker.robots.IColor
getColor, getTransparency, setColor, setTransparency
 

Constructor Detail

ShapeIcon

public ShapeIcon(Shape aShape,
                 Color aColor)
Construct a new icon with the given shape and color.

Parameters:
aShape - The shape of the icon: a rectangle, ellipse, or even a GeneralPath.
aColor - The color the shape should have.

ShapeIcon

public ShapeIcon(Shape aShape,
                 Color aColor,
                 double relativeSize)
Construct a new icon with the given shape and color.

Parameters:
aShape - The shape of the icon: a rectangle, ellipse, or even a GeneralPath.
aColor - The color the shape should have.
relativeSize - A value between 0.0 (very small) and 1.0 (large).
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