1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.styleelement.placement;
|
---|
3 |
|
---|
4 | import java.awt.geom.Rectangle2D;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.gui.draw.MapViewPath;
|
---|
7 | import org.openstreetmap.josm.gui.draw.MapViewPositionAndRotation;
|
---|
8 |
|
---|
9 | /**
|
---|
10 | * A strategy that places the label / icon so that is is on the area.
|
---|
11 | *
|
---|
12 | * The center of that place should be in the area, but the icon / label may overlap on the edges.
|
---|
13 | *
|
---|
14 | * @author Michael Zangl
|
---|
15 | * @since 11722
|
---|
16 | * @since 11748 moved to own file
|
---|
17 | */
|
---|
18 | public final class PartiallyInsideAreaStrategy extends CompletelyInsideAreaStrategy {
|
---|
19 | /**
|
---|
20 | * An instance of this class.
|
---|
21 | */
|
---|
22 | public static final PartiallyInsideAreaStrategy INSTANCE = new PartiallyInsideAreaStrategy();
|
---|
23 |
|
---|
24 | private PartiallyInsideAreaStrategy() {
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public MapViewPositionAndRotation findLabelPlacement(MapViewPath path, Rectangle2D nb) {
|
---|
29 | MapViewPositionAndRotation inside = super.findLabelPlacement(path, nb);
|
---|
30 | if (inside != null) {
|
---|
31 | return inside;
|
---|
32 | }
|
---|
33 |
|
---|
34 | double nbdx = Math.max(0, (nb.getWidth() - 20) / 2);
|
---|
35 | double nbdy = Math.max(0, (nb.getHeight() - 10) / 2);
|
---|
36 |
|
---|
37 | if (nbdx < .5 && nbdy < .5) {
|
---|
38 | // we can't do any better
|
---|
39 | return null;
|
---|
40 | } else {
|
---|
41 | Rectangle2D smallNb = new Rectangle2D.Double(nb.getX() + nbdx, nb.getY() + nbdy,
|
---|
42 | nb.getWidth() - 2 * nbdx, nb.getHeight() - 2 * nbdy);
|
---|
43 | return super.findLabelPlacement(path, smallNb);
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|