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 classLayoutShape.LayoutShapePointThese are the points that make up the outline of the shape.static classLayoutShape.LayoutShapePointTypeenum LayoutShapePointType Straight, Curvestatic classLayoutShape.LayoutShapeTypeenum LayoutShapeType
-
Field Summary
Fields Modifier and Type Field Description static intMAX_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 voidaddPoint(java.awt.geom.Point2D p)add pointvoidaddPoint(java.awt.geom.Point2D p, int nearIndex)add pointvoidaddPoint(LayoutShape.LayoutShapePointType t, java.awt.geom.Point2D p)add point(package private) voiddispose()Clean up when this object is no longer needed.protected voiddraw(java.awt.Graphics2D g2)protected voiddrawEditControls(java.awt.Graphics2D g2)protected HitPointTypefindHitPointType(java.awt.geom.Point2D hitPoint, boolean useRectangles)find the hit (location) type for a pointjava.awt.geom.Rectangle2DgetBounds()getBounds() - return the bounds of this shapejava.awt.geom.Point2DgetCoordsCenter()get coordinates of center point of shapejava.lang.StringgetDisplayName()java.awt.ColorgetFillColor()LayoutEditorgetLayoutEditor()intgetLevel()java.awt.ColorgetLineColor()intgetLineWidth()intgetMaxNumberPoints()get the maximum number of pointsjava.lang.StringgetName()accessor methodsintgetNumberPoints()get the number of pointsjava.awt.geom.Point2DgetPoint(int idx)Get point.java.util.ArrayList<LayoutShape.LayoutShapePoint>getPoints()LayoutShape.LayoutShapeTypegetType()booleanisHidden()static booleanisShapeHitPointType(HitPointType t)(package private) voidremove()Removes this object from display and persistence(package private) voidremoveShape()voidrotateCoords(double angleDEG)rotate this LayoutTrack's coordinates by angleDEG'svoidscaleCoords(double xFactor, double yFactor)scale this shapes coordinates by the x and y factorsvoidsetCoordsCenter(java.awt.geom.Point2D p)set center coordinatesvoidsetFillColor(java.awt.Color color)voidsetHidden(boolean hidden)voidsetLevel(int l)voidsetLineColor(java.awt.Color color)voidsetLineWidth(int w)voidsetName(java.lang.String n)voidsetPoint(int idx, java.awt.geom.Point2D p)set pointvoidsetType(LayoutShape.LayoutShapeType t)protected javax.swing.JPopupMenushowShapePopUp(JmriMouseEvent mouseEvent, HitPointType hitPointType)java.lang.StringtoString()java.awt.geom.Ellipse2DtrackControlCircleAt(java.awt.geom.Point2D inPoint)java.awt.geom.Ellipse2DtrackEditControlCircleAt(java.awt.geom.Point2D inPoint)voidtranslateCoords(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:
toStringin 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)
-
-