1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.*;
|
---|
7 |
|
---|
8 | public class WayConnectionType {
|
---|
9 |
|
---|
10 | /** True, if the corresponding primitive is not a way or the way is incomplete */
|
---|
11 | private final boolean invalid;
|
---|
12 |
|
---|
13 | /** True, if linked to the previous / next member. */
|
---|
14 | public final boolean linkPrev;
|
---|
15 | public final boolean linkNext;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * direction is FORWARD if the first node of this way is connected to the previous way
|
---|
19 | * and / or the last node of this way is connected to the next way.
|
---|
20 | * direction is BACKWARD if it is the other way around.
|
---|
21 | * direction has a ROUNDABOUT value, if it is tagged as such and it is somehow
|
---|
22 | * connected to the previous / next member.
|
---|
23 | * If there is no connection to the previous or next member, then
|
---|
24 | * direction has the value NONE.
|
---|
25 | */
|
---|
26 | public final Direction direction;
|
---|
27 |
|
---|
28 | public enum Direction {
|
---|
29 | FORWARD, BACKWARD, ROUNDABOUT_LEFT, ROUNDABOUT_RIGHT, NONE;
|
---|
30 |
|
---|
31 | public boolean isRoundabout() {
|
---|
32 | return this == ROUNDABOUT_RIGHT || this == ROUNDABOUT_LEFT;
|
---|
33 | }
|
---|
34 | };
|
---|
35 |
|
---|
36 | /** True, if the element is part of a closed loop of ways. */
|
---|
37 | public boolean isLoop;
|
---|
38 |
|
---|
39 | public boolean isRoundabout = false;
|
---|
40 |
|
---|
41 | public WayConnectionType(boolean linkPrev, boolean linkNext, Direction direction) {
|
---|
42 | this.linkPrev = linkPrev;
|
---|
43 | this.linkNext = linkNext;
|
---|
44 | this.isLoop = false;
|
---|
45 | this.direction = direction;
|
---|
46 | invalid = false;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /** construct invalid instance */
|
---|
50 | public WayConnectionType() {
|
---|
51 | this.linkPrev = false;
|
---|
52 | this.linkNext = false;
|
---|
53 | this.isLoop = false;
|
---|
54 | this.direction = NONE;
|
---|
55 | invalid = true;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public boolean isValid() {
|
---|
59 | return !invalid;
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public String toString() {
|
---|
64 | return "[P "+linkPrev+" ;N "+linkNext+" ;D "+direction+" ;L "+isLoop+"]";
|
---|
65 | }
|
---|
66 |
|
---|
67 | public String getToolTip() {
|
---|
68 | if (!isValid()) {
|
---|
69 | return "";
|
---|
70 | }
|
---|
71 | else if (linkPrev && linkNext) {
|
---|
72 | return tr("way is connected");
|
---|
73 | }
|
---|
74 | else if (linkPrev) {
|
---|
75 | return tr("way is connected to previous relation member");
|
---|
76 | }
|
---|
77 | else if (linkNext) {
|
---|
78 | return tr("way is connected to next relation member");
|
---|
79 | }
|
---|
80 | else {
|
---|
81 | return tr("way is not connected to previous or next relation member");
|
---|
82 | }//FIXME: isLoop & direction
|
---|
83 | }
|
---|
84 | }
|
---|