Changeset 23192 in osm for applications/editors/josm/plugins/public_transport
- Timestamp:
- 2010-09-15T18:59:53+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/public_transport/src/public_transport
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSAddCommand.java
r22148 r23192 16 16 private GTFSStopTableModel gtfsStopTM = null; 17 17 private String type = null; 18 18 19 19 public GTFSAddCommand(GTFSImporterAction controller) 20 20 { … … 23 23 workingLines = new Vector< Integer >(); 24 24 typesForUndo = new Vector< String >(); 25 25 26 26 // use either selected lines or all lines if no line is selected 27 27 int[] selectedLines = controller.getDialog().getGTFSStopTable().getSelectedRows(); … … 30 30 { 31 31 for (int i = 0; i < selectedLines.length; ++i) 32 32 consideredLines.add(selectedLines[i]); 33 33 } 34 34 else 35 35 { 36 36 for (int i = 0; i < gtfsStopTM.getRowCount(); ++i) 37 37 consideredLines.add(new Integer(i)); 38 38 } 39 39 40 40 // keep only lines where a node can be added 41 41 for (int i = 0; i < consideredLines.size(); ++i) 42 42 { 43 43 if (gtfsStopTM.nodes.elementAt(consideredLines.elementAt(i)) == null) 44 44 workingLines.add(consideredLines.elementAt(i)); 45 45 } 46 46 } 47 47 48 48 public boolean executeCommand() 49 49 { … … 61 61 return true; 62 62 } 63 63 64 64 public void undoCommand() 65 65 { … … 71 71 gtfsStopTM.setValueAt(typesForUndo.elementAt(i), j, 2); 72 72 if (node == null) 73 73 continue; 74 74 Main.main.getCurrentDataSet().removePrimitive(node); 75 75 node.setDeleted(true); 76 76 } 77 77 } 78 78 79 79 public void fillModifiedData 80 80 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 82 82 { 83 83 } 84 84 85 85 @Override public JLabel getDescription() 86 86 { -
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSCatchCommand.java
r22148 r23192 18 18 private GTFSStopTableModel gtfsStopTM = null; 19 19 private String type = null; 20 20 21 21 public GTFSCatchCommand(GTFSImporterAction controller) 22 22 { 23 23 gtfsStopTM = controller.getGTFSStopTableModel(); 24 24 workingLines = new Vector< Integer >(); 25 25 26 26 // use either selected lines or all lines if no line is selected 27 27 int[] selectedLines = controller.getDialog().getGTFSStopTable().getSelectedRows(); … … 30 30 workingLines.add(selectedLines[0]); 31 31 } 32 32 33 33 public boolean executeCommand() 34 34 { … … 43 43 Node n = iter.next(); 44 44 if ((n != null) && (n.equals(gtfsStopTM.nodes.elementAt(j)))) 45 45 continue; 46 46 if (dest != null) 47 47 return false; 48 48 dest = n; 49 49 } … … 51 51 return false; 52 52 undoMapNode = new Node(dest); 53 53 54 54 Node node = gtfsStopTM.nodes.elementAt(j); 55 55 undoTableNode = node; … … 59 59 node.setDeleted(true); 60 60 } 61 61 62 62 dest.setCoor(gtfsStopTM.coors.elementAt(j)); 63 63 dest.put("highway", "bus_stop"); … … 69 69 type = (String)gtfsStopTM.getValueAt(j, 2); 70 70 gtfsStopTM.setValueAt("fed", j, 2); 71 71 72 72 return true; 73 73 } 74 74 75 75 public void undoCommand() 76 76 { … … 78 78 return; 79 79 int j = workingLines.elementAt(0); 80 80 81 81 Node node = gtfsStopTM.nodes.elementAt(j); 82 82 if (node != null) … … 85 85 node.setDeleted(true); 86 86 } 87 87 88 88 if (undoMapNode != null) 89 89 { … … 99 99 gtfsStopTM.setValueAt(type, j, 2); 100 100 } 101 101 102 102 public void fillModifiedData 103 103 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 105 105 { 106 106 } 107 107 108 108 @Override public JLabel getDescription() 109 109 { -
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSDeleteCommand.java
r22148 r23192 16 16 private Vector< String > typesForUndo = null; 17 17 private GTFSStopTableModel gtfsStopTM = null; 18 18 19 19 public GTFSDeleteCommand(GTFSImporterAction controller) 20 20 { … … 23 23 nodesForUndo = new Vector< Node >(); 24 24 typesForUndo = new Vector< String >(); 25 25 26 26 // use either selected lines or all lines if no line is selected 27 27 int[] selectedLines = controller.getDialog().getGTFSStopTable().getSelectedRows(); … … 30 30 { 31 31 for (int i = 0; i < selectedLines.length; ++i) 32 32 consideredLines.add(selectedLines[i]); 33 33 } 34 34 else 35 35 { 36 36 for (int i = 0; i < gtfsStopTM.getRowCount(); ++i) 37 37 consideredLines.add(new Integer(i)); 38 38 } 39 39 40 40 // keep only lines where a node can be added 41 41 for (int i = 0; i < consideredLines.size(); ++i) 42 42 { 43 43 if (gtfsStopTM.nodes.elementAt(consideredLines.elementAt(i)) != null) 44 44 workingLines.add(consideredLines.elementAt(i)); 45 45 } 46 46 } 47 47 48 48 public boolean executeCommand() 49 49 { … … 57 57 typesForUndo.add((String)gtfsStopTM.getValueAt(j, 2)); 58 58 if (node == null) 59 59 continue; 60 60 gtfsStopTM.nodes.set(j, null); 61 61 gtfsStopTM.setValueAt("skipped", j, 2); … … 65 65 return true; 66 66 } 67 67 68 68 public void undoCommand() 69 69 { … … 75 75 gtfsStopTM.setValueAt(typesForUndo.elementAt(i), j, 2); 76 76 if (node == null) 77 77 continue; 78 78 node.setDeleted(false); 79 79 Main.main.getCurrentDataSet().addPrimitive(node); 80 80 } 81 81 } 82 82 83 83 public void fillModifiedData 84 84 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 86 86 { 87 87 } 88 88 89 89 @Override public JLabel getDescription() 90 90 { -
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSImporterAction.java
r23094 r23192 63 63 64 64 public class GTFSImporterAction extends JosmAction 65 { 65 { 66 66 private static GTFSImporterDialog dialog = null; 67 67 private static DefaultListModel tracksListModel = null; … … 70 70 private static GTFSStopTableModel gtfsStopTM = null; 71 71 public boolean inEvent = false; 72 72 73 73 public GTFSImporterAction() 74 74 { 75 75 super(tr("Create Stops from GTFS ..."), null, 76 76 tr("Create Stops from a GTFS file"), null, true); 77 77 } 78 78 … … 81 81 return gtfsStopTM; 82 82 } 83 83 84 84 public GTFSImporterDialog getDialog() 85 85 { … … 93 93 return tracksListModel; 94 94 } 95 95 96 96 public TrackReference getCurrentTrack() 97 97 { … … 102 102 { 103 103 DataSet mainDataSet = Main.main.getCurrentDataSet(); 104 104 105 105 if (dialog == null) 106 106 dialog = new GTFSImporterDialog(this); 107 107 108 108 dialog.setVisible(true); 109 109 … … 113 113 if (curDir.equals("")) 114 114 { 115 115 curDir = "."; 116 116 } 117 117 JFileChooser fc = new JFileChooser(new File(curDir)); 118 fc.setDialogTitle("Select GTFS file (stops.txt)"); 118 fc.setDialogTitle("Select GTFS file (stops.txt)"); 119 119 fc.setMultiSelectionEnabled(false); 120 120 121 121 int answer = fc.showOpenDialog(Main.parent); 122 122 if (answer != JFileChooser.APPROVE_OPTION) 123 124 123 return; 124 125 125 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) 126 127 126 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 127 128 128 importData(fc.getSelectedFile()); 129 129 130 130 refreshData(); 131 131 } … … 133 133 { 134 134 if ((!inEvent) && (dialog.gpsTimeStartValid()) && (currentTrack != null)) 135 135 Main.main.undoRedo.add(new TrackStoplistRelocateCommand(this)); 136 136 } 137 137 else if ("stopImporter.settingsStopwatchStart".equals(event.getActionCommand())) 138 138 { 139 139 if ((!inEvent) && (dialog.stopwatchStartValid()) && (currentTrack != null)) 140 140 Main.main.undoRedo.add(new TrackStoplistRelocateCommand(this)); 141 141 } 142 142 else if ("stopImporter.settingsTimeWindow".equals(event.getActionCommand())) 143 143 { 144 144 if (currentTrack != null) 145 145 currentTrack.timeWindow = dialog.getTimeWindow(); 146 146 } 147 147 else if ("stopImporter.settingsThreshold".equals(event.getActionCommand())) 148 148 { 149 149 if (currentTrack != null) 150 150 currentTrack.threshold = dialog.getThreshold(); 151 151 } 152 152 else if ("stopImporter.settingsSuggestStops".equals(event.getActionCommand())) … … 181 181 private void importData(final File file) 182 182 { 183 try 183 try 184 184 { 185 185 FileReader is = new FileReader(file); 186 186 final BufferedReader r = new BufferedReader(is); 187 187 188 188 if (data == null) 189 189 data = new Vector< String >(); 190 190 else 191 192 191 data.clear(); 192 193 193 while (r.ready()) 194 195 } 196 catch (FileNotFoundException e) 194 data.add(r.readLine()); 195 } 196 catch (FileNotFoundException e) 197 197 { 198 198 e.printStackTrace(); … … 211 211 { 212 212 Vector< Node > existingStops = new Vector< Node >(); 213 213 214 214 if (Main.main.getCurrentDataSet() == null) 215 215 { 216 216 JOptionPane.showMessageDialog(null, "There exists no dataset." 217 217 + " Try to download data from the server or open an OSM file.", 218 218 "No data found", JOptionPane.ERROR_MESSAGE); 219 219 220 220 System.out.println("Public Transport: StopInserter: No data found"); 221 221 … … 224 224 else 225 225 { 226 227 228 229 230 231 232 233 234 } 235 226 Iterator< Node > iter = 227 Main.main.getCurrentDataSet().getNodes().iterator(); 228 while (iter.hasNext()) 229 { 230 Node node = iter.next(); 231 if ("bus_stop".equals(node.get("highway"))) 232 existingStops.add(node); 233 } 234 } 235 236 236 Iterator< String > iter = data.iterator(); 237 237 if (iter.hasNext()) 238 238 gtfsStopTM = new GTFSStopTableModel(this, iter.next()); 239 239 else 240 240 { 241 242 243 244 241 JOptionPane.showMessageDialog 242 (null, "The GTFS file was empty.", "No data found", 243 JOptionPane.ERROR_MESSAGE); 244 245 245 System.out.println("Public Transport: GTFSImporter: No data found"); 246 246 247 247 return; 248 248 } 249 249 250 250 while (iter.hasNext()) 251 251 { 252 253 252 String s = iter.next(); 253 gtfsStopTM.addRow(s, existingStops); 254 254 } 255 255 dialog.setGTFSStopTableModel(gtfsStopTM); … … 260 260 (null, "The GTFS file was empty.", "No data found", 261 261 JOptionPane.ERROR_MESSAGE); 262 262 263 263 System.out.println("Public Transport: GTFSImporter: No data found"); 264 264 } 265 265 } 266 266 267 267 // public void tracksSelectionChanged(int selectedPos) 268 268 // { … … 271 271 // currentTrack = ((TrackReference)tracksListModel.elementAt(selectedPos)); 272 272 // dialog.setTrackValid(true); 273 // 273 // 274 274 // //Prepare Settings 275 275 // dialog.setSettings 276 // 277 // 278 // 276 // (currentTrack.gpsSyncTime, currentTrack.stopwatchStart, 277 // currentTrack.timeWindow, currentTrack.threshold); 278 // 279 279 // //Prepare Stoplist 280 280 // dialog.setStoplistTableModel … … 297 297 { 298 298 JOptionPane.showMessageDialog(null, "There exists no dataset." 299 299 + " Try to download data from the server or open an OSM file.", 300 300 "No data found", JOptionPane.ERROR_MESSAGE); 301 301 302 302 System.out.println("Public Transport: StopInserter: No data found"); 303 303 304 304 return null; 305 305 } … … 317 317 { 318 318 for (int i = 0; i < selectedLines.length; ++i) 319 319 consideredLines.add(selectedLines[i]); 320 320 } 321 321 else 322 322 { 323 323 for (int i = 0; i < table.getRowCount(); ++i) 324 324 consideredLines.add(new Integer(i)); 325 325 } 326 326 return consideredLines; … … 332 332 if (Main.main.getCurrentDataSet() == null) 333 333 return; 334 334 335 335 table.clearSelection(); 336 336 337 337 for (int i = 0; i < table.getRowCount(); ++i) 338 338 { 339 339 if ((nodes.elementAt(i) != null) && 340 341 342 } 343 } 344 340 (Main.main.getCurrentDataSet().isSelected(nodes.elementAt(i)))) 341 table.addRowSelectionInterval(i, i); 342 } 343 } 344 345 345 /* shows the nodes that correspond to the marked lines in the table. 346 346 If no lines are marked in the table, show all nodes from the vector */ … … 353 353 int j = consideredLines.elementAt(i); 354 354 if (nodes.elementAt(j) != null) 355 355 nodes.elementAt(j).visit(box); 356 356 } 357 357 if (box.getBounds() == null) … … 360 360 Main.map.mapView.recalculateCenterScale(box); 361 361 } 362 362 363 363 /* marks the nodes that correspond to the marked lines in the table. 364 364 If no lines are marked in the table, mark all nodes from the vector */ … … 372 372 int j = consideredLines.elementAt(i); 373 373 if (nodes.elementAt(j) != null) 374 375 } 376 } 377 374 Main.main.getCurrentDataSet().addSelected(nodes.elementAt(j)); 375 } 376 } 377 378 378 public static String timeOf(double t) 379 379 { 380 380 t -= Math.floor(t/24/60/60)*24*60*60; 381 381 382 382 int hour = (int)Math.floor(t/60/60); 383 383 t -= Math.floor(t/60/60)*60*60; … … 385 385 t -= Math.floor(t/60)*60; 386 386 double second = t; 387 387 388 388 Format format = new DecimalFormat("00"); 389 389 Format formatS = new DecimalFormat("00.###"); 390 390 return (format.format(hour) + ":" + format.format(minute) + ":" 391 392 } 393 391 + formatS.format(second)); 392 } 393 394 394 public Action getFocusAddAction() 395 395 { 396 396 return new FocusAddAction(); 397 397 } 398 398 399 399 private class FocusAddAction extends AbstractAction 400 400 { … … 405 405 } 406 406 }; 407 407 408 408 /* public Action getFocusWaypointShelterAction(String shelter) 409 409 { … … 417 417 public void actionPerformed(ActionEvent e) 418 418 { 419 420 421 422 423 424 425 /* 426 419 JTable table = dialog.getWaypointsTable(); 420 int row = table.getEditingRow(); 421 if (row < 0) 422 return; 423 table.clearSelection(); 424 table.addRowSelectionInterval(row, row); 425 /* Main.main.undoRedo.add 426 (new WaypointsDisableCommand(GTFSImporterAction.this));* 427 427 } 428 428 }; … … 433 433 return new FocusTrackStoplistNameAction(); 434 434 } 435 435 436 436 public Action getFocusTrackStoplistShelterAction(String shelter) 437 437 { … … 445 445 public void actionPerformed(ActionEvent e) 446 446 { 447 448 449 450 451 452 453 /* 454 447 JTable table = dialog.getStoplistTable(); 448 int row = table.getEditingRow(); 449 if (row < 0) 450 return; 451 table.clearSelection(); 452 table.addRowSelectionInterval(row, row); 453 /* Main.main.undoRedo.add 454 (new TrackStoplistDeleteCommand(GTFSImporterAction.this));* 455 455 } 456 456 }; … … 466 466 int row = table.getEditingRow(); 467 467 if (row < 0) 468 468 row = 0; 469 469 waypointTM.inEvent = true; 470 470 if (table.getCellEditor() != null) 471 471 { 472 473 472 if (!table.getCellEditor().stopCellEditing()) 473 table.getCellEditor().cancelCellEditing(); 474 474 } 475 475 table.editCellAt(row, 1); 476 476 table.getCellEditor().getTableCellEditorComponent 477 477 (table, "", true, row, 1); 478 478 waypointTM.inEvent = false; 479 479 } 480 480 }; 481 481 482 482 private class FocusWaypointShelterAction extends AbstractAction 483 483 { 484 484 private String defaultShelter = null; 485 485 486 486 public FocusWaypointShelterAction(String defaultShelter) 487 487 { 488 488 this.defaultShelter = defaultShelter; 489 489 } 490 490 491 491 public void actionPerformed(ActionEvent e) 492 492 { … … 496 496 int row = table.getEditingRow(); 497 497 if (row < 0) 498 498 row = 0; 499 499 waypointTM.inEvent = true; 500 500 if (table.getCellEditor() != null) 501 501 { 502 503 502 if (!table.getCellEditor().stopCellEditing()) 503 table.getCellEditor().cancelCellEditing(); 504 504 } 505 505 table.editCellAt(row, 2); … … 509 509 } 510 510 }; 511 511 512 512 private class FocusTrackStoplistNameAction extends AbstractAction 513 513 { … … 519 519 int row = table.getEditingRow(); 520 520 if (row < 0) 521 521 row = 0; 522 522 currentTrack.inEvent = true; 523 523 if (table.getCellEditor() != null) 524 524 { 525 526 525 if (!table.getCellEditor().stopCellEditing()) 526 table.getCellEditor().cancelCellEditing(); 527 527 } 528 528 table.editCellAt(row, 1); … … 532 532 } 533 533 }; 534 534 535 535 private class FocusTrackStoplistShelterAction extends AbstractAction 536 536 { 537 537 private String defaultShelter = null; 538 538 539 539 public FocusTrackStoplistShelterAction(String defaultShelter) 540 540 { 541 541 this.defaultShelter = defaultShelter; 542 542 } 543 543 544 544 public void actionPerformed(ActionEvent e) 545 545 { … … 549 549 int row = table.getEditingRow(); 550 550 if (row < 0) 551 551 row = 0; 552 552 currentTrack.inEvent = true; 553 553 if (table.getCellEditor() != null) 554 554 { 555 556 555 if (!table.getCellEditor().stopCellEditing()) 556 table.getCellEditor().cancelCellEditing(); 557 557 } 558 558 table.editCellAt(row, 2); -
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSImporterDialog.java
r22148 r23192 63 63 64 64 public class GTFSImporterDialog 65 { 65 { 66 66 private JDialog jDialog = null; 67 67 private JTabbedPane tabbedPane = null; … … 74 74 private JTable stoplistTable = null; 75 75 private JTable gtfsStopTable = null; 76 76 77 77 public GTFSImporterDialog(GTFSImporterAction controller) 78 78 { … … 87 87 tabbedPane.setEnabledAt(1, true); 88 88 jDialog.add(tabbedPane); 89 89 90 90 //Settings Tab 91 91 JPanel contentPane = tabSettings; … … 93 93 GridBagConstraints layoutCons = new GridBagConstraints(); 94 94 contentPane.setLayout(gridbag); 95 95 96 96 JLabel label = new JLabel("Type of stops to add"); 97 97 98 98 layoutCons.gridx = 0; 99 99 layoutCons.gridy = 0; … … 104 104 gridbag.setConstraints(label, layoutCons); 105 105 contentPane.add(label); 106 106 107 107 cbStoptype = new JComboBox(); 108 108 cbStoptype.setEditable(false); … … 114 114 cbStoptype.setActionCommand("gtfsImporter.settingsStoptype"); 115 115 cbStoptype.addActionListener(controller); 116 116 117 117 layoutCons.gridx = 0; 118 118 layoutCons.gridy = 1; … … 123 123 gridbag.setConstraints(cbStoptype, layoutCons); 124 124 contentPane.add(cbStoptype); 125 125 126 126 label = new JLabel("Time on your GPS device"); 127 127 128 128 layoutCons.gridx = 0; 129 129 layoutCons.gridy = 2; … … 134 134 gridbag.setConstraints(label, layoutCons); 135 135 contentPane.add(label); 136 136 137 137 tfGPSTimeStart = new JTextField("00:00:00", 15); 138 138 tfGPSTimeStart.setActionCommand("gtfsImporter.settingsGPSTimeStart"); 139 139 tfGPSTimeStart.addActionListener(controller); 140 140 141 141 layoutCons.gridx = 0; 142 142 layoutCons.gridy = 3; … … 147 147 gridbag.setConstraints(tfGPSTimeStart, layoutCons); 148 148 contentPane.add(tfGPSTimeStart); 149 149 150 150 label = new JLabel("HH:MM:SS.sss"); 151 151 152 152 layoutCons.gridx = 1; 153 153 layoutCons.gridy = 3; … … 158 158 gridbag.setConstraints(label, layoutCons); 159 159 contentPane.add(label); 160 160 161 161 label = new JLabel("Time on your stopwatch"); 162 162 163 163 layoutCons.gridx = 0; 164 164 layoutCons.gridy = 4; … … 169 169 gridbag.setConstraints(label, layoutCons); 170 170 contentPane.add(label); 171 171 172 172 tfStopwatchStart = new JTextField("00:00:00", 15); 173 173 tfStopwatchStart.setActionCommand("gtfsImporter.settingsStopwatchStart"); 174 174 tfStopwatchStart.addActionListener(controller); 175 175 176 176 layoutCons.gridx = 0; 177 177 layoutCons.gridy = 5; … … 182 182 gridbag.setConstraints(tfStopwatchStart, layoutCons); 183 183 contentPane.add(tfStopwatchStart); 184 184 185 185 label = new JLabel("HH:MM:SS.sss"); 186 186 187 187 layoutCons.gridx = 1; 188 188 layoutCons.gridy = 5; … … 193 193 gridbag.setConstraints(label, layoutCons); 194 194 contentPane.add(label); 195 195 196 196 label = new JLabel("Time window"); 197 197 198 198 layoutCons.gridx = 0; 199 199 layoutCons.gridy = 6; … … 204 204 gridbag.setConstraints(label, layoutCons); 205 205 contentPane.add(label); 206 206 207 207 tfTimeWindow = new JTextField("15", 4); 208 208 tfTimeWindow.setActionCommand("gtfsImporter.settingsTimeWindow"); 209 209 tfTimeWindow.addActionListener(controller); 210 210 211 211 layoutCons.gridx = 0; 212 212 layoutCons.gridy = 7; … … 217 217 gridbag.setConstraints(tfTimeWindow, layoutCons); 218 218 contentPane.add(tfTimeWindow); 219 219 220 220 label = new JLabel("seconds"); 221 221 222 222 layoutCons.gridx = 1; 223 223 layoutCons.gridy = 7; … … 228 228 gridbag.setConstraints(label, layoutCons); 229 229 contentPane.add(label); 230 230 231 231 label = new JLabel("Move Threshold"); 232 232 233 233 layoutCons.gridx = 0; 234 234 layoutCons.gridy = 8; … … 239 239 gridbag.setConstraints(label, layoutCons); 240 240 contentPane.add(label); 241 241 242 242 tfThreshold = new JTextField("20", 4); 243 243 tfThreshold.setActionCommand("gtfsImporter.settingsThreshold"); 244 244 tfThreshold.addActionListener(controller); 245 245 246 246 layoutCons.gridx = 0; 247 247 layoutCons.gridy = 9; … … 252 252 gridbag.setConstraints(tfThreshold, layoutCons); 253 253 contentPane.add(tfThreshold); 254 254 255 255 label = new JLabel("meters"); 256 256 257 257 layoutCons.gridx = 1; 258 258 layoutCons.gridy = 9; … … 263 263 gridbag.setConstraints(label, layoutCons); 264 264 contentPane.add(label); 265 265 266 266 JButton bSuggestStops = new JButton("Suggest Stops"); 267 267 bSuggestStops.setActionCommand("gtfsImporter.settingsSuggestStops"); 268 268 bSuggestStops.addActionListener(controller); 269 269 270 270 layoutCons.gridx = 0; 271 271 layoutCons.gridy = 10; … … 276 276 gridbag.setConstraints(bSuggestStops, layoutCons); 277 277 contentPane.add(bSuggestStops); 278 278 279 279 //Waypoints Tab 280 280 contentPane = tabWaypoints; … … 285 285 (KeyStroke.getKeyStroke("alt N"), "gtfsImporter.gtfsStopsFocusAdd"); 286 286 contentPane.getActionMap().put 287 287 ("gtfsImporter.gtfsStopsFocusAdd", controller.getFocusAddAction()); 288 288 /* contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 289 289 (KeyStroke.getKeyStroke("alt S"), "gtfsImporter.focusShelterYes"); 290 290 contentPane.getActionMap().put 291 292 291 ("gtfsImporter.focusShelterYes", 292 controller.getFocusWaypointShelterAction("yes")); 293 293 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 294 294 (KeyStroke.getKeyStroke("alt T"), "gtfsImporter.focusShelterNo"); 295 295 contentPane.getActionMap().put 296 297 296 ("gtfsImporter.focusShelterNo", 297 controller.getFocusWaypointShelterAction("no")); 298 298 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 299 299 (KeyStroke.getKeyStroke("alt U"), "gtfsImporter.focusShelterImplicit"); 300 300 contentPane.getActionMap().put 301 302 301 ("gtfsImporter.focusShelterImplicit", 302 controller.getFocusWaypointShelterAction("implicit")); 303 303 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 304 304 (KeyStroke.getKeyStroke("alt D"), "gtfsImporter.gtfsStopsDelete"); 305 305 contentPane.getActionMap().put 306 307 308 306 ("gtfsImporter.gtfsStopsDelete", 307 controller.getFocusWaypointDeleteAction());*/ 308 309 309 gtfsStopTable = new JTable(); 310 310 JScrollPane tableSP = new JScrollPane(gtfsStopTable); 311 311 312 312 layoutCons.gridx = 0; 313 313 layoutCons.gridy = 0; … … 318 318 gridbag.setConstraints(tableSP, layoutCons); 319 319 contentPane.add(tableSP); 320 320 321 321 JButton bFind = new JButton("Find"); 322 322 bFind.setActionCommand("gtfsImporter.gtfsStopsFind"); 323 323 bFind.addActionListener(controller); 324 324 325 325 layoutCons.gridx = 0; 326 326 layoutCons.gridy = 1; … … 331 331 gridbag.setConstraints(bFind, layoutCons); 332 332 contentPane.add(bFind); 333 333 334 334 JButton bShow = new JButton("Show"); 335 335 bShow.setActionCommand("gtfsImporter.gtfsStopsShow"); 336 336 bShow.addActionListener(controller); 337 337 338 338 layoutCons.gridx = 0; 339 339 layoutCons.gridy = 2; … … 344 344 gridbag.setConstraints(bShow, layoutCons); 345 345 contentPane.add(bShow); 346 346 347 347 JButton bMark = new JButton("Mark"); 348 348 bMark.setActionCommand("gtfsImporter.gtfsStopsMark"); 349 349 bMark.addActionListener(controller); 350 350 351 351 layoutCons.gridx = 1; 352 352 layoutCons.gridy = 1; … … 358 358 gridbag.setConstraints(bMark, layoutCons); 359 359 contentPane.add(bMark); 360 360 361 361 JButton bCatch = new JButton("Catch"); 362 362 bCatch.setActionCommand("gtfsImporter.gtfsStopsCatch"); 363 363 bCatch.addActionListener(controller); 364 364 365 365 layoutCons.gridx = 2; 366 366 layoutCons.gridy = 1; … … 372 372 gridbag.setConstraints(bCatch, layoutCons); 373 373 contentPane.add(bCatch); 374 374 375 375 JButton bJoin = new JButton("Join"); 376 376 bJoin.setActionCommand("gtfsImporter.gtfsStopsJoin"); 377 377 bJoin.addActionListener(controller); 378 378 379 379 layoutCons.gridx = 2; 380 380 layoutCons.gridy = 2; … … 386 386 gridbag.setConstraints(bJoin, layoutCons); 387 387 contentPane.add(bJoin); 388 388 389 389 JButton bAdd = new JButton("Enable"); 390 390 bAdd.setActionCommand("gtfsImporter.gtfsStopsAdd"); 391 391 bAdd.addActionListener(controller); 392 392 393 393 layoutCons.gridx = 3; 394 394 layoutCons.gridy = 1; … … 400 400 gridbag.setConstraints(bAdd, layoutCons); 401 401 contentPane.add(bAdd); 402 402 403 403 JButton bDelete = new JButton("Disable"); 404 404 bDelete.setActionCommand("gtfsImporter.gtfsStopsDelete"); 405 405 bDelete.addActionListener(controller); 406 406 407 407 layoutCons.gridx = 3; 408 408 layoutCons.gridy = 2; … … 413 413 gridbag.setConstraints(bDelete, layoutCons); 414 414 contentPane.add(bDelete); 415 415 416 416 jDialog.pack(); 417 417 jDialog.setLocationRelativeTo(frame); 418 418 } 419 419 420 420 public void setTrackValid(boolean valid) 421 421 { 422 422 tabbedPane.setEnabledAt(2, valid); 423 423 } 424 424 425 425 public void setVisible(boolean visible) 426 426 { 427 427 jDialog.setVisible(visible); 428 428 } 429 429 430 430 public void setSettings 431 431 (String gpsSyncTime, String stopwatchStart, … … 437 437 tfThreshold.setText(Double.toString(threshold)); 438 438 } 439 439 440 440 public String getStoptype() 441 441 { 442 442 return (String)cbStoptype.getSelectedItem(); 443 443 } 444 444 445 445 public boolean gpsTimeStartValid() 446 446 { … … 452 452 { 453 453 JOptionPane.showMessageDialog 454 455 454 (null, "Can't parse a time from this string.", "Invalid value", 455 JOptionPane.ERROR_MESSAGE); 456 456 return false; 457 457 } 458 458 } 459 459 460 460 public String getGpsTimeStart() 461 461 { 462 462 return tfGPSTimeStart.getText(); 463 463 } 464 464 465 465 public void setGpsTimeStart(String s) 466 466 { 467 467 tfGPSTimeStart.setText(s); 468 468 } 469 469 470 470 public boolean stopwatchStartValid() 471 471 { … … 477 477 { 478 478 JOptionPane.showMessageDialog 479 480 479 (null, "Can't parse a time from this string.", "Invalid value", 480 JOptionPane.ERROR_MESSAGE); 481 481 return false; 482 482 } 483 483 } 484 484 485 485 public String getStopwatchStart() 486 486 { 487 487 return tfStopwatchStart.getText(); 488 488 } 489 489 490 490 public void setStopwatchStart(String s) 491 491 { 492 492 tfStopwatchStart.setText(s); 493 493 } 494 494 495 495 public double getTimeWindow() 496 496 { 497 497 return Double.parseDouble(tfTimeWindow.getText()); 498 498 } 499 499 500 500 public double getThreshold() 501 501 { 502 502 return Double.parseDouble(tfThreshold.getText()); 503 503 } 504 504 505 505 public JTable getGTFSStopTable() 506 506 { 507 507 return gtfsStopTable; 508 508 } 509 509 510 510 public void setGTFSStopTableModel(GTFSStopTableModel model) 511 511 { … … 516 516 gtfsStopTable.getColumnModel().getColumn(2).setPreferredWidth((int)(width * 0.1)); 517 517 } 518 518 519 519 public static double parseTime(String s) 520 520 { 521 521 double result = 0; 522 522 if ((s.charAt(2) != ':') || (s.charAt(2) != ':') 523 523 || (s.length() < 8)) 524 524 return -1; 525 525 int hour = Integer.parseInt(s.substring(0, 2)); … … 527 527 double second = Double.parseDouble(s.substring(6, s.length())); 528 528 if ((hour < 0) || (hour > 23) || (minute < 0) || (minute > 59) 529 529 || (second < 0) || (second >= 60.0)) 530 530 return -1; 531 531 return (second + minute*60 + hour*60*60); 532 532 } 533 533 534 534 /* private class TracksLSL implements ListSelectionListener 535 535 { 536 536 GTFSImporterAction root = null; 537 537 538 538 public TracksLSL(GTFSImporterAction sia) 539 539 { 540 540 root = sia; 541 541 } 542 542 543 543 public void valueChanged(ListSelectionEvent e) 544 544 { 545 545 int selectedPos = tracksList.getAnchorSelectionIndex(); 546 546 if (tracksList.isSelectedIndex(selectedPos)) 547 547 root.tracksSelectionChanged(selectedPos); 548 548 else 549 549 root.tracksSelectionChanged(-1); 550 550 } 551 551 };*/ -
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSJoinCommand.java
r22148 r23192 18 18 private GTFSStopTableModel gtfsStopTM = null; 19 19 private String type = null; 20 20 21 21 public GTFSJoinCommand(GTFSImporterAction controller) 22 22 { 23 23 gtfsStopTM = controller.getGTFSStopTableModel(); 24 24 workingLines = new Vector< Integer >(); 25 25 26 26 // use either selected lines or all lines if no line is selected 27 27 int[] selectedLines = controller.getDialog().getGTFSStopTable().getSelectedRows(); … … 30 30 workingLines.add(selectedLines[0]); 31 31 } 32 32 33 33 public boolean executeCommand() 34 34 { … … 43 43 Node n = iter.next(); 44 44 if ((n != null) && (n.equals(gtfsStopTM.nodes.elementAt(j)))) 45 45 continue; 46 46 if (dest != null) 47 47 return false; 48 48 dest = n; 49 49 } … … 51 51 return false; 52 52 undoMapNode = new Node(dest); 53 53 54 54 Node node = gtfsStopTM.nodes.elementAt(j); 55 55 undoTableNode = node; … … 59 59 node.setDeleted(true); 60 60 } 61 61 62 62 dest.put("highway", "bus_stop"); 63 63 dest.put("stop_id", (String)gtfsStopTM.getValueAt(j, 0)); … … 67 67 type = (String)gtfsStopTM.getValueAt(j, 2); 68 68 gtfsStopTM.setValueAt("moved", j, 2); 69 69 70 70 return true; 71 71 } 72 72 73 73 public void undoCommand() 74 74 { … … 76 76 return; 77 77 int j = workingLines.elementAt(0); 78 78 79 79 Node node = gtfsStopTM.nodes.elementAt(j); 80 80 if (node != null) … … 83 83 node.setDeleted(true); 84 84 } 85 85 86 86 if (undoMapNode != null) 87 87 { … … 97 97 gtfsStopTM.setValueAt(type, j, 2); 98 98 } 99 99 100 100 public void fillModifiedData 101 101 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 103 103 { 104 104 } 105 105 106 106 @Override public JLabel getDescription() 107 107 { -
applications/editors/josm/plugins/public_transport/src/public_transport/GTFSStopTableModel.java
r23095 r23192 27 27 private int lonCol = -1; 28 28 private char separator = ','; 29 29 30 30 public GTFSStopTableModel(GTFSImporterAction controller, 31 31 String columnConfig) 32 32 { 33 33 int pos = columnConfig.indexOf(separator); … … 48 48 String title = columnConfig.substring(oldPos, pos); 49 49 if ("stop_id".equals(title)) 50 50 idCol = i; 51 51 else if ("stop_name".equals(title)) 52 52 nameCol = i; 53 53 else if ("stop_lat".equals(title)) 54 54 latCol = i; 55 55 else if ("stop_lon".equals(title)) 56 56 lonCol = i; 57 57 ++i; 58 58 oldPos = pos + 1; … … 68 68 else if ("stop_lon".equals(title)) 69 69 lonCol = i; 70 70 71 71 this.controller = controller; 72 72 addColumn("Id"); … … 75 75 addTableModelListener(this); 76 76 } 77 77 78 78 public boolean isCellEditable(int row, int column) 79 79 { 80 80 return false; 81 81 } 82 82 83 83 public void addRow(Object[] obj) 84 84 { 85 85 throw new UnsupportedOperationException(); 86 86 } 87 87 88 88 public void insertRow(int insPos, Object[] obj) 89 89 { 90 90 throw new UnsupportedOperationException(); 91 91 } 92 92 93 93 public void addRow(String s) 94 94 { 95 95 insertRow(-1, s, new Vector< Node >()); 96 96 } 97 97 98 98 public void addRow(String s, Vector< Node > existingStops) 99 99 { … … 135 135 return s; 136 136 } 137 137 138 138 public void insertRow(int insPos, String s, Vector< Node > existingStops) 139 139 { … … 147 147 { 148 148 if (i == idCol) 149 149 buf[0] = stripQuot(s.substring(oldPos, pos)); 150 150 else if (i == nameCol) 151 151 buf[1] = stripQuot(s.substring(oldPos, pos)); 152 152 else if (i == latCol) 153 153 lat = Double.parseDouble(stripQuot(s.substring(oldPos, pos))); 154 154 else if (i == lonCol) 155 155 lon = Double.parseDouble(stripQuot(s.substring(oldPos, pos))); 156 156 ++i; 157 157 oldPos = pos + 1; … … 166 166 else if (i == lonCol) 167 167 lon = Double.parseDouble(stripQuot(s.substring(oldPos))); 168 168 169 169 LatLon coor = new LatLon(lat, lon); 170 170 171 171 if (Main.main.getCurrentDataSet() != null) 172 172 { … … 176 176 while (iter.hasNext()) 177 177 { 178 179 180 181 182 178 if (iter.next().bounds.contains(coor)) 179 { 180 inside = true; 181 break; 182 } 183 183 } 184 184 if (!inside) 185 186 } 187 185 buf[2] = "outside"; 186 } 187 188 188 boolean nearBusStop = false; 189 189 Iterator< Node > iter = existingStops.iterator(); … … 193 193 if (coor.greatCircleDistance(node.getCoor()) < 1000) 194 194 { 195 196 197 } 198 } 199 195 nearBusStop = true; 196 break; 197 } 198 } 199 200 200 if (insPos == -1) 201 201 { 202 202 if ((nearBusStop) || !("pending".equals(buf[2]))) 203 203 nodes.addElement(null); 204 204 else 205 205 { 206 207 208 206 Node node = GTFSImporterAction.createNode(coor, buf[0], buf[1]); 207 nodes.addElement(node); 208 buf[2] = "added"; 209 209 } 210 210 coors.addElement(coor); … … 214 214 { 215 215 if ((nearBusStop) || !("pending".equals(buf[2]))) 216 216 nodes.insertElementAt(null, insPos); 217 217 else 218 218 { 219 220 221 219 Node node = GTFSImporterAction.createNode(coor, buf[0], buf[1]); 220 nodes.insertElementAt(node, insPos); 221 buf[2] = "added"; 222 222 } 223 223 coors.insertElementAt(coor, insPos); … … 225 225 } 226 226 } 227 227 228 228 public void clear() 229 229 { … … 231 231 super.setRowCount(0); 232 232 } 233 233 234 234 public void tableChanged(TableModelEvent e) 235 235 { -
applications/editors/josm/plugins/public_transport/src/public_transport/ItineraryTableModel.java
r20895 r23192 3 3 // import static org.openstreetmap.josm.tools.I18n.marktr; 4 4 // import static org.openstreetmap.josm.tools.I18n.tr; 5 // 5 // 6 6 // import java.awt.BorderLayout; 7 7 // import java.awt.Container; … … 21 21 // import java.util.TreeSet; 22 22 import java.util.Vector; 23 // 23 // 24 24 // import javax.swing.DefaultCellEditor; 25 25 // import javax.swing.DefaultListModel; … … 43 43 import javax.swing.table.DefaultTableModel; 44 44 // import javax.swing.table.TableCellEditor; 45 // 45 // 46 46 // import org.openstreetmap.josm.Main; 47 47 // import org.openstreetmap.josm.actions.JosmAction; … … 64 64 public Vector<Way> ways = new Vector<Way>(); 65 65 public boolean inEvent = false; 66 66 67 67 public boolean isCellEditable(int row, int column) 68 68 { … … 73 73 return true; 74 74 } 75 75 76 76 public void addRow(Object[] obj) 77 77 { … … 79 79 super.addRow(obj); 80 80 } 81 81 82 82 public void insertRow(int insPos, Object[] obj) 83 83 { … … 93 93 } 94 94 } 95 95 96 96 public void addRow(Way way, String role) 97 97 { 98 98 insertRow(-1, way, role); 99 99 } 100 100 101 101 public void insertRow(int insPos, Way way, String role) 102 102 { … … 123 123 } 124 124 } 125 125 126 126 public void clear() 127 127 { … … 129 129 super.setRowCount(0); 130 130 } 131 131 132 132 public void cleanupGaps() 133 133 { 134 134 inEvent = true; 135 135 Node lastNode = null; 136 136 137 137 for (int i = 0; i < getRowCount(); ++i) 138 138 { 139 139 if (ways.elementAt(i) == null) 140 140 { 141 142 143 141 ++i; 142 if (i >= getRowCount()) 143 break; 144 144 } 145 145 while ((ways.elementAt(i) == null) && 146 147 { 148 149 150 151 146 ((i == 0) || (ways.elementAt(i-1) == null))) 147 { 148 ways.removeElementAt(i); 149 removeRow(i); 150 if (i >= getRowCount()) 151 break; 152 152 } 153 153 if (i >= getRowCount()) 154 155 154 break; 155 156 156 boolean gapRequired = gapNecessary 157 157 (ways.elementAt(i), (String)(getValueAt(i, 1)), lastNode); 158 158 if ((i > 0) && (!gapRequired) && (ways.elementAt(i-1) == null)) 159 159 { 160 161 162 160 ways.removeElementAt(i-1); 161 removeRow(i-1); 162 --i; 163 163 } 164 164 else if ((i > 0) && gapRequired && (ways.elementAt(i-1) != null)) 165 165 { 166 167 168 169 166 String[] buf = { "", "" }; 167 buf[0] = "[gap]"; 168 insertRow(i, buf); 169 ++i; 170 170 } 171 171 lastNode = getLastNode(ways.elementAt(i), (String)(getValueAt(i, 1))); … … 179 179 inEvent = false; 180 180 } 181 181 182 182 public void tableChanged(TableModelEvent e) 183 183 { … … 185 185 { 186 186 if (inEvent) 187 187 return; 188 188 cleanupGaps(); 189 189 RoutePatternAction.rebuildWays(); 190 190 } 191 191 } 192 192 193 193 private Node getLastNode(Way way, String role) 194 194 { … … 200 200 return way.getNode(0); 201 201 else 202 203 } 204 } 205 202 return way.getNode(way.getNodesCount() - 1); 203 } 204 } 205 206 206 private boolean gapNecessary(Way way, String role, Node lastNode) 207 207 { … … 212 212 firstNode = way.getNode(way.getNodesCount() - 1); 213 213 else 214 214 firstNode = way.getNode(0); 215 215 if ((lastNode != null) && (!lastNode.equals(firstNode))) 216 216 return true; 217 217 } 218 218 return false; -
applications/editors/josm/plugins/public_transport/src/public_transport/PublicTransportPlugin.java
r22148 r23192 23 23 24 24 public class PublicTransportPlugin extends Plugin { 25 25 26 26 static JMenu jMenu; 27 27 -
applications/editors/josm/plugins/public_transport/src/public_transport/RoutePatternAction.java
r21867 r23192 60 60 61 61 public class RoutePatternAction extends JosmAction { 62 62 63 63 private class RoutesLSL implements ListSelectionListener { 64 64 RoutePatternAction root = null; 65 65 66 66 public RoutesLSL(RoutePatternAction rpa) { 67 67 root = rpa; 68 68 } 69 69 70 70 public void valueChanged(ListSelectionEvent e) { 71 71 root.routesSelectionChanged(); 72 72 } 73 73 }; 74 74 75 75 private class RouteReference implements Comparable< RouteReference > { 76 76 Relation route; 77 77 78 78 public RouteReference(Relation route) { 79 79 this.route = route; 80 80 } 81 81 82 82 public int compareTo(RouteReference rr) { 83 83 if (route.get("route") != null) 84 84 { 85 86 87 88 89 85 if (rr.route.get("route") == null) 86 return -1; 87 int result = route.get("route").compareTo(rr.route.get("route")); 88 if (result != 0) 89 return result; 90 90 } 91 91 else if (rr.route.get("route") != null) 92 92 return 1; 93 93 if (route.get("ref") != null) 94 94 { 95 96 97 98 99 95 if (rr.route.get("ref") == null) 96 return -1; 97 int result = route.get("ref").compareTo(rr.route.get("ref")); 98 if (result != 0) 99 return result; 100 100 } 101 101 else if (rr.route.get("ref") != null) 102 102 return 1; 103 103 if (route.get("to") != null) 104 104 { 105 106 107 108 109 105 if (rr.route.get("to") == null) 106 return -1; 107 int result = route.get("to").compareTo(rr.route.get("to")); 108 if (result != 0) 109 return result; 110 110 } 111 111 else if (rr.route.get("to") != null) 112 112 return 1; 113 113 if (route.get("direction") != null) 114 114 { 115 116 117 118 119 115 if (rr.route.get("direction") == null) 116 return -1; 117 int result = route.get("direction").compareTo(rr.route.get("direction")); 118 if (result != 0) 119 return result; 120 120 } 121 121 else if (rr.route.get("direction") != null) 122 122 return 1; 123 123 if (route.getId() < rr.route.getId()) 124 124 return -1; 125 125 else if (route.getId() > rr.route.getId()) 126 126 return 1; 127 127 return 0; 128 128 } 129 129 130 130 public String toString() { 131 131 String buf = route.get("route"); 132 132 if ((route.get("ref") != null) && (route.get("ref") != "")) 133 133 { 134 135 136 137 138 139 140 141 142 143 144 145 134 if ((route.get("to") != null) && (route.get("to") != "")) 135 { 136 buf += " " + route.get("ref") + ": " + route.get("to"); 137 } 138 else if ((route.get("direction") != null) && (route.get("direction") != "")) 139 { 140 buf += " " + route.get("ref") + ": " + route.get("direction"); 141 } 142 else 143 { 144 buf += " " + route.get("ref"); 145 } 146 146 } 147 147 buf += " [ID " + Long.toString(route.getId()) + "]"; 148 148 149 149 return buf; 150 150 } 151 151 }; 152 152 153 153 private class TagTableModel extends DefaultTableModel implements TableModelListener { 154 154 Relation relation = null; 155 155 TreeSet< String > blacklist = null; 156 156 boolean hasFixedKeys = true; 157 157 158 158 public TagTableModel(boolean hasFixedKeys) { 159 159 this.hasFixedKeys = hasFixedKeys; … … 162 162 public boolean isCellEditable(int row, int column) { 163 163 if ((column == 0) && (hasFixedKeys)) 164 164 return false; 165 165 return true; 166 166 } 167 167 168 168 public void readRelation(Relation rel) { 169 169 relation = rel; 170 170 171 171 for (int i = 0; i < getRowCount(); ++i) 172 172 { 173 174 175 176 177 } 178 } 179 173 String value = rel.get((String)getValueAt(i, 0)); 174 if (value == null) 175 value = ""; 176 setValueAt(value, i, 1); 177 } 178 } 179 180 180 public void readRelation(Relation rel, TreeSet< String > blacklist) { 181 181 relation = rel; 182 182 this.blacklist = blacklist; 183 183 184 184 setRowCount(0); 185 185 Iterator< Map.Entry< String, String > > iter = rel.getKeys().entrySet().iterator(); 186 186 while (iter.hasNext()) 187 187 { 188 189 190 191 192 193 194 195 196 } 197 188 Map.Entry< String, String > entry = iter.next(); 189 if (!blacklist.contains(entry.getKey())) 190 { 191 Vector< String > newRow = new Vector< String >(); 192 newRow.add(entry.getKey()); 193 newRow.add(entry.getValue()); 194 addRow(newRow); 195 } 196 } 197 198 198 for (int i = 0; i < getRowCount(); ++i) 199 199 { 200 201 202 203 204 } 205 } 206 200 String value = rel.get((String)getValueAt(i, 0)); 201 if (value == null) 202 value = ""; 203 setValueAt(value, i, 1); 204 } 205 } 206 207 207 public void tableChanged(TableModelEvent e) 208 208 { 209 209 if (e.getType() == TableModelEvent.UPDATE) 210 210 { 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 211 relation.setModified(true); 212 213 String key = (String)getValueAt(e.getFirstRow(), 0); 214 if (key == null) 215 return; 216 if ((blacklist == null) || (!blacklist.contains(key))) 217 { 218 relation.setModified(true); 219 if ("".equals(getValueAt(e.getFirstRow(), 1))) 220 relation.remove(key); 221 else 222 relation.put(key, (String)getValueAt(e.getFirstRow(), 1)); 223 } 224 else 225 { 226 if (e.getColumn() == 0) 227 setValueAt("", e.getFirstRow(), 0); 228 } 229 229 } 230 230 } 231 231 }; 232 232 233 233 private class CustomCellEditorTable extends JTable { 234 234 TreeMap< Integer, TableCellEditor > col1 = null; 235 235 TreeMap< Integer, TableCellEditor > col2 = null; 236 236 237 237 public CustomCellEditorTable() { 238 238 col1 = new TreeMap< Integer, TableCellEditor >(); 239 239 col2 = new TreeMap< Integer, TableCellEditor >(); 240 240 } 241 241 242 242 public TableCellEditor getCellEditor(int row, int column) { 243 243 TableCellEditor editor = null; 244 244 if (column == 0) 245 245 editor = col1.get(new Integer(row)); 246 246 else 247 247 editor = col2.get(new Integer(row)); 248 248 if (editor == null) 249 249 return new DefaultCellEditor(new JTextField()); 250 250 else 251 252 } 253 251 return editor; 252 } 253 254 254 public void setCellEditor(int row, int column, TableCellEditor editor) { 255 255 if (column == 0) 256 256 col1.put(new Integer(row), editor); 257 257 else 258 258 col2.put(new Integer(row), editor); 259 259 } 260 260 }; 261 261 262 262 private class StoplistTableModel extends DefaultTableModel { 263 263 public Vector<Node> nodes = new Vector<Node>(); 264 264 265 265 public boolean isCellEditable(int row, int column) { 266 266 if (column != 1) 267 267 return false; 268 268 return true; 269 269 } 270 270 271 271 public void addRow(Object[] obj) { 272 272 throw new UnsupportedOperationException(); 273 273 } 274 274 275 275 public void insertRow(int insPos, Object[] obj) { 276 276 throw new UnsupportedOperationException(); 277 277 } 278 278 279 279 public void addRow(Node node, String role) { 280 280 insertRow(-1, node, role); 281 281 } 282 282 283 283 public void insertRow(int insPos, Node node, String role) { 284 284 String[] buf = { "", "" }; … … 286 286 if (curName != null) 287 287 { 288 288 buf[0] = curName; 289 289 } 290 290 else 291 291 { 292 292 buf[0] = "[ID] " + (new Long(node.getId())).toString(); 293 293 } 294 294 buf[1] = role; 295 295 if (insPos == -1) 296 296 { 297 298 297 nodes.addElement(node); 298 super.addRow(buf); 299 299 } 300 300 else 301 301 { 302 303 304 } 305 } 306 302 nodes.insertElementAt(node, insPos); 303 super.insertRow(insPos, buf); 304 } 305 } 306 307 307 public void clear() 308 308 { … … 311 311 } 312 312 }; 313 313 314 314 private class StoplistTableModelListener implements TableModelListener { 315 315 public void tableChanged(TableModelEvent e) … … 317 317 if (e.getType() == TableModelEvent.UPDATE) 318 318 { 319 319 rebuildNodes(); 320 320 } 321 321 } 322 322 }; 323 323 324 324 private class SegmentMetric { 325 325 public double aLat, aLon; 326 326 public double length; 327 327 public double d1, d2, o1, o2; 328 328 329 329 public SegmentMetric(double fromLat, double fromLon, double toLat, double toLon) { 330 330 aLat = fromLat; 331 331 aLon = fromLon; 332 332 333 333 //Compute length and direction 334 334 //length is in units of latitude degrees … … 336 336 d2 = (toLon - fromLon) * Math.cos(fromLat * Math.PI/180.0); 337 337 length = Math.sqrt(d1*d1 + d2*d2); 338 338 339 339 //Normalise direction 340 340 d1 = d1 / length; 341 341 d2 = d2 / length; 342 342 343 343 //Compute orthogonal direction (right hand size is positive) 344 344 o1 = - d2; 345 345 o2 = d1; 346 346 347 347 //Prepare lon direction to reduce the number of necessary multiplications 348 348 d2 = d2 * Math.cos(fromLat * Math.PI/180.0); … … 350 350 } 351 351 }; 352 352 353 353 private class StopReference implements Comparable< StopReference > { 354 354 public int index = 0; … … 358 358 public String role = ""; 359 359 public Node node; 360 360 361 361 public StopReference(int inIndex, double inPos, double inDistance, 362 362 String inName, String inRole, Node inNode) { 363 363 index = inIndex; 364 364 pos = inPos; … … 368 368 node = inNode; 369 369 } 370 370 371 371 public int compareTo(StopReference sr) { 372 372 if (this.index < sr.index) 373 373 return -1; 374 374 if (this.index > sr.index) 375 375 return 1; 376 376 if (this.pos < sr.pos) 377 377 return -1; 378 378 if (this.pos > sr.pos) 379 379 return 1; 380 380 return 0; 381 381 } 382 382 }; 383 383 384 384 private static JDialog jDialog = null; 385 385 private static JTabbedPane tabbedPane = null; … … 403 403 private static Vector< RelationMember > markedWays = new Vector< RelationMember >(); 404 404 private static Vector< RelationMember > markedNodes = new Vector< RelationMember >(); 405 405 406 406 private static Relation copy = null; 407 407 408 408 public RoutePatternAction() { 409 409 super(tr("Route patterns ..."), null, 410 410 tr("Edit Route patterns for public transport"), null, true); 411 411 } 412 412 … … 414 414 Frame frame = JOptionPane.getFrameForComponent(Main.parent); 415 415 DataSet mainDataSet = Main.main.getCurrentDataSet(); 416 416 417 417 if (jDialog == null) 418 418 { … … 435 435 tabbedPane.setEnabledAt(4, false); 436 436 jDialog.add(tabbedPane); 437 437 438 438 //Overview Tab 439 439 Container contentPane = tabOverview; … … 441 441 GridBagConstraints layoutCons = new GridBagConstraints(); 442 442 contentPane.setLayout(gridbag); 443 443 444 444 JLabel headline = new JLabel("Existing route patterns:"); 445 445 446 446 layoutCons.gridx = 0; 447 447 layoutCons.gridy = 0; … … 452 452 gridbag.setConstraints(headline, layoutCons); 453 453 contentPane.add(headline); 454 454 455 455 relsListModel = new DefaultListModel(); 456 456 relsList = new JList(relsListModel); … … 460 460 relsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 461 461 relsList.addListSelectionListener(new RoutesLSL(this)); 462 462 463 463 layoutCons.gridx = 0; 464 464 layoutCons.gridy = 1; … … 469 469 gridbag.setConstraints(rpListSP, layoutCons); 470 470 contentPane.add(rpListSP); 471 471 472 472 JButton bRefresh = new JButton("Refresh"); 473 473 bRefresh.setActionCommand("routePattern.refresh"); 474 474 bRefresh.addActionListener(this); 475 475 476 476 layoutCons.gridx = 0; 477 477 layoutCons.gridy = 2; … … 483 483 gridbag.setConstraints(bRefresh, layoutCons); 484 484 contentPane.add(bRefresh); 485 485 486 486 JButton bNew = new JButton("New"); 487 487 bNew.setActionCommand("routePattern.overviewNew"); 488 488 bNew.addActionListener(this); 489 489 490 490 layoutCons.gridx = 1; 491 491 layoutCons.gridy = 2; … … 497 497 gridbag.setConstraints(bNew, layoutCons); 498 498 contentPane.add(bNew); 499 499 500 500 JButton bDelete = new JButton("Delete"); 501 501 bDelete.setActionCommand("routePattern.overviewDelete"); 502 502 bDelete.addActionListener(this); 503 503 504 504 layoutCons.gridx = 1; 505 505 layoutCons.gridy = 3; … … 511 511 gridbag.setConstraints(bDelete, layoutCons); 512 512 contentPane.add(bDelete); 513 513 514 514 JButton bDuplicate = new JButton("Duplicate"); 515 515 bDuplicate.setActionCommand("routePattern.overviewDuplicate"); 516 516 bDuplicate.addActionListener(this); 517 517 518 518 layoutCons.gridx = 2; 519 519 layoutCons.gridy = 2; … … 525 525 gridbag.setConstraints(bDuplicate, layoutCons); 526 526 contentPane.add(bDuplicate); 527 527 528 528 JButton bReflect = new JButton("Reflect"); 529 529 bReflect.setActionCommand("routePattern.overviewReflect"); 530 530 bReflect.addActionListener(this); 531 531 532 532 layoutCons.gridx = 2; 533 533 layoutCons.gridy = 3; … … 539 539 gridbag.setConstraints(bReflect, layoutCons); 540 540 contentPane.add(bReflect); 541 541 542 542 //Tags Tab 543 543 /*Container*/ contentPane = tabTags; … … 545 545 /*GridBagConstraints*/ layoutCons = new GridBagConstraints(); 546 546 contentPane.setLayout(gridbag); 547 547 548 548 /*JLabel*/ headline = new JLabel("Required tags:"); 549 549 550 550 layoutCons.gridx = 0; 551 551 layoutCons.gridy = 0; … … 555 555 gridbag.setConstraints(headline, layoutCons); 556 556 contentPane.add(headline); 557 557 558 558 requiredTagsTable = new CustomCellEditorTable(); 559 559 requiredTagsData = new TagTableModel(true); … … 600 600 JScrollPane tableSP = new JScrollPane(requiredTagsTable); 601 601 requiredTagsData.addTableModelListener(requiredTagsData); 602 602 603 603 layoutCons.gridx = 0; 604 604 layoutCons.gridy = 1; … … 611 611 tableSP.setPreferredSize(preferredSize); 612 612 contentPane.add(tableSP); 613 613 614 614 headline = new JLabel("Common tags:"); 615 615 616 616 layoutCons.gridx = 0; 617 617 layoutCons.gridy = 2; … … 621 621 gridbag.setConstraints(headline, layoutCons); 622 622 contentPane.add(headline); 623 623 624 624 commonTagsTable = new CustomCellEditorTable(); 625 625 commonTagsData = new TagTableModel(true); … … 654 654 /*JScrollPane*/ tableSP = new JScrollPane(commonTagsTable); 655 655 commonTagsData.addTableModelListener(commonTagsData); 656 656 657 657 layoutCons.gridx = 0; 658 658 layoutCons.gridy = 3; … … 665 665 tableSP.setPreferredSize(preferredSize); 666 666 contentPane.add(tableSP); 667 667 668 668 headline = new JLabel("Additional tags:"); 669 669 670 670 layoutCons.gridx = 0; 671 671 layoutCons.gridy = 4; … … 675 675 gridbag.setConstraints(headline, layoutCons); 676 676 contentPane.add(headline); 677 677 678 678 otherTagsTable = new CustomCellEditorTable(); 679 679 otherTagsData = new TagTableModel(false); … … 683 683 /*JScrollPane*/ tableSP = new JScrollPane(otherTagsTable); 684 684 otherTagsData.addTableModelListener(otherTagsData); 685 685 686 686 layoutCons.gridx = 0; 687 687 layoutCons.gridy = 5; … … 694 694 tableSP.setPreferredSize(preferredSize); 695 695 contentPane.add(tableSP); 696 696 697 697 JButton bAddTag = new JButton("Add a new Tag"); 698 698 bAddTag.setActionCommand("routePattern.tagAddTag"); 699 699 bAddTag.addActionListener(this); 700 700 701 701 layoutCons.gridx = 0; 702 702 layoutCons.gridy = 6; … … 707 707 gridbag.setConstraints(bAddTag, layoutCons); 708 708 contentPane.add(bAddTag); 709 709 710 710 //Itinerary Tab 711 711 contentPane = tabItinerary; … … 713 713 layoutCons = new GridBagConstraints(); 714 714 contentPane.setLayout(gridbag); 715 715 716 716 itineraryTable = new JTable(); 717 717 itineraryData = new ItineraryTableModel(); … … 725 725 comboBox.addItem("backward"); 726 726 itineraryTable.getColumnModel().getColumn(1) 727 727 .setCellEditor(new DefaultCellEditor(comboBox)); 728 728 itineraryData.addTableModelListener(itineraryData); 729 729 730 730 layoutCons.gridx = 0; 731 731 layoutCons.gridy = 0; … … 736 736 gridbag.setConstraints(tableSP, layoutCons); 737 737 contentPane.add(tableSP); 738 738 739 739 JButton bFind = new JButton("Find"); 740 740 bFind.setActionCommand("routePattern.itineraryFind"); 741 741 bFind.addActionListener(this); 742 742 743 743 layoutCons.gridx = 0; 744 744 layoutCons.gridy = 1; … … 749 749 gridbag.setConstraints(bFind, layoutCons); 750 750 contentPane.add(bFind); 751 751 752 752 JButton bShow = new JButton("Show"); 753 753 bShow.setActionCommand("routePattern.itineraryShow"); 754 754 bShow.addActionListener(this); 755 755 756 756 layoutCons.gridx = 0; 757 757 layoutCons.gridy = 2; … … 762 762 gridbag.setConstraints(bShow, layoutCons); 763 763 contentPane.add(bShow); 764 764 765 765 JButton bMark = new JButton("Mark"); 766 766 bMark.setActionCommand("routePattern.itineraryMark"); 767 767 bMark.addActionListener(this); 768 768 769 769 layoutCons.gridx = 1; 770 770 layoutCons.gridy = 1; … … 776 776 gridbag.setConstraints(bMark, layoutCons); 777 777 contentPane.add(bMark); 778 778 779 779 JButton bAdd = new JButton("Add"); 780 780 bAdd.setActionCommand("routePattern.itineraryAdd"); 781 781 bAdd.addActionListener(this); 782 782 783 783 layoutCons.gridx = 2; 784 784 layoutCons.gridy = 1; … … 790 790 gridbag.setConstraints(bAdd, layoutCons); 791 791 contentPane.add(bAdd); 792 792 793 793 /*JButton*/ bDelete = new JButton("Delete"); 794 794 bDelete.setActionCommand("routePattern.itineraryDelete"); 795 795 bDelete.addActionListener(this); 796 796 797 797 layoutCons.gridx = 2; 798 798 layoutCons.gridy = 2; … … 803 803 gridbag.setConstraints(bDelete, layoutCons); 804 804 contentPane.add(bDelete); 805 805 806 806 JButton bSort = new JButton("Sort"); 807 807 bSort.setActionCommand("routePattern.itinerarySort"); 808 808 bSort.addActionListener(this); 809 809 810 810 layoutCons.gridx = 3; 811 811 layoutCons.gridy = 1; … … 816 816 gridbag.setConstraints(bSort, layoutCons); 817 817 contentPane.add(bSort); 818 818 819 819 /*JButton*/ bReflect = new JButton("Reflect"); 820 820 bReflect.setActionCommand("routePattern.itineraryReflect"); 821 821 bReflect.addActionListener(this); 822 822 823 823 layoutCons.gridx = 3; 824 824 layoutCons.gridy = 2; … … 829 829 gridbag.setConstraints(bReflect, layoutCons); 830 830 contentPane.add(bReflect); 831 831 832 832 //Stoplist Tab 833 833 contentPane = tabStoplist; … … 835 835 layoutCons = new GridBagConstraints(); 836 836 contentPane.setLayout(gridbag); 837 837 838 838 stoplistTable = new JTable(); 839 839 stoplistData = new StoplistTableModel(); … … 847 847 comboBox.addItem("backward_stop"); 848 848 stoplistTable.getColumnModel().getColumn(1) 849 849 .setCellEditor(new DefaultCellEditor(comboBox)); 850 850 stoplistData.addTableModelListener(new StoplistTableModelListener()); 851 851 852 852 layoutCons.gridx = 0; 853 853 layoutCons.gridy = 0; … … 858 858 gridbag.setConstraints(tableSP, layoutCons); 859 859 contentPane.add(tableSP); 860 860 861 861 /*JButton*/ bFind = new JButton("Find"); 862 862 bFind.setActionCommand("routePattern.stoplistFind"); 863 863 bFind.addActionListener(this); 864 864 865 865 layoutCons.gridx = 0; 866 866 layoutCons.gridy = 1; … … 871 871 gridbag.setConstraints(bFind, layoutCons); 872 872 contentPane.add(bFind); 873 873 874 874 /*JButton*/ bShow = new JButton("Show"); 875 875 bShow.setActionCommand("routePattern.stoplistShow"); 876 876 bShow.addActionListener(this); 877 877 878 878 layoutCons.gridx = 0; 879 879 layoutCons.gridy = 2; … … 884 884 gridbag.setConstraints(bShow, layoutCons); 885 885 contentPane.add(bShow); 886 886 887 887 /*JButton*/ bMark = new JButton("Mark"); 888 888 bMark.setActionCommand("routePattern.stoplistMark"); 889 889 bMark.addActionListener(this); 890 890 891 891 layoutCons.gridx = 1; 892 892 layoutCons.gridy = 1; … … 898 898 gridbag.setConstraints(bMark, layoutCons); 899 899 contentPane.add(bMark); 900 900 901 901 /*JButton*/ bAdd = new JButton("Add"); 902 902 bAdd.setActionCommand("routePattern.stoplistAdd"); 903 903 bAdd.addActionListener(this); 904 904 905 905 layoutCons.gridx = 2; 906 906 layoutCons.gridy = 1; … … 912 912 gridbag.setConstraints(bAdd, layoutCons); 913 913 contentPane.add(bAdd); 914 914 915 915 /*JButton*/ bDelete = new JButton("Delete"); 916 916 bDelete.setActionCommand("routePattern.stoplistDelete"); 917 917 bDelete.addActionListener(this); 918 918 919 919 layoutCons.gridx = 2; 920 920 layoutCons.gridy = 2; … … 925 925 gridbag.setConstraints(bDelete, layoutCons); 926 926 contentPane.add(bDelete); 927 927 928 928 /*JButton*/ bSort = new JButton("Sort"); 929 929 bSort.setActionCommand("routePattern.stoplistSort"); 930 930 bSort.addActionListener(this); 931 931 932 932 layoutCons.gridx = 3; 933 933 layoutCons.gridy = 1; … … 938 938 gridbag.setConstraints(bSort, layoutCons); 939 939 contentPane.add(bSort); 940 940 941 941 /*JButton*/ bReflect = new JButton("Reflect"); 942 942 bReflect.setActionCommand("routePattern.stoplistReflect"); 943 943 bReflect.addActionListener(this); 944 944 945 945 layoutCons.gridx = 3; 946 946 layoutCons.gridy = 2; … … 951 951 gridbag.setConstraints(bReflect, layoutCons); 952 952 contentPane.add(bReflect); 953 953 954 954 //Meta Tab 955 955 contentPane = tabMeta; … … 957 957 layoutCons = new GridBagConstraints(); 958 958 contentPane.setLayout(gridbag); 959 959 960 960 JLabel rightleft = new JLabel("Stops are possible on the"); 961 961 962 962 layoutCons.gridx = 0; 963 963 layoutCons.gridy = 1; … … 968 968 gridbag.setConstraints(rightleft, layoutCons); 969 969 contentPane.add(rightleft); 970 970 971 971 cbRight = new JCheckBox("right hand side", true); 972 972 973 973 layoutCons.gridx = 0; 974 974 layoutCons.gridy = 2; … … 979 979 gridbag.setConstraints(cbRight, layoutCons); 980 980 contentPane.add(cbRight); 981 981 982 982 cbLeft = new JCheckBox("left hand side", false); 983 983 984 984 layoutCons.gridx = 0; 985 985 layoutCons.gridy = 3; … … 990 990 gridbag.setConstraints(cbLeft, layoutCons); 991 991 contentPane.add(cbLeft); 992 992 993 993 JLabel maxdist = new JLabel("Maximum distance from route"); 994 994 995 995 layoutCons.gridx = 0; 996 996 layoutCons.gridy = 4; … … 1001 1001 gridbag.setConstraints(maxdist, layoutCons); 1002 1002 contentPane.add(maxdist); 1003 1003 1004 1004 tfSuggestStopsLimit = new JTextField("20", 4); 1005 1005 1006 1006 layoutCons.gridx = 0; 1007 1007 layoutCons.gridy = 5; … … 1012 1012 gridbag.setConstraints(tfSuggestStopsLimit, layoutCons); 1013 1013 contentPane.add(tfSuggestStopsLimit); 1014 1014 1015 1015 JLabel meters = new JLabel("meters"); 1016 1016 1017 1017 layoutCons.gridx = 1; 1018 1018 layoutCons.gridy = 5; … … 1023 1023 gridbag.setConstraints(meters, layoutCons); 1024 1024 contentPane.add(meters); 1025 1025 1026 1026 JButton bSuggestStops = new JButton("Suggest Stops"); 1027 1027 bSuggestStops.setActionCommand("routePattern.metaSuggestStops"); 1028 1028 bSuggestStops.addActionListener(this); 1029 1029 1030 1030 layoutCons.gridx = 0; 1031 1031 layoutCons.gridy = 6; … … 1036 1036 gridbag.setConstraints(bSuggestStops, layoutCons); 1037 1037 contentPane.add(bSuggestStops); 1038 1038 1039 1039 jDialog.pack(); 1040 1040 } 1041 1041 1042 1042 if ("routePattern.refresh".equals(event.getActionCommand())) 1043 1043 { … … 1050 1050 currentRoute.put("route", "bus"); 1051 1051 mainDataSet.addPrimitive(currentRoute); 1052 1052 1053 1053 refreshData(); 1054 1054 1055 1055 for (int i = 0; i < relsListModel.size(); ++i) 1056 1056 { 1057 1058 1057 if (currentRoute == ((RouteReference)relsListModel.elementAt(i)).route) 1058 relsList.setSelectedIndex(i); 1059 1059 } 1060 1060 } … … 1065 1065 currentRoute.put("route", "bus"); 1066 1066 mainDataSet.addPrimitive(currentRoute); 1067 1067 1068 1068 refreshData(); 1069 1069 1070 1070 for (int i = 0; i < relsListModel.size(); ++i) 1071 1071 { 1072 1073 1072 if (currentRoute == ((RouteReference)relsListModel.elementAt(i)).route) 1073 relsList.setSelectedIndex(i); 1074 1074 } 1075 1075 } … … 1081 1081 currentRoute.put("from", tag_to); 1082 1082 currentRoute.put("to", tag_from); 1083 1083 1084 1084 Vector< RelationMember > itemsToReflect = new Vector< RelationMember >(); 1085 1085 Vector< RelationMember > otherItems = new Vector< RelationMember >(); 1086 1086 int insPos = itineraryTable.getSelectedRow(); 1087 1087 1088 1088 for (int i = 0; i < currentRoute.getMembersCount(); ++i) 1089 1089 { 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 } 1109 1090 RelationMember item = currentRoute.getMember(i); 1091 1092 if (item.isWay()) 1093 { 1094 String role = item.getRole(); 1095 if ("backward".equals(role)) 1096 role = "forward"; 1097 else if ("forward".equals(role)) 1098 role = "backward"; 1099 else 1100 role = "backward"; 1101 1102 itemsToReflect.add(new RelationMember(role, item.getWay())); 1103 } 1104 else if (item.isNode()) 1105 itemsToReflect.add(item); 1106 else 1107 otherItems.add(item); 1108 } 1109 1110 1110 currentRoute.setMembers(null); 1111 1111 for (int i = itemsToReflect.size()-1; i >= 0; --i) 1112 1112 currentRoute.addMember(itemsToReflect.elementAt(i)); 1113 1113 for (int i = 0; i < otherItems.size(); ++i) 1114 1115 1114 currentRoute.addMember(otherItems.elementAt(i)); 1115 1116 1116 refreshData(); 1117 1117 1118 1118 for (int i = 0; i < relsListModel.size(); ++i) 1119 1119 { 1120 1121 1120 if (currentRoute == ((RouteReference)relsListModel.elementAt(i)).route) 1121 relsList.setSelectedIndex(i); 1122 1122 } 1123 1123 } … … 1125 1125 { 1126 1126 DeleteAction.deleteRelation(Main.main.getEditLayer(), currentRoute); 1127 1127 1128 1128 currentRoute = null; 1129 1129 tabbedPane.setEnabledAt(1, false); … … 1131 1131 tabbedPane.setEnabledAt(3, false); 1132 1132 tabbedPane.setEnabledAt(4, false); 1133 1133 1134 1134 refreshData(); 1135 1135 } … … 1144 1144 { 1145 1145 if (mainDataSet == null) 1146 1147 1146 return; 1147 1148 1148 itineraryTable.clearSelection(); 1149 1149 1150 1150 for (int i = 0; i < itineraryData.getRowCount(); ++i) 1151 1151 { 1152 1153 1154 1152 if ((itineraryData.ways.elementAt(i) != null) && 1153 (mainDataSet.isSelected(itineraryData.ways.elementAt(i)))) 1154 itineraryTable.addRowSelectionInterval(i, i); 1155 1155 } 1156 1156 } … … 1160 1160 if (itineraryTable.getSelectedRowCount() > 0) 1161 1161 { 1162 1163 1164 1165 1166 1167 1168 1162 for (int i = 0; i < itineraryData.getRowCount(); ++i) 1163 { 1164 if ((itineraryTable.isRowSelected(i)) && (itineraryData.ways.elementAt(i) != null)) 1165 { 1166 itineraryData.ways.elementAt(i).visit(box); 1167 } 1168 } 1169 1169 } 1170 1170 else 1171 1171 { 1172 1173 1174 1175 1176 1177 1178 1172 for (int i = 0; i < itineraryData.getRowCount(); ++i) 1173 { 1174 if (itineraryData.ways.elementAt(i) != null) 1175 { 1176 itineraryData.ways.elementAt(i).visit(box); 1177 } 1178 } 1179 1179 } 1180 1180 if (box.getBounds() == null) 1181 1181 return; 1182 1182 box.enlargeBoundingBox(); 1183 1183 Main.map.mapView.recalculateCenterScale(box); … … 1190 1190 if (itineraryTable.getSelectedRowCount() > 0) 1191 1191 { 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1192 for (int i = 0; i < itineraryData.getRowCount(); ++i) 1193 { 1194 if ((itineraryTable.isRowSelected(i)) && (itineraryData.ways.elementAt(i) != null)) 1195 { 1196 mainDataSet.addSelected(itineraryData.ways.elementAt(i)); 1197 1198 RelationMember markedWay = new RelationMember 1199 ((String)(itineraryData.getValueAt(i, 1)), itineraryData.ways.elementAt(i)); 1200 markedWays.addElement(markedWay); 1201 } 1202 } 1203 1203 } 1204 1204 else 1205 1205 { 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1206 for (int i = 0; i < itineraryData.getRowCount(); ++i) 1207 { 1208 if (itineraryData.ways.elementAt(i) != null) 1209 { 1210 mainDataSet.addSelected(itineraryData.ways.elementAt(i)); 1211 1212 RelationMember markedWay = new RelationMember 1213 ((String)(itineraryData.getValueAt(i, 1)), itineraryData.ways.elementAt(i)); 1214 markedWays.addElement(markedWay); 1215 } 1216 } 1217 1217 } 1218 1218 } … … 1223 1223 TreeSet<Way> addedWays = new TreeSet<Way>(); 1224 1224 if (mainDataSet == null) 1225 1226 1225 return; 1226 1227 1227 while (relIter.hasNext()) 1228 1228 { 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 } 1239 1229 RelationMember curMember = relIter.next(); 1230 if ((curMember.isWay()) && (mainDataSet.isSelected(curMember.getWay()))) 1231 { 1232 itineraryData.insertRow(insPos, curMember.getWay(), curMember.getRole()); 1233 if (insPos >= 0) 1234 ++insPos; 1235 1236 addedWays.add(curMember.getWay()); 1237 } 1238 } 1239 1240 1240 Collection<Way> selectedWays = mainDataSet.getSelectedWays(); 1241 1241 Iterator<Way> wayIter = selectedWays.iterator(); 1242 1242 1243 1243 while (wayIter.hasNext()) 1244 1244 { 1245 1246 1247 1248 1249 1250 1251 1252 } 1253 1245 Way curMember = wayIter.next(); 1246 if (!(addedWays.contains(curMember))) 1247 { 1248 itineraryData.insertRow(insPos, curMember, ""); 1249 if (insPos >= 0) 1250 ++insPos; 1251 } 1252 } 1253 1254 1254 if ((insPos > 0) && (insPos < itineraryData.getRowCount())) 1255 1255 { 1256 1257 1258 1259 1260 1261 1256 while ((insPos < itineraryData.getRowCount()) 1257 && (itineraryData.ways.elementAt(insPos) == null)) 1258 ++insPos; 1259 itineraryTable.removeRowSelectionInterval(0, itineraryData.getRowCount()-1); 1260 if (insPos < itineraryData.getRowCount()) 1261 itineraryTable.addRowSelectionInterval(insPos, insPos); 1262 1262 } 1263 1263 … … 1269 1269 for (int i = itineraryData.getRowCount()-1; i >=0; --i) 1270 1270 { 1271 1272 1273 1274 1275 1276 } 1277 1271 if ((itineraryTable.isRowSelected(i)) && (itineraryData.ways.elementAt(i) != null)) 1272 { 1273 itineraryData.ways.removeElementAt(i); 1274 itineraryData.removeRow(i); 1275 } 1276 } 1277 1278 1278 itineraryData.cleanupGaps(); 1279 1279 rebuildWays(); … … 1283 1283 TreeSet<Way> usedWays = new TreeSet<Way>(); 1284 1284 TreeMap<Node, LinkedList<RelationMember> > frontNodes = 1285 1285 new TreeMap<Node, LinkedList<RelationMember> >(); 1286 1286 TreeMap<Node, LinkedList<RelationMember> > backNodes = 1287 1287 new TreeMap<Node, LinkedList<RelationMember> >(); 1288 1288 Vector< LinkedList<RelationMember> > loops = 1289 1289 new Vector< LinkedList<RelationMember> >(); 1290 1290 int insPos = itineraryTable.getSelectedRow(); 1291 1291 1292 1292 if (itineraryTable.getSelectedRowCount() > 0) 1293 1293 { 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1294 for (int i = itineraryData.getRowCount()-1; i >=0; --i) 1295 { 1296 if ((itineraryTable.isRowSelected(i)) && (itineraryData.ways.elementAt(i) != null)) 1297 { 1298 if (!(usedWays.contains(itineraryData.ways.elementAt(i)))) 1299 { 1300 addWayToSortingData 1301 (itineraryData.ways.elementAt(i), frontNodes, backNodes, loops); 1302 usedWays.add(itineraryData.ways.elementAt(i)); 1303 } 1304 1305 itineraryData.ways.removeElementAt(i); 1306 itineraryData.removeRow(i); 1307 } 1308 } 1309 1309 } 1310 1310 else 1311 1311 { 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1312 for (int i = itineraryData.getRowCount()-1; i >=0; --i) 1313 { 1314 if (itineraryData.ways.elementAt(i) != null) 1315 { 1316 if (!(usedWays.contains(itineraryData.ways.elementAt(i)))) 1317 { 1318 addWayToSortingData 1319 (itineraryData.ways.elementAt(i), frontNodes, backNodes, loops); 1320 usedWays.add(itineraryData.ways.elementAt(i)); 1321 } 1322 } 1323 } 1324 1325 itineraryData.clear(); 1326 1326 } 1327 1327 1328 1328 Iterator< Map.Entry< Node, LinkedList<RelationMember> > > entryIter 1329 1329 = frontNodes.entrySet().iterator(); 1330 1330 while (entryIter.hasNext()) 1331 1331 { 1332 1333 1334 1335 1336 1337 1338 1339 1340 } 1341 1332 Iterator<RelationMember> relIter = entryIter.next().getValue().iterator(); 1333 while (relIter.hasNext()) 1334 { 1335 RelationMember curMember = relIter.next(); 1336 itineraryData.insertRow(insPos, curMember.getWay(), curMember.getRole()); 1337 if (insPos >= 0) 1338 ++insPos; 1339 } 1340 } 1341 1342 1342 Iterator< LinkedList<RelationMember> > listIter = loops.iterator(); 1343 1343 while (listIter.hasNext()) 1344 1344 { 1345 1346 1347 1348 1349 1350 1351 1352 1353 } 1354 1345 Iterator<RelationMember> relIter = listIter.next().iterator(); 1346 while (relIter.hasNext()) 1347 { 1348 RelationMember curMember = relIter.next(); 1349 itineraryData.insertRow(insPos, curMember.getWay(), curMember.getRole()); 1350 if (insPos >= 0) 1351 ++insPos; 1352 } 1353 } 1354 1355 1355 itineraryData.cleanupGaps(); 1356 1356 rebuildWays(); … … 1360 1360 Vector<RelationMember> itemsToReflect = new Vector<RelationMember>(); 1361 1361 int insPos = itineraryTable.getSelectedRow(); 1362 1362 1363 1363 if (itineraryTable.getSelectedRowCount() > 0) 1364 1364 { 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1365 for (int i = itineraryData.getRowCount()-1; i >=0; --i) 1366 { 1367 if ((itineraryTable.isRowSelected(i)) && (itineraryData.ways.elementAt(i) != null)) 1368 { 1369 String role = (String)(itineraryData.getValueAt(i, 1)); 1370 if ("backward".equals(role)) 1371 role = "forward"; 1372 else if ("forward".equals(role)) 1373 role = "backward"; 1374 else 1375 role = "backward"; 1376 RelationMember markedWay = new RelationMember 1377 (role, itineraryData.ways.elementAt(i)); 1378 itemsToReflect.addElement(markedWay); 1379 1380 itineraryData.ways.removeElementAt(i); 1381 itineraryData.removeRow(i); 1382 } 1383 } 1384 1384 } 1385 1385 else 1386 1386 { 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1387 for (int i = itineraryData.getRowCount()-1; i >=0; --i) 1388 { 1389 if (itineraryData.ways.elementAt(i) != null) 1390 { 1391 String role = (String)(itineraryData.getValueAt(i, 1)); 1392 if ("backward".equals(role)) 1393 role = "forward"; 1394 else if ("forward".equals(role)) 1395 role = "backward"; 1396 else 1397 role = "backward"; 1398 RelationMember markedWay = new RelationMember 1399 (role, itineraryData.ways.elementAt(i)); 1400 itemsToReflect.addElement(markedWay); 1401 } 1402 } 1403 1404 itineraryData.clear(); 1405 1405 } 1406 1406 … … 1409 1409 while (relIter.hasNext()) 1410 1410 { 1411 RelationMember curMember = relIter.next(); 1412 if (curMember.isWay()) 1413 { 1414 itineraryData.insertRow(insPos, curMember.getWay(), curMember.getRole()); 1415 if (insPos >= 0) 1416 ++insPos; 1417 } 1418 } 1411 RelationMember curMember = relIter.next(); 1412 if (curMember.isWay()) 1413 { 1414 itineraryData.insertRow(insPos, curMember.getWay(), curMember.getRole()); 1419 1415 if (insPos >= 0) 1420 itineraryTable.addRowSelectionInterval(startPos, insPos-1); 1421 1416 ++insPos; 1417 } 1418 } 1419 if (insPos >= 0) 1420 itineraryTable.addRowSelectionInterval(startPos, insPos-1); 1421 1422 1422 itineraryData.cleanupGaps(); 1423 1423 rebuildWays(); … … 1426 1426 { 1427 1427 if (mainDataSet == null) 1428 1429 1428 return; 1429 1430 1430 stoplistTable.clearSelection(); 1431 1431 1432 1432 for (int i = 0; i < stoplistData.getRowCount(); ++i) 1433 1433 { 1434 1435 1436 1434 if ((stoplistData.nodes.elementAt(i) != null) && 1435 (mainDataSet.isSelected(stoplistData.nodes.elementAt(i)))) 1436 stoplistTable.addRowSelectionInterval(i, i); 1437 1437 } 1438 1438 } … … 1442 1442 if (stoplistTable.getSelectedRowCount() > 0) 1443 1443 { 1444 1445 1446 1447 1448 1449 1450 1444 for (int i = 0; i < stoplistData.getRowCount(); ++i) 1445 { 1446 if (stoplistTable.isRowSelected(i)) 1447 { 1448 stoplistData.nodes.elementAt(i).visit(box); 1449 } 1450 } 1451 1451 } 1452 1452 else 1453 1453 { 1454 1455 1456 1457 1454 for (int i = 0; i < stoplistData.getRowCount(); ++i) 1455 { 1456 stoplistData.nodes.elementAt(i).visit(box); 1457 } 1458 1458 } 1459 1459 if (box.getBounds() == null) 1460 1460 return; 1461 1461 box.enlargeBoundingBox(); 1462 1462 Main.map.mapView.recalculateCenterScale(box); … … 1469 1469 if (stoplistTable.getSelectedRowCount() > 0) 1470 1470 { 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1471 for (int i = 0; i < stoplistData.getRowCount(); ++i) 1472 { 1473 if (stoplistTable.isRowSelected(i)) 1474 { 1475 mainDataSet.addSelected(stoplistData.nodes.elementAt(i)); 1476 1477 RelationMember markedNode = new RelationMember 1478 ((String)(stoplistData.getValueAt(i, 1)), stoplistData.nodes.elementAt(i)); 1479 markedNodes.addElement(markedNode); 1480 } 1481 } 1482 1482 } 1483 1483 else 1484 1484 { 1485 1486 1487 1488 1489 1490 1491 1492 1485 for (int i = 0; i < stoplistData.getRowCount(); ++i) 1486 { 1487 mainDataSet.addSelected(stoplistData.nodes.elementAt(i)); 1488 1489 RelationMember markedNode = new RelationMember 1490 ((String)(stoplistData.getValueAt(i, 1)), stoplistData.nodes.elementAt(i)); 1491 markedNodes.addElement(markedNode); 1492 } 1493 1493 } 1494 1494 } … … 1499 1499 TreeSet<Node> addedNodes = new TreeSet<Node>(); 1500 1500 if (mainDataSet == null) 1501 1502 1501 return; 1502 1503 1503 while (relIter.hasNext()) 1504 1504 { 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 } 1515 1505 RelationMember curMember = relIter.next(); 1506 if ((curMember.isNode()) && (mainDataSet.isSelected(curMember.getNode()))) 1507 { 1508 stoplistData.insertRow(insPos, curMember.getNode(), curMember.getRole()); 1509 if (insPos >= 0) 1510 ++insPos; 1511 1512 addedNodes.add(curMember.getNode()); 1513 } 1514 } 1515 1516 1516 Collection<Node> selectedNodes = mainDataSet.getSelectedNodes(); 1517 1517 Iterator<Node> nodeIter = selectedNodes.iterator(); 1518 1518 1519 1519 while (nodeIter.hasNext()) 1520 1520 { 1521 1522 1523 1524 1525 1526 1527 1528 } 1529 1521 Node curMember = nodeIter.next(); 1522 if (!(addedNodes.contains(curMember))) 1523 { 1524 stoplistData.insertRow(insPos, curMember, ""); 1525 if (insPos >= 0) 1526 ++insPos; 1527 } 1528 } 1529 1530 1530 if ((insPos > 0) && (insPos < stoplistData.getRowCount())) 1531 1531 { 1532 1533 1534 1535 1536 1537 1532 while ((insPos < stoplistData.getRowCount()) 1533 && (stoplistData.nodes.elementAt(insPos) == null)) 1534 ++insPos; 1535 stoplistTable.removeRowSelectionInterval(0, stoplistData.getRowCount()-1); 1536 if (insPos < stoplistData.getRowCount()) 1537 stoplistTable.addRowSelectionInterval(insPos, insPos); 1538 1538 } 1539 1539 … … 1544 1544 for (int i = stoplistData.getRowCount()-1; i >=0; --i) 1545 1545 { 1546 1547 1548 1549 1550 1551 } 1552 1546 if (stoplistTable.isRowSelected(i)) 1547 { 1548 stoplistData.nodes.removeElementAt(i); 1549 stoplistData.removeRow(i); 1550 } 1551 } 1552 1553 1553 rebuildNodes(); 1554 1554 } … … 1560 1560 for (int i = 0; i < itineraryData.getRowCount(); ++i) 1561 1561 { 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 } 1594 1562 if (itineraryData.ways.elementAt(i) != null) 1563 { 1564 Way way = itineraryData.ways.elementAt(i); 1565 if (!(way.isIncomplete())) 1566 { 1567 if ("backward".equals((String)(itineraryData.getValueAt(i, 1)))) 1568 { 1569 for (int j = way.getNodesCount()-2; j >= 0; --j) 1570 { 1571 SegmentMetric sm = new SegmentMetric 1572 (way.getNode(j+1).getCoor().lat(), way.getNode(j+1).getCoor().lon(), 1573 way.getNode(j).getCoor().lat(), way.getNode(j).getCoor().lon()); 1574 segmentMetrics.add(sm); 1575 } 1576 } 1577 else 1578 { 1579 for (int j = 0; j < way.getNodesCount()-1; ++j) 1580 { 1581 SegmentMetric sm = new SegmentMetric 1582 (way.getNode(j).getCoor().lat(), way.getNode(j).getCoor().lon(), 1583 way.getNode(j+1).getCoor().lat(), way.getNode(j+1).getCoor().lon()); 1584 segmentMetrics.add(sm); 1585 } 1586 } 1587 } 1588 } 1589 else 1590 { 1591 segmentMetrics.add(null); 1592 } 1593 } 1594 1595 1595 Vector< StopReference > srm = new Vector< StopReference >(); 1596 1596 int insPos = stoplistTable.getSelectedRow(); … … 1599 1599 // Determine for each member its position on the itinerary: position means here the 1600 1600 // point on the itinerary that has minimal distance to the coor 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1601 for (int i = stoplistData.getRowCount()-1; i >= 0; --i) 1602 { 1603 if (stoplistTable.isRowSelected(i)) 1604 { 1605 StopReference sr = detectMinDistance 1606 (stoplistData.nodes.elementAt(i), segmentMetrics, 1607 cbRight.isSelected(), cbLeft.isSelected()); 1608 if (sr != null) 1609 { 1610 if (sr.distance < 1611 Double.parseDouble(tfSuggestStopsLimit.getText()) * 9.0 / 1000000.0 ) 1612 { 1613 sr.role = (String)stoplistData.getValueAt(i, 1); 1614 srm.addElement(sr); 1615 } 1616 else 1617 { 1618 sr.role = (String)stoplistData.getValueAt(i, 1); 1619 sr.index = segmentMetrics.size()*2; 1620 sr.pos = 0; 1621 srm.addElement(sr); 1622 } 1623 1624 stoplistData.nodes.removeElementAt(i); 1625 stoplistData.removeRow(i); 1626 } 1627 1628 } 1629 } 1630 1630 } 1631 1631 else 1632 1632 { 1633 1633 // Determine for each member its position on the itinerary: position means here the 1634 1634 // point on the itinerary that has minimal distance to the coor 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1635 for (int i = stoplistData.getRowCount()-1; i >= 0; --i) 1636 { 1637 StopReference sr = detectMinDistance 1638 (stoplistData.nodes.elementAt(i), segmentMetrics, 1639 cbRight.isSelected(), cbLeft.isSelected()); 1640 if (sr != null) 1641 { 1642 if (sr.distance < 1643 Double.parseDouble(tfSuggestStopsLimit.getText()) * 9.0 / 1000000.0 ) 1644 { 1645 sr.role = (String)stoplistData.getValueAt(i, 1); 1646 srm.addElement(sr); 1647 } 1648 else 1649 { 1650 sr.role = (String)stoplistData.getValueAt(i, 1); 1651 sr.index = segmentMetrics.size()*2; 1652 sr.pos = 0; 1653 srm.addElement(sr); 1654 } 1655 } 1656 } 1657 1658 stoplistData.clear(); 1659 1659 } 1660 1660 1661 1661 Collections.sort(srm); 1662 1662 1663 1663 for (int i = 0; i < srm.size(); ++i) 1664 1664 { 1665 1666 1667 1668 } 1669 1665 stoplistData.insertRow(insPos, srm.elementAt(i).node, srm.elementAt(i).role); 1666 if (insPos >= 0) 1667 ++insPos; 1668 } 1669 1670 1670 rebuildNodes(); 1671 1671 } … … 1674 1674 Vector<RelationMember> itemsToReflect = new Vector<RelationMember>(); 1675 1675 int insPos = stoplistTable.getSelectedRow(); 1676 1676 1677 1677 if (stoplistTable.getSelectedRowCount() > 0) 1678 1678 { 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1679 for (int i = stoplistData.getRowCount()-1; i >=0; --i) 1680 { 1681 if (stoplistTable.isRowSelected(i)) 1682 { 1683 String role = (String)(stoplistData.getValueAt(i, 1)); 1684 RelationMember markedNode = new RelationMember 1685 (role, stoplistData.nodes.elementAt(i)); 1686 itemsToReflect.addElement(markedNode); 1687 1688 stoplistData.nodes.removeElementAt(i); 1689 stoplistData.removeRow(i); 1690 } 1691 } 1692 1692 } 1693 1693 else 1694 1694 { 1695 1696 1697 1698 1699 1700 1701 1702 1703 1695 for (int i = stoplistData.getRowCount()-1; i >=0; --i) 1696 { 1697 String role = (String)(stoplistData.getValueAt(i, 1)); 1698 RelationMember markedNode = new RelationMember 1699 (role, stoplistData.nodes.elementAt(i)); 1700 itemsToReflect.addElement(markedNode); 1701 } 1702 1703 stoplistData.clear(); 1704 1704 } 1705 1705 … … 1708 1708 while (relIter.hasNext()) 1709 1709 { 1710 RelationMember curMember = relIter.next(); 1711 if (curMember.isNode()) 1712 { 1713 stoplistData.insertRow(insPos, curMember.getNode(), curMember.getRole()); 1714 if (insPos >= 0) 1715 ++insPos; 1716 } 1717 } 1710 RelationMember curMember = relIter.next(); 1711 if (curMember.isNode()) 1712 { 1713 stoplistData.insertRow(insPos, curMember.getNode(), curMember.getRole()); 1718 1714 if (insPos >= 0) 1719 stoplistTable.addRowSelectionInterval(startPos, insPos-1); 1720 1715 ++insPos; 1716 } 1717 } 1718 if (insPos >= 0) 1719 stoplistTable.addRowSelectionInterval(startPos, insPos-1); 1720 1721 1721 rebuildNodes(); 1722 1722 } … … 1728 1728 for (int i = 0; i < itineraryData.getRowCount(); ++i) 1729 1729 { 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 } 1762 1730 if (itineraryData.ways.elementAt(i) != null) 1731 { 1732 Way way = itineraryData.ways.elementAt(i); 1733 if (!(way.isIncomplete())) 1734 { 1735 if ("backward".equals((String)(itineraryData.getValueAt(i, 1)))) 1736 { 1737 for (int j = way.getNodesCount()-2; j >= 0; --j) 1738 { 1739 SegmentMetric sm = new SegmentMetric 1740 (way.getNode(j+1).getCoor().lat(), way.getNode(j+1).getCoor().lon(), 1741 way.getNode(j).getCoor().lat(), way.getNode(j).getCoor().lon()); 1742 segmentMetrics.add(sm); 1743 } 1744 } 1745 else 1746 { 1747 for (int j = 0; j < way.getNodesCount()-1; ++j) 1748 { 1749 SegmentMetric sm = new SegmentMetric 1750 (way.getNode(j).getCoor().lat(), way.getNode(j).getCoor().lon(), 1751 way.getNode(j+1).getCoor().lat(), way.getNode(j+1).getCoor().lon()); 1752 segmentMetrics.add(sm); 1753 } 1754 } 1755 } 1756 } 1757 else 1758 { 1759 segmentMetrics.add(null); 1760 } 1761 } 1762 1763 1763 Vector< StopReference > srm = new Vector< StopReference >(); 1764 1764 // Determine for each member its position on the itinerary: position means here the … … 1767 1767 if (mainDataSet != null) 1768 1768 { 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1769 String stopKey = ""; 1770 String stopValue = ""; 1771 if ("bus".equals(currentRoute.get("route"))) 1772 { 1773 stopKey = "highway"; 1774 stopValue = "bus_stop"; 1775 } 1776 else if ("trolleybus".equals(currentRoute.get("route"))) 1777 { 1778 stopKey = "highway"; 1779 stopValue = "bus_stop"; 1780 } 1781 else if ("tram".equals(currentRoute.get("route"))) 1782 { 1783 stopKey = "railway"; 1784 stopValue = "tram_stop"; 1785 } 1786 else if ("light_rail".equals(currentRoute.get("route"))) 1787 { 1788 stopKey = "railway"; 1789 stopValue = "station"; 1790 } 1791 else if ("subway".equals(currentRoute.get("route"))) 1792 { 1793 stopKey = "railway"; 1794 stopValue = "station"; 1795 } 1796 else if ("rail".equals(currentRoute.get("route"))) 1797 { 1798 stopKey = "railway"; 1799 stopValue = "station"; 1800 } 1801 1802 Collection< Node > nodeCollection = mainDataSet.getNodes(); 1803 Iterator< Node > nodeIter = nodeCollection.iterator(); 1804 while (nodeIter.hasNext()) 1805 { 1806 Node currentNode = nodeIter.next(); 1807 if (!currentNode.isUsable()) 1808 continue; 1809 if (stopValue.equals(currentNode.get(stopKey))) 1810 { 1811 StopReference sr = detectMinDistance 1812 (currentNode, segmentMetrics, 1813 cbRight.isSelected(), cbLeft.isSelected()); 1814 if ((sr != null) && (sr.distance < 1815 Double.parseDouble(tfSuggestStopsLimit.getText()) * 9.0 / 1000000.0 )) 1816 srm.addElement(sr); 1817 } 1818 } 1819 1819 } 1820 1820 else 1821 1821 { 1822 1823 1822 JOptionPane.showMessageDialog(null, "There exists no dataset." 1823 + " Try to download data from the server or open an OSM file.", 1824 1824 "No data found", JOptionPane.ERROR_MESSAGE); 1825 1826 1827 } 1828 1825 1826 System.out.println("Public Transport: RoutePattern: No data found"); 1827 } 1828 1829 1829 for (int i = 0; i < stoplistData.getRowCount(); ++i) 1830 1830 { … … 1832 1832 1833 1833 Collections.sort(srm); 1834 1834 1835 1835 stoplistData.clear(); 1836 1836 for (int i = 0; i < srm.size(); ++i) 1837 1837 { 1838 1839 } 1840 1838 stoplistData.addRow(srm.elementAt(i).node, srm.elementAt(i).role); 1839 } 1840 1841 1841 rebuildNodes(); 1842 1842 } … … 1844 1844 { 1845 1845 refreshData(); 1846 1846 1847 1847 jDialog.setLocationRelativeTo(frame); 1848 1848 jDialog.setVisible(true); 1849 1849 } 1850 1850 } 1851 1851 1852 1852 private void refreshData() { 1853 1853 Relation copy = currentRoute; 1854 1854 relsListModel.clear(); 1855 1855 currentRoute = copy; 1856 1856 1857 1857 DataSet mainDataSet = Main.main.getCurrentDataSet(); 1858 1858 if (mainDataSet != null) … … 1861 1861 Collection< Relation > relCollection = mainDataSet.getRelations(); 1862 1862 Iterator< Relation > relIter = relCollection.iterator(); 1863 1863 1864 1864 while (relIter.hasNext()) 1865 1865 { 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 } 1884 1866 Relation currentRel = relIter.next(); 1867 if (!currentRel.isDeleted()) 1868 { 1869 String routeVal = currentRel.get("route"); 1870 if ("bus".equals(routeVal)) 1871 relRefs.add(new RouteReference(currentRel)); 1872 else if ("trolleybus".equals(routeVal)) 1873 relRefs.add(new RouteReference(currentRel)); 1874 else if ("tram".equals(routeVal)) 1875 relRefs.add(new RouteReference(currentRel)); 1876 else if ("light_rail".equals(routeVal)) 1877 relRefs.add(new RouteReference(currentRel)); 1878 else if ("subway".equals(routeVal)) 1879 relRefs.add(new RouteReference(currentRel)); 1880 else if ("rail".equals(routeVal)) 1881 relRefs.add(new RouteReference(currentRel)); 1882 } 1883 } 1884 1885 1885 Collections.sort(relRefs); 1886 1886 1887 1887 Iterator< RouteReference > iter = relRefs.iterator(); 1888 1888 while (iter.hasNext()) 1889 1889 relsListModel.addElement(iter.next()); 1890 1890 } 1891 1891 else 1892 1892 { 1893 1893 JOptionPane.showMessageDialog(null, "There exists no dataset." 1894 1894 + " Try to download data from the server or open an OSM file.", 1895 1895 "No data found", JOptionPane.ERROR_MESSAGE); 1896 1896 1897 1897 System.out.println("Public Transport: No data found"); 1898 1898 } 1899 1899 } 1900 1900 1901 1901 //Rebuild ways in the relation currentRoute 1902 1902 public static void rebuildWays() { … … 1907 1907 { 1908 1908 if (iter.next().isWay()) 1909 1909 iter.remove(); 1910 1910 } 1911 1911 for (int i = 0; i < itineraryData.getRowCount(); ++i) … … 1913 1913 if (itineraryData.ways.elementAt(i) != null) 1914 1914 { 1915 1916 1917 1918 1915 RelationMember member = new RelationMember 1916 ((String)(itineraryData.getValueAt(i, 1)), 1917 itineraryData.ways.elementAt(i)); 1918 members.add(member); 1919 1919 } 1920 1920 } 1921 1921 currentRoute.setMembers(members); 1922 1922 } 1923 1923 1924 1924 //Rebuild nodes in the relation currentRoute 1925 1925 private void rebuildNodes() { … … 1929 1929 if (currentRoute.getMember(i).isNode()) 1930 1930 { 1931 1931 currentRoute.removeMember(i); 1932 1932 } 1933 1933 } … … 1935 1935 { 1936 1936 RelationMember member = new RelationMember 1937 1937 ((String)(stoplistData.getValueAt(i, 1)), stoplistData.nodes.elementAt(i)); 1938 1938 currentRoute.addMember(member); 1939 1939 } 1940 1940 } 1941 1941 1942 1942 private void addWayToSortingData 1943 1943 (Way way, TreeMap<Node, LinkedList<RelationMember> > frontNodes, … … 1947 1947 if (way.getNodesCount() < 1) 1948 1948 return; 1949 1949 1950 1950 Node firstNode = way.getNode(0); 1951 1951 Node lastNode = way.getNode(way.getNodesCount() - 1); 1952 1952 1953 1953 if (frontNodes.get(firstNode) != null) 1954 1954 { … … 1956 1956 list.addFirst(new RelationMember("backward", way)); 1957 1957 frontNodes.remove(firstNode); 1958 1958 1959 1959 Node lastListNode = null; 1960 1960 if ("backward".equals(list.getLast().getRole())) 1961 1961 lastListNode = list.getLast().getWay().getNode(0); 1962 1962 else 1963 1964 1963 lastListNode = list.getLast().getWay().getNode 1964 (list.getLast().getWay().getNodesCount() - 1); 1965 1965 if (lastNode.equals(lastListNode)) 1966 1966 { 1967 1968 1967 backNodes.remove(lastListNode); 1968 loops.add(list); 1969 1969 } 1970 1970 else if (frontNodes.get(lastNode) != null) 1971 1971 { 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1972 backNodes.remove(lastListNode); 1973 LinkedList<RelationMember> listToAppend = frontNodes.get(lastNode); 1974 Iterator<RelationMember> memberIter = list.iterator(); 1975 while (memberIter.hasNext()) 1976 { 1977 RelationMember member = memberIter.next(); 1978 if ("backward".equals(member.getRole())) 1979 listToAppend.addFirst(new RelationMember("forward", member.getWay())); 1980 else 1981 listToAppend.addFirst(new RelationMember("backward", member.getWay())); 1982 } 1983 frontNodes.remove(lastNode); 1984 frontNodes.put(lastListNode, listToAppend); 1985 1985 } 1986 1986 else if (backNodes.get(lastNode) != null) 1987 1987 { 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1988 backNodes.remove(lastListNode); 1989 LinkedList<RelationMember> listToAppend = backNodes.get(lastNode); 1990 Iterator<RelationMember> memberIter = list.iterator(); 1991 while (memberIter.hasNext()) 1992 { 1993 RelationMember member = memberIter.next(); 1994 listToAppend.addLast(member); 1995 } 1996 backNodes.remove(lastNode); 1997 backNodes.put(lastListNode, listToAppend); 1998 1998 } 1999 1999 else 2000 2000 frontNodes.put(lastNode, list); 2001 2001 } 2002 2002 else if (backNodes.get(firstNode) != null) … … 2005 2005 list.addLast(new RelationMember("forward", way)); 2006 2006 backNodes.remove(firstNode); 2007 2007 2008 2008 Node firstListNode = null; 2009 2009 if ("backward".equals(list.getFirst().getRole())) 2010 2011 2010 firstListNode = list.getFirst().getWay().getNode 2011 (list.getFirst().getWay().getNodesCount() - 1); 2012 2012 else 2013 2013 firstListNode = list.getFirst().getWay().getNode(0); 2014 2014 if (lastNode.equals(firstListNode)) 2015 2015 { 2016 2017 2016 frontNodes.remove(firstListNode); 2017 loops.add(list); 2018 2018 } 2019 2019 else if (frontNodes.get(lastNode) != null) 2020 2020 { 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2021 frontNodes.remove(firstListNode); 2022 LinkedList<RelationMember> listToAppend = frontNodes.get(lastNode); 2023 ListIterator<RelationMember> memberIter = list.listIterator(list.size()); 2024 while (memberIter.hasPrevious()) 2025 { 2026 RelationMember member = memberIter.previous(); 2027 listToAppend.addFirst(member); 2028 } 2029 frontNodes.remove(lastNode); 2030 frontNodes.put(firstListNode, listToAppend); 2031 2031 } 2032 2032 else if (backNodes.get(lastNode) != null) 2033 2033 { 2034 frontNodes.remove(firstListNode); 2035 LinkedList<RelationMember> listToAppend = backNodes.get(lastNode); 2036 ListIterator<RelationMember> memberIter = list.listIterator(list.size()); 2037 while (memberIter.hasPrevious()) 2038 { 2039 RelationMember member = memberIter.previous(); 2040 if ("backward".equals(member.getRole())) 2041 listToAppend.addLast(new RelationMember("forward", member.getWay())); 2042 else 2043 listToAppend.addLast(new RelationMember("backward", member.getWay())); 2044 } 2045 backNodes.remove(lastNode); 2046 backNodes.put(firstListNode, listToAppend); 2047 } 2034 frontNodes.remove(firstListNode); 2035 LinkedList<RelationMember> listToAppend = backNodes.get(lastNode); 2036 ListIterator<RelationMember> memberIter = list.listIterator(list.size()); 2037 while (memberIter.hasPrevious()) 2038 { 2039 RelationMember member = memberIter.previous(); 2040 if ("backward".equals(member.getRole())) 2041 listToAppend.addLast(new RelationMember("forward", member.getWay())); 2048 2042 else 2049 backNodes.put(lastNode, list); 2043 listToAppend.addLast(new RelationMember("backward", member.getWay())); 2044 } 2045 backNodes.remove(lastNode); 2046 backNodes.put(firstListNode, listToAppend); 2047 } 2048 else 2049 backNodes.put(lastNode, list); 2050 2050 } 2051 2051 else if (frontNodes.get(lastNode) != null) … … 2071 2071 } 2072 2072 } 2073 2073 2074 2074 private void routesSelectionChanged() { 2075 2075 int selectedPos = relsList.getAnchorSelectionIndex(); … … 2081 2081 tabbedPane.setEnabledAt(3, true); 2082 2082 tabbedPane.setEnabledAt(4, true); 2083 2083 2084 2084 //Prepare Tags 2085 2085 requiredTagsData.readRelation(currentRoute); 2086 2086 commonTagsData.readRelation(currentRoute); 2087 2087 otherTagsData.readRelation(currentRoute, tagBlacklist); 2088 2088 2089 2089 //Prepare Itinerary 2090 2090 itineraryData.clear(); … … 2092 2092 Iterator<RelationMember> relIter = relMembers.iterator(); 2093 2093 fillItineraryTable(relIter, 0, -1); 2094 2094 2095 2095 //Prepare Stoplist 2096 2096 stoplistData.clear(); … … 2108 2108 } 2109 2109 } 2110 2110 2111 2111 private void fillItineraryTable 2112 2112 (Iterator<RelationMember> relIter, long lastNodeId, int insPos) { … … 2116 2116 if (curMember.isWay()) 2117 2117 { 2118 2119 2120 2118 itineraryData.insertRow(insPos, curMember.getWay(), curMember.getRole()); 2119 if (insPos >= 0) 2120 ++insPos; 2121 2121 } 2122 2122 } 2123 2123 itineraryData.cleanupGaps(); 2124 2124 } 2125 2125 2126 2126 private void fillStoplistTable 2127 2127 (Iterator<RelationMember> relIter, int insPos) { … … 2131 2131 if (curMember.isNode()) 2132 2132 { 2133 2134 2135 2133 stoplistData.insertRow(insPos, curMember.getNode(), curMember.getRole()); 2134 if (insPos >= 0) 2135 ++insPos; 2136 2136 } 2137 2137 } 2138 2138 } 2139 2139 2140 2140 private StopReference detectMinDistance 2141 2141 (Node node, Vector< SegmentMetric > segmentMetrics, … … 2146 2146 double lat = node.getCoor().lat(); 2147 2147 double lon = node.getCoor().lon(); 2148 2148 2149 2149 int curIndex = -2; 2150 2150 double angleLat = 100.0; … … 2155 2155 curIndex += 2; 2156 2156 SegmentMetric sm = iter.next(); 2157 2157 2158 2158 if (sm == null) 2159 2159 { 2160 2161 2162 2163 2164 } 2165 2160 angleLat = 100.0; 2161 angleLon = 200.0; 2162 2163 continue; 2164 } 2165 2166 2166 double curPosition = (lat - sm.aLat)*sm.d1 + (lon - sm.aLon)*sm.d2; 2167 2167 2168 2168 if (curPosition < 0) 2169 2169 { 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2170 if (angleLat <= 90.0) 2171 { 2172 double lastSegAngle = Math.atan2(angleLat - sm.aLat, angleLon - sm.aLon); 2173 double segAngle = Math.atan2(sm.d1, -sm.o1); 2174 double vertexAngle = Math.atan2(lat - sm.aLat, lon - sm.aLon); 2175 2176 boolean vertexOnSeg = (vertexAngle == segAngle) || 2177 (vertexAngle == lastSegAngle); 2178 boolean vertexOnTheLeft = (!vertexOnSeg) && 2179 (((lastSegAngle > vertexAngle) && (vertexAngle > segAngle)) 2180 || ((vertexAngle > segAngle) && (segAngle > lastSegAngle)) 2181 || ((segAngle > lastSegAngle) && (lastSegAngle > vertexAngle))); 2182 2183 double currentDistance = Math.sqrt((lat - sm.aLat)*(lat - sm.aLat) 2184 + (lon - sm.aLon)*(lon - sm.aLon) 2185 *Math.cos(sm.aLat * Math.PI/180.0)*Math.cos(sm.aLat * Math.PI/180.0)); 2186 curPosition = vertexAngle - segAngle; 2187 if (vertexOnTheLeft) 2188 curPosition = -curPosition; 2189 if (curPosition < 0) 2190 curPosition += 2*Math.PI; 2191 if ((Math.abs(currentDistance) < distance) 2192 && (((!vertexOnTheLeft) && (rhsPossible)) 2193 || ((vertexOnTheLeft) && (lhsPossible)) 2194 || (vertexOnSeg))) 2195 { 2196 distance = Math.abs(currentDistance); 2197 minIndex = curIndex-1; 2198 position = curPosition; 2199 } 2200 } 2201 angleLat = 100.0; 2202 angleLon = 200.0; 2203 2203 } 2204 2204 else if (curPosition > sm.length) 2205 2205 { 2206 2207 2206 angleLat = sm.aLat; 2207 angleLon = sm.aLon; 2208 2208 } 2209 2209 else 2210 2210 { 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 } 2224 } 2225 2211 double currentDistance = (lat - sm.aLat)*sm.o1 + (lon - sm.aLon)*sm.o2; 2212 if ((Math.abs(currentDistance) < distance) 2213 && (((currentDistance >= 0) && (rhsPossible)) 2214 || ((currentDistance <= 0) && (lhsPossible)))) 2215 { 2216 distance = Math.abs(currentDistance); 2217 minIndex = curIndex; 2218 position = curPosition; 2219 } 2220 2221 angleLat = 100.0; 2222 angleLon = 200.0; 2223 } 2224 } 2225 2226 2226 if (minIndex == -1) 2227 2227 return new StopReference(segmentMetrics.size()*2, 0, 180.0, node.get("name"), 2228 2229 2228 "", node); 2229 2230 2230 return new StopReference(minIndex, position, distance, node.get("name"), 2231 2231 "", node); 2232 2232 } 2233 2233 } -
applications/editors/josm/plugins/public_transport/src/public_transport/SettingsStoptypeCommand.java
r22048 r23192 21 21 railway = node.get("railway"); 22 22 } 23 23 24 24 public Node node; 25 25 public String highway; 26 26 public String railway; 27 27 }; 28 28 29 29 private Vector< HighwayRailway > oldStrings = null; 30 30 private WaypointTableModel waypointTM = null; 31 31 private DefaultListModel tracksListModel = null; 32 32 private String type = null; 33 33 34 34 public SettingsStoptypeCommand(StopImporterAction controller) 35 35 { … … 39 39 oldStrings = new Vector< HighwayRailway >(); 40 40 } 41 41 42 42 public boolean executeCommand() 43 43 { … … 47 47 if ((Node)waypointTM.nodes.elementAt(i) != null) 48 48 { 49 50 51 49 Node node = (Node)waypointTM.nodes.elementAt(i); 50 oldStrings.add(new HighwayRailway(node)); 51 StopImporterAction.setTagsWrtType(node, type); 52 52 } 53 53 } … … 57 57 for (int i = 0; i < track.stoplistTM.getRowCount(); ++i) 58 58 { 59 60 61 62 63 64 59 if (track.stoplistTM.nodeAt(i) != null) 60 { 61 Node node = track.stoplistTM.nodeAt(i); 62 oldStrings.add(new HighwayRailway(node)); 63 StopImporterAction.setTagsWrtType(node, type); 64 } 65 65 } 66 66 } 67 67 return true; 68 68 } 69 69 70 70 public void undoCommand() 71 71 { … … 77 77 } 78 78 } 79 79 80 80 public void fillModifiedData 81 81 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 83 83 { 84 84 } 85 85 86 86 @Override public JLabel getDescription() 87 87 { 88 88 return new JLabel("public_transport.Settings.ChangeStoptype"); 89 89 } 90 90 91 91 }; -
applications/editors/josm/plugins/public_transport/src/public_transport/StopImporterAction.java
r20867 r23192 62 62 63 63 public class StopImporterAction extends JosmAction 64 { 64 { 65 65 private static StopImporterDialog dialog = null; 66 66 private static DefaultListModel tracksListModel = null; … … 69 69 private static WaypointTableModel waypointTM = null; 70 70 public boolean inEvent = false; 71 71 72 72 public StopImporterAction() 73 73 { 74 74 super(tr("Create Stops from GPX ..."), null, 75 75 tr("Create Stops from a GPX file"), null, true); 76 76 } 77 77 … … 80 80 return waypointTM; 81 81 } 82 82 83 83 public StopImporterDialog getDialog() 84 84 { … … 92 92 return tracksListModel; 93 93 } 94 94 95 95 public TrackReference getCurrentTrack() 96 96 { … … 101 101 { 102 102 DataSet mainDataSet = Main.main.getCurrentDataSet(); 103 103 104 104 if (dialog == null) 105 105 dialog = new StopImporterDialog(this); 106 106 107 107 dialog.setVisible(true); 108 108 … … 112 112 if (curDir.equals("")) 113 113 { 114 114 curDir = "."; 115 115 } 116 116 JFileChooser fc = new JFileChooser(new File(curDir)); 117 fc.setDialogTitle("Select GPX file"); 117 fc.setDialogTitle("Select GPX file"); 118 118 fc.setMultiSelectionEnabled(false); 119 119 120 120 int answer = fc.showOpenDialog(Main.parent); 121 121 if (answer != JFileChooser.APPROVE_OPTION) 122 123 122 return; 123 124 124 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) 125 126 125 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 126 127 127 importData(fc.getSelectedFile()); 128 128 129 129 refreshData(); 130 130 } … … 132 132 { 133 133 if ((!inEvent) && (dialog.gpsTimeStartValid()) && (currentTrack != null)) 134 134 Main.main.undoRedo.add(new TrackStoplistRelocateCommand(this)); 135 135 } 136 136 else if ("stopImporter.settingsStopwatchStart".equals(event.getActionCommand())) 137 137 { 138 138 if ((!inEvent) && (dialog.stopwatchStartValid()) && (currentTrack != null)) 139 139 Main.main.undoRedo.add(new TrackStoplistRelocateCommand(this)); 140 140 } 141 141 else if ("stopImporter.settingsTimeWindow".equals(event.getActionCommand())) 142 142 { 143 143 if (currentTrack != null) 144 144 currentTrack.timeWindow = dialog.getTimeWindow(); 145 145 } 146 146 else if ("stopImporter.settingsThreshold".equals(event.getActionCommand())) 147 147 { 148 148 if (currentTrack != null) 149 149 currentTrack.threshold = dialog.getThreshold(); 150 150 } 151 151 else if ("stopImporter.settingsSuggestStops".equals(event.getActionCommand())) … … 189 189 private void importData(final File file) 190 190 { 191 try 191 try 192 192 { 193 193 InputStream is; 194 194 if (file.getName().endsWith(".gpx.gz")) 195 195 is = new GZIPInputStream(new FileInputStream(file)); 196 196 else 197 197 is = new FileInputStream(file); 198 198 // Workaround for SAX BOM bug 199 199 // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206835 200 200 if (!((is.read() == 0xef) && (is.read() == 0xbb) && (is.read() == 0xbf))) 201 201 { 202 203 204 205 206 202 is.close(); 203 if (file.getName().endsWith(".gpx.gz")) 204 is = new GZIPInputStream(new FileInputStream(file)); 205 else 206 is = new FileInputStream(file); 207 207 } 208 208 final GpxReader r = new GpxReader(is); 209 209 final boolean parsedProperly = r.parse(true); 210 210 data = r.data; 211 211 212 212 if (!parsedProperly) 213 213 { 214 215 } 216 } 217 catch (FileNotFoundException e) 214 JOptionPane.showMessageDialog(null, tr("Error occured while parsing gpx file {0}. Only part of the file will be available", file.getName())); 215 } 216 } 217 catch (FileNotFoundException e) 218 218 { 219 219 e.printStackTrace(); … … 241 241 while (trackIter.hasNext()) 242 242 { 243 244 245 } 246 243 GpxTrack track = trackIter.next(); 244 trackRefs.add(new TrackReference(track, this)); 245 } 246 247 247 Collections.sort(trackRefs); 248 248 249 249 Iterator< TrackReference > iter = trackRefs.iterator(); 250 250 while (iter.hasNext()) 251 252 251 tracksListModel.addElement(iter.next()); 252 253 253 waypointTM = new WaypointTableModel(this); 254 254 Iterator< WayPoint > waypointIter = data.waypoints.iterator(); 255 255 while (waypointIter.hasNext()) 256 256 { 257 258 257 WayPoint waypoint = waypointIter.next(); 258 waypointTM.addRow(waypoint); 259 259 } 260 260 dialog.setWaypointsTableModel(waypointTM); … … 265 265 (null, "The GPX file contained no tracks or waypoints.", "No data found", 266 266 JOptionPane.ERROR_MESSAGE); 267 267 268 268 System.out.println("Public Transport: StopImporter: No data found"); 269 269 } 270 270 } 271 271 272 272 public void tracksSelectionChanged(int selectedPos) 273 273 { … … 276 276 currentTrack = ((TrackReference)tracksListModel.elementAt(selectedPos)); 277 277 dialog.setTrackValid(true); 278 278 279 279 //Prepare Settings 280 280 dialog.setSettings 281 282 283 281 (currentTrack.gpsSyncTime, currentTrack.stopwatchStart, 282 currentTrack.timeWindow, currentTrack.threshold); 283 284 284 //Prepare Stoplist 285 285 dialog.setStoplistTableModel … … 297 297 return createNode(latLon, dialog.getStoptype(), name); 298 298 } 299 299 300 300 public static Node createNode(LatLon latLon, String type, String name) 301 301 { … … 306 306 { 307 307 JOptionPane.showMessageDialog(null, "There exists no dataset." 308 308 + " Try to download data from the server or open an OSM file.", 309 309 "No data found", JOptionPane.ERROR_MESSAGE); 310 310 311 311 System.out.println("Public Transport: StopInserter: No data found"); 312 312 313 313 return null; 314 314 } … … 333 333 node.put("railway", "station"); 334 334 } 335 335 336 336 /* returns a collection of all selected lines or 337 337 a collection of all lines otherwise */ … … 343 343 { 344 344 for (int i = 0; i < selectedLines.length; ++i) 345 345 consideredLines.add(selectedLines[i]); 346 346 } 347 347 else 348 348 { 349 349 for (int i = 0; i < table.getRowCount(); ++i) 350 350 consideredLines.add(new Integer(i)); 351 351 } 352 352 return consideredLines; … … 358 358 if (Main.main.getCurrentDataSet() == null) 359 359 return; 360 360 361 361 table.clearSelection(); 362 362 363 363 for (int i = 0; i < table.getRowCount(); ++i) 364 364 { 365 365 if ((nodes.elementAt(i) != null) && 366 367 368 } 369 } 370 366 (Main.main.getCurrentDataSet().isSelected(nodes.elementAt(i)))) 367 table.addRowSelectionInterval(i, i); 368 } 369 } 370 371 371 /* shows the nodes that correspond to the marked lines in the table. 372 372 If no lines are marked in the table, show all nodes from the vector */ … … 379 379 int j = consideredLines.elementAt(i); 380 380 if (nodes.elementAt(j) != null) 381 381 nodes.elementAt(j).visit(box); 382 382 } 383 383 if (box.getBounds() == null) … … 386 386 Main.map.mapView.recalculateCenterScale(box); 387 387 } 388 388 389 389 /* marks the nodes that correspond to the marked lines in the table. 390 390 If no lines are marked in the table, mark all nodes from the vector */ … … 398 398 int j = consideredLines.elementAt(i); 399 399 if (nodes.elementAt(j) != null) 400 401 } 402 } 403 400 Main.main.getCurrentDataSet().addSelected(nodes.elementAt(j)); 401 } 402 } 403 404 404 public static String timeOf(double t) 405 405 { 406 406 t -= Math.floor(t/24/60/60)*24*60*60; 407 407 408 408 int hour = (int)Math.floor(t/60/60); 409 409 t -= Math.floor(t/60/60)*60*60; … … 411 411 t -= Math.floor(t/60)*60; 412 412 double second = t; 413 413 414 414 Format format = new DecimalFormat("00"); 415 415 Format formatS = new DecimalFormat("00.###"); 416 416 return (format.format(hour) + ":" + format.format(minute) + ":" 417 418 } 419 417 + formatS.format(second)); 418 } 419 420 420 public Action getFocusWaypointNameAction() 421 421 { 422 422 return new FocusWaypointNameAction(); 423 423 } 424 424 425 425 public Action getFocusWaypointShelterAction(String shelter) 426 426 { … … 434 434 public void actionPerformed(ActionEvent e) 435 435 { 436 437 438 439 440 441 442 443 436 JTable table = dialog.getWaypointsTable(); 437 int row = table.getEditingRow(); 438 if (row < 0) 439 return; 440 table.clearSelection(); 441 table.addRowSelectionInterval(row, row); 442 Main.main.undoRedo.add 443 (new WaypointsDisableCommand(StopImporterAction.this)); 444 444 } 445 445 }; … … 450 450 return new FocusTrackStoplistNameAction(); 451 451 } 452 452 453 453 public Action getFocusTrackStoplistShelterAction(String shelter) 454 454 { … … 462 462 public void actionPerformed(ActionEvent e) 463 463 { 464 465 466 467 468 469 470 471 464 JTable table = dialog.getStoplistTable(); 465 int row = table.getEditingRow(); 466 if (row < 0) 467 return; 468 table.clearSelection(); 469 table.addRowSelectionInterval(row, row); 470 Main.main.undoRedo.add 471 (new TrackStoplistDeleteCommand(StopImporterAction.this)); 472 472 } 473 473 }; … … 483 483 int row = table.getEditingRow(); 484 484 if (row < 0) 485 485 row = 0; 486 486 waypointTM.inEvent = true; 487 487 if (table.getCellEditor() != null) 488 488 { 489 490 489 if (!table.getCellEditor().stopCellEditing()) 490 table.getCellEditor().cancelCellEditing(); 491 491 } 492 492 table.editCellAt(row, 1); 493 493 table.getCellEditor().getTableCellEditorComponent 494 494 (table, "", true, row, 1); 495 495 waypointTM.inEvent = false; 496 496 } 497 497 }; 498 498 499 499 private class FocusWaypointShelterAction extends AbstractAction 500 500 { 501 501 private String defaultShelter = null; 502 502 503 503 public FocusWaypointShelterAction(String defaultShelter) 504 504 { 505 505 this.defaultShelter = defaultShelter; 506 506 } 507 507 508 508 public void actionPerformed(ActionEvent e) 509 509 { … … 513 513 int row = table.getEditingRow(); 514 514 if (row < 0) 515 515 row = 0; 516 516 waypointTM.inEvent = true; 517 517 if (table.getCellEditor() != null) 518 518 { 519 520 519 if (!table.getCellEditor().stopCellEditing()) 520 table.getCellEditor().cancelCellEditing(); 521 521 } 522 522 table.editCellAt(row, 2); … … 526 526 } 527 527 }; 528 528 529 529 private class FocusTrackStoplistNameAction extends AbstractAction 530 530 { … … 536 536 int row = table.getEditingRow(); 537 537 if (row < 0) 538 538 row = 0; 539 539 currentTrack.inEvent = true; 540 540 if (table.getCellEditor() != null) 541 541 { 542 543 542 if (!table.getCellEditor().stopCellEditing()) 543 table.getCellEditor().cancelCellEditing(); 544 544 } 545 545 table.editCellAt(row, 1); … … 549 549 } 550 550 }; 551 551 552 552 private class FocusTrackStoplistShelterAction extends AbstractAction 553 553 { 554 554 private String defaultShelter = null; 555 555 556 556 public FocusTrackStoplistShelterAction(String defaultShelter) 557 557 { 558 558 this.defaultShelter = defaultShelter; 559 559 } 560 560 561 561 public void actionPerformed(ActionEvent e) 562 562 { … … 566 566 int row = table.getEditingRow(); 567 567 if (row < 0) 568 568 row = 0; 569 569 currentTrack.inEvent = true; 570 570 if (table.getCellEditor() != null) 571 571 { 572 573 572 if (!table.getCellEditor().stopCellEditing()) 573 table.getCellEditor().cancelCellEditing(); 574 574 } 575 575 table.editCellAt(row, 2); -
applications/editors/josm/plugins/public_transport/src/public_transport/StopImporterDialog.java
r20867 r23192 63 63 64 64 public class StopImporterDialog 65 { 65 { 66 66 private JDialog jDialog = null; 67 67 private JTabbedPane tabbedPane = null; … … 74 74 private JTable stoplistTable = null; 75 75 private JTable waypointTable = null; 76 76 77 77 public StopImporterDialog(StopImporterAction controller) 78 78 { … … 93 93 tabbedPane.setEnabledAt(3, true); 94 94 jDialog.add(tabbedPane); 95 95 96 96 //Tracks Tab 97 97 JPanel contentPane = tabTracks; … … 99 99 GridBagConstraints layoutCons = new GridBagConstraints(); 100 100 contentPane.setLayout(gridbag); 101 101 102 102 JLabel label = new JLabel("Tracks in this GPX file:"); 103 103 104 104 layoutCons.gridx = 0; 105 105 layoutCons.gridy = 0; … … 110 110 gridbag.setConstraints(label, layoutCons); 111 111 contentPane.add(label); 112 112 113 113 DefaultListModel tracksListModel = controller.getTracksListModel(); 114 114 tracksList = new JList(tracksListModel); … … 118 118 tracksList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 119 119 tracksList.addListSelectionListener(new TracksLSL(controller)); 120 120 121 121 layoutCons.gridx = 0; 122 122 layoutCons.gridy = 1; … … 124 124 layoutCons.weightx = 1.0; 125 125 layoutCons.weighty = 1.0; 126 layoutCons.fill = GridBagConstraints.BOTH; 126 layoutCons.fill = GridBagConstraints.BOTH; 127 127 gridbag.setConstraints(rpListSP, layoutCons); 128 128 contentPane.add(rpListSP); 129 129 130 130 //Settings Tab 131 131 contentPane = tabSettings; … … 133 133 layoutCons = new GridBagConstraints(); 134 134 contentPane.setLayout(gridbag); 135 135 136 136 label = new JLabel("Type of stops to add"); 137 137 138 138 layoutCons.gridx = 0; 139 139 layoutCons.gridy = 0; … … 144 144 gridbag.setConstraints(label, layoutCons); 145 145 contentPane.add(label); 146 146 147 147 cbStoptype = new JComboBox(); 148 148 cbStoptype.setEditable(false); … … 154 154 cbStoptype.setActionCommand("stopImporter.settingsStoptype"); 155 155 cbStoptype.addActionListener(controller); 156 156 157 157 layoutCons.gridx = 0; 158 158 layoutCons.gridy = 1; … … 163 163 gridbag.setConstraints(cbStoptype, layoutCons); 164 164 contentPane.add(cbStoptype); 165 165 166 166 label = new JLabel("Time on your GPS device"); 167 167 168 168 layoutCons.gridx = 0; 169 169 layoutCons.gridy = 2; … … 174 174 gridbag.setConstraints(label, layoutCons); 175 175 contentPane.add(label); 176 176 177 177 tfGPSTimeStart = new JTextField("00:00:00", 15); 178 178 tfGPSTimeStart.setActionCommand("stopImporter.settingsGPSTimeStart"); 179 179 tfGPSTimeStart.addActionListener(controller); 180 180 181 181 layoutCons.gridx = 0; 182 182 layoutCons.gridy = 3; … … 187 187 gridbag.setConstraints(tfGPSTimeStart, layoutCons); 188 188 contentPane.add(tfGPSTimeStart); 189 189 190 190 label = new JLabel("HH:MM:SS.sss"); 191 191 192 192 layoutCons.gridx = 1; 193 193 layoutCons.gridy = 3; … … 198 198 gridbag.setConstraints(label, layoutCons); 199 199 contentPane.add(label); 200 200 201 201 label = new JLabel("Time on your stopwatch"); 202 202 203 203 layoutCons.gridx = 0; 204 204 layoutCons.gridy = 4; … … 209 209 gridbag.setConstraints(label, layoutCons); 210 210 contentPane.add(label); 211 211 212 212 tfStopwatchStart = new JTextField("00:00:00", 15); 213 213 tfStopwatchStart.setActionCommand("stopImporter.settingsStopwatchStart"); 214 214 tfStopwatchStart.addActionListener(controller); 215 215 216 216 layoutCons.gridx = 0; 217 217 layoutCons.gridy = 5; … … 222 222 gridbag.setConstraints(tfStopwatchStart, layoutCons); 223 223 contentPane.add(tfStopwatchStart); 224 224 225 225 label = new JLabel("HH:MM:SS.sss"); 226 226 227 227 layoutCons.gridx = 1; 228 228 layoutCons.gridy = 5; … … 233 233 gridbag.setConstraints(label, layoutCons); 234 234 contentPane.add(label); 235 235 236 236 label = new JLabel("Time window"); 237 237 238 238 layoutCons.gridx = 0; 239 239 layoutCons.gridy = 6; … … 244 244 gridbag.setConstraints(label, layoutCons); 245 245 contentPane.add(label); 246 246 247 247 tfTimeWindow = new JTextField("15", 4); 248 248 tfTimeWindow.setActionCommand("stopImporter.settingsTimeWindow"); 249 249 tfTimeWindow.addActionListener(controller); 250 250 251 251 layoutCons.gridx = 0; 252 252 layoutCons.gridy = 7; … … 257 257 gridbag.setConstraints(tfTimeWindow, layoutCons); 258 258 contentPane.add(tfTimeWindow); 259 259 260 260 label = new JLabel("seconds"); 261 261 262 262 layoutCons.gridx = 1; 263 263 layoutCons.gridy = 7; … … 268 268 gridbag.setConstraints(label, layoutCons); 269 269 contentPane.add(label); 270 270 271 271 label = new JLabel("Move Threshold"); 272 272 273 273 layoutCons.gridx = 0; 274 274 layoutCons.gridy = 8; … … 279 279 gridbag.setConstraints(label, layoutCons); 280 280 contentPane.add(label); 281 281 282 282 tfThreshold = new JTextField("20", 4); 283 283 tfThreshold.setActionCommand("stopImporter.settingsThreshold"); 284 284 tfThreshold.addActionListener(controller); 285 285 286 286 layoutCons.gridx = 0; 287 287 layoutCons.gridy = 9; … … 292 292 gridbag.setConstraints(tfThreshold, layoutCons); 293 293 contentPane.add(tfThreshold); 294 294 295 295 label = new JLabel("meters"); 296 296 297 297 layoutCons.gridx = 1; 298 298 layoutCons.gridy = 9; … … 303 303 gridbag.setConstraints(label, layoutCons); 304 304 contentPane.add(label); 305 305 306 306 JButton bSuggestStops = new JButton("Suggest Stops"); 307 307 bSuggestStops.setActionCommand("stopImporter.settingsSuggestStops"); 308 308 bSuggestStops.addActionListener(controller); 309 309 310 310 layoutCons.gridx = 0; 311 311 layoutCons.gridy = 10; … … 316 316 gridbag.setConstraints(bSuggestStops, layoutCons); 317 317 contentPane.add(bSuggestStops); 318 318 319 319 //Stops Tab 320 320 contentPane = tabStops; … … 325 325 (KeyStroke.getKeyStroke("alt N"), "stopImporter.focusName"); 326 326 contentPane.getActionMap().put 327 327 ("stopImporter.focusName", controller.getFocusTrackStoplistNameAction()); 328 328 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 329 329 (KeyStroke.getKeyStroke("alt S"), "stopImporter.focusShelterYes"); 330 330 contentPane.getActionMap().put 331 332 331 ("stopImporter.focusShelterYes", 332 controller.getFocusTrackStoplistShelterAction("yes")); 333 333 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 334 334 (KeyStroke.getKeyStroke("alt T"), "stopImporter.focusShelterNo"); 335 335 contentPane.getActionMap().put 336 337 336 ("stopImporter.focusShelterNo", 337 controller.getFocusTrackStoplistShelterAction("no")); 338 338 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 339 339 (KeyStroke.getKeyStroke("alt U"), "stopImporter.focusShelterImplicit"); 340 340 contentPane.getActionMap().put 341 342 341 ("stopImporter.focusShelterImplicit", 342 controller.getFocusTrackStoplistShelterAction("implicit")); 343 343 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 344 344 (KeyStroke.getKeyStroke("alt D"), "stopImporter.stoplistDelete"); 345 345 contentPane.getActionMap().put 346 347 348 346 ("stopImporter.stoplistDelete", 347 controller.getFocusStoplistDeleteAction()); 348 349 349 stoplistTable = new JTable(); 350 350 JScrollPane tableSP = new JScrollPane(stoplistTable); 351 351 352 352 layoutCons.gridx = 0; 353 353 layoutCons.gridy = 0; … … 358 358 gridbag.setConstraints(tableSP, layoutCons); 359 359 contentPane.add(tableSP); 360 360 361 361 JButton bFind = new JButton("Find"); 362 362 bFind.setActionCommand("stopImporter.stoplistFind"); 363 363 bFind.addActionListener(controller); 364 364 365 365 layoutCons.gridx = 0; 366 366 layoutCons.gridy = 1; … … 371 371 gridbag.setConstraints(bFind, layoutCons); 372 372 contentPane.add(bFind); 373 373 374 374 JButton bShow = new JButton("Show"); 375 375 bShow.setActionCommand("stopImporter.stoplistShow"); 376 376 bShow.addActionListener(controller); 377 377 378 378 layoutCons.gridx = 0; 379 379 layoutCons.gridy = 2; … … 384 384 gridbag.setConstraints(bShow, layoutCons); 385 385 contentPane.add(bShow); 386 386 387 387 JButton bMark = new JButton("Mark"); 388 388 bMark.setActionCommand("stopImporter.stoplistMark"); 389 389 bMark.addActionListener(controller); 390 390 391 391 layoutCons.gridx = 1; 392 392 layoutCons.gridy = 1; … … 398 398 gridbag.setConstraints(bMark, layoutCons); 399 399 contentPane.add(bMark); 400 400 401 401 JButton bDetach = new JButton("Detach"); 402 402 bDetach.setActionCommand("stopImporter.stoplistDetach"); 403 403 bDetach.addActionListener(controller); 404 404 405 405 layoutCons.gridx = 1; 406 406 layoutCons.gridy = 2; … … 412 412 gridbag.setConstraints(bDetach, layoutCons); 413 413 contentPane.add(bDetach); 414 414 415 415 JButton bAdd = new JButton("Add"); 416 416 bAdd.setActionCommand("stopImporter.stoplistAdd"); 417 417 bAdd.addActionListener(controller); 418 418 419 419 layoutCons.gridx = 2; 420 420 layoutCons.gridy = 1; … … 426 426 gridbag.setConstraints(bAdd, layoutCons); 427 427 contentPane.add(bAdd); 428 428 429 429 JButton bDelete = new JButton("Delete"); 430 430 bDelete.setActionCommand("stopImporter.stoplistDelete"); 431 431 bDelete.addActionListener(controller); 432 432 433 433 layoutCons.gridx = 2; 434 434 layoutCons.gridy = 2; … … 439 439 gridbag.setConstraints(bDelete, layoutCons); 440 440 contentPane.add(bDelete); 441 441 442 442 JButton bSort = new JButton("Sort"); 443 443 bSort.setActionCommand("stopImporter.stoplistSort"); 444 444 bSort.addActionListener(controller); 445 445 446 446 layoutCons.gridx = 3; 447 447 layoutCons.gridy = 1; … … 453 453 gridbag.setConstraints(bSort, layoutCons); 454 454 contentPane.add(bSort); 455 455 456 456 //Waypoints Tab 457 457 contentPane = tabWaypoints; … … 462 462 (KeyStroke.getKeyStroke("alt N"), "stopImporter.focusName"); 463 463 contentPane.getActionMap().put 464 464 ("stopImporter.focusName", controller.getFocusWaypointNameAction()); 465 465 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 466 466 (KeyStroke.getKeyStroke("alt S"), "stopImporter.focusShelterYes"); 467 467 contentPane.getActionMap().put 468 469 468 ("stopImporter.focusShelterYes", 469 controller.getFocusWaypointShelterAction("yes")); 470 470 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 471 471 (KeyStroke.getKeyStroke("alt T"), "stopImporter.focusShelterNo"); 472 472 contentPane.getActionMap().put 473 474 473 ("stopImporter.focusShelterNo", 474 controller.getFocusWaypointShelterAction("no")); 475 475 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 476 476 (KeyStroke.getKeyStroke("alt U"), "stopImporter.focusShelterImplicit"); 477 477 contentPane.getActionMap().put 478 479 478 ("stopImporter.focusShelterImplicit", 479 controller.getFocusWaypointShelterAction("implicit")); 480 480 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put 481 481 (KeyStroke.getKeyStroke("alt D"), "stopImporter.waypointsDelete"); 482 482 contentPane.getActionMap().put 483 484 485 483 ("stopImporter.waypointsDelete", 484 controller.getFocusWaypointDeleteAction()); 485 486 486 waypointTable = new JTable(); 487 487 tableSP = new JScrollPane(waypointTable); 488 488 489 489 layoutCons.gridx = 0; 490 490 layoutCons.gridy = 0; … … 495 495 gridbag.setConstraints(tableSP, layoutCons); 496 496 contentPane.add(tableSP); 497 497 498 498 bFind = new JButton("Find"); 499 499 bFind.setActionCommand("stopImporter.waypointsFind"); 500 500 bFind.addActionListener(controller); 501 501 502 502 layoutCons.gridx = 0; 503 503 layoutCons.gridy = 1; … … 508 508 gridbag.setConstraints(bFind, layoutCons); 509 509 contentPane.add(bFind); 510 510 511 511 bShow = new JButton("Show"); 512 512 bShow.setActionCommand("stopImporter.waypointsShow"); 513 513 bShow.addActionListener(controller); 514 514 515 515 layoutCons.gridx = 0; 516 516 layoutCons.gridy = 2; … … 521 521 gridbag.setConstraints(bShow, layoutCons); 522 522 contentPane.add(bShow); 523 523 524 524 bMark = new JButton("Mark"); 525 525 bMark.setActionCommand("stopImporter.waypointsMark"); 526 526 bMark.addActionListener(controller); 527 527 528 528 layoutCons.gridx = 1; 529 529 layoutCons.gridy = 1; … … 535 535 gridbag.setConstraints(bMark, layoutCons); 536 536 contentPane.add(bMark); 537 537 538 538 bDetach = new JButton("Detach"); 539 539 bDetach.setActionCommand("stopImporter.waypointsDetach"); 540 540 bDetach.addActionListener(controller); 541 541 542 542 layoutCons.gridx = 1; 543 543 layoutCons.gridy = 2; … … 549 549 gridbag.setConstraints(bDetach, layoutCons); 550 550 contentPane.add(bDetach); 551 551 552 552 bAdd = new JButton("Enable"); 553 553 bAdd.setActionCommand("stopImporter.waypointsAdd"); 554 554 bAdd.addActionListener(controller); 555 555 556 556 layoutCons.gridx = 2; 557 557 layoutCons.gridy = 1; … … 563 563 gridbag.setConstraints(bAdd, layoutCons); 564 564 contentPane.add(bAdd); 565 565 566 566 bDelete = new JButton("Disable"); 567 567 bDelete.setActionCommand("stopImporter.waypointsDelete"); 568 568 bDelete.addActionListener(controller); 569 569 570 570 layoutCons.gridx = 2; 571 571 layoutCons.gridy = 2; … … 576 576 gridbag.setConstraints(bDelete, layoutCons); 577 577 contentPane.add(bDelete); 578 578 579 579 jDialog.pack(); 580 580 jDialog.setLocationRelativeTo(frame); 581 581 } 582 582 583 583 public void setTrackValid(boolean valid) 584 584 { 585 585 tabbedPane.setEnabledAt(2, valid); 586 586 } 587 587 588 588 public void setVisible(boolean visible) 589 589 { 590 590 jDialog.setVisible(visible); 591 591 } 592 592 593 593 public void setSettings 594 594 (String gpsSyncTime, String stopwatchStart, … … 600 600 tfThreshold.setText(Double.toString(threshold)); 601 601 } 602 602 603 603 public String getStoptype() 604 604 { 605 605 return (String)cbStoptype.getSelectedItem(); 606 606 } 607 607 608 608 public boolean gpsTimeStartValid() 609 609 { … … 615 615 { 616 616 JOptionPane.showMessageDialog 617 618 617 (null, "Can't parse a time from this string.", "Invalid value", 618 JOptionPane.ERROR_MESSAGE); 619 619 return false; 620 620 } 621 621 } 622 622 623 623 public String getGpsTimeStart() 624 624 { 625 625 return tfGPSTimeStart.getText(); 626 626 } 627 627 628 628 public void setGpsTimeStart(String s) 629 629 { 630 630 tfGPSTimeStart.setText(s); 631 631 } 632 632 633 633 public boolean stopwatchStartValid() 634 634 { … … 640 640 { 641 641 JOptionPane.showMessageDialog 642 643 642 (null, "Can't parse a time from this string.", "Invalid value", 643 JOptionPane.ERROR_MESSAGE); 644 644 return false; 645 645 } 646 646 } 647 647 648 648 public String getStopwatchStart() 649 649 { 650 650 return tfStopwatchStart.getText(); 651 651 } 652 652 653 653 public void setStopwatchStart(String s) 654 654 { 655 655 tfStopwatchStart.setText(s); 656 656 } 657 657 658 658 public double getTimeWindow() 659 659 { 660 660 return Double.parseDouble(tfTimeWindow.getText()); 661 661 } 662 662 663 663 public double getThreshold() 664 664 { 665 665 return Double.parseDouble(tfThreshold.getText()); 666 666 } 667 667 668 668 public JTable getStoplistTable() 669 669 { 670 670 return stoplistTable; 671 671 } 672 672 673 673 public void setStoplistTableModel(TrackStoplistTableModel model) 674 674 { … … 680 680 comboBox.addItem("implicit"); 681 681 stoplistTable.getColumnModel().getColumn(2) 682 682 .setCellEditor(new DefaultCellEditor(comboBox)); 683 683 int width = stoplistTable.getPreferredSize().width; 684 684 stoplistTable.getColumnModel().getColumn(0).setPreferredWidth((int)(width * 0.4)); … … 686 686 stoplistTable.getColumnModel().getColumn(2).setPreferredWidth((int)(width * 0.1)); 687 687 } 688 688 689 689 public JTable getWaypointsTable() 690 690 { 691 691 return waypointTable; 692 692 } 693 693 694 694 public void setWaypointsTableModel(WaypointTableModel model) 695 695 { … … 701 701 comboBox.addItem("implicit"); 702 702 waypointTable.getColumnModel().getColumn(2) 703 703 .setCellEditor(new DefaultCellEditor(comboBox)); 704 704 int width = waypointTable.getPreferredSize().width; 705 705 waypointTable.getColumnModel().getColumn(0).setPreferredWidth((int)(width * 0.4)); … … 707 707 waypointTable.getColumnModel().getColumn(2).setPreferredWidth((int)(width * 0.1)); 708 708 } 709 709 710 710 public static double parseTime(String s) 711 711 { 712 712 double result = 0; 713 713 if ((s.charAt(2) != ':') || (s.charAt(2) != ':') 714 714 || (s.length() < 8)) 715 715 return -1; 716 716 int hour = Integer.parseInt(s.substring(0, 2)); … … 718 718 double second = Double.parseDouble(s.substring(6, s.length())); 719 719 if ((hour < 0) || (hour > 23) || (minute < 0) || (minute > 59) 720 720 || (second < 0) || (second >= 60.0)) 721 721 return -1; 722 722 return (second + minute*60 + hour*60*60); 723 723 } 724 724 725 725 private class TracksLSL implements ListSelectionListener 726 726 { 727 727 StopImporterAction root = null; 728 728 729 729 public TracksLSL(StopImporterAction sia) 730 730 { 731 731 root = sia; 732 732 } 733 733 734 734 public void valueChanged(ListSelectionEvent e) 735 735 { 736 736 int selectedPos = tracksList.getAnchorSelectionIndex(); 737 737 if (tracksList.isSelectedIndex(selectedPos)) 738 738 root.tracksSelectionChanged(selectedPos); 739 739 else 740 740 root.tracksSelectionChanged(-1); 741 741 } 742 742 }; -
applications/editors/josm/plugins/public_transport/src/public_transport/TrackReference.java
r20839 r23192 32 32 private StopImporterAction controller = null; 33 33 public boolean inEvent = false; 34 34 35 35 public TrackReference(GpxTrack track, StopImporterAction controller) 36 36 { … … 46 46 while ((siter.hasNext()) && (this.gpsSyncTime == null)) 47 47 { 48 49 50 51 52 53 54 48 Iterator< WayPoint > witer = siter.next().getWayPoints().iterator(); 49 if (witer.hasNext()) 50 { 51 this.gpsStartTime = witer.next().getString("time"); 52 if (this.gpsStartTime != null) 53 this.gpsSyncTime = this.gpsStartTime.substring(11, 19); 54 } 55 55 } 56 56 if (this.gpsSyncTime == null) 57 57 { 58 59 60 58 JOptionPane.showMessageDialog 59 (null, "The GPX file doesn't contain valid trackpoints. " 60 + "Please use a GPX file that has trackpoints.", "GPX File Trouble", 61 61 JOptionPane.ERROR_MESSAGE); 62 63 64 62 63 this.gpsStartTime = "1970-01-01T00:00:00Z"; 64 this.gpsSyncTime = this.stopwatchStart; 65 65 } 66 66 } … … 70 70 this.threshold = 20; 71 71 } 72 72 73 73 public GpxTrack getGpxTrack() 74 74 { 75 75 return track; 76 76 } 77 77 78 78 public int compareTo(TrackReference tr) 79 79 { … … 83 83 { 84 84 if (tr_name == null) 85 85 return -1; 86 86 return name.compareTo(tr_name); 87 87 } 88 88 return 1; 89 89 } 90 90 91 91 public String toString() 92 92 { … … 96 96 return buf; 97 97 } 98 98 99 99 public void tableChanged(TableModelEvent e) 100 100 { … … 102 102 { 103 103 if (inEvent) 104 105 104 return; 105 106 106 double time = StopImporterDialog.parseTime 107 107 ((String)stoplistTM.getValueAt(e.getFirstRow(), 0)); 108 108 if (time < 0) 109 109 { 110 111 112 113 114 115 110 stoplistTM.setValueAt 111 (stoplistTM.timeAt(e.getFirstRow()), e.getFirstRow(), 0); 112 JOptionPane.showMessageDialog 113 (null, "Can't parse a time from this string.", "Invalid value", 114 JOptionPane.ERROR_MESSAGE); 115 return; 116 116 } 117 117 … … 119 119 (this, e.getFirstRow())); 120 120 stoplistTM.setTimeAt 121 121 (e.getFirstRow(), (String)stoplistTM.getValueAt(e.getFirstRow(), 0)); 122 122 } 123 123 } 124 124 125 125 public LatLon computeCoor(double time) 126 126 { … … 131 131 double timeDelta = gpsSyncTime - StopImporterDialog.parseTime(stopwatchStart); 132 132 time += timeDelta; 133 133 134 134 WayPoint wayPoint = null; 135 135 WayPoint lastWayPoint = null; … … 142 142 while (witer.hasNext()) 143 143 { 144 145 146 147 148 149 150 151 152 144 wayPoint = witer.next(); 145 String startTime = wayPoint.getString("time"); 146 wayPointTime = StopImporterDialog.parseTime(startTime.substring(11, 19)); 147 if (startTime.substring(11, 19).compareTo(gpsStartTime.substring(11, 19)) == -1) 148 wayPointTime += 24*60*60; 149 if (wayPointTime >= time) 150 break; 151 lastWayPoint = wayPoint; 152 lastWayPointTime = wayPointTime; 153 153 } 154 154 if (wayPointTime >= time) 155 155 break; 156 156 } 157 157 158 158 double lat = 0; 159 159 if ((wayPointTime == lastWayPointTime) || (lastWayPoint == null)) … … 161 161 else 162 162 lat = wayPoint.getCoor().lat() 163 164 165 163 *(time - lastWayPointTime)/(wayPointTime - lastWayPointTime) 164 + lastWayPoint.getCoor().lat() 165 *(wayPointTime - time)/(wayPointTime - lastWayPointTime); 166 166 double lon = 0; 167 167 if ((wayPointTime == lastWayPointTime) || (lastWayPoint == null)) … … 169 169 else 170 170 lon = wayPoint.getCoor().lon() 171 172 173 174 171 *(time - lastWayPointTime)/(wayPointTime - lastWayPointTime) 172 + lastWayPoint.getCoor().lon() 173 *(wayPointTime - time)/(wayPointTime - lastWayPointTime); 174 175 175 return new LatLon(lat, lon); 176 176 } 177 177 178 178 public void relocateNodes() 179 179 { … … 182 182 Node node = stoplistTM.nodeAt(i); 183 183 if (node == null) 184 185 184 continue; 185 186 186 double time = StopImporterDialog.parseTime 187 187 ((String)stoplistTM.getValueAt(i, 0)); 188 188 LatLon latLon = computeCoor(time); 189 189 … … 193 193 if (cmd != null) 194 194 { 195 195 Main.main.undoRedo.add(cmd); 196 196 } 197 197 } -
applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistAddCommand.java
r22048 r23192 14 14 private int workingLine; 15 15 private TrackStoplistTableModel stoplistTM = null; 16 16 17 17 public TrackStoplistAddCommand(StopImporterAction controller) 18 18 { … … 20 20 workingLine = controller.getDialog().getStoplistTable().getSelectedRow(); 21 21 } 22 22 23 23 public boolean executeCommand() 24 24 { … … 26 26 return true; 27 27 } 28 28 29 29 public void undoCommand() 30 30 { … … 34 34 stoplistTM.removeRow(workingLine); 35 35 } 36 36 37 37 public void fillModifiedData 38 38 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 40 40 { 41 41 } 42 42 43 43 @Override public JLabel getDescription() 44 44 { -
applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistDeleteCommand.java
r22048 r23192 21 21 this.shelter = shelter; 22 22 } 23 23 24 24 public Node node; 25 25 public String time; … … 27 27 public String shelter; 28 28 }; 29 29 30 30 private Vector< Integer > workingLines = null; 31 31 private Vector< NodeTimeName > nodesForUndo = null; 32 32 private TrackStoplistTableModel stoplistTM = null; 33 33 34 34 public TrackStoplistDeleteCommand(StopImporterAction controller) 35 35 { … … 37 37 workingLines = new Vector< Integer >(); 38 38 nodesForUndo = new Vector< NodeTimeName >(); 39 39 40 40 // use selected lines or all lines if no line is selected 41 41 int[] selectedLines = controller.getDialog().getStoplistTable().getSelectedRows(); … … 44 44 for (int i = 0; i < selectedLines.length; ++i) 45 45 { 46 46 workingLines.add(selectedLines[i]); 47 47 } 48 48 } … … 50 50 { 51 51 for (int i = 0; i < stoplistTM.getRowCount(); ++i) 52 52 workingLines.add(new Integer(i)); 53 53 } 54 54 } 55 55 56 56 public boolean executeCommand() 57 57 { … … 62 62 Node node = stoplistTM.nodeAt(j); 63 63 nodesForUndo.add(new NodeTimeName 64 65 66 64 (node, (String)stoplistTM.getValueAt(j, 0), 65 (String)stoplistTM.getValueAt(j, 1), 66 (String)stoplistTM.getValueAt(j, 2))); 67 67 stoplistTM.removeRow(j); 68 68 if (node == null) 69 69 continue; 70 70 Main.main.getCurrentDataSet().removePrimitive(node); 71 71 node.setDeleted(true); … … 73 73 return true; 74 74 } 75 75 76 76 public void undoCommand() 77 77 { … … 82 82 stoplistTM.insertRow(j, ntn.node, ntn.time, ntn.name, ntn.shelter); 83 83 if (ntn.node == null) 84 84 continue; 85 85 ntn.node.setDeleted(false); 86 86 Main.main.getCurrentDataSet().addPrimitive(ntn.node); 87 87 } 88 88 } 89 89 90 90 public void fillModifiedData 91 91 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 93 93 { 94 94 } 95 95 96 96 @Override public JLabel getDescription() 97 97 { -
applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistDetachCommand.java
r22048 r23192 15 15 private Vector< Node > nodesForUndo = null; 16 16 private TrackStoplistTableModel stoplistTM = null; 17 17 18 18 public TrackStoplistDetachCommand(StopImporterAction controller) 19 19 { … … 21 21 workingLines = new Vector< Integer >(); 22 22 nodesForUndo = new Vector< Node >(); 23 23 24 24 // use either selected lines or all lines if no line is selected 25 25 int[] selectedLines = controller.getDialog().getStoplistTable().getSelectedRows(); … … 28 28 { 29 29 for (int i = 0; i < selectedLines.length; ++i) 30 30 consideredLines.add(selectedLines[i]); 31 31 } 32 32 else 33 33 { 34 34 for (int i = 0; i < stoplistTM.getRowCount(); ++i) 35 35 consideredLines.add(new Integer(i)); 36 36 } 37 37 38 38 // keep only lines where a node can be added 39 39 for (int i = 0; i < consideredLines.size(); ++i) 40 40 { 41 41 if (stoplistTM.nodeAt(consideredLines.elementAt(i)) != null) 42 42 workingLines.add(consideredLines.elementAt(i)); 43 43 } 44 44 } 45 45 46 46 public boolean executeCommand() 47 47 { … … 56 56 return true; 57 57 } 58 58 59 59 public void undoCommand() 60 60 { … … 66 66 } 67 67 } 68 68 69 69 public void fillModifiedData 70 70 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 72 72 { 73 73 } 74 74 75 75 @Override public JLabel getDescription() 76 76 { -
applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistNameCommand.java
r22048 r23192 22 22 private String shelter = null; 23 23 private LatLon oldLatLon = null; 24 24 25 25 @SuppressWarnings("unchecked") 26 26 public TrackStoplistNameCommand(TrackReference trackref, int workingLine) … … 42 42 this.shelter = null; 43 43 } 44 44 45 45 public boolean executeCommand() 46 46 { … … 69 69 return true; 70 70 } 71 71 72 72 public void undoCommand() 73 73 { … … 94 94 trackref.inEvent = false; 95 95 } 96 96 97 97 public void fillModifiedData 98 98 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 100 100 { 101 101 } 102 102 103 103 @Override public JLabel getDescription() 104 104 { -
applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistRelocateCommand.java
r22048 r23192 21 21 private String gpsSyncTime = null; 22 22 private String stopwatchStart = null; 23 23 24 24 public TrackStoplistRelocateCommand(StopImporterAction controller) 25 25 { … … 31 31 this.oldStopwatchStart = currentTrack.stopwatchStart; 32 32 } 33 33 34 34 public boolean executeCommand() 35 35 { … … 40 40 Node node = currentTrack.stoplistTM.nodeAt(i); 41 41 if (node == null) 42 43 42 continue; 43 44 44 double time = StopImporterDialog.parseTime 45 45 ((String)currentTrack.stoplistTM.getValueAt(i, 0)); 46 46 node.setCoor(currentTrack.computeCoor(time)); 47 47 } … … 53 53 controller.inEvent = false; 54 54 } 55 55 56 56 return true; 57 57 } 58 58 59 59 public void undoCommand() 60 60 { … … 65 65 Node node = currentTrack.stoplistTM.nodeAt(i); 66 66 if (node == null) 67 68 67 continue; 68 69 69 double time = StopImporterDialog.parseTime 70 70 ((String)currentTrack.stoplistTM.getValueAt(i, 0)); 71 71 node.setCoor(currentTrack.computeCoor(time)); 72 72 } … … 79 79 } 80 80 } 81 81 82 82 public void fillModifiedData 83 83 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 85 85 { 86 86 } 87 87 88 88 @Override public JLabel getDescription() 89 89 { -
applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistSortCommand.java
r22048 r23192 22 22 private int insPos; 23 23 private String stopwatchStart; 24 24 25 25 public TrackStoplistSortCommand(StopImporterAction controller) 26 26 { … … 29 29 insPos = controller.getDialog().getStoplistTable().getSelectedRow(); 30 30 stopwatchStart = controller.getCurrentTrack().stopwatchStart; 31 31 32 32 // use either selected lines or all lines if no line is selected 33 33 int[] selectedLines = controller.getDialog().getStoplistTable().getSelectedRows(); … … 35 35 { 36 36 for (int i = 0; i < selectedLines.length; ++i) 37 37 workingLines.add(selectedLines[i]); 38 38 } 39 39 else 40 40 { 41 41 for (int i = 0; i < stoplistTM.getRowCount(); ++i) 42 42 workingLines.add(new Integer(i)); 43 43 } 44 44 } 45 45 46 46 @SuppressWarnings("unchecked") 47 47 public boolean executeCommand() 48 48 { 49 49 tableDataModel = (Vector< Vector< Object > >)stoplistTM.getDataVector() 50 50 .clone(); 51 51 nodes = (Vector< Node >)stoplistTM.getNodes().clone(); 52 52 times = (Vector< String >)stoplistTM.getTimes().clone(); 53 53 54 54 Vector< NodeSortEntry > nodesToSort = new Vector< NodeSortEntry >(); 55 55 for (int i = workingLines.size()-1; i >= 0; --i) … … 57 57 int j = workingLines.elementAt(i).intValue(); 58 58 nodesToSort.add(new NodeSortEntry 59 60 61 62 59 (stoplistTM.nodeAt(j), (String)stoplistTM.getValueAt(j, 0), 60 (String)stoplistTM.getValueAt(j, 1), 61 (String)stoplistTM.getValueAt(j, 2), 62 StopImporterDialog.parseTime(stopwatchStart))); 63 63 stoplistTM.removeRow(j); 64 64 } 65 65 66 66 Collections.sort(nodesToSort); 67 67 68 68 int insPos = this.insPos; 69 69 Iterator< NodeSortEntry > iter = nodesToSort.iterator(); … … 73 73 stoplistTM.insertRow(insPos, nse.node, nse.time, nse.name, nse.shelter); 74 74 if (insPos >= 0) 75 75 ++insPos; 76 76 } 77 77 return true; 78 78 } 79 79 80 80 public void undoCommand() 81 81 { … … 84 84 stoplistTM.setTimes(times); 85 85 } 86 86 87 87 public void fillModifiedData 88 88 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 90 90 { 91 91 } 92 92 93 93 @Override public JLabel getDescription() 94 94 { 95 95 return new JLabel("public_transport.TrackStoplist.Sort"); 96 96 } 97 97 98 98 private class NodeSortEntry implements Comparable< NodeSortEntry > 99 99 { … … 103 103 public String shelter = null; 104 104 public double startTime = 0; 105 105 106 106 public NodeSortEntry 107 107 (Node node, String time, String name, String shelter, double startTime) … … 112 112 this.shelter = shelter; 113 113 } 114 114 115 115 public int compareTo(NodeSortEntry nse) 116 116 { 117 117 double time = StopImporterDialog.parseTime(this.time); 118 118 if (time - startTime > 12*60*60) 119 120 119 time -= 24*60*60; 120 121 121 double nseTime = StopImporterDialog.parseTime(nse.time); 122 122 if (nseTime - startTime > 12*60*60) 123 124 123 nseTime -= 24*60*60; 124 125 125 if (time < nseTime) 126 126 return -1; 127 127 else if (time > nseTime) 128 128 return 1; 129 129 else 130 130 return 0; 131 131 } 132 132 }; -
applications/editors/josm/plugins/public_transport/src/public_transport/TrackStoplistTableModel.java
r20839 r23192 14 14 private Vector< String > times = null; 15 15 private static Vector< String > columns = null; 16 16 17 17 public TrackStoplistTableModel(TrackReference tr) 18 18 { … … 26 26 nodes = new Vector< Node >(); 27 27 times = new Vector< String >(); 28 28 29 29 setColumnIdentifiers(columns); 30 30 addTableModelListener(tr); 31 31 } 32 32 33 33 public boolean isCellEditable(int row, int column) { 34 34 return true; 35 35 } 36 36 37 37 public void addRow(Object[] obj) { 38 38 throw new UnsupportedOperationException(); 39 39 } 40 40 41 41 public void insertRow(int insPos, Object[] obj) { 42 42 throw new UnsupportedOperationException(); 43 43 } 44 44 45 45 public void addRow(String time) { 46 46 insertRow(-1, time); 47 47 } 48 48 49 49 public void insertRow(int insPos, String time) 50 50 { … … 118 118 } 119 119 } 120 120 121 121 public void clear() 122 122 { … … 125 125 super.setRowCount(0); 126 126 } 127 127 128 128 public void setDataVector(Vector< Vector< Object > > dataVector) 129 129 { -
applications/editors/josm/plugins/public_transport/src/public_transport/TrackSuggestStopsCommand.java
r22048 r23192 29 29 private Vector< Node > nodes = null; 30 30 private Vector< String > times = null; 31 31 32 32 public TrackSuggestStopsCommand(StopImporterAction controller) 33 33 { … … 43 43 segments = controller.getCurrentTrack().getGpxTrack().getSegments(); 44 44 } 45 45 46 46 @SuppressWarnings("unchecked") 47 47 public boolean executeCommand() … … 50 50 return false; 51 51 tableDataModel = (Vector< Vector< Object > >)stoplistTM.getDataVector() 52 52 .clone(); 53 53 nodes = (Vector< Node >)stoplistTM.getNodes().clone(); 54 54 times = (Vector< String >)stoplistTM.getTimes().clone(); 55 55 56 56 for (int i = 0; i < stoplistTM.getNodes().size(); ++i) 57 57 { 58 58 Node node = stoplistTM.nodeAt(i); 59 59 if (node == null) 60 60 continue; 61 61 Main.main.getCurrentDataSet().removePrimitive(node); 62 62 node.setDeleted(true); … … 70 70 Iterator< WayPoint > witer = siter.next().getWayPoints().iterator(); 71 71 while (witer.hasNext()) 72 72 wayPoints.add(witer.next()); 73 73 } 74 74 Vector< Double > wayPointsDist = new Vector< Double >(wayPoints.size()); 75 75 76 76 int i = 0; 77 77 double time = -48*60*60; … … 80 80 { 81 81 if (wayPoints.elementAt(i).getString("time") != null) 82 83 82 time = StopImporterDialog.parseTime(wayPoints.elementAt(i) 83 .getString("time").substring(11,19)); 84 84 if (time < dGpsStartTime) 85 85 time += 24*60*60; 86 86 wayPointsDist.add(Double.valueOf(Double.POSITIVE_INFINITY)); 87 87 ++i; … … 93 93 while ((j > 0) && (time - timeWindow/2 < time2)) 94 94 { 95 96 97 98 99 100 95 --j; 96 if (wayPoints.elementAt(j).getString("time") != null) 97 time2 = StopImporterDialog.parseTime(wayPoints.elementAt(j) 98 .getString("time").substring(11,19)); 99 if (time2 < dGpsStartTime) 100 time2 += 24*60*60; 101 101 } 102 102 int k = i + 1; … … 104 104 while ((k < wayPoints.size()) && (time + timeWindow/2 > time2)) 105 105 { 106 107 108 109 110 111 112 } 113 106 if (wayPoints.elementAt(k).getString("time") != null) 107 time2 = StopImporterDialog.parseTime(wayPoints.elementAt(k) 108 .getString("time").substring(11,19)); 109 if (time2 < dGpsStartTime) 110 time2 += 24*60*60; 111 ++k; 112 } 113 114 114 if (j < k) 115 115 { 116 117 118 119 120 121 122 123 124 116 double dist = 0; 117 LatLon latLonI = wayPoints.elementAt(i).getCoor(); 118 for (int l = j; l < k; ++l) 119 { 120 double distL = latLonI.greatCircleDistance(wayPoints.elementAt(l).getCoor()); 121 if (distL > dist) 122 dist = distL; 123 } 124 wayPointsDist.add(Double.valueOf(dist)); 125 125 } 126 126 else 127 128 127 wayPointsDist.add(Double.valueOf(Double.POSITIVE_INFINITY)); 128 129 129 if (wayPoints.elementAt(i).getString("time") != null) 130 131 130 time = StopImporterDialog.parseTime(wayPoints.elementAt(i) 131 .getString("time").substring(11,19)); 132 132 if (time < dGpsStartTime) 133 133 time += 24*60*60; 134 134 ++i; 135 135 } 136 136 137 137 LatLon lastStopCoor = null; 138 138 for (i = 1; i < wayPoints.size()-1; ++i) 139 139 { 140 140 if (wayPointsDist.elementAt(i).doubleValue() >= threshold) 141 141 continue; 142 142 if ((wayPointsDist.elementAt(i).compareTo(wayPointsDist.elementAt(i-1)) != -1) 143 144 145 143 || (wayPointsDist.elementAt(i).compareTo(wayPointsDist.elementAt(i+1)) != -1)) 144 continue; 145 146 146 LatLon latLon = wayPoints.elementAt(i).getCoor(); 147 147 if ((lastStopCoor != null) && (lastStopCoor.greatCircleDistance(latLon) < threshold)) 148 149 148 continue; 149 150 150 if (wayPoints.elementAt(i).getString("time") != null) 151 151 { 152 153 154 155 156 157 158 159 160 161 } 162 152 time = StopImporterDialog.parseTime(wayPoints.elementAt(i) 153 .getString("time").substring(11,19)); 154 double gpsSyncTime = StopImporterDialog.parseTime(this.gpsSyncTime); 155 if (gpsSyncTime < dGpsStartTime - 12*60*60) 156 gpsSyncTime += 24*60*60; 157 double timeDelta = gpsSyncTime - StopImporterDialog.parseTime(stopwatchStart); 158 time -= timeDelta; 159 Node node = StopImporterAction.createNode(latLon, type, ""); 160 stoplistTM.insertRow(-1, node, StopImporterAction.timeOf(time), "", ""); 161 } 162 163 163 lastStopCoor = latLon; 164 164 } 165 165 166 166 return true; 167 167 } 168 168 169 169 public void undoCommand() 170 170 { … … 175 175 Node node = stoplistTM.nodeAt(i); 176 176 if (node == null) 177 177 continue; 178 178 Main.main.getCurrentDataSet().removePrimitive(node); 179 179 node.setDeleted(true); 180 180 } 181 181 182 182 stoplistTM.setDataVector(tableDataModel); 183 183 stoplistTM.setNodes(nodes); 184 184 stoplistTM.setTimes(times); 185 185 186 186 for (int i = 0; i < stoplistTM.getNodes().size(); ++i) 187 187 { 188 188 Node node = stoplistTM.nodeAt(i); 189 189 if (node == null) 190 190 continue; 191 191 node.setDeleted(false); 192 192 Main.main.getCurrentDataSet().addPrimitive(node); 193 193 } 194 194 } 195 195 196 196 public void fillModifiedData 197 197 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 199 199 { 200 200 } 201 201 202 202 @Override public JLabel getDescription() 203 203 { 204 204 return new JLabel("public_transport.TrackStoplist.SuggestStops"); 205 205 } 206 206 207 207 private class NodeSortEntry implements Comparable< NodeSortEntry > 208 208 { … … 211 211 public String name = null; 212 212 public double startTime = 0; 213 213 214 214 public NodeSortEntry(Node node, String time, String name, double startTime) 215 215 { … … 218 218 this.name = name; 219 219 } 220 220 221 221 public int compareTo(NodeSortEntry nse) 222 222 { 223 223 double time = StopImporterDialog.parseTime(this.time); 224 224 if (time - startTime > 12*60*60) 225 226 225 time -= 24*60*60; 226 227 227 double nseTime = StopImporterDialog.parseTime(nse.time); 228 228 if (nseTime - startTime > 12*60*60) 229 230 229 nseTime -= 24*60*60; 230 231 231 if (time < nseTime) 232 232 return -1; 233 233 else if (time > nseTime) 234 234 return 1; 235 235 else 236 236 return 0; 237 237 } 238 238 }; -
applications/editors/josm/plugins/public_transport/src/public_transport/WaypointTableModel.java
r20835 r23192 21 21 public Vector< Node > nodes = new Vector< Node >(); 22 22 public Vector< LatLon > coors = new Vector< LatLon >(); 23 23 24 24 public WaypointTableModel(StopImporterAction controller) 25 25 { … … 30 30 addTableModelListener(this); 31 31 } 32 32 33 33 public boolean isCellEditable(int row, int column) 34 34 { … … 37 37 return false; 38 38 } 39 39 40 40 public void addRow(Object[] obj) 41 41 { 42 42 throw new UnsupportedOperationException(); 43 43 } 44 44 45 45 public void insertRow(int insPos, Object[] obj) 46 46 { 47 47 throw new UnsupportedOperationException(); 48 48 } 49 49 50 50 public void addRow(WayPoint wp) 51 51 { 52 52 insertRow(-1, wp); 53 53 } 54 54 55 55 public void insertRow(int insPos, WayPoint wp) 56 56 { … … 64 64 65 65 Node node = controller.createNode(wp.getCoor(), buf[1]); 66 66 67 67 if (insPos == -1) 68 68 { … … 78 78 } 79 79 } 80 80 81 81 public void clear() 82 82 { … … 84 84 super.setRowCount(0); 85 85 } 86 86 87 87 public void tableChanged(TableModelEvent e) 88 88 { … … 90 90 { 91 91 if (inEvent) 92 92 return; 93 93 Main.main.undoRedo.add(new WaypointsNameCommand 94 95 94 (this, e.getFirstRow(), (String)getValueAt(e.getFirstRow(), 1), 95 (String)getValueAt(e.getFirstRow(), 2))); 96 96 } 97 97 } -
applications/editors/josm/plugins/public_transport/src/public_transport/WaypointsDetachCommand.java
r22048 r23192 15 15 private Vector< Node > nodesForUndo = null; 16 16 private WaypointTableModel waypointTM = null; 17 17 18 18 public WaypointsDetachCommand(StopImporterAction controller) 19 19 { … … 21 21 workingLines = new Vector< Integer >(); 22 22 nodesForUndo = new Vector< Node >(); 23 23 24 24 // use either selected lines or all lines if no line is selected 25 25 int[] selectedLines = controller.getDialog().getWaypointsTable().getSelectedRows(); … … 28 28 { 29 29 for (int i = 0; i < selectedLines.length; ++i) 30 30 consideredLines.add(selectedLines[i]); 31 31 } 32 32 else 33 33 { 34 34 for (int i = 0; i < waypointTM.getRowCount(); ++i) 35 35 consideredLines.add(new Integer(i)); 36 36 } 37 37 38 38 // keep only lines where a node can be added 39 39 for (int i = 0; i < consideredLines.size(); ++i) 40 40 { 41 41 if (waypointTM.nodes.elementAt(consideredLines.elementAt(i)) != null) 42 42 workingLines.add(consideredLines.elementAt(i)); 43 43 } 44 44 } 45 45 46 46 public boolean executeCommand() 47 47 { … … 56 56 return true; 57 57 } 58 58 59 59 public void undoCommand() 60 60 { … … 66 66 } 67 67 } 68 68 69 69 public void fillModifiedData 70 70 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 72 72 { 73 73 } 74 74 75 75 @Override public JLabel getDescription() 76 76 { -
applications/editors/josm/plugins/public_transport/src/public_transport/WaypointsDisableCommand.java
r22048 r23192 15 15 private Vector< Node > nodesForUndo = null; 16 16 private WaypointTableModel waypointTM = null; 17 17 18 18 public WaypointsDisableCommand(StopImporterAction controller) 19 19 { … … 21 21 workingLines = new Vector< Integer >(); 22 22 nodesForUndo = new Vector< Node >(); 23 23 24 24 // use either selected lines or all lines if no line is selected 25 25 int[] selectedLines = controller.getDialog().getWaypointsTable().getSelectedRows(); … … 28 28 { 29 29 for (int i = 0; i < selectedLines.length; ++i) 30 30 consideredLines.add(selectedLines[i]); 31 31 } 32 32 else 33 33 { 34 34 for (int i = 0; i < waypointTM.getRowCount(); ++i) 35 35 consideredLines.add(new Integer(i)); 36 36 } 37 37 38 38 // keep only lines where a node can be added 39 39 for (int i = 0; i < consideredLines.size(); ++i) 40 40 { 41 41 if (waypointTM.nodes.elementAt(consideredLines.elementAt(i)) != null) 42 42 workingLines.add(consideredLines.elementAt(i)); 43 43 } 44 44 } 45 45 46 46 public boolean executeCommand() 47 47 { … … 53 53 nodesForUndo.add(node); 54 54 if (node == null) 55 55 continue; 56 56 waypointTM.nodes.set(j, null); 57 57 Main.main.getCurrentDataSet().removePrimitive(node); … … 60 60 return true; 61 61 } 62 62 63 63 public void undoCommand() 64 64 { … … 69 69 waypointTM.nodes.set(j, node); 70 70 if (node == null) 71 71 continue; 72 72 node.setDeleted(false); 73 73 Main.main.getCurrentDataSet().addPrimitive(node); 74 74 } 75 75 } 76 76 77 77 public void fillModifiedData 78 78 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 80 80 { 81 81 } 82 82 83 83 @Override public JLabel getDescription() 84 84 { -
applications/editors/josm/plugins/public_transport/src/public_transport/WaypointsEnableCommand.java
r22048 r23192 15 15 private WaypointTableModel waypointTM = null; 16 16 private String type = null; 17 17 18 18 public WaypointsEnableCommand(StopImporterAction controller) 19 19 { … … 21 21 type = controller.getDialog().getStoptype(); 22 22 workingLines = new Vector< Integer >(); 23 23 24 24 // use either selected lines or all lines if no line is selected 25 25 int[] selectedLines = controller.getDialog().getWaypointsTable().getSelectedRows(); … … 28 28 { 29 29 for (int i = 0; i < selectedLines.length; ++i) 30 30 consideredLines.add(selectedLines[i]); 31 31 } 32 32 else 33 33 { 34 34 for (int i = 0; i < waypointTM.getRowCount(); ++i) 35 35 consideredLines.add(new Integer(i)); 36 36 } 37 37 38 38 // keep only lines where a node can be added 39 39 for (int i = 0; i < consideredLines.size(); ++i) 40 40 { 41 41 if (waypointTM.nodes.elementAt(consideredLines.elementAt(i)) == null) 42 42 workingLines.add(consideredLines.elementAt(i)); 43 43 } 44 44 } 45 45 46 46 public boolean executeCommand() 47 47 { … … 52 52 (waypointTM.coors.elementAt(j), type, (String)waypointTM.getValueAt(j, 1)); 53 53 if ("".equals((String)waypointTM.getValueAt(j, 2))) 54 54 node.put("shelter", null); 55 55 else 56 56 node.put("shelter", (String)waypointTM.getValueAt(j, 2)); 57 57 waypointTM.nodes.set(j, node); 58 58 } 59 59 return true; 60 60 } 61 61 62 62 public void undoCommand() 63 63 { … … 68 68 waypointTM.nodes.set(j, null); 69 69 if (node == null) 70 70 continue; 71 71 Main.main.getCurrentDataSet().removePrimitive(node); 72 72 node.setDeleted(true); 73 73 } 74 74 } 75 75 76 76 public void fillModifiedData 77 77 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 79 79 { 80 80 } 81 81 82 82 @Override public JLabel getDescription() 83 83 { -
applications/editors/josm/plugins/public_transport/src/public_transport/WaypointsNameCommand.java
r22048 r23192 18 18 private String oldShelter = null; 19 19 private String shelter = null; 20 20 21 21 public WaypointsNameCommand 22 22 (WaypointTableModel waypointTM, int workingLine, String name, String shelter) … … 34 34 this.shelter = null; 35 35 } 36 36 37 37 public boolean executeCommand() 38 38 { … … 54 54 return true; 55 55 } 56 56 57 57 public void undoCommand() 58 58 { … … 73 73 waypointTM.inEvent = false; 74 74 } 75 75 76 76 public void fillModifiedData 77 77 (Collection< OsmPrimitive > modified, Collection< OsmPrimitive > deleted, … … 79 79 { 80 80 } 81 81 82 82 @Override public JLabel getDescription() 83 83 {
Note:
See TracChangeset
for help on using the changeset viewer.