|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.kolls.railworld.RailSegment
public abstract class RailSegment
The interface which must be implemented for something to be considered a rail segment.
Most segments will derive from an existing segment (usually TrackSegment and not implement this interface directly!
| Field Summary | |
|---|---|
protected RailSegment[] |
dests
Various connections to this segment. |
EditCanvas |
ec
The canvas to register undo information with, if any. |
protected static Distance |
MOUSE_NEAR
How close does the mouse need to be to count as being "near" something? |
protected java.awt.geom.Point2D[] |
pts
Points that make up this segment. |
static Distance |
RAIL_BED_WIDTH
The width of the rail bed (gravel) |
static Distance |
RAIL_WIDTH
The width of the rail line itself. |
protected java.util.Set<Train> |
trains
Trains present in this segment |
| Constructor Summary | |
|---|---|
RailSegment()
|
|
| Method Summary | |
|---|---|
abstract boolean |
canErase()
Can this segment be erased? In some cases, other segments must be erased first. |
boolean |
carHidden()
Should cars on this segment be drawn, or hidden? Defaults to false (not hidden). |
boolean |
click(java.awt.geom.Point2D pos,
RailCanvas rc)
Whenever a user clicks on the canvas, all dynamic segments receive this event. |
protected abstract SegmentEditPoint |
createSEP(int ptIdx,
RailSegment attach)
Given a point index in the pts array and possibly a railsegment to attach, return a segmenteditpoint if such attachment is possible. |
abstract RailSegment |
dest(RailSegment source)
Each rail segment must at the very least tell us where it comes from and where it goes, currently. |
java.util.ArrayList<RailSegment> |
destNZ(RailSegment source)
Finds the first non-zero length RailSegment going away from the source. |
abstract void |
draw(int z,
java.awt.Graphics2D gc)
Draw the segment. |
abstract javax.swing.JPanel |
editPanel()
You are guaranteed that the variable ec will be set prior to this call. |
void |
enter(Train t)
Notification that a train is in the segment. |
RailSegment |
getDest(int dest)
Returns a given destination RailSegment. |
int |
getDests()
|
java.awt.geom.Point2D |
getPoint(int ptIdx)
Returns a given point. |
abstract java.awt.geom.Point2D |
getPoint(RailSegment start,
double myPos)
|
int |
getPoints()
|
boolean |
isDynamic()
Dynamic segments receive additional events while the game is running; non-dynamic segments are only asked to draw z levels 1 and 2 at draw static time. |
abstract Distance |
length()
all segments have a length can be 0 for signals, etc. |
java.lang.String |
mouseOver(java.awt.geom.Point2D pos)
Whenever a user mouses over the canvas, all dynamic segments receive this event. |
SegmentEditPoint |
nearEditPoint(java.awt.geom.Point2D loc,
RailSegment attach)
Given a point, find out if it is near one of our edit handles (z=5). |
double |
pixelStep(double myPos)
Given a position (percentage), move one pixel and give the new percentage. |
abstract void |
recomp()
Called when changes are made; recompute or update any associated values. |
void |
setDest(int point,
boolean ifNotNull,
RailSegment value)
Updates one of the connecting segments to this segment. |
void |
setPoint(int point,
java.awt.geom.Point2D p)
Update a drawing point. |
boolean |
singleton()
Singleton segments may only have one train in them at a time. |
double |
step(double myPos,
double mySpeed)
|
java.util.Set<Train> |
trains()
Note: Set contents will be maintained automatically, read only |
void |
update(java.awt.geom.Point2D original,
java.awt.geom.Point2D replacement)
Update a point location for this segment. |
int |
update(RailSegment test,
RailSegment newValue)
Updates a connection from a given segment to a new one. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Distance RAIL_BED_WIDTH
public static final Distance RAIL_WIDTH
protected static final Distance MOUSE_NEAR
public EditCanvas ec
editPanel()protected RailSegment[] dests
protected java.awt.geom.Point2D[] pts
protected java.util.Set<Train> trains
| Constructor Detail |
|---|
public RailSegment()
| Method Detail |
|---|
public abstract boolean canErase()
public boolean carHidden()
public boolean click(java.awt.geom.Point2D pos,
RailCanvas rc)
pos - The click positionrc - The current canvas which contains this segment
isDynamic()public abstract RailSegment dest(RailSegment source)
source - The rail segment of origin
null if there is none.public final java.util.ArrayList<RailSegment> destNZ(RailSegment source)
source - The originating segment
dest(RailSegment)
public abstract void draw(int z,
java.awt.Graphics2D gc)
z - The currently z-layer to drawgc - A Graphics2D graphics context.isDynamic()public abstract javax.swing.JPanel editPanel()
ec will be set prior to this call.
So if you need to refresh the canvas or make any changes to it, you can use
that variable.
JPanel to display in the sidebar to edit this segment's properties. Please keep width at 200 pixels top.public void enter(Train t)
trains() to see if it remains.
Defaults to no behavior.
t - The train in the segment.public final RailSegment getDest(int dest)
dest - Which connection number (as defined by the individual class) to retrieve.
public final java.awt.geom.Point2D getPoint(int ptIdx)
ptIdx - The point index to retreive.
public abstract java.awt.geom.Point2D getPoint(RailSegment start,
double myPos)
start - The segment of originmyPos - Percentage (0-1) along the segment
Point2D indicating the actual point that location representspublic boolean isDynamic()
draw events
and click events.draw(int, Graphics2D),
click(Point2D, RailCanvas)public abstract Distance length()
Distance of the segment.public java.lang.String mouseOver(java.awt.geom.Point2D pos)
pos - The mouse position
isDynamic()
public final SegmentEditPoint nearEditPoint(java.awt.geom.Point2D loc,
RailSegment attach)
loc - The point locationattach - The segment (or null) that wants to attach here
SegmentEditPoint, or null.public final double pixelStep(double myPos)
myPos - The current percentage (0-1) along the segment.
public final void setDest(int point,
boolean ifNotNull,
RailSegment value)
point - A value defined by the rail segment to indicate one of its endsifNotNull - Only perform the update if the value is currently nullvalue - The new rail segment
public final void setPoint(int point,
java.awt.geom.Point2D p)
point - The point index (meaning defined by the individual segment) to update.p - The new pointpublic final int getDests()
public final int getPoints()
public boolean singleton()
public final double step(double myPos,
double mySpeed)
myPos - The current percentage (0-1) along the segmentmySpeed - The current MPH
public final java.util.Set<Train> trains()
public final void update(java.awt.geom.Point2D original,
java.awt.geom.Point2D replacement)
original - The original locationreplacement - The new location
public final int update(RailSegment test,
RailSegment newValue)
test - The original segment to replacenewValue - The new segment to replace it with
protected abstract SegmentEditPoint createSEP(int ptIdx,
RailSegment attach)
ptIdx - The index into the pts array.attach - The segment that desires to attach. (Note: do not attach the segment
automatically; it will be called through the anchor method in the edit point).
null.public abstract void recomp()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||