Package jmri.jmrit.display.layoutEditor
Class LayoutShape
- java.lang.Object
-
- jmri.jmrit.display.layoutEditor.LayoutShape
-
public class LayoutShape extends java.lang.Object
A LayoutShape is a set of LayoutShapePoint used to draw a shape. Each point can ether be a point on the shape or a control point that defines a curve that's part of the shape. The shape can be open (end points not connected) or closed (end points connected)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LayoutShape.LayoutShapePoint
These are the points that make up the outline of the shape.static class
LayoutShape.LayoutShapePointType
enum LayoutShapePointType Straight, Curvestatic class
LayoutShape.LayoutShapeType
enum LayoutShapeType
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_LINEWIDTH
-
Constructor Summary
Constructors Constructor Description LayoutShape(java.lang.String name, java.awt.geom.Point2D c, LayoutEditor layoutEditor)
constructor method (used by LayoutEditor)LayoutShape(java.lang.String name, LayoutEditor layoutEditor)
constructor method (used by XML loading code)LayoutShape(java.lang.String name, LayoutShape.LayoutShapeType t, LayoutEditor layoutEditor)
constructor method (used by XML loading code)LayoutShape(LayoutShape layoutShape)
constructor method (used by duplicate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPoint(java.awt.geom.Point2D p)
add pointvoid
addPoint(java.awt.geom.Point2D p, int nearIndex)
add pointvoid
addPoint(LayoutShape.LayoutShapePointType t, java.awt.geom.Point2D p)
add point(package private) void
dispose()
Clean up when this object is no longer needed.protected void
draw(java.awt.Graphics2D g2)
protected void
drawEditControls(java.awt.Graphics2D g2)
protected HitPointType
findHitPointType(java.awt.geom.Point2D hitPoint, boolean useRectangles)
find the hit (location) type for a pointjava.awt.geom.Rectangle2D
getBounds()
getBounds() - return the bounds of this shapejava.awt.geom.Point2D
getCoordsCenter()
get coordinates of center point of shapejava.lang.String
getDisplayName()
java.awt.Color
getFillColor()
LayoutEditor
getLayoutEditor()
int
getLevel()
java.awt.Color
getLineColor()
int
getLineWidth()
int
getMaxNumberPoints()
get the maximum number of pointsjava.lang.String
getName()
accessor methodsint
getNumberPoints()
get the number of pointsjava.awt.geom.Point2D
getPoint(int idx)
Get point.java.util.ArrayList<LayoutShape.LayoutShapePoint>
getPoints()
LayoutShape.LayoutShapeType
getType()
boolean
isHidden()
static boolean
isShapeHitPointType(HitPointType t)
(package private) void
remove()
Removes this object from display and persistence(package private) void
removeShape()
void
rotateCoords(double angleDEG)
rotate this LayoutTrack's coordinates by angleDEG'svoid
scaleCoords(double xFactor, double yFactor)
scale this shapes coordinates by the x and y factorsvoid
setCoordsCenter(java.awt.geom.Point2D p)
set center coordinatesvoid
setFillColor(java.awt.Color color)
void
setHidden(boolean hidden)
void
setLevel(int l)
void
setLineColor(java.awt.Color color)
void
setLineWidth(int w)
void
setName(java.lang.String n)
void
setPoint(int idx, java.awt.geom.Point2D p)
set pointvoid
setType(LayoutShape.LayoutShapeType t)
protected javax.swing.JPopupMenu
showShapePopUp(JmriMouseEvent mouseEvent, HitPointType hitPointType)
java.lang.String
toString()
java.awt.geom.Ellipse2D
trackControlCircleAt(java.awt.geom.Point2D inPoint)
java.awt.geom.Ellipse2D
trackEditControlCircleAt(java.awt.geom.Point2D inPoint)
void
translateCoords(double xFactor, double yFactor)
translate this shapes coordinates by the x and y factors
-
-
-
Field Detail
-
MAX_LINEWIDTH
public static final int MAX_LINEWIDTH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LayoutShape
public LayoutShape(java.lang.String name, LayoutEditor layoutEditor)
constructor method (used by XML loading code)- Parameters:
name
- the name of the shapelayoutEditor
- reference to the LayoutEditor this shape is in
-
LayoutShape
public LayoutShape(java.lang.String name, LayoutShape.LayoutShapeType t, LayoutEditor layoutEditor)
constructor method (used by XML loading code)- Parameters:
name
- the name of the shapet
- the layout shape type.layoutEditor
- reference to the LayoutEditor this shape is in
-
LayoutShape
public LayoutShape(java.lang.String name, java.awt.geom.Point2D c, LayoutEditor layoutEditor)
constructor method (used by LayoutEditor)- Parameters:
name
- the name of the shapec
- the Point2D for the initial pointlayoutEditor
- reference to the LayoutEditor this shape is in
-
LayoutShape
public LayoutShape(LayoutShape layoutShape)
constructor method (used by duplicate)- Parameters:
layoutShape
- to duplicate (deep copy)
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getDisplayName
public java.lang.String getDisplayName()
-
getName
public java.lang.String getName()
accessor methods- Returns:
- the name of this shape
-
setName
public void setName(java.lang.String n)
-
getType
public LayoutShape.LayoutShapeType getType()
-
setType
public void setType(LayoutShape.LayoutShapeType t)
-
getLineWidth
public int getLineWidth()
-
setLineWidth
public void setLineWidth(int w)
-
getLineColor
public java.awt.Color getLineColor()
-
setLineColor
public void setLineColor(java.awt.Color color)
-
getFillColor
public java.awt.Color getFillColor()
-
setFillColor
public void setFillColor(java.awt.Color color)
-
getLevel
public int getLevel()
-
setLevel
public void setLevel(int l)
-
setHidden
public void setHidden(boolean hidden)
-
isHidden
public boolean isHidden()
-
getLayoutEditor
public LayoutEditor getLayoutEditor()
-
addPoint
public void addPoint(java.awt.geom.Point2D p)
add point- Parameters:
p
- the point to add
-
addPoint
public void addPoint(java.awt.geom.Point2D p, int nearIndex)
add point- Parameters:
p
- the point to addnearIndex
- the index of the existing point to add it near note: "near" is defined as before or after depending on closest neighbor
-
addPoint
public void addPoint(LayoutShape.LayoutShapePointType t, java.awt.geom.Point2D p)
add point- Parameters:
t
- the type of point to addp
- the point to add
-
setPoint
public void setPoint(int idx, java.awt.geom.Point2D p)
set point- Parameters:
idx
- the index of the point to addp
- the point to add
-
getPoint
public java.awt.geom.Point2D getPoint(int idx)
Get point.- Parameters:
idx
- the index of the point to add.- Returns:
- the 2D point of the ID, MathUtil.zeroPoint2D if no result.
-
getPoints
public java.util.ArrayList<LayoutShape.LayoutShapePoint> getPoints()
-
getNumberPoints
public int getNumberPoints()
get the number of points- Returns:
- the number of points
-
getMaxNumberPoints
public int getMaxNumberPoints()
get the maximum number of points- Returns:
- the maximum number of points
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
getBounds() - return the bounds of this shape- Returns:
- Rectangle2D as bound of this shape
-
findHitPointType
protected HitPointType findHitPointType(@Nonnull java.awt.geom.Point2D hitPoint, boolean useRectangles)
find the hit (location) type for a point- Parameters:
hitPoint
- the pointuseRectangles
- whether to use (larger) rectangles or (smaller) circles for hit testing- Returns:
- the hit point type for the point (or NONE)
-
isShapeHitPointType
public static boolean isShapeHitPointType(HitPointType t)
-
getCoordsCenter
public java.awt.geom.Point2D getCoordsCenter()
get coordinates of center point of shape- Returns:
- Point2D coordinates of center point of shape
-
setCoordsCenter
public void setCoordsCenter(@Nonnull java.awt.geom.Point2D p)
set center coordinates- Parameters:
p
- the coordinates to set
-
scaleCoords
public void scaleCoords(double xFactor, double yFactor)
scale this shapes coordinates by the x and y factors- Parameters:
xFactor
- the amount to scale X coordinatesyFactor
- the amount to scale Y coordinates
-
translateCoords
public void translateCoords(double xFactor, double yFactor)
translate this shapes coordinates by the x and y factors- Parameters:
xFactor
- the amount to translate X coordinatesyFactor
- the amount to translate Y coordinates
-
rotateCoords
public void rotateCoords(double angleDEG)
rotate this LayoutTrack's coordinates by angleDEG's- Parameters:
angleDEG
- the amount to rotate in degrees
-
showShapePopUp
@Nonnull protected javax.swing.JPopupMenu showShapePopUp(@CheckForNull JmriMouseEvent mouseEvent, HitPointType hitPointType)
-
removeShape
void removeShape()
-
dispose
void dispose()
Clean up when this object is no longer needed. Should not be called while the object is still displayed; see remove()
-
remove
void remove()
Removes this object from display and persistence
-
draw
protected void draw(java.awt.Graphics2D g2)
-
drawEditControls
protected void drawEditControls(java.awt.Graphics2D g2)
-
trackEditControlCircleAt
public java.awt.geom.Ellipse2D trackEditControlCircleAt(@Nonnull java.awt.geom.Point2D inPoint)
-
trackControlCircleAt
public java.awt.geom.Ellipse2D trackControlCircleAt(@Nonnull java.awt.geom.Point2D inPoint)
-
-