net.kolls.railworld.segment
Class Curve

java.lang.Object
  extended by net.kolls.railworld.RailSegment
      extended by net.kolls.railworld.segment.Curve

public class Curve
extends RailSegment

A curved track segment represented using a cubic curve. The system finds sub-lines using a flatness of 5.

Author:
Steve Kollmansberger

Nested Class Summary
 class Curve.CSEP
          Edit point for setting up cubic curves
 
Field Summary
protected  java.awt.geom.QuadCurve2D cc
          The curve itself
protected  Distance len
          Length of this curve, as calculated by sub lines
protected  double[] lens
          The length of each subline
static int POINT_BEGIN
          Line begin point
static int POINT_CP1
          Control point 1
static int POINT_END
          Line end point
protected  java.awt.Stroke railBedStroke
          The rail bed pen
protected  java.awt.Stroke railStroke
          The rail line pen
protected  java.awt.geom.Point2D[] seq
          The sequence of points in the sublines
 
Fields inherited from class net.kolls.railworld.RailSegment
dests, ec, MOUSE_NEAR, pts, RAIL_BED_WIDTH, RAIL_WIDTH, trains
 
Constructor Summary
Curve(RailSegment bg, RailSegment en, java.awt.geom.QuadCurve2D crds)
          Create a new curve segment.
 
Method Summary
 boolean canErase()
          Can this segment be erased? In some cases, other segments must be erased first.
protected  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.
 RailSegment dest(RailSegment source)
          Each rail segment must at the very least tell us where it comes from and where it goes, currently.
 void draw(int z, java.awt.Graphics2D gc)
          Draw the segment.
 javax.swing.JPanel editPanel()
          You are guaranteed that the variable RailSegment.ec will be set prior to this call.
 java.awt.geom.Point2D getPoint(RailSegment start, double myPos)
           
 Distance length()
          all segments have a length can be 0 for signals, etc.
 void recomp()
          Called when changes are made; recompute or update any associated values.
 
Methods inherited from class net.kolls.railworld.RailSegment
carHidden, click, destNZ, enter, getDest, getDests, getPoint, getPoints, isDynamic, mouseOver, nearEditPoint, pixelStep, setDest, setPoint, singleton, step, trains, update, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cc

protected java.awt.geom.QuadCurve2D cc
The curve itself


POINT_BEGIN

public static final int POINT_BEGIN
Line begin point

See Also:
Constant Field Values

POINT_END

public static final int POINT_END
Line end point

See Also:
Constant Field Values

POINT_CP1

public static final int POINT_CP1
Control point 1

See Also:
Constant Field Values

len

protected Distance len
Length of this curve, as calculated by sub lines


seq

protected java.awt.geom.Point2D[] seq
The sequence of points in the sublines


lens

protected double[] lens
The length of each subline


railBedStroke

protected java.awt.Stroke railBedStroke
The rail bed pen


railStroke

protected java.awt.Stroke railStroke
The rail line pen

Constructor Detail

Curve

public Curve(RailSegment bg,
             RailSegment en,
             java.awt.geom.QuadCurve2D crds)
Create a new curve segment. The beginning and ending segment must both be TrackSegments.

Parameters:
bg - Beginning rail segment
en - Ending rail segment
crds - Curve
Method Detail

canErase

public boolean canErase()
Description copied from class: RailSegment
Can this segment be erased? In some cases, other segments must be erased first.

Specified by:
canErase in class RailSegment
Returns:
Indicates if the segment may be erased as-is.

createSEP

protected SegmentEditPoint createSEP(int ptIdx,
                                     RailSegment attach)
Description copied from class: RailSegment
Given a point index in the pts array and possibly a railsegment to attach, return a segmenteditpoint if such attachment is possible. If the attach segment is null, no segment is attaching, just user editing.

Specified by:
createSEP in class RailSegment
Parameters:
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).
Returns:
A SegmentEditPoint if possible, otherwise null.

dest

public RailSegment dest(RailSegment source)
Description copied from class: RailSegment
Each rail segment must at the very least tell us where it comes from and where it goes, currently. Indicate where you are coming from, it says where you're going. Null value means end of line. These values may be dynamic, as in a switch.

Specified by:
dest in class RailSegment
Parameters:
source - The rail segment of origin
Returns:
The destination rail segment, or null if there is none.

draw

public void draw(int z,
                 java.awt.Graphics2D gc)
Description copied from class: RailSegment
Draw the segment. Segments have several z-layers to allowed slightly overlaping pieces to still look nice. z = 1 is a static layer (lowest) z = 2 is a static layer (highest) z = 3 is reserved z = 4 is the dynamic layer. This is redrawn frequently, if requested by the segment.

Specified by:
draw in class RailSegment
Parameters:
z - The currently z-layer to draw
gc - A Graphics2D graphics context.
See Also:
RailSegment.isDynamic()

editPanel

public javax.swing.JPanel editPanel()
Description copied from class: RailSegment
You are guaranteed that the variable RailSegment.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.

Specified by:
editPanel in class RailSegment
Returns:
A JPanel to display in the sidebar to edit this segment's properties. Please keep width at 200 pixels top.

getPoint

public java.awt.geom.Point2D getPoint(RailSegment start,
                                      double myPos)
Specified by:
getPoint in class RailSegment
Parameters:
start - The segment of origin
myPos - Percentage (0-1) along the segment
Returns:
A Point2D indicating the actual point that location represents

length

public Distance length()
Description copied from class: RailSegment
all segments have a length can be 0 for signals, etc. length must be the same no mattter which 'way' you traverse the segment Distance may be a 0-foot distance, but not may be null.

Specified by:
length in class RailSegment
Returns:
The Distance of the segment.

recomp

public void recomp()
Description copied from class: RailSegment
Called when changes are made; recompute or update any associated values.

Specified by:
recomp in class RailSegment