[11748] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.mappaint.styleelement.placement;
|
---|
| 3 |
|
---|
| 4 | import java.awt.font.GlyphVector;
|
---|
[12476] | 5 | import java.awt.geom.Point2D;
|
---|
[11748] | 6 | import java.awt.geom.Rectangle2D;
|
---|
| 7 | import java.util.List;
|
---|
| 8 |
|
---|
| 9 | import org.openstreetmap.josm.gui.draw.MapViewPath;
|
---|
| 10 | import org.openstreetmap.josm.gui.draw.MapViewPositionAndRotation;
|
---|
| 11 | import org.openstreetmap.josm.gui.mappaint.Keyword;
|
---|
| 12 |
|
---|
| 13 | /**
|
---|
| 14 | * This strategy defines how to place a label or icon inside the area.
|
---|
| 15 | *
|
---|
| 16 | * @author Michael Zangl
|
---|
| 17 | * @since 11722
|
---|
| 18 | * @since 11748 moved to own file
|
---|
| 19 | */
|
---|
| 20 | public interface PositionForAreaStrategy {
|
---|
| 21 | /**
|
---|
| 22 | * Finds the correct position of a label / icon inside the area.
|
---|
| 23 | * @param path The area to search in
|
---|
| 24 | * @param nb The bounding box of the thing we are searching a place for.
|
---|
| 25 | * @return The position as rectangle with the same dimension as nb. <code>null</code> if none was found.
|
---|
| 26 | */
|
---|
| 27 | MapViewPositionAndRotation findLabelPlacement(MapViewPath path, Rectangle2D nb);
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * Checks whether this placement strategy supports more detailed (rotation / ...) placement using a glyph vector.
|
---|
| 31 | * @return <code>true</code> if it is supported.
|
---|
| 32 | */
|
---|
| 33 | boolean supportsGlyphVector();
|
---|
| 34 |
|
---|
| 35 | /**
|
---|
| 36 | * Generates the transformed glyph vectors for the given text.
|
---|
| 37 | * @param path The path to place the text along
|
---|
| 38 | * @param nb The bounds of the text
|
---|
| 39 | * @param gvs The glyph vectors for the text. May be modified
|
---|
| 40 | * @param isDoubleTranslationBug <code>true</code> to fix a glyph placement bug.
|
---|
| 41 | *
|
---|
[11754] | 42 | * @return The glyph vectors.
|
---|
| 43 | * @throws UnsupportedOperationException if {@link #supportsGlyphVector()} returns false
|
---|
[11748] | 44 | */
|
---|
| 45 | default List<GlyphVector> generateGlyphVectors(
|
---|
| 46 | MapViewPath path, Rectangle2D nb, List<GlyphVector> gvs, boolean isDoubleTranslationBug) {
|
---|
[11755] | 47 | throw new UnsupportedOperationException("Single glyph transformation is not supported by this implementation");
|
---|
[11748] | 48 | }
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | * Gets a strategy for the given keyword.
|
---|
| 52 | * @param keyword The text position keyword.
|
---|
| 53 | * @return The strategy or line if none was specified.
|
---|
| 54 | * @since 11722
|
---|
| 55 | */
|
---|
| 56 | static PositionForAreaStrategy forKeyword(Keyword keyword) {
|
---|
| 57 | return forKeyword(keyword, OnLineStrategy.INSTANCE);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | /**
|
---|
| 61 | * Gets a strategy for the given keyword.
|
---|
| 62 | * @param keyword The text position keyword.
|
---|
| 63 | * @param defaultStrategy The default if no strategy was recognized.
|
---|
| 64 | * @return The strategy or line if none was specified.
|
---|
| 65 | * @since 11722
|
---|
| 66 | */
|
---|
| 67 | static PositionForAreaStrategy forKeyword(Keyword keyword, PositionForAreaStrategy defaultStrategy) {
|
---|
| 68 | if (keyword == null) {
|
---|
| 69 | return defaultStrategy;
|
---|
| 70 | }
|
---|
| 71 | switch (keyword.val) {
|
---|
| 72 | case "center":
|
---|
| 73 | return PartiallyInsideAreaStrategy.INSTANCE;
|
---|
| 74 | case "inside":
|
---|
| 75 | return CompletelyInsideAreaStrategy.INSTANCE;
|
---|
| 76 | case "line":
|
---|
| 77 | return OnLineStrategy.INSTANCE;
|
---|
| 78 | default:
|
---|
| 79 | return defaultStrategy;
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
[12476] | 82 |
|
---|
| 83 | /**
|
---|
| 84 | * Create a new instance of the same strategy adding a offset
|
---|
| 85 | * @param addToOffset The offset to add
|
---|
| 86 | * @return The new strategy
|
---|
| 87 | * @since 12476
|
---|
| 88 | */
|
---|
| 89 | PositionForAreaStrategy withAddedOffset(Point2D addToOffset);
|
---|
[11748] | 90 | }
|
---|