source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionType.java@ 7937

Last change on this file since 7937 was 5630, checked in by jttt, 11 years ago

Relation sorting and way connection refactored, added tests

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