Changeset 34994 in osm for applications/editors
- Timestamp:
- 2019-05-04T14:48:53+02:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/gui/LaneGui.java
r33085 r34994 312 312 area.reset(); 313 313 314 final double W = getContainer().getLaneWidth(); 314 double W = road.getContainer().getModel().isLeftDirection() ? -getContainer().getLaneWidth() : getContainer().getLaneWidth(); 315 315 316 final double L = getLength(); 316 317 -
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/gui/RoadGui.java
r34976 r34994 197 197 @Override 198 198 void paint(Graphics2D g2d, State state) { 199 if (!isVisible( state)) {199 if (!isVisible()) { 200 200 return; 201 201 } … … 214 214 } 215 215 216 private boolean isVisible( State state) {216 private boolean isVisible() { 217 217 return end.getJunction().isPrimary(); 218 218 } … … 220 220 @Override 221 221 boolean contains(Point2D p, State state) { 222 return isVisible( state) && background.contains(p);222 return isVisible() && background.contains(p); 223 223 } 224 224 … … 544 544 545 545 private Point2D getLeftCorner(Road.End end) { 546 return getCorner(end, true); 546 if (this.container.getModel().isLeftDirection()) { 547 return getCorner(end, false); 548 } else { 549 return getCorner(end, true); 550 } 547 551 } 548 552 549 553 private Point2D getRightCorner(Road.End end) { 550 return getCorner(end, false); 554 if (this.container.getModel().isLeftDirection()) { 555 return getCorner(end, true); 556 } else { 557 return getCorner(end, false); 558 } 551 559 } 552 560 553 561 private Point2D getCorner(Road.End end, boolean left) { 554 562 final JunctionGui j = end.isFromEnd() ? a : b; 555 final double w = left ? getWidth(end, true) : getWidth(end, false); 563 564 double w = left ? getWidth(end, false) : getWidth(end, true); 565 if (!this.container.getModel().isLeftDirection()) { 566 w = left ? getWidth(end, true) : getWidth(end, false); 567 } 568 556 569 final double s = (left ? 1 : -1); 557 570 final double a = getAngle(end) + PI; … … 598 611 g2d.setColor(Color.RED); 599 612 for (Segment s : segments) { 600 g2d.fill(new Ellipse2D.Double(s.from.getX() - 1, s.from.getY() - 1, 2, 2));613 g2d.fill(new Ellipse2D.Double(s.from.getX() - 0.5, s.from.getY() - 0.5, 1, 1)); 601 614 } 602 615 … … 621 634 622 635 private List<Extender> extenders(Road.End end) { 623 if (!end.isExtendable()) {624 return Collections.emptyList();625 }626 627 636 final List<Extender> result = new ArrayList<>(); 628 637 629 final Node n = end.getJunction().getNode(); 630 for (Way w : org.openstreetmap.josm.tools.Utils.filteredCollection(n.getReferrers(), Way.class)) { 631 if (w.getNodesCount() > 1 && !end.getWay().equals(w) && w.isFirstLastNode(n) && TurnlanesUtils.isRoad(w)) { 632 final Node nextNode = w.firstNode().equals(n) ? w.getNode(1) : w.getNode(w.getNodesCount() - 2); 633 final Point2D nextNodeLoc = getContainer().translateAndScale(loc(nextNode)); 634 result.add(new Extender(end, w, angle(a.getPoint(), nextNodeLoc))); 638 if (end.isExtendable()) { 639 final Node n = end.getJunction().getNode(); 640 for (Way w : org.openstreetmap.josm.tools.Utils.filteredCollection(n.getReferrers(), Way.class)) { 641 if (w.getNodesCount() > 1 && !end.getWay().equals(w) && w.isFirstLastNode(n) && TurnlanesUtils.isRoad(w)) { 642 final Node nextNode = w.firstNode().equals(n) ? w.getNode(1) : w.getNode(w.getNodesCount() - 2); 643 final Point2D nextNodeLoc = getContainer().translateAndScale(loc(nextNode)); 644 result.add(new Extender(end, w, angle(a.getPoint(), nextNodeLoc))); 645 } 635 646 } 636 647 } … … 668 679 middleArea = new Path2D.Double(); 669 680 middleArea.append(middleLines.getPathIterator(null), false); 670 middleArea.append(middlePath(backward).offset(outerMargin, -1, -1, outerMargin).getIterator(), true); 681 if (this.container.getModel().isLeftDirection()) { 682 middleArea.append(middlePath(backward).offset(-outerMargin, -1, -1, -outerMargin).getIterator(), true); 683 } else { 684 middleArea.append(middlePath(backward).offset(outerMargin, -1, -1, outerMargin).getIterator(), true); 685 } 671 686 middleArea.closePath(); 672 687 g2d.setColor(Color.GRAY); … … 707 722 final Path middle = middlePath(forward); 708 723 709 Path innerPath = middle.offset(innerMargin, -1, -1, innerMargin); 724 Path innerPath; 725 if (this.container.getModel().isLeftDirection()) { 726 innerPath = middle.offset(-innerMargin, -1, -1, -innerMargin); 727 } else { 728 innerPath = middle.offset(innerMargin, -1, -1, innerMargin); 729 } 730 710 731 final List<Path> linePaths = new ArrayList<>(); 711 732 linePaths.add(innerPath); … … 718 739 719 740 final Path2D area = new Path2D.Double(); 720 area(area, middle, innerPath.offset(outerMargin, -1, -1, outerMargin)); 741 if (this.container.getModel().isLeftDirection()) { 742 area(area, middle, innerPath.offset(-outerMargin, -1, -1, -outerMargin)); 743 } else { 744 area(area, middle, innerPath.offset(outerMargin, -1, -1, outerMargin)); 745 } 721 746 g2d.setColor(Color.GRAY); 722 747 g2d.fill(area); … … 786 811 public Path getLaneMiddle(boolean forward) { 787 812 final Path mid = middlePath(!forward); 788 final double w = getWidth(forward ? getModel().getFromEnd() : getModel().getToEnd(), true); 789 final double o = (w - outerMargin) / 2; 813 814 double w = getWidth(forward ? getModel().getFromEnd() : getModel().getToEnd(), true); 815 double o = (w + outerMargin) / 2; 816 if (this.container.getModel().isLeftDirection()) { 817 w = -getWidth(forward ? getModel().getFromEnd() : getModel().getToEnd(), false); 818 o = (w - outerMargin) / 2; 819 } 790 820 791 821 return o > 0 ? mid.offset(-o, -1, -1, -o) : mid; -
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/gui/TurnLanesDialog.java
r34926 r34994 6 6 import java.awt.BorderLayout; 7 7 import java.awt.CardLayout; 8 import java.awt.GridBagConstraints; 8 9 import java.awt.GridLayout; 9 10 import java.awt.event.ActionEvent; … … 13 14 14 15 import javax.swing.ButtonGroup; 16 import javax.swing.JCheckBox; 17 import javax.swing.JLabel; 15 18 import javax.swing.JPanel; 16 19 import javax.swing.JToggleButton; … … 132 135 133 136 private final JPanel body = new JPanel(); 137 138 134 139 private final JunctionPane junctionPane = new JunctionPane(GuiContainer.empty()); 135 140 … … 141 146 private boolean editing = true; 142 147 private boolean wasShowing = false; 148 149 private ModelContainer modelContainer; 150 private boolean leftDirection = ModelContainer.empty().isLeftDirection(); 143 151 144 152 public TurnLanesDialog() { … … 152 160 group.add(editButton); 153 161 group.add(validateButton); 162 addTrafficDirectionCheckBox(buttonPanel); 154 163 buttonPanel.add(editButton); 155 164 buttonPanel.add(validateButton); … … 164 173 165 174 editButton.doClick(); 175 } 176 177 /** 178 * Add label and checkbox for traffic direction and change flag 179 * @param buttonPanel button panel 180 */ 181 private void addTrafficDirectionCheckBox(JPanel buttonPanel) { 182 GridBagConstraints constraints = new GridBagConstraints(); 183 JLabel aoiLabel = new JLabel(tr("Left-hand traffic direction:")); 184 constraints.gridx = 0; 185 constraints.gridwidth = 1; //next-to-last 186 constraints.fill = GridBagConstraints.NONE; //reset to default 187 constraints.weightx = 0.0; 188 buttonPanel.add(aoiLabel, constraints); 189 190 constraints.gridx = 1; 191 constraints.gridwidth = GridBagConstraints.REMAINDER; //end row 192 constraints.fill = GridBagConstraints.HORIZONTAL; 193 constraints.weightx = 1.0; 194 JCheckBox leftDirectionCheckbox = new JCheckBox(); 195 leftDirectionCheckbox.setSelected(leftDirection); 196 buttonPanel.add(leftDirectionCheckbox, constraints); 197 leftDirectionCheckbox.addChangeListener(e -> { 198 if (modelContainer == null) { 199 return; 200 } 201 leftDirection = leftDirectionCheckbox.isSelected(); 202 refresh(); 203 }); 204 166 205 } 167 206 … … 179 218 final Collection<Way> ways = org.openstreetmap.josm.tools.Utils.filteredCollection(selected, Way.class); 180 219 181 final ModelContainer mc= nodes.isEmpty() ? ModelContainer.empty() : ModelContainer220 modelContainer = nodes.isEmpty() ? ModelContainer.empty() : ModelContainer 182 221 .createEmpty(nodes, ways); 183 184 junctionPane.setJunction(new GuiContainer(mc)); 222 modelContainer.setLeftDirection(leftDirection); 223 224 junctionPane.setJunction(new GuiContainer(modelContainer)); 185 225 } 186 226 } -
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model/ModelContainer.java
r34976 r34994 21 21 22 22 public final class ModelContainer { 23 24 //set default direction of traffic for connecting lanes 25 private static final boolean DEFAULT_LEFT_DIRECTION = false; 26 23 27 private static final ModelContainer EMPTY = new ModelContainer(Collections.<Node>emptySet(), 24 Collections.<Way>emptySet(), false );28 Collections.<Way>emptySet(), false, DEFAULT_LEFT_DIRECTION); 25 29 26 30 public static ModelContainer create(Iterable<Node> primaryNodes, Iterable<Way> primaryWays) { 27 31 return new ModelContainer(new HashSet<>(CollectionUtils.toList(primaryNodes)), new HashSet<>( 28 CollectionUtils.toList(primaryWays)), false );32 CollectionUtils.toList(primaryWays)), false, DEFAULT_LEFT_DIRECTION); 29 33 } 30 34 31 35 public static ModelContainer createEmpty(Iterable<Node> primaryNodes, Iterable<Way> primaryWays) { 32 36 return new ModelContainer(new HashSet<>(CollectionUtils.toList(primaryNodes)), new HashSet<>( 33 CollectionUtils.toList(primaryWays)), true );37 CollectionUtils.toList(primaryWays)), true, DEFAULT_LEFT_DIRECTION); 34 38 } 35 39 … … 122 126 private final boolean empty; 123 127 124 private ModelContainer(Set<Node> primaryNodes, Set<Way> primaryWays, boolean empty) { 128 private boolean leftDirection; 129 130 private ModelContainer(Set<Node> primaryNodes, Set<Way> primaryWays, boolean empty, boolean leftDirection) { 125 131 if (empty) { 126 132 this.primaryNodes = Collections.unmodifiableSet(new HashSet<>(primaryNodes)); … … 152 158 this.empty = junctions.isEmpty(); 153 159 } 160 this.leftDirection = leftDirection; 154 161 } 155 162 … … 283 290 284 291 public ModelContainer recalculate() { 285 return new ModelContainer(primaryNodes, primaryWays, false );292 return new ModelContainer(primaryNodes, primaryWays, false, leftDirection); 286 293 } 287 294 … … 298 305 } 299 306 307 public boolean isLeftDirection() { 308 return leftDirection; 309 } 310 311 public void setLeftDirection(boolean leftDirection) { 312 this.leftDirection = leftDirection; 313 } 314 300 315 public boolean hasRoad(Way w) { 301 316 return roads.containsKey(w); -
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model/Validator.java
r34976 r34994 7 7 import java.util.Arrays; 8 8 import java.util.BitSet; 9 import java.util.Collections;10 9 import java.util.HashMap; 11 10 import java.util.HashSet; … … 363 362 private List<Integer> splitInts(Relation r, String key, List<Issue> issues) { 364 363 final String ints = r.get(key); 365 366 if (ints == null) {367 return Collections.emptyList();368 }369 370 364 final List<Integer> result = new ArrayList<>(); 371 365 372 for (String s : Constants.SPLIT_PATTERN.split(ints)) { 373 try { 374 int i = Integer.parseInt(s.trim()); 375 result.add(Integer.valueOf(i)); 376 } catch (NumberFormatException e) { 377 issues.add(Issue.newError(r, tr("Integer list \"{0}\" contains unexpected values.", key))); 366 if (ints != null) { 367 for (String s : Constants.SPLIT_PATTERN.split(ints)) { 368 try { 369 int i = Integer.parseInt(s.trim()); 370 result.add(Integer.valueOf(i)); 371 } catch (NumberFormatException e) { 372 issues.add(Issue.newError(r, tr("Integer list \"{0}\" contains unexpected values.", key))); 373 } 378 374 } 379 375 }
Note:
See TracChangeset
for help on using the changeset viewer.