|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbecker.robots.icons.Icon
public abstract class Icon
Icons are used to display Robot
s, Intersection
s and
Thing
s. This
class is abstract, merely defining what kinds of behaviors are required
by the system. Subclasses define icons for specific purposes.
A very simple icon which displays a blue square could be defined as
The drawing area is from from 0.0 to 1.0 in both dimensions. An alternative approach that is more consistent with usingpublic class BlueIcon extends Icon { public BlueIcon(double relativeSize) { super(relativeSize); } protected void renderImage(Graphics2D g2, int width, int height) { g2.setColor(Color.blue); g2.fill(new Rectangle2D.Double(0.0, 0.0, 1.0, 1.0)); } }
paintComponent
is
In this approach the implicit drawing area is 100 x 100 pixels. The system scales and rotates the image appropriately when it is drawn. Thepublic class BlueIcon extends Icon { public BlueIcon(double relativeSize) { super(relativeSize); } protected void paintIcon(Graphics g) { g.setColor(Color.blue); g.fillRect(0, 0, 100, 100); } }
ShapeIcon
class makes this even easier.
Field Summary | |
---|---|
static Color |
transparent
A transparent "color" which allows the underlying image to show through. |
Constructor Summary | |
---|---|
Icon()
Construct a new, full-sized, transparent icon. |
|
Icon(Color color)
Construct a new icon of the specified color. |
|
Icon(double relativeSize)
Construct a new icon of the specified size. |
|
Icon(double relativeSize,
Color color)
Construct a new icon of the specified size and color. |
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. |
Color |
getColor()
Get this icon's current color. |
Image |
getImage(int width,
int height,
double rotation)
Get this icon's image with a preferred size (in pixels). |
String |
getLabel()
Get the label currently being displayed on this icon. |
protected double |
getRotation()
Get number of radians this icon is rotated. |
double |
getSize()
Get the relative size of this icon. |
double |
getTransparency()
Get this icon's current transparency. |
protected boolean |
hasChanged()
Has this icon changed since it was last rendered? |
protected void |
markChanged()
Mark this icon as changed so it is rendered again. |
protected void |
paintIcon(Graphics g)
Override this method (or renderImage(java.awt.Graphics2D, int, int) ) to specify how this icon
looks. |
protected void |
renderImage(Graphics2D g2,
int width,
int height)
Override either this method or paintIcon(java.awt.Graphics) to specify how the
icon looks. |
void |
setColor(Color newColor)
Change the color of this icon. |
void |
setLabel(String aLabel)
Set the label to display on this icon. |
void |
setSize(double relativeSize)
Change the relative size of this icon. |
void |
setTransparency(double trans)
Set the transparency for this icon; that is, the degree to which it permits objects under it show through. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Color transparent
Constructor Detail |
---|
public Icon()
public Icon(double relativeSize)
public Icon(Color color)
public Icon(double relativeSize, Color color)
Method Detail |
---|
public Color getColor()
public void setColor(Color newColor)
newColor
- The new color.public double getTransparency()
public void setTransparency(double trans)
trans
- A number between 0.0 (fully opaque) and 1.0 (fully transparent).public double getSize()
public void setSize(double relativeSize)
relativeSize
- a number which specifies how large the icon should
be. 1.0 is as large as possible, 0.5 is half-size, 0.001 is very, very
small. 0.0 < relativeSize <= 1.0.protected double getRotation()
public String getLabel()
public void setLabel(String aLabel)
aLabel
- The label to display.protected void markChanged()
protected boolean hasChanged()
protected void renderImage(Graphics2D g2, int width, int height)
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.
g2
- the graphics context where the icon should be drawn.width
- the number of pixels wide the image will beheight
- the number of pixels high the image will beprotected void paintIcon(Graphics g)
renderImage(java.awt.Graphics2D, int, int)
) to specify how this icon
looks. For this method, the uper left corner of the icon has coordinates
(0,0) and width and height of 100 pixels each. It's standard position is
facing NORTH; other methods will rotate it, if required.
g
- The graphics context where the icon should be drawn.public Image getImage(int width, int height, double rotation)
protected void applyTransforms(Graphics2D g2, int width, int height, double rotation, double relSize)
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));
g2
- The graphics context to apply transformations towidth
- the width (in pixels) of the iconheight
- the height (in pixels) of the iconrotation
- the rotation of the icon, in radiansrelSize
- the relative size (0.0 < relSize <= 1.0) of the icon
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |