edu.rit.draw.item
Class Bullet

java.lang.Object
  extended by edu.rit.draw.item.Bullet
All Implemented Interfaces:
Externalizable, Serializable

public class Bullet
extends Object
implements Externalizable

Class Bullet provides various kinds of bullets that can be added to a Text item. The bullet is always added to the left of the text item, with a specified distance from the left side of the bullet to the left side of the text item.

See Also:
Serialized Form

Field Summary
static Bullet CIRCLE
          A bullet in the shape of a medium sized circle, offset the normal offset (36.0, or 1/2 inch) from the text item.
static Bullet DOT
          A bullet in the shape of a medium sized dot, offset the normal offset (36.0, or 1/2 inch) from the text item.
static Bullet NONE
          A nonexistent bullet.
static double NORMAL_OFFSET
          The normal bullet offset, 36.0 (1/2 inch).
 
Constructor Summary
Bullet()
          Construct a new nonexistent bullet.
Bullet(Bullet theBullet)
          Construct a new bullet of the same kind as the given bullet, but with the default offset.
 
Method Summary
static double defaultOffset()
          Returns the default offset for bullets.
static void defaultOffset(double theOffset)
          Set the default offset for bullets.
 void draw(Graphics2D g2d, double ascent, double x, double y)
          Draw this bullet in the given graphics context.
 double offset()
          Returns this bullet's offset.
 Bullet offset(double theOffset)
          Set this bullet's offset.
 void readExternal(ObjectInput in)
          Read this bullet from the given object input stream.
 void writeExternal(ObjectOutput out)
          Write this bullet to the given object output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORMAL_OFFSET

public static final double NORMAL_OFFSET
The normal bullet offset, 36.0 (1/2 inch).

See Also:
Constant Field Values

NONE

public static final Bullet NONE
A nonexistent bullet.


DOT

public static final Bullet DOT
A bullet in the shape of a medium sized dot, offset the normal offset (36.0, or 1/2 inch) from the text item.


CIRCLE

public static final Bullet CIRCLE
A bullet in the shape of a medium sized circle, offset the normal offset (36.0, or 1/2 inch) from the text item.

Constructor Detail

Bullet

public Bullet()
Construct a new nonexistent bullet.


Bullet

public Bullet(Bullet theBullet)
Construct a new bullet of the same kind as the given bullet, but with the default offset.

Parameters:
theBullet - Bullet.
Throws:
NullPointerException - (unchecked exception) Thrown if theBullet is null.
Method Detail

defaultOffset

public static double defaultOffset()
Returns the default offset for bullets. The offset is the distance between the left side of the bullet and the left side of the text.

Returns:
Default offset.

defaultOffset

public static void defaultOffset(double theOffset)
Set the default offset for bullets. The offset is the distance between the left side of the bullet and the left side of the text.

Parameters:
theOffset - Default offset.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theOffset is less than 0.

offset

public double offset()
Returns this bullet's offset. The offset is the distance between the left side of the bullet and the left side of the text.

Returns:
Offset.

offset

public Bullet offset(double theOffset)
Set this bullet's offset. The offset is the distance between the left side of the bullet and the left side of the text.

Parameters:
theOffset - Offset.
Returns:
This bullet.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theOffset is less than 0.

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Write this bullet to the given object output stream.

Specified by:
writeExternal in interface Externalizable
Parameters:
out - Object output stream.
Throws:
IOException - Thrown if an I/O error occurred.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException
Read this bullet from the given object input stream.

Specified by:
readExternal in interface Externalizable
Parameters:
in - Object input stream.
Throws:
IOException - Thrown if an I/O error occurred.

draw

public void draw(Graphics2D g2d,
                 double ascent,
                 double x,
                 double y)
Draw this bullet in the given graphics context. It assumes the graphics context's paint is already set to the correct value. The bullet is scaled to match the ascent. The bullet's left side is placed relative to the coordinates of the left end of the text baseline (x,y).

Parameters:
g2d - 2-D graphics context.
ascent - Text font ascent.
x - X coordinate of the left end of the text baseline.
y - Y coordinate of the left end of the text baseline.


Copyright © 2005-2012 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.