Changeset 20772 in osm for applications/editors/josm
- Timestamp:
- 2010-04-02T04:37:48+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/public_transport/src/public_transport
- Files:
-
- 8 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/public_transport/src/public_transport/StopImporterAction.java
r20752 r20772 60 60 61 61 public class StopImporterAction extends JosmAction 62 { 63 private class TrackReference 64 implements Comparable< TrackReference >, TableModelListener 65 { 66 public GpxTrack track; 67 public StoplistTableModel stoplistTM; 68 public String stopwatchStart; 69 public String gpsStartTime; 70 public String gpsSyncTime; 71 public double timeWindow; 72 public double threshold; 73 74 public TrackReference(GpxTrack track) 75 { 76 this.track = track; 77 this.stoplistTM = new StoplistTableModel(this); 78 this.stopwatchStart = "00:00:00"; 79 this.gpsStartTime = null; 80 this.gpsSyncTime = null; 81 if (track != null) 82 { 83 Iterator< GpxTrackSegment > siter = track.getSegments().iterator(); 84 while ((siter.hasNext()) && (this.gpsSyncTime == null)) 85 { 86 Iterator< WayPoint > witer = siter.next().getWayPoints().iterator(); 87 if (witer.hasNext()) 88 { 89 this.gpsStartTime = witer.next().getString("time"); 90 if (this.gpsStartTime != null) 91 this.gpsSyncTime = this.gpsStartTime.substring(11, 19); 92 } 93 } 94 if (this.gpsSyncTime == null) 95 { 96 JOptionPane.showMessageDialog 97 (null, "The GPX file doesn't contain valid trackpoints. " 98 + "Please use a GPX file that has trackpoints.", "GPX File Trouble", 99 JOptionPane.ERROR_MESSAGE); 100 101 this.gpsStartTime = "1970-01-01T00:00:00Z"; 102 this.gpsSyncTime = this.stopwatchStart; 103 } 104 } 105 else 106 this.gpsSyncTime = this.stopwatchStart; 107 this.timeWindow = 20; 108 this.threshold = 20; 109 } 110 111 public int compareTo(TrackReference tr) 112 { 113 String name = (String)track.getAttributes().get("name"); 114 String tr_name = (String)tr.track.getAttributes().get("name"); 115 if (name != null) 116 { 117 if (tr_name == null) 118 return -1; 119 return name.compareTo(tr_name); 120 } 121 return 1; 122 } 123 124 public String toString() 125 { 126 String buf = (String)track.getAttributes().get("name"); 127 if (buf == null) 128 return "unnamed"; 129 return buf; 130 } 131 132 public void tableChanged(TableModelEvent e) 133 { 134 if (e.getType() == TableModelEvent.UPDATE) 135 { 136 double time = StopImporterDialog.parseTime 137 ((String)stoplistTM.getValueAt(e.getFirstRow(), 0)); 138 if (time < 0) 139 { 140 JOptionPane.showMessageDialog 141 (null, "Can't parse a time from this string.", "Invalid value", 142 JOptionPane.ERROR_MESSAGE); 143 return; 144 } 145 146 LatLon latLon = computeCoor(time); 147 148 if (stoplistTM.nodes.elementAt(e.getFirstRow()) == null) 149 { 150 Node node = createNode 151 (latLon, (String)stoplistTM.getValueAt(e.getFirstRow(), 1)); 152 stoplistTM.nodes.set(e.getFirstRow(), node); 153 } 154 else 155 { 156 Node node = new Node(stoplistTM.nodes.elementAt(e.getFirstRow())); 157 node.setCoor(latLon); 158 node.put("name", (String)stoplistTM.getValueAt(e.getFirstRow(), 1)); 159 Command cmd = new ChangeCommand(stoplistTM.nodes.elementAt(e.getFirstRow()), node); 160 if (cmd != null) { 161 Main.main.undoRedo.add(cmd); 162 } 163 } 164 } 165 } 166 167 public LatLon computeCoor(double time) 168 { 169 double gpsSyncTime = StopImporterDialog.parseTime(this.gpsSyncTime); 170 double dGpsStartTime = StopImporterDialog.parseTime(gpsStartTime); 171 if (gpsSyncTime < dGpsStartTime - 12*60*60) 172 gpsSyncTime += 24*60*60; 173 double timeDelta = gpsSyncTime - StopImporterDialog.parseTime(stopwatchStart); 174 time += timeDelta; 175 176 WayPoint wayPoint = null; 177 WayPoint lastWayPoint = null; 178 double wayPointTime = 0; 179 double lastWayPointTime = 0; 180 Iterator< GpxTrackSegment > siter = track.getSegments().iterator(); 181 while (siter.hasNext()) 182 { 183 Iterator< WayPoint > witer = siter.next().getWayPoints().iterator(); 184 while (witer.hasNext()) 185 { 186 wayPoint = witer.next(); 187 String startTime = wayPoint.getString("time"); 188 wayPointTime = StopImporterDialog.parseTime(startTime.substring(11, 19)); 189 if (startTime.substring(11, 19).compareTo(gpsStartTime.substring(11, 19)) == -1) 190 wayPointTime += 24*60*60; 191 if (wayPointTime >= time) 192 break; 193 lastWayPoint = wayPoint; 194 lastWayPointTime = wayPointTime; 195 } 196 if (wayPointTime >= time) 197 break; 198 } 199 200 double lat = 0; 201 if ((wayPointTime == lastWayPointTime) || (lastWayPoint == null)) 202 lat = wayPoint.getCoor().lat(); 203 else 204 lat = wayPoint.getCoor().lat() 205 *(time - lastWayPointTime)/(wayPointTime - lastWayPointTime) 206 + lastWayPoint.getCoor().lat() 207 *(wayPointTime - time)/(wayPointTime - lastWayPointTime); 208 double lon = 0; 209 if ((wayPointTime == lastWayPointTime) || (lastWayPoint == null)) 210 lon = wayPoint.getCoor().lon(); 211 else 212 lon = wayPoint.getCoor().lon() 213 *(time - lastWayPointTime)/(wayPointTime - lastWayPointTime) 214 + lastWayPoint.getCoor().lon() 215 *(wayPointTime - time)/(wayPointTime - lastWayPointTime); 216 217 return new LatLon(lat, lon); 218 } 219 220 public void relocateNodes() 221 { 222 for (int i = 0; i < stoplistTM.nodes.size(); ++i) 223 { 224 Node node = stoplistTM.nodes.elementAt(i); 225 if (node == null) 226 continue; 227 228 double time = StopImporterDialog.parseTime 229 ((String)stoplistTM.getValueAt(i, 0)); 230 LatLon latLon = computeCoor(time); 231 232 Node newNode = new Node(node); 233 newNode.setCoor(latLon); 234 Command cmd = new ChangeCommand(node, newNode); 235 if (cmd != null) 236 { 237 Main.main.undoRedo.add(cmd); 238 } 239 } 240 } 241 242 public void suggestStops() 243 { 244 Vector< WayPoint > wayPoints = new Vector< WayPoint >(); 245 Iterator< GpxTrackSegment > siter = track.getSegments().iterator(); 246 while (siter.hasNext()) 247 { 248 Iterator< WayPoint > witer = siter.next().getWayPoints().iterator(); 249 while (witer.hasNext()) 250 wayPoints.add(witer.next()); 251 } 252 Vector< Double > wayPointsDist = new Vector< Double >(wayPoints.size()); 253 254 int i = 0; 255 double time = -48*60*60; 256 double dGpsStartTime = StopImporterDialog.parseTime(gpsStartTime); 257 while ((i < wayPoints.size()) && (time < dGpsStartTime + timeWindow/2)) 258 { 259 if (wayPoints.elementAt(i).getString("time") != null) 260 time = StopImporterDialog.parseTime(wayPoints.elementAt(i) 261 .getString("time").substring(11,19)); 262 if (time < dGpsStartTime) 263 time += 24*60*60; 264 wayPointsDist.add(Double.valueOf(Double.POSITIVE_INFINITY)); 265 ++i; 266 } 267 while (i < wayPoints.size()) 268 { 269 int j = i; 270 double time2 = time; 271 while ((j > 0) && (time - timeWindow/2 < time2)) 272 { 273 --j; 274 if (wayPoints.elementAt(j).getString("time") != null) 275 time2 = StopImporterDialog.parseTime(wayPoints.elementAt(j) 276 .getString("time").substring(11,19)); 277 if (time2 < dGpsStartTime) 278 time2 += 24*60*60; 279 } 280 int k = i + 1; 281 time2 = time; 282 while ((k < wayPoints.size()) && (time + timeWindow/2 > time2)) 283 { 284 if (wayPoints.elementAt(k).getString("time") != null) 285 time2 = StopImporterDialog.parseTime(wayPoints.elementAt(k) 286 .getString("time").substring(11,19)); 287 if (time2 < dGpsStartTime) 288 time2 += 24*60*60; 289 ++k; 290 } 291 292 if (j < k) 293 { 294 double dist = 0; 295 LatLon latLonI = wayPoints.elementAt(i).getCoor(); 296 for (int l = j; l < k; ++l) 297 { 298 double distL = latLonI.greatCircleDistance(wayPoints.elementAt(l).getCoor()); 299 if (distL > dist) 300 dist = distL; 301 } 302 wayPointsDist.add(Double.valueOf(dist)); 303 } 304 else 305 wayPointsDist.add(Double.valueOf(Double.POSITIVE_INFINITY)); 306 307 if (wayPoints.elementAt(i).getString("time") != null) 308 time = StopImporterDialog.parseTime(wayPoints.elementAt(i) 309 .getString("time").substring(11,19)); 310 if (time < dGpsStartTime) 311 time += 24*60*60; 312 ++i; 313 } 314 315 Vector< Node > toDelete = new Vector< Node >(); 316 for (i = 0; i < stoplistTM.getRowCount(); ++i) 317 { 318 if ((Node)stoplistTM.nodes.elementAt(i) != null) 319 toDelete.add((Node)stoplistTM.nodes.elementAt(i)); 320 } 321 if (!toDelete.isEmpty()) 322 { 323 Command cmd = DeleteCommand.delete 324 (Main.main.getEditLayer(), toDelete); 325 if (cmd == null) 326 return; 327 Main.main.undoRedo.add(cmd); 328 } 329 stoplistTM.clear(); 330 331 LatLon lastStopCoor = null; 332 for (i = 1; i < wayPoints.size()-1; ++i) 333 { 334 if (wayPointsDist.elementAt(i).doubleValue() >= threshold) 335 continue; 336 if ((wayPointsDist.elementAt(i).compareTo(wayPointsDist.elementAt(i-1)) != -1) 337 || (wayPointsDist.elementAt(i).compareTo(wayPointsDist.elementAt(i+1)) != -1)) 338 continue; 339 340 LatLon latLon = wayPoints.elementAt(i).getCoor(); 341 if ((lastStopCoor != null) && (lastStopCoor.greatCircleDistance(latLon) < threshold)) 342 continue; 343 344 if (wayPoints.elementAt(i).getString("time") != null) 345 { 346 time = StopImporterDialog.parseTime(wayPoints.elementAt(i) 347 .getString("time").substring(11,19)); 348 double gpsSyncTime = StopImporterDialog.parseTime(this.gpsSyncTime); 349 if (gpsSyncTime < dGpsStartTime - 12*60*60) 350 gpsSyncTime += 24*60*60; 351 double timeDelta = gpsSyncTime - StopImporterDialog.parseTime(stopwatchStart); 352 time -= timeDelta; 353 stoplistTM.insertRow(-1, timeOf(time)); 354 Node node = createNode(latLon, ""); 355 stoplistTM.nodes.set(stoplistTM.getRowCount()-1, node); 356 } 357 358 lastStopCoor = latLon; 359 } 360 } 361 }; 362 363 private class NodeSortEntry implements Comparable< NodeSortEntry > 364 { 365 public Node node = null; 366 public String time = null; 367 public String name = null; 368 public double startTime = 0; 369 370 public NodeSortEntry(Node node, String time, String name, double startTime) 371 { 372 this.node = node; 373 this.time = time; 374 this.name = name; 375 } 376 377 public int compareTo(NodeSortEntry nse) 378 { 379 double time = StopImporterDialog.parseTime(this.time); 380 if (time - startTime > 12*60*60) 381 time -= 24*60*60; 382 383 double nseTime = StopImporterDialog.parseTime(nse.time); 384 if (nseTime - startTime > 12*60*60) 385 nseTime -= 24*60*60; 386 387 if (time < nseTime) 388 return -1; 389 else if (time > nseTime) 390 return 1; 391 else 392 return 0; 393 } 394 }; 395 396 private class StoplistTableModel extends DefaultTableModel 397 { 398 public Vector< Node > nodes = new Vector< Node >(); 399 400 public StoplistTableModel(TrackReference tr) 401 { 402 addColumn("Time"); 403 addColumn("Name"); 404 addTableModelListener(tr); 405 } 406 407 public boolean isCellEditable(int row, int column) { 408 return true; 409 } 410 411 public void addRow(Object[] obj) { 412 throw new UnsupportedOperationException(); 413 } 414 415 public void insertRow(int insPos, Object[] obj) { 416 throw new UnsupportedOperationException(); 417 } 418 419 public void addRow(String time) { 420 insertRow(-1, time); 421 } 422 423 public void insertRow(int insPos, String time) 424 { 425 insertRow(insPos, null, time, ""); 426 } 427 428 public void insertRow(int insPos, Node node, String time, String name) 429 { 430 String[] buf = { "", "" }; 431 buf[0] = time; 432 buf[1] = name; 433 if (insPos == -1) 434 { 435 nodes.addElement(node); 436 super.addRow(buf); 437 } 438 else 439 { 440 nodes.insertElementAt(node, insPos); 441 super.insertRow(insPos, buf); 442 } 443 } 444 445 public void clear() 446 { 447 nodes.clear(); 448 super.setRowCount(0); 449 } 450 }; 451 452 public class WaypointTableModel extends DefaultTableModel 453 implements TableModelListener 454 { 455 public Vector< Node > nodes = new Vector< Node >(); 456 public Vector< LatLon > coors = new Vector< LatLon >(); 457 458 public WaypointTableModel() 459 { 460 addColumn("Time"); 461 addColumn("Stopname"); 462 addTableModelListener(this); 463 } 464 465 public boolean isCellEditable(int row, int column) 466 { 467 if (column == 1) 468 return true; 469 return false; 470 } 471 472 public void addRow(Object[] obj) 473 { 474 throw new UnsupportedOperationException(); 475 } 476 477 public void insertRow(int insPos, Object[] obj) 478 { 479 throw new UnsupportedOperationException(); 480 } 481 482 public void addRow(WayPoint wp) 483 { 484 insertRow(-1, wp); 485 } 486 487 public void insertRow(int insPos, WayPoint wp) 488 { 489 String[] buf = { "", "" }; 490 buf[0] = wp.getString("time"); 491 if (buf[0] == null) 492 buf[0] = ""; 493 buf[1] = wp.getString("name"); 494 if (buf[1] == null) 495 buf[1] = ""; 496 497 Node node = createNode(wp.getCoor(), buf[1]); 498 499 if (insPos == -1) 500 { 501 nodes.addElement(node); 502 coors.addElement(wp.getCoor()); 503 super.addRow(buf); 504 } 505 else 506 { 507 nodes.insertElementAt(node, insPos); 508 coors.insertElementAt(wp.getCoor(), insPos); 509 super.insertRow(insPos, buf); 510 } 511 } 512 513 public void clear() 514 { 515 nodes.clear(); 516 super.setRowCount(0); 517 } 518 519 public void tableChanged(TableModelEvent e) 520 { 521 if (e.getType() == TableModelEvent.UPDATE) 522 { 523 if (nodes.elementAt(e.getFirstRow()) != null) 524 { 525 Node node = nodes.elementAt(e.getFirstRow()); 526 node.put("name", (String)getValueAt(e.getFirstRow(), 1)); 527 } 528 } 529 } 530 }; 531 62 { 532 63 private static StopImporterDialog dialog = null; 533 64 private static DefaultListModel tracksListModel = null; … … 559 90 } 560 91 92 public TrackReference getCurrentTrack() 93 { 94 return currentTrack; 95 } 96 561 97 public void actionPerformed(ActionEvent event) 562 98 { … … 590 126 refreshData(); 591 127 } 592 else if ("stopImporter.settingsGPSTimeStart" 593 .equals(event.getActionCommand())) 594 { 595 if (dialog.gpsTimeStartValid()) 596 { 597 if (currentTrack != null) 598 { 599 currentTrack.gpsSyncTime = dialog.getGpsTimeStart(); 600 currentTrack.relocateNodes(); 601 } 602 } 603 } 604 else if ("stopImporter.settingsStopwatchStart" 605 .equals(event.getActionCommand())) 606 { 607 if (dialog.stopwatchStartValid()) 608 { 609 if (currentTrack != null) 610 { 611 currentTrack.stopwatchStart = dialog.getStopwatchStart(); 612 currentTrack.relocateNodes(); 613 } 614 } 615 else 616 { 617 } 618 } 619 else if ("stopImporter.settingsTimeWindow" 620 .equals(event.getActionCommand())) 128 else if ("stopImporter.settingsGPSTimeStart".equals(event.getActionCommand())) 129 { 130 if ((dialog.gpsTimeStartValid()) && (currentTrack != null)) 131 { 132 currentTrack.gpsSyncTime = dialog.getGpsTimeStart(); 133 currentTrack.relocateNodes(); 134 } 135 } 136 else if ("stopImporter.settingsStopwatchStart".equals(event.getActionCommand())) 137 { 138 if ((dialog.stopwatchStartValid()) && (currentTrack != null)) 139 { 140 currentTrack.stopwatchStart = dialog.getStopwatchStart(); 141 currentTrack.relocateNodes(); 142 } 143 } 144 else if ("stopImporter.settingsTimeWindow".equals(event.getActionCommand())) 621 145 { 622 146 if (currentTrack != null) … … 633 157 } 634 158 else if ("stopImporter.stoplistFind".equals(event.getActionCommand())) 635 { 636 if (Main.main.getCurrentDataSet() == null) 637 return; 638 159 findNodesInTable(dialog.getStoplistTable(), currentTrack.stoplistTM.nodes); 160 else if ("stopImporter.stoplistShow".equals(event.getActionCommand())) 161 showNodesFromTable(dialog.getStoplistTable(), currentTrack.stoplistTM.nodes); 162 else if ("stopImporter.stoplistMark".equals(event.getActionCommand())) 163 markNodesFromTable(dialog.getStoplistTable(), currentTrack.stoplistTM.nodes); 164 else if ("stopImporter.stoplistDetach".equals(event.getActionCommand())) 165 { 166 Main.main.undoRedo.add(new TrackStoplistDetachCommand(this)); 639 167 dialog.getStoplistTable().clearSelection(); 640 641 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)642 {643 if ((currentTrack.stoplistTM.nodes.elementAt(i) != null) &&644 (Main.main.getCurrentDataSet().isSelected(currentTrack.stoplistTM.nodes.elementAt(i))))645 dialog.getStoplistTable().addRowSelectionInterval(i, i);646 }647 }648 else if ("stopImporter.stoplistShow".equals(event.getActionCommand()))649 {650 BoundingXYVisitor box = new BoundingXYVisitor();651 if (dialog.getStoplistTable().getSelectedRowCount() > 0)652 {653 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)654 {655 if ((dialog.getStoplistTable().isRowSelected(i)) &&656 (currentTrack.stoplistTM.nodes.elementAt(i) != null))657 {658 currentTrack.stoplistTM.nodes.elementAt(i).visit(box);659 }660 }661 }662 else663 {664 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)665 {666 if (currentTrack.stoplistTM.nodes.elementAt(i) != null)667 currentTrack.stoplistTM.nodes.elementAt(i).visit(box);668 }669 }670 if (box.getBounds() == null)671 return;672 box.enlargeBoundingBox();673 Main.map.mapView.recalculateCenterScale(box);674 }675 else if ("stopImporter.stoplistMark".equals(event.getActionCommand()))676 {677 OsmPrimitive[] osmp = { null };678 Main.main.getCurrentDataSet().setSelected(osmp);679 if (dialog.getStoplistTable().getSelectedRowCount() > 0)680 {681 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)682 {683 if ((dialog.getStoplistTable().isRowSelected(i)) &&684 (currentTrack.stoplistTM.nodes.elementAt(i) != null))685 {686 Main.main.getCurrentDataSet().addSelected(currentTrack.stoplistTM.nodes.elementAt(i));687 }688 }689 }690 else691 {692 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)693 {694 if (currentTrack.stoplistTM.nodes.elementAt(i) != null)695 Main.main.getCurrentDataSet().addSelected(currentTrack.stoplistTM.nodes.elementAt(i));696 }697 }698 }699 else if ("stopImporter.stoplistDetach".equals(event.getActionCommand()))700 {701 if (dialog.getStoplistTable().getSelectedRowCount() > 0)702 {703 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)704 {705 if ((dialog.getStoplistTable().isRowSelected(i)) &&706 (currentTrack.stoplistTM.nodes.elementAt(i) != null))707 {708 currentTrack.stoplistTM.nodes.set(i, null);709 }710 }711 }712 else713 {714 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)715 {716 if (currentTrack.stoplistTM.nodes.elementAt(i) != null)717 currentTrack.stoplistTM.nodes.set(i, null);718 }719 }720 dialog.getStoplistTable().clearSelection();721 168 } 722 169 else if ("stopImporter.stoplistAdd".equals(event.getActionCommand())) 723 { 724 int insPos = dialog.getStoplistTable().getSelectedRow(); 725 if (currentTrack != null) 726 currentTrack.stoplistTM.insertRow(insPos, "00:00:00"); 727 } 170 Main.main.undoRedo.add(new TrackStoplistAddCommand(this)); 728 171 else if ("stopImporter.stoplistDelete".equals(event.getActionCommand())) 729 { 730 Vector< Node > toDelete = new Vector< Node >(); 731 if (currentTrack == null) 732 return; 733 for (int i = currentTrack.stoplistTM.getRowCount()-1; i >=0; --i) 734 { 735 if (dialog.getStoplistTable().isRowSelected(i)) 736 { 737 if ((Node)currentTrack.stoplistTM.nodes.elementAt(i) != null) 738 toDelete.add((Node)currentTrack.stoplistTM.nodes.elementAt(i)); 739 currentTrack.stoplistTM.nodes.removeElementAt(i); 740 currentTrack.stoplistTM.removeRow(i); 741 } 742 } 743 Command cmd = DeleteCommand.delete 744 (Main.main.getEditLayer(), toDelete); 745 if (cmd != null) { 746 // cmd can be null if the user cancels dialogs DialogCommand displays 747 Main.main.undoRedo.add(cmd); 748 } 749 } 172 Main.main.undoRedo.add(new TrackStoplistDeleteCommand(this)); 750 173 else if ("stopImporter.stoplistSort".equals(event.getActionCommand())) 751 { 752 int insPos = dialog.getStoplistTable().getSelectedRow(); 753 Vector< NodeSortEntry > nodesToSort = new Vector< NodeSortEntry >(); 754 if (currentTrack == null) 755 return; 756 if (dialog.getStoplistTable().getSelectedRowCount() > 0) 757 { 758 for (int i = currentTrack.stoplistTM.getRowCount()-1; i >=0; --i) 759 { 760 if (dialog.getStoplistTable().isRowSelected(i)) 761 { 762 nodesToSort.add(new NodeSortEntry 763 (currentTrack.stoplistTM.nodes.elementAt(i), 764 (String)currentTrack.stoplistTM.getValueAt(i, 0), 765 (String)currentTrack.stoplistTM.getValueAt(i, 1), 766 StopImporterDialog.parseTime(currentTrack.stopwatchStart))); 767 currentTrack.stoplistTM.nodes.removeElementAt(i); 768 currentTrack.stoplistTM.removeRow(i); 769 } 770 } 771 } 772 else 773 { 774 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i) 775 { 776 nodesToSort.add(new NodeSortEntry 777 (currentTrack.stoplistTM.nodes.elementAt(i), 778 (String)currentTrack.stoplistTM.getValueAt(i, 0), 779 (String)currentTrack.stoplistTM.getValueAt(i, 1), 780 StopImporterDialog.parseTime(currentTrack.stopwatchStart))); 781 } 782 currentTrack.stoplistTM.clear(); 783 } 784 785 Collections.sort(nodesToSort); 786 787 Iterator< NodeSortEntry > iter = nodesToSort.iterator(); 788 while (iter.hasNext()) 789 { 790 NodeSortEntry nse = iter.next(); 791 currentTrack.stoplistTM.insertRow 792 (insPos, nse.node, nse.time, nse.name); 793 if (insPos >= 0) 794 ++insPos; 795 } 796 } 174 Main.main.undoRedo.add(new TrackStoplistSortCommand(this)); 797 175 else if ("stopImporter.waypointsFind".equals(event.getActionCommand())) 798 { 799 if (Main.main.getCurrentDataSet() == null) 800 return; 801 802 dialog.getWaypointsTable().clearSelection(); 803 804 for (int i = 0; i < waypointTM.getRowCount(); ++i) 805 { 806 if ((waypointTM.nodes.elementAt(i) != null) && 807 (Main.main.getCurrentDataSet().isSelected(waypointTM.nodes.elementAt(i)))) 808 dialog.getWaypointsTable().addRowSelectionInterval(i, i); 809 } 810 } 176 findNodesInTable(dialog.getWaypointsTable(), waypointTM.nodes); 811 177 else if ("stopImporter.waypointsShow".equals(event.getActionCommand())) 812 { 813 BoundingXYVisitor box = new BoundingXYVisitor(); 814 Vector< Integer > consideredLines = getConsideredLines 815 (dialog.getWaypointsTable()); 816 for (int i = 0; i < consideredLines.size(); ++i) 817 { 818 int j = consideredLines.elementAt(i); 819 if (waypointTM.nodes.elementAt(j) != null) 820 waypointTM.nodes.elementAt(j).visit(box); 821 } 822 if (box.getBounds() == null) 823 return; 824 box.enlargeBoundingBox(); 825 Main.map.mapView.recalculateCenterScale(box); 826 } 178 showNodesFromTable(dialog.getWaypointsTable(), waypointTM.nodes); 827 179 else if ("stopImporter.waypointsMark".equals(event.getActionCommand())) 828 { 829 OsmPrimitive[] osmp = { null }; 830 Main.main.getCurrentDataSet().setSelected(osmp); 831 Vector< Integer > consideredLines = getConsideredLines 832 (dialog.getWaypointsTable()); 833 for (int i = 0; i < consideredLines.size(); ++i) 834 { 835 int j = consideredLines.elementAt(i); 836 if (waypointTM.nodes.elementAt(j) != null) 837 Main.main.getCurrentDataSet().addSelected(waypointTM.nodes.elementAt(j)); 838 } 839 } 180 markNodesFromTable(dialog.getWaypointsTable(), waypointTM.nodes); 840 181 else if ("stopImporter.waypointsDetach".equals(event.getActionCommand())) 841 182 { … … 844 185 } 845 186 else if ("stopImporter.waypointsAdd".equals(event.getActionCommand())) 846 {847 187 Main.main.undoRedo.add(new WaypointsEnableCommand(this)); 848 }849 188 else if ("stopImporter.waypointsDelete".equals(event.getActionCommand())) 850 {851 189 Main.main.undoRedo.add(new WaypointsDisableCommand(this)); 852 }853 190 else if ("stopImporter.settingsStoptype".equals(event.getActionCommand())) 854 { 855 for (int i = 0; i < waypointTM.getRowCount(); ++i) 856 { 857 if ((Node)waypointTM.nodes.elementAt(i) != null) 858 { 859 Node node = (Node)waypointTM.nodes.elementAt(i); 860 node.remove("highway"); 861 node.remove("railway"); 862 if ("bus".equals(dialog.getStoptype())) 863 node.put("highway", "bus_stop"); 864 else if ("tram".equals(dialog.getStoptype())) 865 node.put("railway", "tram_stop"); 866 else if ("light_rail".equals(dialog.getStoptype())) 867 node.put("railway", "station"); 868 else if ("subway".equals(dialog.getStoptype())) 869 node.put("railway", "station"); 870 else if ("rail".equals(dialog.getStoptype())) 871 node.put("railway", "station"); 872 } 873 } 874 for (int j = 0; j < tracksListModel.size(); ++j) 875 { 876 TrackReference track = (TrackReference)tracksListModel.elementAt(j); 877 for (int i = 0; i < track.stoplistTM.getRowCount(); ++i) 878 { 879 if ((Node)track.stoplistTM.nodes.elementAt(i) != null) 880 { 881 Node node = (Node)track.stoplistTM.nodes.elementAt(i); 882 node.remove("highway"); 883 node.remove("railway"); 884 if ("bus".equals(dialog.getStoptype())) 885 node.put("highway", "bus_stop"); 886 else if ("tram".equals(dialog.getStoptype())) 887 node.put("railway", "tram_stop"); 888 else if ("light_rail".equals(dialog.getStoptype())) 889 node.put("railway", "station"); 890 else if ("subway".equals(dialog.getStoptype())) 891 node.put("railway", "station"); 892 else if ("rail".equals(dialog.getStoptype())) 893 node.put("railway", "station"); 894 } 895 } 896 } 897 } 191 Main.main.undoRedo.add(new SettingsStoptypeCommand(this)); 898 192 } 899 193 … … 953 247 { 954 248 GpxTrack track = trackIter.next(); 955 trackRefs.add(new TrackReference(track ));249 trackRefs.add(new TrackReference(track, this)); 956 250 } 957 251 … … 962 256 tracksListModel.addElement(iter.next()); 963 257 964 waypointTM = new WaypointTableModel( );258 waypointTM = new WaypointTableModel(this); 965 259 Iterator< WayPoint > waypointIter = data.waypoints.iterator(); 966 260 while (waypointIter.hasNext()) … … 1004 298 } 1005 299 1006 p rivateNode createNode(LatLon latLon, String name)300 public Node createNode(LatLon latLon, String name) 1007 301 { 1008 302 return createNode(latLon, dialog.getStoptype(), name); … … 1037 331 } 1038 332 1039 /* returns a collection of all slected lines or 333 /* sets the tags of the node according to the type */ 334 public static void setTagsWrtType(Node node, String type) 335 { 336 node.remove("highway"); 337 node.remove("railway"); 338 if ("bus".equals(type)) 339 node.put("highway", "bus_stop"); 340 else if ("tram".equals(type)) 341 node.put("railway", "tram_stop"); 342 else if ("light_rail".equals(type)) 343 node.put("railway", "station"); 344 else if ("subway".equals(type)) 345 node.put("railway", "station"); 346 else if ("rail".equals(type)) 347 node.put("railway", "station"); 348 } 349 350 /* returns a collection of all selected lines or 1040 351 a collection of all lines otherwise */ 1041 352 public static Vector< Integer > getConsideredLines(JTable table) … … 1056 367 } 1057 368 1058 private static String timeOf(double t) 369 /* marks the table items whose nodes are marked on the map */ 370 public static void findNodesInTable(JTable table, Vector< Node > nodes) 371 { 372 if (Main.main.getCurrentDataSet() == null) 373 return; 374 375 table.clearSelection(); 376 377 for (int i = 0; i < table.getRowCount(); ++i) 378 { 379 if ((nodes.elementAt(i) != null) && 380 (Main.main.getCurrentDataSet().isSelected(nodes.elementAt(i)))) 381 table.addRowSelectionInterval(i, i); 382 } 383 } 384 385 /* shows the nodes that correspond to the marked lines in the table. 386 If no lines are marked in the table, show all nodes from the vector */ 387 public static void showNodesFromTable(JTable table, Vector< Node > nodes) 388 { 389 BoundingXYVisitor box = new BoundingXYVisitor(); 390 Vector< Integer > consideredLines = getConsideredLines(table); 391 for (int i = 0; i < consideredLines.size(); ++i) 392 { 393 int j = consideredLines.elementAt(i); 394 if (nodes.elementAt(j) != null) 395 nodes.elementAt(j).visit(box); 396 } 397 if (box.getBounds() == null) 398 return; 399 box.enlargeBoundingBox(); 400 Main.map.mapView.recalculateCenterScale(box); 401 } 402 403 /* marks the nodes that correspond to the marked lines in the table. 404 If no lines are marked in the table, mark all nodes from the vector */ 405 public static void markNodesFromTable(JTable table, Vector< Node > nodes) 406 { 407 OsmPrimitive[] osmp = { null }; 408 Main.main.getCurrentDataSet().setSelected(osmp); 409 Vector< Integer > consideredLines = getConsideredLines(table); 410 for (int i = 0; i < consideredLines.size(); ++i) 411 { 412 int j = consideredLines.elementAt(i); 413 if (nodes.elementAt(j) != null) 414 Main.main.getCurrentDataSet().addSelected(nodes.elementAt(j)); 415 } 416 } 417 418 public static String timeOf(double t) 1059 419 { 1060 420 t -= Math.floor(t/24/60/60)*24*60*60; -
applications/editors/josm/plugins/public_transport/src/public_transport/WaypointsDetachCommand.java
r20750 r20772 15 15 private Vector< Integer > workingLines = null; 16 16 private Vector< Node > nodesForUndo = null; 17 private StopImporterAction.WaypointTableModel waypointTM = null; 18 private String type = null; 17 private WaypointTableModel waypointTM = null; 19 18 20 19 public WaypointsDetachCommand(StopImporterAction controller) 21 20 { 22 21 waypointTM = controller.getWaypointTableModel(); 23 type = controller.getDialog().getStoptype();24 22 workingLines = new Vector< Integer >(); 25 23 nodesForUndo = new Vector< Node >(); -
applications/editors/josm/plugins/public_transport/src/public_transport/WaypointsDisableCommand.java
r20748 r20772 15 15 private Vector< Integer > workingLines = null; 16 16 private Vector< Node > nodesForUndo = null; 17 private StopImporterAction.WaypointTableModel waypointTM = null; 18 private String type = null; 17 private WaypointTableModel waypointTM = null; 19 18 20 19 public WaypointsDisableCommand(StopImporterAction controller) 21 20 { 22 21 waypointTM = controller.getWaypointTableModel(); 23 type = controller.getDialog().getStoptype();24 22 workingLines = new Vector< Integer >(); 25 23 nodesForUndo = new Vector< Node >(); … … 70 68 int j = workingLines.elementAt(i).intValue(); 71 69 Node node = nodesForUndo.elementAt(i); 70 waypointTM.nodes.set(j, node); 71 if (node == null) 72 continue; 72 73 node.setDeleted(false); 73 74 Main.main.getCurrentDataSet().addPrimitive(node); 74 waypointTM.nodes.set(j, node);75 75 } 76 76 } -
applications/editors/josm/plugins/public_transport/src/public_transport/WaypointsEnableCommand.java
r20748 r20772 14 14 { 15 15 private Vector< Integer > workingLines = null; 16 private StopImporterAction.WaypointTableModel waypointTM = null;16 private WaypointTableModel waypointTM = null; 17 17 private String type = null; 18 18 … … 64 64 Node node = waypointTM.nodes.elementAt(j); 65 65 waypointTM.nodes.set(j, null); 66 if (node == null) 67 continue; 66 68 Main.main.getCurrentDataSet().removePrimitive(node); 67 69 node.setDeleted(true);
Note:
See TracChangeset
for help on using the changeset viewer.