com.bbn.openmap.omGraphics
Class OMLine

java.lang.Object
  |
  +--com.bbn.openmap.omGraphics.geom.BasicGeometry
        |
        +--com.bbn.openmap.omGraphics.OMGraphic
              |
              +--com.bbn.openmap.omGraphics.OMLine
All Implemented Interfaces:
java.lang.Cloneable, OMGeometry, OMGraphicConstants, java.io.Serializable
Direct Known Subclasses:
Line, RoadFinder.BlueLine, RoadFinder.YellowLine, RoadLine.Graphic

public class OMLine
extends OMGraphic
implements java.io.Serializable

Graphic object that represents a simple line.

The OMLine is used to create simple lines, from one point on the window to the other. If you want to have a line with several parts, use OMPoly as a polyline with no fillColor.

NOTE:

See the RESTRICTIONS on Lat/Lon lines. Not following the guidelines listed may result in ambiguous/undefined shapes! Similar assumptions apply to the other vector graphics that we define: circles, ellipses, rects, polys.

See Also:
OMPoly, Serialized Form

Field Summary
protected  ArcCalc arc
          For x-y and offset lines, there is the ability to put a curve in the line.
protected  int arrowDirectionType
          Used to draw the ArrowHead on the finishing end, the starting end, or both.
protected  int arrowLocation
          Where on the line to put the ArrowHead, from 0 (start) to 100 (end) of the line.
static int CURVED_LINE
           
protected  boolean doArrowHead
          Flag used to create arrow heads on lines.
protected  boolean isPolyline
           
protected  float[] latlons
          latlons is a array of 4 floats - lat1, lon1, lat2, lon2.
protected  int nsegs
          Number of segments to draw (used only for LINETYPE_GREATCIRCLE or LINETYPE_RHUMB lines).
protected  int[] pts
          pts is an array of 4 ints - px1, py1, px2, py2.
static int STRAIGHT_LINE
           
protected  int wingLength
          For arrowhead creation, the pixel distance from the tip of the arrowhead to the base.
protected  int wingTip
          For arrowhead creation, the width of half of the base of the arrowhead.
protected  int[][] xpoints
          X coordinate arrays of the projected points.
protected  int[][] ypoints
          Y coordinate arrays of the projected points.
 
Fields inherited from class com.bbn.openmap.omGraphics.OMGraphic
declutterType, displayPaint, edgeMatchesFill, fillPaint, hasLabel, linePaint, matted, mattingPaint, renderType, selected, selectPaint, showEditablePalette, stroke, textureMask
 
Fields inherited from class com.bbn.openmap.omGraphics.geom.BasicGeometry
APP_OBJECT_KEY, appObject, ATT_MAP_KEY, lineType, needToRegenerate, shape, visible
 
Fields inherited from interface com.bbn.openmap.omGraphics.OMGraphicConstants
ADD_GRAPHIC_MASK, BASIC_STROKE, clear, DECIMAL_DEGREES, DECLUTTERTYPE_LINE, DECLUTTERTYPE_MOVE, DECLUTTERTYPE_NONE, DECLUTTERTYPE_SPACE, DEFAULT_ROTATIONANGLE, DELETE_GRAPHIC_MASK, DESELECT_GRAPHIC_MASK, DESELECTALL_GRAPHIC_MASK, GRAPHICTYPE_ARC, GRAPHICTYPE_BITMAP, GRAPHICTYPE_CIRCLE, GRAPHICTYPE_GRAPHIC, GRAPHICTYPE_GRID, GRAPHICTYPE_LINE, GRAPHICTYPE_POINT, GRAPHICTYPE_POLY, GRAPHICTYPE_RASTER, GRAPHICTYPE_RECTANGLE, GRAPHICTYPE_TEXT, INFOLINE, LABEL, LINETYPE_GREATCIRCLE, LINETYPE_RHUMB, LINETYPE_STRAIGHT, LINETYPE_UNKNOWN, LOWER_GRAPHIC_MASK, LOWER_TO_BOTTOM_GRAPHIC_MASK, RADIANS, RAISE_GRAPHIC_MASK, RAISE_TO_TOP_GRAPHIC_MASK, RENDERTYPE_LATLON, RENDERTYPE_OFFSET, RENDERTYPE_UNKNOWN, RENDERTYPE_XY, SELECT_GRAPHIC_MASK, SORT_GRAPHICS_MASK, TOOLTIP, UPDATE_GRAPHIC_MASK
 
Constructor Summary
OMLine()
          Generic constructor, attributes need to filled later.
OMLine(float lat_1, float lon_1, float lat_2, float lon_2, int lineType)
          Create a line from lat lon points.
OMLine(float lat_1, float lon_1, float lat_2, float lon_2, int lineType, int nsegs)
          Create a line from lat lon points.
