Class OnLineStrategy
- java.lang.Object
-
- org.openstreetmap.josm.gui.mappaint.styleelement.placement.OnLineStrategy
-
- All Implemented Interfaces:
PositionForAreaStrategy
public class OnLineStrategy extends java.lang.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 classOnLineStrategy.GlyphRotatingVisitorRotate the glyphs along a path.private static classOnLineStrategy.HalfSegmentA half segment that can be used to place text on it.private static classOnLineStrategy.OffsetGlyphprivate static classOnLineStrategy.UpsideComputingVisitorA 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 OnLineStrategyINSTANCEAn instance of this class.private doubleyOffset
-
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 java.util.List<OnLineStrategy.OffsetGlyph>computeOffsetGlyphs(java.util.List<java.awt.font.GlyphVector> gvs, double startOffset, boolean rotateText)Create a list of glyphs with an offset along the wayprivate static doublecomputeQuality(MapViewState.MapViewPoint p1, MapViewState.MapViewPoint p2)booleanequals(java.lang.Object obj)MapViewPositionAndRotationfindLabelPlacement(MapViewPath path, java.awt.geom.Rectangle2D nb)Finds the correct position of a label / icon inside the area.private static java.util.Optional<OnLineStrategy.HalfSegment>findOptimalWayPosition(java.awt.geom.Rectangle2D rect, MapViewPath path)java.util.List<java.awt.font.GlyphVector>generateGlyphVectors(MapViewPath path, java.awt.geom.Rectangle2D nb, java.util.List<java.awt.font.GlyphVector> gvs, boolean isDoubleTranslationBug)Generates the transformed glyph vectors for the given text.inthashCode()booleansupportsGlyphVector()Checks whether this placement strategy supports more detailed (rotation / ...) placement using a glyph vector.private static doubletheta(MapViewState.MapViewPoint start, MapViewState.MapViewPoint end)java.lang.StringtoString()private static doubleupsideTheta(OnLineStrategy.HalfSegment best)PositionForAreaStrategywithAddedOffset(java.awt.geom.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, java.awt.geom.Rectangle2D nb)
Description copied from interface:PositionForAreaStrategyFinds the correct position of a label / icon inside the area.- Specified by:
findLabelPlacementin 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.
nullif none was found.
-
upsideTheta
private static double upsideTheta(OnLineStrategy.HalfSegment best)
-
supportsGlyphVector
public boolean supportsGlyphVector()
Description copied from interface:PositionForAreaStrategyChecks whether this placement strategy supports more detailed (rotation / ...) placement using a glyph vector.- Specified by:
supportsGlyphVectorin interfacePositionForAreaStrategy- Returns:
trueif it is supported.
-
generateGlyphVectors
public java.util.List<java.awt.font.GlyphVector> generateGlyphVectors(MapViewPath path, java.awt.geom.Rectangle2D nb, java.util.List<java.awt.font.GlyphVector> gvs, boolean isDoubleTranslationBug)
Description copied from interface:PositionForAreaStrategyGenerates the transformed glyph vectors for the given text.- Specified by:
generateGlyphVectorsin interfacePositionForAreaStrategy- Parameters:
path- The path to place the text alongnb- The bounds of the textgvs- The glyph vectors for the text. May be modifiedisDoubleTranslationBug-trueto fix a glyph placement bug.- Returns:
- The glyph vectors.
-
computeOffsetGlyphs
private static java.util.List<OnLineStrategy.OffsetGlyph> computeOffsetGlyphs(java.util.List<java.awt.font.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 java.util.Optional<OnLineStrategy.HalfSegment> findOptimalWayPosition(java.awt.geom.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(java.awt.geom.Point2D addToOffset)
Description copied from interface:PositionForAreaStrategyCreate a new instance of the same strategy adding a offset- Specified by:
withAddedOffsetin interfacePositionForAreaStrategy- Parameters:
addToOffset- The offset to add- Returns:
- The new strategy
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-