Class OnLineStrategy
- java.lang.Object
-
- org.openstreetmap.josm.gui.mappaint.styleelement.placement.OnLineStrategy
-
- All Implemented Interfaces:
PositionForAreaStrategy
public class OnLineStrategy extends Object implements PositionForAreaStrategy
Places the label onto the line.- Since:
- 11722, 11748 moved to own file
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
OnLineStrategy.GlyphRotatingVisitor
Rotate the glyphs along a path.private static class
OnLineStrategy.HalfSegment
A half segment that can be used to place text on it.private static class
OnLineStrategy.OffsetGlyph
private static class
OnLineStrategy.UpsideComputingVisitor
A visitor that computes the side of the way that is the upper one for each segment and computes the dominant upper side of the way.
-
Field Summary
Fields Modifier and Type Field Description static OnLineStrategy
INSTANCE
An instance of this class.private double
yOffset
-
Constructor Summary
Constructors Constructor Description OnLineStrategy(double yOffset)
Create a new strategy that places the text on the line.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static List<OnLineStrategy.OffsetGlyph>
computeOffsetGlyphs(List<GlyphVector> gvs, double startOffset, boolean rotateText)
Create a list of glyphs with an offset along the wayprivate static double
computeQuality(MapViewState.MapViewPoint p1, MapViewState.MapViewPoint p2)
boolean
equals(Object obj)
MapViewPositionAndRotation
findLabelPlacement(MapViewPath path, Rectangle2D nb)
Finds the correct position of a label / icon inside the area.private static Optional<OnLineStrategy.HalfSegment>
findOptimalWayPosition(Rectangle2D rect, MapViewPath path)
List<GlyphVector>
generateGlyphVectors(MapViewPath path, Rectangle2D nb, List<GlyphVector> gvs, boolean isDoubleTranslationBug)
Generates the transformed glyph vectors for the given text.int
hashCode()
boolean
supportsGlyphVector()
Checks whether this placement strategy supports more detailed (rotation / ...) placement using a glyph vector.private static double
theta(MapViewState.MapViewPoint start, MapViewState.MapViewPoint end)
String
toString()
private static double
upsideTheta(OnLineStrategy.HalfSegment best)
PositionForAreaStrategy
withAddedOffset(Point2D addToOffset)
Create a new instance of the same strategy adding a offset
-
-
-
Field Detail
-
INSTANCE
public static final OnLineStrategy INSTANCE
An instance of this class.
-
yOffset
private final double yOffset
-
-
Constructor Detail
-
OnLineStrategy
public OnLineStrategy(double yOffset)
Create a new strategy that places the text on the line.- Parameters:
yOffset
- The offset sidewards to the line.
-
-
Method Detail
-
findLabelPlacement
public MapViewPositionAndRotation findLabelPlacement(MapViewPath path, Rectangle2D nb)
Description copied from interface:PositionForAreaStrategy
Finds the correct position of a label / icon inside the area.- Specified by:
findLabelPlacement
in interfacePositionForAreaStrategy
- Parameters:
path
- The area to search innb
- The bounding box of the thing we are searching a place for.- Returns:
- The position as rectangle with the same dimension as nb.
null
if none was found.
-
upsideTheta
private static double upsideTheta(OnLineStrategy.HalfSegment best)
-
supportsGlyphVector
public boolean supportsGlyphVector()
Description copied from interface:PositionForAreaStrategy
Checks whether this placement strategy supports more detailed (rotation / ...) placement using a glyph vector.- Specified by:
supportsGlyphVector
in interfacePositionForAreaStrategy
- Returns:
true
if it is supported.
-
generateGlyphVectors
public List<GlyphVector> generateGlyphVectors(MapViewPath path, Rectangle2D nb, List<GlyphVector> gvs, boolean isDoubleTranslationBug)
Description copied from interface:PositionForAreaStrategy
Generates the transformed glyph vectors for the given text.- Specified by:
generateGlyphVectors
in interfacePositionForAreaStrategy
- Parameters:
path
- The path to place the text alongnb
- The bounds of the textgvs
- The glyph vectors for the text. May be modifiedisDoubleTranslationBug
-true
to fix a glyph placement bug.- Returns:
- The glyph vectors.
-
computeOffsetGlyphs
private static List<OnLineStrategy.OffsetGlyph> computeOffsetGlyphs(List<GlyphVector> gvs, double startOffset, boolean rotateText)
Create a list of glyphs with an offset along the way- Parameters:
gvs
- The list of glyphsstartOffset
- The offset in the linerotateText
- Rotate the text by 180°- Returns:
- The list of glyphs.
-
findOptimalWayPosition
private static Optional<OnLineStrategy.HalfSegment> findOptimalWayPosition(Rectangle2D rect, MapViewPath path)
-
computeQuality
private static double computeQuality(MapViewState.MapViewPoint p1, MapViewState.MapViewPoint p2)
-
theta
private static double theta(MapViewState.MapViewPoint start, MapViewState.MapViewPoint end)
-
withAddedOffset
public PositionForAreaStrategy withAddedOffset(Point2D addToOffset)
Description copied from interface:PositionForAreaStrategy
Create a new instance of the same strategy adding a offset- Specified by:
withAddedOffset
in interfacePositionForAreaStrategy
- Parameters:
addToOffset
- The offset to add- Returns:
- The new strategy
-
-