source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/placement/PositionForAreaStrategy.java@ 11754

Last change on this file since 11754 was 11754, checked in by michael2402, 7 years ago

Throw UnsupportedOperationException if implementation does not support glyph rotation.

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