Changeset 20728 in osm for applications/editors/josm/plugins
- Timestamp:
- 2010-03-29T10:48:35+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/public_transport/src/public_transport/StopImporterAction.java
r20673 r20728 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 // import java.awt.BorderLayout;7 6 import java.awt.Container; 8 // import java.awt.Dimension;9 7 import java.awt.Frame; 10 8 import java.awt.GridBagConstraints; … … 18 16 import java.text.DecimalFormat; 19 17 import java.text.Format; 20 // import java.util.Collection;21 18 import java.util.Collections; 22 19 import java.util.Iterator; 23 // import java.util.LinkedList;24 // import java.util.List;25 // import java.util.ListIterator;26 // import java.util.Map;27 // import java.util.TreeMap;28 // import java.util.TreeSet;29 20 import java.util.Vector; 30 21 import java.util.zip.GZIPInputStream; 31 // 32 // import javax.swing.DefaultCellEditor; 22 33 23 import javax.swing.DefaultListModel; 34 24 import javax.swing.JButton; 35 // import javax.swing.JCheckBox;36 // import javax.swing.JComboBox;37 25 import javax.swing.JDialog; 38 26 import javax.swing.JFileChooser; … … 51 39 import javax.swing.event.TableModelListener; 52 40 import javax.swing.table.DefaultTableModel; 53 // import javax.swing.table.TableCellEditor;54 41 55 42 import org.openstreetmap.josm.Main; … … 66 53 import org.openstreetmap.josm.data.osm.Node; 67 54 import org.openstreetmap.josm.data.osm.OsmPrimitive; 68 // import org.openstreetmap.josm.data.osm.Relation;69 // import org.openstreetmap.josm.data.osm.RelationMember;70 // import org.openstreetmap.josm.data.osm.Way;71 55 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 72 // import org.openstreetmap.josm.gui.ExtendedDialog;73 56 import org.openstreetmap.josm.io.GpxReader; 74 // import org.openstreetmap.josm.tools.GBC;75 // import org.openstreetmap.josm.tools.Shortcut;76 // import org.openstreetmap.josm.tools.UrlLabel;77 57 78 58 import org.xml.sax.SAXException; … … 183 163 if (stoplistTM.nodes.elementAt(e.getFirstRow()) == null) 184 164 { 185 createNode(e.getFirstRow(), latLon, (String)stoplistTM.getValueAt(e.getFirstRow(), 1)); 165 Node node = createNode 166 (latLon, (String)stoplistTM.getValueAt(e.getFirstRow(), 1)); 167 stoplistTM.nodes.set(e.getFirstRow(), node); 186 168 } 187 169 else … … 251 233 } 252 234 253 public void createNode(int index, LatLon latLon, String name)254 {255 Node node = new Node(latLon);256 node.put("highway", "bus_stop");257 node.put("name", name);258 if (Main.main.getCurrentDataSet() == null)259 {260 JOptionPane.showMessageDialog(null, "There exists no dataset."261 + " Try to download data from the server or open an OSM file.",262 "No data found", JOptionPane.ERROR_MESSAGE);263 264 System.out.println("Public Transport: StopInserter: No data found");265 266 return;267 }268 Main.main.getCurrentDataSet().addPrimitive(node);269 stoplistTM.nodes.set(index, node);270 }271 272 235 public void relocateNodes() 273 236 { … … 399 362 time -= timeDelta; 400 363 stoplistTM.insertRow(-1, timeOf(time)); 401 createNode(stoplistTM.getRowCount()-1, latLon, ""); 364 Node node = createNode(latLon, ""); 365 stoplistTM.nodes.set(stoplistTM.getRowCount()-1, node); 402 366 } 403 367 … … 472 436 } 473 437 474 public void insertRow(int insPos, Node node, String time, String name) { 438 public void insertRow(int insPos, Node node, String time, String name) 439 { 475 440 String[] buf = { "", "" }; 476 441 buf[0] = time; … … 492 457 nodes.clear(); 493 458 super.setRowCount(0); 459 } 460 }; 461 462 private class WaypointTableModel extends DefaultTableModel 463 implements TableModelListener 464 { 465 public Vector< Node > nodes = new Vector< Node >(); 466 public Vector< LatLon > coors = new Vector< LatLon >(); 467 468 public WaypointTableModel() 469 { 470 addColumn("Time"); 471 addColumn("Stopname"); 472 addTableModelListener(this); 473 } 474 475 public boolean isCellEditable(int row, int column) 476 { 477 if (column == 1) 478 return true; 479 return false; 480 } 481 482 public void addRow(Object[] obj) 483 { 484 throw new UnsupportedOperationException(); 485 } 486 487 public void insertRow(int insPos, Object[] obj) 488 { 489 throw new UnsupportedOperationException(); 490 } 491 492 public void addRow(WayPoint wp) 493 { 494 insertRow(-1, wp); 495 } 496 497 public void insertRow(int insPos, WayPoint wp) 498 { 499 Node node = createNode(wp.getCoor(), ""); 500 501 String[] buf = { "", "" }; 502 buf[0] = wp.getString("time"); 503 if (buf[0] == null) 504 buf[0] = ""; 505 buf[1] = wp.getString("name"); 506 if (buf[1] == null) 507 buf[1] = ""; 508 if (insPos == -1) 509 { 510 nodes.addElement(node); 511 coors.addElement(wp.getCoor()); 512 super.addRow(buf); 513 } 514 else 515 { 516 nodes.insertElementAt(node, insPos); 517 coors.insertElementAt(wp.getCoor(), insPos); 518 super.insertRow(insPos, buf); 519 } 520 } 521 522 public void clear() 523 { 524 nodes.clear(); 525 super.setRowCount(0); 526 } 527 528 public void tableChanged(TableModelEvent e) 529 { 530 if (e.getType() == TableModelEvent.UPDATE) 531 { 532 if (nodes.elementAt(e.getFirstRow()) != null) 533 { 534 Node node = nodes.elementAt(e.getFirstRow()); 535 node.put("name", (String)getValueAt(e.getFirstRow(), 1)); 536 } 537 } 494 538 } 495 539 }; … … 504 548 private static JTextField tfThreshold = null; 505 549 private static JTable stoplistTable = null; 550 private static JTable waypointTable = null; 506 551 private static GpxData data = null; 507 552 private static TrackReference currentTrack = null; 553 private static WaypointTableModel waypointTM = null; 508 554 509 555 public StopImporterAction() … … 528 574 JPanel tabStops = new JPanel(); 529 575 tabbedPane.addTab(marktr("Stops"), tabStops); 576 JPanel tabWaypoints = new JPanel(); 577 tabbedPane.addTab(marktr("Waypoints"), tabWaypoints); 530 578 tabbedPane.setEnabledAt(0, true); 531 579 tabbedPane.setEnabledAt(1, false); 532 580 tabbedPane.setEnabledAt(2, false); 581 tabbedPane.setEnabledAt(3, true); 533 582 jDialog.add(tabbedPane); 534 583 … … 776 825 layoutCons.gridx = 1; 777 826 layoutCons.gridy = 1; 778 layoutCons.gridheight = 2;827 layoutCons.gridheight = 1; 779 828 layoutCons.gridwidth = 1; 780 829 layoutCons.weightx = 1.0; … … 783 832 gridbag.setConstraints(bMark, layoutCons); 784 833 contentPane.add(bMark); 834 835 JButton bDetach = new JButton("Detach"); 836 bDetach.setActionCommand("stopImporter.stoplistDetach"); 837 bDetach.addActionListener(this); 838 839 layoutCons.gridx = 1; 840 layoutCons.gridy = 2; 841 layoutCons.gridheight = 1; 842 layoutCons.gridwidth = 1; 843 layoutCons.weightx = 1.0; 844 layoutCons.weighty = 0.0; 845 layoutCons.fill = GridBagConstraints.BOTH; 846 gridbag.setConstraints(bDetach, layoutCons); 847 contentPane.add(bDetach); 785 848 786 849 JButton bAdd = new JButton("Add"); … … 824 887 gridbag.setConstraints(bSort, layoutCons); 825 888 contentPane.add(bSort); 889 890 //Waypoints Tab 891 contentPane = tabWaypoints; 892 gridbag = new GridBagLayout(); 893 layoutCons = new GridBagConstraints(); 894 contentPane.setLayout(gridbag); 895 896 waypointTable = new JTable(); 897 /*JScrollPane*/ tableSP = new JScrollPane(waypointTable); 898 899 layoutCons.gridx = 0; 900 layoutCons.gridy = 0; 901 layoutCons.gridwidth = 3; 902 layoutCons.weightx = 1.0; 903 layoutCons.weighty = 1.0; 904 layoutCons.fill = GridBagConstraints.BOTH; 905 gridbag.setConstraints(tableSP, layoutCons); 906 contentPane.add(tableSP); 907 908 /*JButton*/ bFind = new JButton("Find"); 909 bFind.setActionCommand("stopImporter.waypointsFind"); 910 bFind.addActionListener(this); 911 912 layoutCons.gridx = 0; 913 layoutCons.gridy = 1; 914 layoutCons.gridwidth = 1; 915 layoutCons.weightx = 1.0; 916 layoutCons.weighty = 0.0; 917 layoutCons.fill = GridBagConstraints.BOTH; 918 gridbag.setConstraints(bFind, layoutCons); 919 contentPane.add(bFind); 920 921 /*JButton*/ bShow = new JButton("Show"); 922 bShow.setActionCommand("stopImporter.waypointsShow"); 923 bShow.addActionListener(this); 924 925 layoutCons.gridx = 0; 926 layoutCons.gridy = 2; 927 layoutCons.gridwidth = 1; 928 layoutCons.weightx = 1.0; 929 layoutCons.weighty = 0.0; 930 layoutCons.fill = GridBagConstraints.BOTH; 931 gridbag.setConstraints(bShow, layoutCons); 932 contentPane.add(bShow); 933 934 /*JButton*/ bMark = new JButton("Mark"); 935 bMark.setActionCommand("stopImporter.waypointsMark"); 936 bMark.addActionListener(this); 937 938 layoutCons.gridx = 1; 939 layoutCons.gridy = 1; 940 layoutCons.gridheight = 1; 941 layoutCons.gridwidth = 1; 942 layoutCons.weightx = 1.0; 943 layoutCons.weighty = 0.0; 944 layoutCons.fill = GridBagConstraints.BOTH; 945 gridbag.setConstraints(bMark, layoutCons); 946 contentPane.add(bMark); 947 948 /*JButton*/ bDetach = new JButton("Detach"); 949 bDetach.setActionCommand("stopImporter.waypointsDetach"); 950 bDetach.addActionListener(this); 951 952 layoutCons.gridx = 1; 953 layoutCons.gridy = 2; 954 layoutCons.gridheight = 1; 955 layoutCons.gridwidth = 1; 956 layoutCons.weightx = 1.0; 957 layoutCons.weighty = 0.0; 958 layoutCons.fill = GridBagConstraints.BOTH; 959 gridbag.setConstraints(bDetach, layoutCons); 960 contentPane.add(bDetach); 961 962 /*JButton*/ bAdd = new JButton("Enable"); 963 bAdd.setActionCommand("stopImporter.waypointsAdd"); 964 bAdd.addActionListener(this); 965 966 layoutCons.gridx = 2; 967 layoutCons.gridy = 1; 968 layoutCons.gridheight = 1; 969 layoutCons.gridwidth = 1; 970 layoutCons.weightx = 1.0; 971 layoutCons.weighty = 0.0; 972 layoutCons.fill = GridBagConstraints.BOTH; 973 gridbag.setConstraints(bAdd, layoutCons); 974 contentPane.add(bAdd); 975 976 /*JButton*/ bDelete = new JButton("Disable"); 977 bDelete.setActionCommand("stopImporter.waypointsDelete"); 978 bDelete.addActionListener(this); 979 980 layoutCons.gridx = 2; 981 layoutCons.gridy = 2; 982 layoutCons.gridwidth = 1; 983 layoutCons.weightx = 1.0; 984 layoutCons.weighty = 0.0; 985 layoutCons.fill = GridBagConstraints.BOTH; 986 gridbag.setConstraints(bDelete, layoutCons); 987 contentPane.add(bDelete); 826 988 827 989 jDialog.pack(); … … 982 1144 } 983 1145 } 1146 } 1147 else if ("stopImporter.stoplistDetach".equals(event.getActionCommand())) 1148 { 1149 if (stoplistTable.getSelectedRowCount() > 0) 1150 { 1151 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i) 1152 { 1153 if ((stoplistTable.isRowSelected(i)) && 1154 (currentTrack.stoplistTM.nodes.elementAt(i) != null)) 1155 { 1156 currentTrack.stoplistTM.nodes.set(i, null); 1157 } 1158 } 1159 } 1160 else 1161 { 1162 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i) 1163 { 1164 if (currentTrack.stoplistTM.nodes.elementAt(i) != null) 1165 currentTrack.stoplistTM.nodes.set(i, null); 1166 } 1167 } 1168 stoplistTable.clearSelection(); 984 1169 } 985 1170 else if ("stopImporter.stoplistAdd".equals(event.getActionCommand())) … … 1058 1243 } 1059 1244 } 1245 else if ("stopImporter.waypointsFind".equals(event.getActionCommand())) 1246 { 1247 if (Main.main.getCurrentDataSet() == null) 1248 return; 1249 1250 waypointTable.clearSelection(); 1251 1252 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1253 { 1254 if ((waypointTM.nodes.elementAt(i) != null) && 1255 (Main.main.getCurrentDataSet().isSelected(waypointTM.nodes.elementAt(i)))) 1256 waypointTable.addRowSelectionInterval(i, i); 1257 } 1258 } 1259 else if ("stopImporter.waypointsShow".equals(event.getActionCommand())) 1260 { 1261 BoundingXYVisitor box = new BoundingXYVisitor(); 1262 if (waypointTable.getSelectedRowCount() > 0) 1263 { 1264 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1265 { 1266 if ((waypointTable.isRowSelected(i)) && 1267 (waypointTM.nodes.elementAt(i) != null)) 1268 { 1269 waypointTM.nodes.elementAt(i).visit(box); 1270 } 1271 } 1272 } 1273 else 1274 { 1275 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1276 { 1277 if (waypointTM.nodes.elementAt(i) != null) 1278 waypointTM.nodes.elementAt(i).visit(box); 1279 } 1280 } 1281 if (box.getBounds() == null) 1282 return; 1283 box.enlargeBoundingBox(); 1284 Main.map.mapView.recalculateCenterScale(box); 1285 } 1286 else if ("stopImporter.waypointsMark".equals(event.getActionCommand())) 1287 { 1288 OsmPrimitive[] osmp = { null }; 1289 Main.main.getCurrentDataSet().setSelected(osmp); 1290 if (waypointTable.getSelectedRowCount() > 0) 1291 { 1292 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1293 { 1294 if ((waypointTable.isRowSelected(i)) && 1295 (waypointTM.nodes.elementAt(i) != null)) 1296 { 1297 Main.main.getCurrentDataSet().addSelected(waypointTM.nodes.elementAt(i)); 1298 } 1299 } 1300 } 1301 else 1302 { 1303 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1304 { 1305 if (waypointTM.nodes.elementAt(i) != null) 1306 Main.main.getCurrentDataSet().addSelected(waypointTM.nodes.elementAt(i)); 1307 } 1308 } 1309 } 1310 else if ("stopImporter.waypointsDetach".equals(event.getActionCommand())) 1311 { 1312 if (waypointTable.getSelectedRowCount() > 0) 1313 { 1314 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1315 { 1316 if ((waypointTable.isRowSelected(i)) && 1317 (waypointTM.nodes.elementAt(i) != null)) 1318 { 1319 waypointTM.nodes.set(i, null); 1320 } 1321 } 1322 } 1323 else 1324 { 1325 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1326 { 1327 if (waypointTM.nodes.elementAt(i) != null) 1328 waypointTM.nodes.set(i, null); 1329 } 1330 } 1331 waypointTable.clearSelection(); 1332 } 1333 else if ("stopImporter.waypointsAdd".equals(event.getActionCommand())) 1334 { 1335 if (waypointTable.getSelectedRowCount() > 0) 1336 { 1337 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1338 { 1339 if ((waypointTable.isRowSelected(i)) && 1340 (waypointTM.nodes.elementAt(i) == null)) 1341 { 1342 Node node = createNode(waypointTM.coors.elementAt(i), (String)waypointTM.getValueAt(i, 1)); 1343 waypointTM.nodes.set(i, node); 1344 Main.main.getCurrentDataSet().addSelected(waypointTM.nodes.elementAt(i)); 1345 } 1346 } 1347 } 1348 else 1349 { 1350 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1351 { 1352 if (waypointTM.nodes.elementAt(i) == null) 1353 Main.main.getCurrentDataSet().addSelected(waypointTM.nodes.elementAt(i)); 1354 } 1355 } 1356 } 1357 else if ("stopImporter.waypointsDelete".equals(event.getActionCommand())) 1358 { 1359 Vector< Node > toDelete = new Vector< Node >(); 1360 for (int i = waypointTM.getRowCount()-1; i >=0; --i) 1361 { 1362 if (waypointTable.isRowSelected(i)) 1363 { 1364 if ((Node)waypointTM.nodes.elementAt(i) != null) 1365 toDelete.add((Node)waypointTM.nodes.elementAt(i)); 1366 waypointTM.nodes.set(i, null); 1367 } 1368 } 1369 Command cmd = DeleteCommand.delete 1370 (Main.main.getEditLayer(), toDelete); 1371 if (cmd != null) { 1372 // cmd can be null if the user cancels dialogs DialogCommand displays 1373 Main.main.undoRedo.add(cmd); 1374 } 1375 } 1060 1376 } 1061 1377 … … 1107 1423 private void refreshData() 1108 1424 { 1109 tracksListModel.clear(); 1425 tracksListModel.clear(); 1110 1426 if (data != null) 1111 1427 { … … 1123 1439 while (iter.hasNext()) 1124 1440 tracksListModel.addElement(iter.next()); 1441 1442 waypointTM = new WaypointTableModel(); 1443 Iterator< WayPoint > waypointIter = data.waypoints.iterator(); 1444 while (waypointIter.hasNext()) 1445 { 1446 WayPoint waypoint = waypointIter.next(); 1447 waypointTM.addRow(waypoint); 1448 } 1449 waypointTable.setModel(waypointTM); 1125 1450 } 1126 1451 else 1127 1452 { 1128 1453 JOptionPane.showMessageDialog 1129 (null, "The GPX file contained no tracks .", "No data found",1454 (null, "The GPX file contained no tracks or waypoints.", "No data found", 1130 1455 JOptionPane.ERROR_MESSAGE); 1131 1456 … … 1161 1486 } 1162 1487 1488 private Node createNode(LatLon latLon, String name) 1489 { 1490 Node node = new Node(latLon); 1491 node.put("highway", "bus_stop"); 1492 node.put("name", name); 1493 if (Main.main.getCurrentDataSet() == null) 1494 { 1495 JOptionPane.showMessageDialog(null, "There exists no dataset." 1496 + " Try to download data from the server or open an OSM file.", 1497 "No data found", JOptionPane.ERROR_MESSAGE); 1498 1499 System.out.println("Public Transport: StopInserter: No data found"); 1500 1501 return null; 1502 } 1503 Main.main.getCurrentDataSet().addPrimitive(node); 1504 return node; 1505 } 1506 1163 1507 private static double parseTime(String s) 1164 1508 {
Note:
See TracChangeset
for help on using the changeset viewer.