Changeset 3928 in josm for trunk/src/org
- Timestamp:
- 2011-02-23T21:45:50+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r3925 r3928 2 2 package org.openstreetmap.josm.gui.dialogs.relation; 3 3 4 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.*; 4 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.BACKWARD; 5 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.FORWARD; 6 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.NONE; 7 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.ROUNDABOUT_LEFT; 8 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.ROUNDABOUT_RIGHT; 5 9 6 10 import java.util.ArrayList; … … 377 381 } 378 382 379 p ublic void addMembersAtBeginning(List<OsmPrimitive> primitives) {383 private void addMembersAtIndex(List<? extends OsmPrimitive> primitives, int index) { 380 384 if (primitives == null) 381 385 return; 382 int index = 0; 383 for (OsmPrimitive primitive : primitives) { 384 RelationMember member = new RelationMember("", primitive); 385 members.add(index++, member); 386 } 387 fireTableDataChanged(); 388 getSelectionModel().clearSelection(); 389 for (int i = 0; i < primitives.size(); i++) { 390 getSelectionModel().addSelectionInterval(i, i); 391 } 392 fireMakeMemberVisible(0); 393 } 394 395 public void addMembersAtEnd(List<? extends OsmPrimitive> primitives) { 396 if (primitives == null) 397 return; 398 399 for (OsmPrimitive primitive : primitives) { 400 RelationMember member = new RelationMember("", primitive); 401 members.add(member); 402 } 403 fireTableDataChanged(); 404 getSelectionModel().clearSelection(); 405 for (int i = 0; i < primitives.size(); i++) { 406 getSelectionModel().addSelectionInterval(members.size() - 1 - i, members.size() - 1 - i); 407 } 408 fireMakeMemberVisible(members.size() - 1); 409 } 410 411 public void addMembersBeforeIdx(List<? extends OsmPrimitive> primitives, int idx) { 412 if (primitives == null) 413 return; 414 386 int idx = index; 415 387 for (OsmPrimitive primitive : primitives) { 416 388 RelationMember member = new RelationMember("", primitive); … … 418 390 } 419 391 fireTableDataChanged(); 420 getSelectionModel().setValueIsAdjusting(true);421 392 getSelectionModel().clearSelection(); 422 for (int i = 0; i < primitives.size(); i++) { 423 getSelectionModel().addSelectionInterval(idx + i, idx + i); 424 } 425 getSelectionModel().setValueIsAdjusting(false); 426 fireMakeMemberVisible(idx); 393 getSelectionModel().addSelectionInterval(index, index + primitives.size() - 1); 394 fireMakeMemberVisible(index); 395 } 396 397 public void addMembersAtBeginning(List<? extends OsmPrimitive> primitives) { 398 addMembersAtIndex(primitives, 0); 399 } 400 401 public void addMembersAtEnd(List<? extends OsmPrimitive> primitives) { 402 addMembersAtIndex(primitives, members.size()); 403 } 404 405 public void addMembersBeforeIdx(List<? extends OsmPrimitive> primitives, int idx) { 406 addMembersAtIndex(primitives, idx); 427 407 } 428 408 429 409 public void addMembersAfterIdx(List<? extends OsmPrimitive> primitives, int idx) { 430 if (primitives == null) 431 return; 432 int j = 1; 433 for (OsmPrimitive primitive : primitives) { 434 RelationMember member = new RelationMember("", primitive); 435 members.add(idx + j, member); 436 j++; 437 } 438 fireTableDataChanged(); 439 getSelectionModel().setValueIsAdjusting(true); 440 getSelectionModel().clearSelection(); 441 for (int i = 0; i < primitives.size(); i++) { 442 getSelectionModel().addSelectionInterval(idx + 1 + i, idx + 1 + i); 443 } 444 getSelectionModel().setValueIsAdjusting(false); 445 fireMakeMemberVisible(idx + 1); 410 addMembersAtIndex(primitives, idx + 1); 446 411 } 447 412 … … 962 927 final RelationMember m = members.get(i); 963 928 if (!m.isWay() || m.getWay() == null || m.getWay().isIncomplete()) { 964 if(i > 0) makeLoopIfNeeded(con, i-1); 929 if(i > 0) { 930 makeLoopIfNeeded(con, i-1); 931 } 965 932 con.set(i, new WayConnectionType()); 966 933 firstGroupIdx = i; 967 934 continue; 968 935 } 969 936 970 937 WayConnectionType wct = new WayConnectionType(false); 971 938 wct.linkPrev = i>0 && con.get(i-1) != null && con.get(i-1).isValid(); … … 973 940 974 941 if(isOneway(m)){ 975 if(lastWct != null && lastWct.isOnewayTail) 942 if(lastWct != null && lastWct.isOnewayTail) { 976 943 wct.isOnewayHead = true; 944 } 977 945 if(lastBackwardWay == UNCONNECTED && lastForwardWay == UNCONNECTED){ //Beginning of new oneway 978 946 wct.isOnewayHead = true; … … 981 949 onewayBeginning = true; 982 950 } 983 } 951 } 984 952 985 953 if (wct.linkPrev) { 986 954 if(lastBackwardWay != UNCONNECTED && lastForwardWay != UNCONNECTED) { 987 955 wct = determineOnewayConnectionType(con, m, i, wct); 988 if(!wct.linkPrev) 956 if(!wct.linkPrev) { 989 957 firstGroupIdx = i; 958 } 990 959 } 991 960 … … 993 962 wct.direction = determineDirection(i-1, lastWct.direction, i); 994 963 wct.linkPrev = (wct.direction != NONE); 995 } 996 } 997 964 } 965 } 966 998 967 if (!wct.linkPrev) { 999 968 wct.direction = determineDirectionOfFirst(i, m); … … 1005 974 1006 975 wct.linkNext = false; 1007 if(lastWct != null) 976 if(lastWct != null) { 1008 977 lastWct.linkNext = wct.linkPrev; 978 } 1009 979 con.set(i, wct); 1010 980 lastWct = wct; 1011 981 1012 982 if(!wct.linkPrev) { 1013 if(i > 0) makeLoopIfNeeded(con, i-1); 983 if(i > 0) { 984 makeLoopIfNeeded(con, i-1); 985 } 1014 986 firstGroupIdx = i; 1015 987 } … … 1019 991 } 1020 992 1021 // private static void unconnectPreviousLink(List<WayConnectionType> con, int beg, boolean backward){1022 // int i = beg;1023 // while(true){1024 // WayConnectionType t = con.get(i--);1025 // t.isOnewayOppositeConnected = false;1026 // if(backward && t.isOnewayLoopBackwardPart) break;1027 // if(!backward && t.isOnewayLoopForwardPart) break;1028 // }1029 // }993 // private static void unconnectPreviousLink(List<WayConnectionType> con, int beg, boolean backward){ 994 // int i = beg; 995 // while(true){ 996 // WayConnectionType t = con.get(i--); 997 // t.isOnewayOppositeConnected = false; 998 // if(backward && t.isOnewayLoopBackwardPart) break; 999 // if(!backward && t.isOnewayLoopForwardPart) break; 1000 // } 1001 // } 1030 1002 1031 1003 private static Direction reverse(final Direction dir){ … … 1042 1014 return member.getRole().equals("forward"); 1043 1015 } 1044 1016 1045 1017 public static boolean isOneway(final RelationMember member){ 1046 1018 return isForward(member) || isBackward(member); … … 1063 1035 1064 1036 private Direction determineDirectionOfFirst(final int i, final RelationMember m) { 1065 if (roundaboutType(i) != NONE) {1037 if (roundaboutType(i) != NONE) 1066 1038 return roundaboutType(i); 1067 } 1068 1039 1069 1040 if (isOneway(m)){ 1070 1041 if(isBackward(m)) return BACKWARD; … … 1084 1055 Direction dirBW = NONE; 1085 1056 if(onewayBeginning) { 1086 if(lastBackwardWay < 0) 1057 if(lastBackwardWay < 0) { 1087 1058 dirBW = determineDirection(firstGroupIdx, reverse(con.get(firstGroupIdx).direction), i, true); 1088 else1059 } else { 1089 1060 dirBW = determineDirection(lastBackwardWay, con.get(lastBackwardWay).direction, i, true); 1090 1091 if(dirBW != NONE) 1061 } 1062 1063 if(dirBW != NONE) { 1092 1064 onewayBeginning = false; 1093 } else 1065 } 1066 } else { 1094 1067 dirBW = determineDirection(lastBackwardWay, con.get(lastBackwardWay).direction, i, true); 1068 } 1095 1069 1096 1070 if(isOneway(m)) { … … 1106 1080 } 1107 1081 if(dirFW == NONE && dirBW == NONE) { //Not connected to previous 1108 // unconnectPreviousLink(con, i, true);1109 // unconnectPreviousLink(con, i, false);1082 // unconnectPreviousLink(con, i, true); 1083 // unconnectPreviousLink(con, i, false); 1110 1084 wct.linkPrev = false; 1111 1085 if(isOneway(m)){ … … 1137 1111 lastForwardWay = UNCONNECTED; 1138 1112 lastBackwardWay = UNCONNECTED; 1139 if(dirFW == NONE || dirBW == NONE) 1113 if(dirFW == NONE || dirBW == NONE) { 1140 1114 wct.linkPrev = false; 1115 } 1141 1116 } 1142 1117 return wct;
Note:
See TracChangeset
for help on using the changeset viewer.