edu.rit.draw.item
Class Bullet
- java.lang.Object
-
- edu.rit.draw.item.Bullet
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable
public class Bullet extends java.lang.Object implements java.io.ExternalizableClass 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
Fields Modifier and Type Field and Description static BulletCIRCLEA bullet in the shape of a medium sized circle, offset the normal offset (36.0, or 1/2 inch) from the text item.static BulletDOTA bullet in the shape of a medium sized dot, offset the normal offset (36.0, or 1/2 inch) from the text item.static BulletNONEA nonexistent bullet.static doubleNORMAL_OFFSETThe normal bullet offset, 36.0 (1/2 inch).
-
Constructor Summary
Constructors Constructor and Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static doubledefaultOffset()Returns the default offset for bullets.static voiddefaultOffset(double theOffset)Set the default offset for bullets.voiddraw(java.awt.Graphics2D g2d, double ascent, double x, double y)Draw this bullet in the given graphics context.doubleoffset()Returns this bullet's offset.Bulletoffset(double theOffset)Set this bullet's offset.voidreadExternal(java.io.ObjectInput in)Read this bullet from the given object input stream.voidwriteExternal(java.io.ObjectOutput out)Write this bullet to the given object output stream.
-
-
-
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:
java.lang.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:
java.lang.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:
java.lang.IllegalArgumentException- (unchecked exception) Thrown if theOffset is less than 0.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this bullet to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Parameters:
out- Object output stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOExceptionRead this bullet from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Parameters:
in- Object input stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
draw
public void draw(java.awt.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.
-
-
DMelt 3.0 © DataMelt by jWork.ORG