OMLine(float lat_1, float lon_1, int x1, int y1, int x2, int y2)
          Create a line between two x-y points on the window, where the x-y points are offsets from a lat-lon point.
OMLine(int x1, int y1, int x2, int y2)
          Create a line between two xy points on the window.
 
Method Summary
 void addArrowHead(boolean value)
          Turn the ArrowHead on/off.
 void addArrowHead(int directionType)
          Turn the ArrowHead on.
 void addArrowHead(int directionType, int location)
          Turn the ArrowHead on.
 void addArrowHead(int directionType, int location, int tipWidth, int arrowLength)
          Turn the ArrowHead on.
 boolean contains(int x, int y)
          This takes the area out of OMLines that may look like they have area, depending on their shape.
 java.awt.geom.GeneralPath createArrowHeads()
          This is a method that you can extend to create the GeneralPath for the arrowheads, if you want a different way of doing it.
 boolean generate(Projection proj)
          Prepare the line for rendering.
 ArcCalc getArc()
          Return the arc angle set for this line.
 float[] getLL()
          Get the lat lon values of the end points of the line in an array of floats - lat1, lon1, lat2, lon2.
 int getNumSegs()
          Get the number of segments of the lat/lon line.
 int[] getPts()
          Get the xy values of the end points of the line in an array of ints - x1, y1, x2, y2 .
 int getWingLength()
          Arrowhead function, to find out the arrowhead length.
 int getWingTip()
          Arrowhead function, to find out the wing tip width.
 boolean isPolyline()
          Check to see if this line is a polyline.
 void render(java.awt.Graphics g)
          Paint the line.
 void setArc(ArcCalc ac)
          Set the arc that is drawn between the points of a x-y or offset line.
 void setLL(float[] lls)
          Set the lat lon values of the end points of the line from an array of floats - lat1, lon1, lat2, lon2.
 void setNumSegs(int nsegs)
          Set the number of segments of the lat/lon line.
 void setPts(int[] xys)
          Set the xy values of the end points of the line from an array of ints - x1, y1, x2, y2 .
 boolean shouldRenderFill()
          The OMLine should never render fill.
 
Methods inherited from class com.bbn.openmap.omGraphics.OMGraphic
clone, deselect, distance, getDeclutterType, getDescription, getDescription, getDisplayColor, getDisplayPaint, getEdgeMatchesFill, getFillColor, getFillPaint, getHasLabel, getLineColor, getLinePaint, getMattingPaint, getRenderType, getSelectColor, getSelectPaint, getShowEditablePalette, getStroke, getTextureMask, hasLineTypeChoice, initLabelingDuringGenerate, isClear, isMatted, isSelected, normalizeDistanceForLineWidth, regenerate, renderLabel, select, setDeclutterType, setEdgeMatchesFill, setFillColor, setFillPaint, setGraphicsColor, setGraphicsForEdge, setGraphicsForFill, setHasLabel, setLabelLocation, setLabelLocation, setLabelLocation, setLineColor, setLinePaint, setMatted, setMattingPaint, setRenderType, setSelectColor, setSelected, setSelectPaint, setShape, setShowEditablePalette, setStroke, setTextureMask, shouldRenderEdge
 
Methods inherited from class com.bbn.openmap.omGraphics.geom.BasicGeometry
_distance, appendShapeEdge, appendShapeEdge, appendShapeEdge, appendShapeEdge, checkAttributeMap, checkAttributeMap, clearAttributes, createAttributeMap, createBoxShape, createShape, createShape, describeShapeDetail, describeShapeDetail, distanceToEdge, draw, fill, getAppObject, getAppObject, getAttribute, getAttributeMap, getAttributes, getLineType, getNeedToRegenerate, getShape, isRenderable, isVisible, putAttribute, removeAttribute, replaceAppObjectWithAttributeMap, setAppObject, setAppObject, setAttributes, setLineType, setNeedToRegenerate, setVisible
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.bbn.openmap.omGraphics.OMGeometry
clearAttributes, draw, fill, getAppObject, getAttribute, getAttributes, getLineType, getNeedToRegenerate, getShape, isRenderable, isVisible, putAttribute, removeAttribute, setAppObject, setAttributes, setLineType, setNeedToRegenerate, setVisible
 

Field Detail

isPolyline

protected boolean isPolyline

latlons

protected float[] latlons
latlons is a array of 4 floats - lat1, lon1, lat2, lon2.


pts

protected int[] pts
pts is an array of 4 ints - px1, py1, px2, py2.


xpoints

protected int[][] xpoints
X coordinate arrays of the projected points.


ypoints

protected int[][] ypoints
Y coordinate arrays of the projected points.


doArrowHead

protected boolean doArrowHead
Flag used to create arrow heads on lines.


arrowDirectionType

protected int arrowDirectionType
Used to draw the ArrowHead on the finishing end, the starting end, or both.


