net.kolls.railworld.edit
Class SegmentEditPoint

java.lang.Object
  extended by net.kolls.railworld.edit.SegmentEditPoint
Direct Known Subclasses:
Curve.CSEP, TrackSegment.TSEP

public abstract class SegmentEditPoint
extends java.lang.Object

A segment edit point consists of a point on a segment as well as some extra abilities for editing, such as drawing temporary versions, moving the point (which should in turn move all segments connected to it) and determining if it should connect to other segments

Author:
Steve Kollmansberger

Field Summary
protected  java.awt.Color c
          The color that the handle should use.
 RailSegment[] myr
          Segments involved in this edit point.
protected  int pidx
          The point index of the segment we are editting
 
Constructor Summary
SegmentEditPoint(RailSegment[] segs, int ptIndex, java.awt.Color col)
          Create a segment edit point.
 
Method Summary
abstract  RailSegment anchor(RailSegment r)
          Attachs a segment to this edit point.
 void draw(java.awt.Graphics2D gc)
          Draws this edit point.
 java.awt.Color getColor()
          Gets the color of this point.
 java.awt.geom.Point2D getPoint()
          Returns the current location of this edit point.
 RailSegment getSegment()
          Returns the railsegment this edit point is associated with.
abstract  boolean isAnchorSource()
          If this segment is being moved, should it offer to anchor onto other segments? Note that the other segment will be asked to approve with RailSegment.nearEditPoint(Point2D, RailSegment).
 void moveTo(java.awt.geom.Point2D p)
          Moves this edit point.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pidx

protected int pidx
The point index of the segment we are editting


c

protected java.awt.Color c
The color that the handle should use. Red = may connect to another segment Green = already connected/not connectable


myr

public RailSegment[] myr
Segments involved in this edit point. There must be at least one -- and the first *MUST* be the segment which owns this edit point.

Constructor Detail

SegmentEditPoint

public SegmentEditPoint(RailSegment[] segs,
                        int ptIndex,
                        java.awt.Color col)
Create a segment edit point.

Parameters:
segs - The segments involved. See myr for details.
ptIndex - The index of the point on the owning segment. See pidx
col - Color of the handle to display. See c
Method Detail

anchor

public abstract RailSegment anchor(RailSegment r)
Attachs a segment to this edit point.

Parameters:
r - The RailSegment to anchor to this point.
Returns:
Returns a new segment if that segment should be added to the array of segments, and also anything else that wanted to anchor here should anchor at the returned segment. May return null.

getColor

public final java.awt.Color getColor()
Gets the color of this point. Green indicates a connected segment, Yellow indicates an non-connectable segment, red indicates a disconnected segment.

Returns:
The color to display the edit point as.

getSegment

public final RailSegment getSegment()
Returns the railsegment this edit point is associated with.

Returns:
The RailSegment associated with this edit segment; the first entry in myr.

getPoint

public final java.awt.geom.Point2D getPoint()
Returns the current location of this edit point.

Returns:
A point2D containing the current, zoomed, location of this edit point.

moveTo

public final void moveTo(java.awt.geom.Point2D p)
Moves this edit point.

Parameters:
p - New location.

draw

public final void draw(java.awt.Graphics2D gc)
Draws this edit point.

Parameters:
gc - The graphics context

isAnchorSource

public abstract boolean isAnchorSource()
If this segment is being moved, should it offer to anchor onto other segments? Note that the other segment will be asked to approve with RailSegment.nearEditPoint(Point2D, RailSegment).

Returns:
true if we should snap-to and anchor onto other segments.