arrowLocation

protected int arrowLocation
Where on the line to put the ArrowHead, from 0 (start) to 100 (end) of the line. For BACKWARDS directions, 100 would be at the beginning of the line.


wingTip

protected int wingTip
For arrowhead creation, the width of half of the base of the arrowhead.


wingLength

protected int wingLength
For arrowhead creation, the pixel distance from the tip of the arrowhead to the base.


nsegs

protected int nsegs
Number of segments to draw (used only for LINETYPE_GREATCIRCLE or LINETYPE_RHUMB lines).


arc

protected ArcCalc arc
For x-y and offset lines, there is the ability to put a curve in the line. This setting is the amount of an angle, limited to a semi-circle (PI) that the curve will represent. In other words, the arc between the two end points is going to look like a 0 degrees of a circle (straight line, which is the default), or 180 degrees of a circle (full semi-circle). Given in radians, though, not degrees. The ArcCalc object handles all the details.


STRAIGHT_LINE

public static final int STRAIGHT_LINE
See Also:
Constant Field Values

CURVED_LINE

public static final int CURVED_LINE
See Also:
Constant Field Values
Constructor Detail

OMLine

public OMLine()
Generic constructor, attributes need to filled later.


OMLine

public OMLine(float lat_1,
              float lon_1,
              float lat_2,
              float lon_2,
              int lineType)
Create a line from lat lon points.

Parameters:
lat_1 - latitude of first point, decimal degrees.
lon_1 - longitude of first point, decimal degrees.
lat_2 - latitude of second point, decimal degrees.
lon_2 - longitude of second point, decimal degrees.
lineType - a choice between LINETYPE_STRAIGHT, LINETYPE_GREATCIRCLE or LINETYPE_RHUMB.

OMLine

public OMLine(float lat_1,
              float lon_1,
              float lat_2,
              float lon_2,
              int lineType,
              int nsegs)
Create a line from lat lon points.

Parameters:
lat_1 - latitude of first point, decimal degrees.
lon_1 - longitude of first point, decimal degrees.
lat_2 - latitude of second point, decimal degrees.
lon_2 - longitude of second point, decimal degrees.
lineType - a choice between LINETYPE_STRAIGHT, LINETYPE_GREATCIRCLE or LINETYPE_RHUMB.
nsegs - number of segment points (only for LINETYPE_GREATCIRCLE or LINETYPE_RHUMB line types, and if < 1, this value is generated internally)

OMLine

public OMLine(int x1,
              int y1,
              int x2,
              int y2)
Create a line between two xy points on the window.

Parameters:
x1 - the x location of the first point, in pixels from the left of the window.
y1 - the y location of the first point, in pixels from the top of the window.
x2 - the x location of the second point, in pixels from the left of the window.
y2 - the y location of the second point, in pixels from the top of the window.

OMLine

public OMLine(float lat_1,
              float lon_1,
              int x1,
              int y1,
              int x2,
              int y2)
Create a line between two x-y points on the window, where the x-y points are offsets from a lat-lon point. It assumes that you'll want a straight window line between the points, so if you don't, use the setLineType() method to change it.

Parameters:
lat_1 - the latitude of the reference point of the line, in decimal degrees.
lon_1 - the longitude of the reference point of the line, in decimal degrees.
x1 - the x location of the first point, in pixels from the longitude point.
y1 - the y location of the first point, in pixels from the latitude point.
x2 - the x location of the second point, in pixels from the longitude point.
y2 - the y location of the second point, in pixels from the latitude point.
Method Detail

setLL

public void setLL(float[] lls)
Set the lat lon values of the end points of the line from an array of floats - lat1, lon1, lat2, lon2. This does not look at the line render type, so it acts accordingly. LL1 is only used in RENDERTYPE_LATLON, RENDERTYPE_OFFSET, and LL2 is only used in RENDERTYPE_LATLON.

Parameters:
lls - array of floats - lat1, lon1, lat2, lon2

getLL

public float[] getLL()
Get the lat lon values of the end points of the line in an array of floats - lat1, lon1, lat2, lon2. Again, this does not look at the line render type, so it acts accordingly. LL1 is only used in RENDERTYPE_LATLON, RENDERTYPE_OFFSET, and LL2 is only used in RENDERTYPE_LATLON.

Returns:
the lat lon array, and all are decimal degrees.

setPts

public void setPts(int[] xys)
Set the xy values of the end points of the line from an array of ints - x1, y1, x2, y2 . This does not look at the line render type, so it acts accordingly. p1 and p2 are only used in RENDERTYPE_XY, RENDERTYPE_OFFSET.

Parameters:
xys - array of ints for the points - x1, y1, x2, y2

getPts

public int[] getPts()
Get the xy values of the end points of the line in an array of ints - x1, y1, x2, y2 . This does not look at the line render type, so it acts accordingly. p1 and p2 are only used in RENDERTYPE_XY, RENDERTYPE_OFFSET.

Returns:
the array of x-y points, and all are pixel values

isPolyline

public boolean isPolyline()
Check to see if this line is a polyline. This is a polyline if it is LINETYPE_GREATCIRCLE or LINETYPE_RHUMB for RENDERTYPE_LATLON polys.

Returns:
true if polyline false if not

setNumSegs

public void setNumSegs(int nsegs)
Set the number of segments of the lat/lon line. (This is only for LINETYPE_GREATCIRCLE or LINETYPE_RHUMB line types, and if < 1, this value is generated internally).

Parameters:
nsegs - number of segment points

getNumSegs

public int getNumSegs()
Get the number of segments of the lat/lon line. (This is only for LINETYPE_GREATCIRCLE or LINETYPE_RHUMB line types).

Returns:
int number of segment points

addArrowHead

public void addArrowHead(boolean value)
Turn the ArrowHead on/off. The ArrowHead is placed on the finishing end.

Parameters:
value - on/off

addArrowHead

public void addArrowHead(int directionType)
Turn the ArrowHead on. The ArrowHead is placed on the finishing end (OMArrowHead.ARROWHEAD_DIRECTION_FORWARD), beginning end (OMArrowHead.ARROWHEAD_DIRECTION_BACKWARD), or both ends(OMArrowHead.ARROWHEAD_DIRECTION_BOTH).

Parameters:
directionType - which way to point the arrow head.

addArrowHead

public void addArrowHead(int directionType,
                         int location)
Turn the ArrowHead on. The ArrowHead is placed on the finishing end (OMArrowHead.ARROWHEAD_DIRECTION_FORWARD), beginning end (OMArrowHead.ARROWHEAD_DIRECTION_BACKWARD), or both ends(OMArrowHead.ARROWHEAD_DIRECTION_BOTH).

Parameters:
directionType - which way to point the arrow head.
location - where on the line to put the arrow head - 0 for the starting point, 100 for the end.

addArrowHead

public void addArrowHead(int directionType,
                         int location,
                         int tipWidth,
                         int arrowLength)
Turn the ArrowHead on. The ArrowHead is placed on the finishing end (OMArrowHead.ARROWHEAD_DIRECTION_FORWARD), beginning end (OMArrowHead.ARROWHEAD_DIRECTION_BACKWARD), or both ends(OMArrowHead.ARROWHEAD_DIRECTION_BOTH).

Parameters:
directionType - which way to point the arrow head.
location - where on the line to put the arrow head - 0 for the starting point, 100 for the end.
tipWidth - the width factor for the base of the arrowhead, on one side of the line. (Default is 5)
arrowLength - the length factor of the arrowhead, from the tip of the line to the base of the arrowhead. (Default is 20)

getWingTip

public int getWingTip()
Arrowhead function, to find out the wing tip width.


getWingLength

public int getWingLength()
Arrowhead function, to find out the arrowhead length.


setArc

public void setArc(ArcCalc ac)
Set the arc that is drawn between the points of a x-y or offset line.


getArc

public ArcCalc getArc()
Return the arc angle set for this line. Will only be set if it was set externally.

Returns:
arc angle in radians.

generate

public boolean generate(Projection proj)
Prepare the line for rendering.

Specified by:
generate in interface OMGeometry
Specified by:
generate in class OMGraphic
Parameters:
proj - Projection
Returns:
true if generate was successful
See Also:
OMGraphic.regenerate(com.bbn.openmap.proj.Projection)

createArrowHeads

public java.awt.geom.GeneralPath createArrowHeads()
This is a method that you can extend to create the GeneralPath for the arrowheads, if you want a different way of doing it. By default, it calls OMArrowHead.createArrowHeads(), using the different arrowhead variables set in the OMLine.


render

public void render(java.awt.Graphics g)
Paint the line.

Overrides:
render in class OMGraphic
Parameters:
g - Graphics context to render into

shouldRenderFill

public boolean shouldRenderFill()
The OMLine should never render fill. It can think it does, if the geometry turns out to be curved. Returning false affects distance() and contains() methods.

Overrides:
shouldRenderFill in class OMGraphic

contains

public boolean contains(int x,
                        int y)
This takes the area out of OMLines that may look like they have area, depending on their shape. Checks to see what shouldRenderFill() returns (false by default) to decide how to measure this. If shouldRenderFill == true, the super.contains() method is returned, which assumes the line shape has area if it is curved. Otherwise, it returns true if the point is on the line.

Specified by:
contains in interface OMGeometry
Overrides:
contains in class BasicGeometry
Parameters:
x - X pixel coordinate of the point.
y - Y pixel coordinate of the point.
Returns:
getShape().contains(x, y), false if the OMGraphic hasn't been generated yet.


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details