Changeset 20741 in osm for applications
- Timestamp:
- 2010-03-30T08:28:06+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/public_transport/src/public_transport/StopImporterAction.java
r20730 r20741 61 61 public class StopImporterAction extends JosmAction 62 62 { 63 64 private class TracksLSL implements ListSelectionListener65 {66 StopImporterAction root = null;67 68 public TracksLSL(StopImporterAction sia)69 {70 root = sia;71 }72 73 public void valueChanged(ListSelectionEvent e)74 {75 root.tracksSelectionChanged();76 }77 };78 79 63 private class TrackReference 80 64 implements Comparable< TrackReference >, TableModelListener … … 150 134 if (e.getType() == TableModelEvent.UPDATE) 151 135 { 152 double time = parseTime 136 double time = StopImporterDialog.parseTime 153 137 ((String)stoplistTM.getValueAt(e.getFirstRow(), 0)); 154 138 if (time < 0) … … 183 167 public LatLon computeCoor(double time) 184 168 { 185 double gpsSyncTime = parseTime(this.gpsSyncTime); 186 double dGpsStartTime = parseTime(gpsStartTime); 169 double gpsSyncTime = StopImporterDialog.parseTime(this.gpsSyncTime); 170 double dGpsStartTime = StopImporterDialog.parseTime(gpsStartTime); 187 171 if (gpsSyncTime < dGpsStartTime - 12*60*60) 188 172 gpsSyncTime += 24*60*60; 189 double timeDelta = gpsSyncTime - parseTime(stopwatchStart); 173 double timeDelta = gpsSyncTime - StopImporterDialog.parseTime(stopwatchStart); 190 174 time += timeDelta; 191 175 … … 202 186 wayPoint = witer.next(); 203 187 String startTime = wayPoint.getString("time"); 204 wayPointTime = parseTime(startTime.substring(11, 19)); 188 wayPointTime = StopImporterDialog.parseTime(startTime.substring(11, 19)); 205 189 if (startTime.substring(11, 19).compareTo(gpsStartTime.substring(11, 19)) == -1) 206 190 wayPointTime += 24*60*60; … … 242 226 continue; 243 227 244 double time = parseTime 228 double time = StopImporterDialog.parseTime 245 229 ((String)stoplistTM.getValueAt(i, 0)); 246 230 LatLon latLon = computeCoor(time); … … 270 254 int i = 0; 271 255 double time = -48*60*60; 272 double dGpsStartTime = parseTime(gpsStartTime); 256 double dGpsStartTime = StopImporterDialog.parseTime(gpsStartTime); 273 257 while ((i < wayPoints.size()) && (time < dGpsStartTime + timeWindow/2)) 274 258 { 275 259 if (wayPoints.elementAt(i).getString("time") != null) 276 time = parseTime(wayPoints.elementAt(i).getString("time").substring(11,19)); 260 time = StopImporterDialog.parseTime(wayPoints.elementAt(i) 261 .getString("time").substring(11,19)); 277 262 if (time < dGpsStartTime) 278 263 time += 24*60*60; … … 288 273 --j; 289 274 if (wayPoints.elementAt(j).getString("time") != null) 290 time2 = parseTime(wayPoints.elementAt(j).getString("time").substring(11,19)); 275 time2 = StopImporterDialog.parseTime(wayPoints.elementAt(j) 276 .getString("time").substring(11,19)); 291 277 if (time2 < dGpsStartTime) 292 278 time2 += 24*60*60; … … 297 283 { 298 284 if (wayPoints.elementAt(k).getString("time") != null) 299 time2 = parseTime(wayPoints.elementAt(k).getString("time").substring(11,19)); 285 time2 = StopImporterDialog.parseTime(wayPoints.elementAt(k) 286 .getString("time").substring(11,19)); 300 287 if (time2 < dGpsStartTime) 301 288 time2 += 24*60*60; … … 319 306 320 307 if (wayPoints.elementAt(i).getString("time") != null) 321 time = parseTime(wayPoints.elementAt(i).getString("time").substring(11,19)); 308 time = StopImporterDialog.parseTime(wayPoints.elementAt(i) 309 .getString("time").substring(11,19)); 322 310 if (time < dGpsStartTime) 323 311 time += 24*60*60; … … 356 344 if (wayPoints.elementAt(i).getString("time") != null) 357 345 { 358 time = parseTime(wayPoints.elementAt(i).getString("time").substring(11,19)); 359 double gpsSyncTime = parseTime(this.gpsSyncTime); 346 time = StopImporterDialog.parseTime(wayPoints.elementAt(i) 347 .getString("time").substring(11,19)); 348 double gpsSyncTime = StopImporterDialog.parseTime(this.gpsSyncTime); 360 349 if (gpsSyncTime < dGpsStartTime - 12*60*60) 361 350 gpsSyncTime += 24*60*60; 362 double timeDelta = gpsSyncTime - parseTime(stopwatchStart); 351 double timeDelta = gpsSyncTime - StopImporterDialog.parseTime(stopwatchStart); 363 352 time -= timeDelta; 364 353 stoplistTM.insertRow(-1, timeOf(time)); … … 388 377 public int compareTo(NodeSortEntry nse) 389 378 { 390 double time = parseTime(this.time); 379 double time = StopImporterDialog.parseTime(this.time); 391 380 if (time - startTime > 12*60*60) 392 381 time -= 24*60*60; 393 382 394 double nseTime = parseTime(nse.time); 383 double nseTime = StopImporterDialog.parseTime(nse.time); 395 384 if (nseTime - startTime > 12*60*60) 396 385 nseTime -= 24*60*60; … … 541 530 }; 542 531 543 private static JDialog jDialog = null; 544 private static JTabbedPane tabbedPane = null; 532 private static StopImporterDialog dialog = null; 545 533 private static DefaultListModel tracksListModel = null; 546 private static JComboBox cbStoptype = null;547 private static JList tracksList = null;548 private static JTextField tfGPSTimeStart = null;549 private static JTextField tfStopwatchStart = null;550 private static JTextField tfTimeWindow = null;551 private static JTextField tfThreshold = null;552 private static JTable stoplistTable = null;553 private static JTable waypointTable = null;554 534 private static GpxData data = null; 555 535 private static TrackReference currentTrack = null; … … 562 542 } 563 543 544 public DefaultListModel getTracksListModel() 545 { 546 if (tracksListModel == null) 547 tracksListModel = new DefaultListModel(); 548 return tracksListModel; 549 } 550 564 551 public void actionPerformed(ActionEvent event) 565 552 { 566 Frame frame = JOptionPane.getFrameForComponent(Main.parent);567 553 DataSet mainDataSet = Main.main.getCurrentDataSet(); 568 554 569 if (jDialog == null) 570 { 571 jDialog = new JDialog(frame, "Create Stops from GPX", false); 572 tabbedPane = new JTabbedPane(); 573 JPanel tabTracks = new JPanel(); 574 tabbedPane.addTab(marktr("Tracks"), tabTracks); 575 JPanel tabSettings = new JPanel(); 576 tabbedPane.addTab(marktr("Settings"), tabSettings); 577 JPanel tabStops = new JPanel(); 578 tabbedPane.addTab(marktr("Stops"), tabStops); 579 JPanel tabWaypoints = new JPanel(); 580 tabbedPane.addTab(marktr("Waypoints"), tabWaypoints); 581 tabbedPane.setEnabledAt(0, true); 582 tabbedPane.setEnabledAt(1, true); 583 tabbedPane.setEnabledAt(2, false); 584 tabbedPane.setEnabledAt(3, true); 585 jDialog.add(tabbedPane); 586 587 //Tracks Tab 588 Container contentPane = tabTracks; 589 GridBagLayout gridbag = new GridBagLayout(); 590 GridBagConstraints layoutCons = new GridBagConstraints(); 591 contentPane.setLayout(gridbag); 592 593 JLabel label = new JLabel("Tracks in this GPX file:"); 594 595 layoutCons.gridx = 0; 596 layoutCons.gridy = 0; 597 layoutCons.gridwidth = 3; 598 layoutCons.weightx = 0.0; 599 layoutCons.weighty = 0.0; 600 layoutCons.fill = GridBagConstraints.BOTH; 601 gridbag.setConstraints(label, layoutCons); 602 contentPane.add(label); 603 604 tracksListModel = new DefaultListModel(); 605 tracksList = new JList(tracksListModel); 606 JScrollPane rpListSP = new JScrollPane(tracksList); 607 String[] data = {"1", "2", "3", "4", "5", "6"}; 608 tracksListModel.copyInto(data); 609 tracksList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 610 tracksList.addListSelectionListener(new TracksLSL(this)); 611 612 layoutCons.gridx = 0; 613 layoutCons.gridy = 1; 614 layoutCons.gridwidth = 3; 615 layoutCons.weightx = 1.0; 616 layoutCons.weighty = 1.0; 617 layoutCons.fill = GridBagConstraints.BOTH; 618 gridbag.setConstraints(rpListSP, layoutCons); 619 contentPane.add(rpListSP); 620 621 //Settings Tab 622 /*Container*/ contentPane = tabSettings; 623 /*GridBagLayout*/ gridbag = new GridBagLayout(); 624 /*GridBagConstraints*/ layoutCons = new GridBagConstraints(); 625 contentPane.setLayout(gridbag); 626 627 /*JLabel*/ label = new JLabel("Type of stops to add"); 628 629 layoutCons.gridx = 0; 630 layoutCons.gridy = 0; 631 layoutCons.gridwidth = 2; 632 layoutCons.weightx = 0.0; 633 layoutCons.weighty = 0.0; 634 layoutCons.fill = GridBagConstraints.BOTH; 635 gridbag.setConstraints(label, layoutCons); 636 contentPane.add(label); 637 638 cbStoptype = new JComboBox(); 639 cbStoptype.setEditable(false); 640 cbStoptype.addItem("bus"); 641 cbStoptype.addItem("tram"); 642 cbStoptype.addItem("light_rail"); 643 cbStoptype.addItem("subway"); 644 cbStoptype.addItem("rail"); 645 cbStoptype.setActionCommand("stopImporter.settingsStoptype"); 646 cbStoptype.addActionListener(this); 647 648 layoutCons.gridx = 0; 649 layoutCons.gridy = 1; 650 layoutCons.gridwidth = 1; 651 layoutCons.weightx = 0.0; 652 layoutCons.weighty = 0.0; 653 layoutCons.fill = GridBagConstraints.BOTH; 654 gridbag.setConstraints(cbStoptype, layoutCons); 655 contentPane.add(cbStoptype); 656 657 /*JLabel*/ label = new JLabel("Time on your GPS device"); 658 659 layoutCons.gridx = 0; 660 layoutCons.gridy = 2; 661 layoutCons.gridwidth = 2; 662 layoutCons.weightx = 0.0; 663 layoutCons.weighty = 0.0; 664 layoutCons.fill = GridBagConstraints.BOTH; 665 gridbag.setConstraints(label, layoutCons); 666 contentPane.add(label); 667 668 tfGPSTimeStart = new JTextField("00:00:00", 15); 669 tfGPSTimeStart.setActionCommand("stopImporter.settingsGPSTimeStart"); 670 tfGPSTimeStart.addActionListener(this); 671 672 layoutCons.gridx = 0; 673 layoutCons.gridy = 3; 674 layoutCons.gridwidth = 1; 675 layoutCons.weightx = 0.0; 676 layoutCons.weighty = 0.0; 677 layoutCons.fill = GridBagConstraints.BOTH; 678 gridbag.setConstraints(tfGPSTimeStart, layoutCons); 679 contentPane.add(tfGPSTimeStart); 680 681 /*JLabel*/ label = new JLabel("HH:MM:SS.sss"); 682 683 layoutCons.gridx = 1; 684 layoutCons.gridy = 3; 685 layoutCons.gridwidth = 1; 686 layoutCons.weightx = 0.0; 687 layoutCons.weighty = 0.0; 688 layoutCons.fill = GridBagConstraints.BOTH; 689 gridbag.setConstraints(label, layoutCons); 690 contentPane.add(label); 691 692 /*JLabel*/ label = new JLabel("Time on your stopwatch"); 693 694 layoutCons.gridx = 0; 695 layoutCons.gridy = 4; 696 layoutCons.gridwidth = 2; 697 layoutCons.weightx = 0.0; 698 layoutCons.weighty = 0.0; 699 layoutCons.fill = GridBagConstraints.BOTH; 700 gridbag.setConstraints(label, layoutCons); 701 contentPane.add(label); 702 703 tfStopwatchStart = new JTextField("00:00:00", 15); 704 tfStopwatchStart.setActionCommand("stopImporter.settingsStopwatchStart"); 705 tfStopwatchStart.addActionListener(this); 706 707 layoutCons.gridx = 0; 708 layoutCons.gridy = 5; 709 layoutCons.gridwidth = 1; 710 layoutCons.weightx = 0.0; 711 layoutCons.weighty = 0.0; 712 layoutCons.fill = GridBagConstraints.BOTH; 713 gridbag.setConstraints(tfStopwatchStart, layoutCons); 714 contentPane.add(tfStopwatchStart); 715 716 /*JLabel*/ label = new JLabel("HH:MM:SS.sss"); 717 718 layoutCons.gridx = 1; 719 layoutCons.gridy = 5; 720 layoutCons.gridwidth = 1; 721 layoutCons.weightx = 0.0; 722 layoutCons.weighty = 0.0; 723 layoutCons.fill = GridBagConstraints.BOTH; 724 gridbag.setConstraints(label, layoutCons); 725 contentPane.add(label); 726 727 /*JLabel*/ label = new JLabel("Time window"); 728 729 layoutCons.gridx = 0; 730 layoutCons.gridy = 6; 731 layoutCons.gridwidth = 2; 732 layoutCons.weightx = 0.0; 733 layoutCons.weighty = 0.0; 734 layoutCons.fill = GridBagConstraints.BOTH; 735 gridbag.setConstraints(label, layoutCons); 736 contentPane.add(label); 737 738 tfTimeWindow = new JTextField("15", 4); 739 tfTimeWindow.setActionCommand("stopImporter.settingsTimeWindow"); 740 tfTimeWindow.addActionListener(this); 741 742 layoutCons.gridx = 0; 743 layoutCons.gridy = 7; 744 layoutCons.gridwidth = 1; 745 layoutCons.weightx = 0.0; 746 layoutCons.weighty = 0.0; 747 layoutCons.fill = GridBagConstraints.BOTH; 748 gridbag.setConstraints(tfTimeWindow, layoutCons); 749 contentPane.add(tfTimeWindow); 750 751 /*JLabel*/ label = new JLabel("seconds"); 752 753 layoutCons.gridx = 1; 754 layoutCons.gridy = 7; 755 layoutCons.gridwidth = 1; 756 layoutCons.weightx = 0.0; 757 layoutCons.weighty = 0.0; 758 layoutCons.fill = GridBagConstraints.BOTH; 759 gridbag.setConstraints(label, layoutCons); 760 contentPane.add(label); 761 762 /*JLabel*/ label = new JLabel("Move Threshold"); 763 764 layoutCons.gridx = 0; 765 layoutCons.gridy = 8; 766 layoutCons.gridwidth = 2; 767 layoutCons.weightx = 0.0; 768 layoutCons.weighty = 0.0; 769 layoutCons.fill = GridBagConstraints.BOTH; 770 gridbag.setConstraints(label, layoutCons); 771 contentPane.add(label); 772 773 tfThreshold = new JTextField("20", 4); 774 tfThreshold.setActionCommand("stopImporter.settingsThreshold"); 775 tfThreshold.addActionListener(this); 776 777 layoutCons.gridx = 0; 778 layoutCons.gridy = 9; 779 layoutCons.gridwidth = 1; 780 layoutCons.weightx = 0.0; 781 layoutCons.weighty = 0.0; 782 layoutCons.fill = GridBagConstraints.BOTH; 783 gridbag.setConstraints(tfThreshold, layoutCons); 784 contentPane.add(tfThreshold); 785 786 /*JLabel*/ label = new JLabel("meters"); 787 788 layoutCons.gridx = 1; 789 layoutCons.gridy = 9; 790 layoutCons.gridwidth = 1; 791 layoutCons.weightx = 0.0; 792 layoutCons.weighty = 0.0; 793 layoutCons.fill = GridBagConstraints.BOTH; 794 gridbag.setConstraints(label, layoutCons); 795 contentPane.add(label); 796 797 JButton bSuggestStops = new JButton("Suggest Stops"); 798 bSuggestStops.setActionCommand("stopImporter.settingsSuggestStops"); 799 bSuggestStops.addActionListener(this); 800 801 layoutCons.gridx = 0; 802 layoutCons.gridy = 10; 803 layoutCons.gridwidth = 3; 804 layoutCons.weightx = 1.0; 805 layoutCons.weighty = 0.0; 806 layoutCons.fill = GridBagConstraints.BOTH; 807 gridbag.setConstraints(bSuggestStops, layoutCons); 808 contentPane.add(bSuggestStops); 809 810 //Stops Tab 811 contentPane = tabStops; 812 gridbag = new GridBagLayout(); 813 layoutCons = new GridBagConstraints(); 814 contentPane.setLayout(gridbag); 815 816 stoplistTable = new JTable(); 817 JScrollPane tableSP = new JScrollPane(stoplistTable); 818 819 layoutCons.gridx = 0; 820 layoutCons.gridy = 0; 821 layoutCons.gridwidth = 4; 822 layoutCons.weightx = 1.0; 823 layoutCons.weighty = 1.0; 824 layoutCons.fill = GridBagConstraints.BOTH; 825 gridbag.setConstraints(tableSP, layoutCons); 826 contentPane.add(tableSP); 827 828 JButton bFind = new JButton("Find"); 829 bFind.setActionCommand("stopImporter.stoplistFind"); 830 bFind.addActionListener(this); 831 832 layoutCons.gridx = 0; 833 layoutCons.gridy = 1; 834 layoutCons.gridwidth = 1; 835 layoutCons.weightx = 1.0; 836 layoutCons.weighty = 0.0; 837 layoutCons.fill = GridBagConstraints.BOTH; 838 gridbag.setConstraints(bFind, layoutCons); 839 contentPane.add(bFind); 840 841 JButton bShow = new JButton("Show"); 842 bShow.setActionCommand("stopImporter.stoplistShow"); 843 bShow.addActionListener(this); 844 845 layoutCons.gridx = 0; 846 layoutCons.gridy = 2; 847 layoutCons.gridwidth = 1; 848 layoutCons.weightx = 1.0; 849 layoutCons.weighty = 0.0; 850 layoutCons.fill = GridBagConstraints.BOTH; 851 gridbag.setConstraints(bShow, layoutCons); 852 contentPane.add(bShow); 853 854 JButton bMark = new JButton("Mark"); 855 bMark.setActionCommand("stopImporter.stoplistMark"); 856 bMark.addActionListener(this); 857 858 layoutCons.gridx = 1; 859 layoutCons.gridy = 1; 860 layoutCons.gridheight = 1; 861 layoutCons.gridwidth = 1; 862 layoutCons.weightx = 1.0; 863 layoutCons.weighty = 0.0; 864 layoutCons.fill = GridBagConstraints.BOTH; 865 gridbag.setConstraints(bMark, layoutCons); 866 contentPane.add(bMark); 867 868 JButton bDetach = new JButton("Detach"); 869 bDetach.setActionCommand("stopImporter.stoplistDetach"); 870 bDetach.addActionListener(this); 871 872 layoutCons.gridx = 1; 873 layoutCons.gridy = 2; 874 layoutCons.gridheight = 1; 875 layoutCons.gridwidth = 1; 876 layoutCons.weightx = 1.0; 877 layoutCons.weighty = 0.0; 878 layoutCons.fill = GridBagConstraints.BOTH; 879 gridbag.setConstraints(bDetach, layoutCons); 880 contentPane.add(bDetach); 881 882 JButton bAdd = new JButton("Add"); 883 bAdd.setActionCommand("stopImporter.stoplistAdd"); 884 bAdd.addActionListener(this); 885 886 layoutCons.gridx = 2; 887 layoutCons.gridy = 1; 888 layoutCons.gridheight = 1; 889 layoutCons.gridwidth = 1; 890 layoutCons.weightx = 1.0; 891 layoutCons.weighty = 0.0; 892 layoutCons.fill = GridBagConstraints.BOTH; 893 gridbag.setConstraints(bAdd, layoutCons); 894 contentPane.add(bAdd); 895 896 JButton bDelete = new JButton("Delete"); 897 bDelete.setActionCommand("stopImporter.stoplistDelete"); 898 bDelete.addActionListener(this); 899 900 layoutCons.gridx = 2; 901 layoutCons.gridy = 2; 902 layoutCons.gridwidth = 1; 903 layoutCons.weightx = 1.0; 904 layoutCons.weighty = 0.0; 905 layoutCons.fill = GridBagConstraints.BOTH; 906 gridbag.setConstraints(bDelete, layoutCons); 907 contentPane.add(bDelete); 908 909 JButton bSort = new JButton("Sort"); 910 bSort.setActionCommand("stopImporter.stoplistSort"); 911 bSort.addActionListener(this); 912 913 layoutCons.gridx = 3; 914 layoutCons.gridy = 1; 915 layoutCons.gridheight = 2; 916 layoutCons.gridwidth = 1; 917 layoutCons.weightx = 1.0; 918 layoutCons.weighty = 0.0; 919 layoutCons.fill = GridBagConstraints.BOTH; 920 gridbag.setConstraints(bSort, layoutCons); 921 contentPane.add(bSort); 922 923 //Waypoints Tab 924 contentPane = tabWaypoints; 925 gridbag = new GridBagLayout(); 926 layoutCons = new GridBagConstraints(); 927 contentPane.setLayout(gridbag); 928 929 waypointTable = new JTable(); 930 /*JScrollPane*/ tableSP = new JScrollPane(waypointTable); 931 932 layoutCons.gridx = 0; 933 layoutCons.gridy = 0; 934 layoutCons.gridwidth = 3; 935 layoutCons.weightx = 1.0; 936 layoutCons.weighty = 1.0; 937 layoutCons.fill = GridBagConstraints.BOTH; 938 gridbag.setConstraints(tableSP, layoutCons); 939 contentPane.add(tableSP); 940 941 /*JButton*/ bFind = new JButton("Find"); 942 bFind.setActionCommand("stopImporter.waypointsFind"); 943 bFind.addActionListener(this); 944 945 layoutCons.gridx = 0; 946 layoutCons.gridy = 1; 947 layoutCons.gridwidth = 1; 948 layoutCons.weightx = 1.0; 949 layoutCons.weighty = 0.0; 950 layoutCons.fill = GridBagConstraints.BOTH; 951 gridbag.setConstraints(bFind, layoutCons); 952 contentPane.add(bFind); 953 954 /*JButton*/ bShow = new JButton("Show"); 955 bShow.setActionCommand("stopImporter.waypointsShow"); 956 bShow.addActionListener(this); 957 958 layoutCons.gridx = 0; 959 layoutCons.gridy = 2; 960 layoutCons.gridwidth = 1; 961 layoutCons.weightx = 1.0; 962 layoutCons.weighty = 0.0; 963 layoutCons.fill = GridBagConstraints.BOTH; 964 gridbag.setConstraints(bShow, layoutCons); 965 contentPane.add(bShow); 966 967 /*JButton*/ bMark = new JButton("Mark"); 968 bMark.setActionCommand("stopImporter.waypointsMark"); 969 bMark.addActionListener(this); 970 971 layoutCons.gridx = 1; 972 layoutCons.gridy = 1; 973 layoutCons.gridheight = 1; 974 layoutCons.gridwidth = 1; 975 layoutCons.weightx = 1.0; 976 layoutCons.weighty = 0.0; 977 layoutCons.fill = GridBagConstraints.BOTH; 978 gridbag.setConstraints(bMark, layoutCons); 979 contentPane.add(bMark); 980 981 /*JButton*/ bDetach = new JButton("Detach"); 982 bDetach.setActionCommand("stopImporter.waypointsDetach"); 983 bDetach.addActionListener(this); 984 985 layoutCons.gridx = 1; 986 layoutCons.gridy = 2; 987 layoutCons.gridheight = 1; 988 layoutCons.gridwidth = 1; 989 layoutCons.weightx = 1.0; 990 layoutCons.weighty = 0.0; 991 layoutCons.fill = GridBagConstraints.BOTH; 992 gridbag.setConstraints(bDetach, layoutCons); 993 contentPane.add(bDetach); 994 995 /*JButton*/ bAdd = new JButton("Enable"); 996 bAdd.setActionCommand("stopImporter.waypointsAdd"); 997 bAdd.addActionListener(this); 998 999 layoutCons.gridx = 2; 1000 layoutCons.gridy = 1; 1001 layoutCons.gridheight = 1; 1002 layoutCons.gridwidth = 1; 1003 layoutCons.weightx = 1.0; 1004 layoutCons.weighty = 0.0; 1005 layoutCons.fill = GridBagConstraints.BOTH; 1006 gridbag.setConstraints(bAdd, layoutCons); 1007 contentPane.add(bAdd); 1008 1009 /*JButton*/ bDelete = new JButton("Disable"); 1010 bDelete.setActionCommand("stopImporter.waypointsDelete"); 1011 bDelete.addActionListener(this); 1012 1013 layoutCons.gridx = 2; 1014 layoutCons.gridy = 2; 1015 layoutCons.gridwidth = 1; 1016 layoutCons.weightx = 1.0; 1017 layoutCons.weighty = 0.0; 1018 layoutCons.fill = GridBagConstraints.BOTH; 1019 gridbag.setConstraints(bDelete, layoutCons); 1020 contentPane.add(bDelete); 1021 1022 jDialog.pack(); 1023 jDialog.setLocationRelativeTo(frame); 1024 } 1025 1026 jDialog.setVisible(true); 555 if (dialog == null) 556 dialog = new StopImporterDialog(this); 557 558 dialog.setVisible(true); 1027 559 1028 560 if (tr("Create Stops from GPX ...").equals(event.getActionCommand())) … … 1047 579 1048 580 refreshData(); 1049 1050 /* Iterator< GpxTrack > iter = data.tracks.iterator();1051 while (iter.hasNext())1052 {1053 GpxTrack track = iter.next();1054 System.out.println("");1055 System.out.println(track.getAttributes().get("name"));1056 Iterator< GpxTrackSegment > siter = track.getSegments().iterator();1057 while (siter.hasNext())1058 {1059 Iterator< WayPoint > witer = siter.next().getWayPoints().iterator();1060 while (witer.hasNext())1061 {1062 System.out.println(witer.next());1063 }1064 }1065 }*/1066 581 } 1067 582 else if ("stopImporter.settingsGPSTimeStart" 1068 583 .equals(event.getActionCommand())) 1069 584 { 1070 if ( parseTime(tfGPSTimeStart.getText()) >= 0)585 if (dialog.gpsTimeStartValid()) 1071 586 { 1072 587 if (currentTrack != null) 1073 588 { 1074 currentTrack.gpsSyncTime = tfGPSTimeStart.getText();589 currentTrack.gpsSyncTime = dialog.getGpsTimeStart(); 1075 590 currentTrack.relocateNodes(); 1076 591 } 1077 }1078 else1079 {1080 JOptionPane.showMessageDialog1081 (null, "Can't parse a time from this string.", "Invalid value",1082 JOptionPane.ERROR_MESSAGE);1083 592 } 1084 593 } … … 1086 595 .equals(event.getActionCommand())) 1087 596 { 1088 if ( parseTime(tfStopwatchStart.getText()) >= 0)597 if (dialog.stopwatchStartValid()) 1089 598 { 1090 599 if (currentTrack != null) 1091 600 { 1092 currentTrack.stopwatchStart = tfStopwatchStart.getText();601 currentTrack.stopwatchStart = dialog.getStopwatchStart(); 1093 602 currentTrack.relocateNodes(); 1094 603 } … … 1102 611 { 1103 612 if (currentTrack != null) 1104 currentTrack.timeWindow = Double.parseDouble(tfTimeWindow.getText());613 currentTrack.timeWindow = dialog.getTimeWindow(); 1105 614 } 1106 615 else if ("stopImporter.settingsThreshold".equals(event.getActionCommand())) 1107 616 { 1108 617 if (currentTrack != null) 1109 currentTrack.threshold = Double.parseDouble(tfThreshold.getText());618 currentTrack.threshold = dialog.getThreshold(); 1110 619 } 1111 620 else if ("stopImporter.settingsSuggestStops".equals(event.getActionCommand())) … … 1118 627 return; 1119 628 1120 stoplistTable.clearSelection();629 dialog.getStoplistTable().clearSelection(); 1121 630 1122 631 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i) … … 1124 633 if ((currentTrack.stoplistTM.nodes.elementAt(i) != null) && 1125 634 (Main.main.getCurrentDataSet().isSelected(currentTrack.stoplistTM.nodes.elementAt(i)))) 1126 stoplistTable.addRowSelectionInterval(i, i);635 dialog.getStoplistTable().addRowSelectionInterval(i, i); 1127 636 } 1128 637 } … … 1130 639 { 1131 640 BoundingXYVisitor box = new BoundingXYVisitor(); 1132 if ( stoplistTable.getSelectedRowCount() > 0)641 if (dialog.getStoplistTable().getSelectedRowCount() > 0) 1133 642 { 1134 643 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i) 1135 644 { 1136 if (( stoplistTable.isRowSelected(i)) &&645 if ((dialog.getStoplistTable().isRowSelected(i)) && 1137 646 (currentTrack.stoplistTM.nodes.elementAt(i) != null)) 1138 647 { … … 1158 667 OsmPrimitive[] osmp = { null }; 1159 668 Main.main.getCurrentDataSet().setSelected(osmp); 1160 if ( stoplistTable.getSelectedRowCount() > 0)669 if (dialog.getStoplistTable().getSelectedRowCount() > 0) 1161 670 { 1162 671 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i) 1163 672 { 1164 if (( stoplistTable.isRowSelected(i)) &&673 if ((dialog.getStoplistTable().isRowSelected(i)) && 1165 674 (currentTrack.stoplistTM.nodes.elementAt(i) != null)) 1166 675 { … … 1180 689 else if ("stopImporter.stoplistDetach".equals(event.getActionCommand())) 1181 690 { 1182 if ( stoplistTable.getSelectedRowCount() > 0)691 if (dialog.getStoplistTable().getSelectedRowCount() > 0) 1183 692 { 1184 693 for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i) 1185 694 { 1186 if (( stoplistTable.isRowSelected(i)) &&695 if ((dialog.getStoplistTable().isRowSelected(i)) && 1187 696 (currentTrack.stoplistTM.nodes.elementAt(i) != null)) 1188 697 { … … 1199 708 } 1200 709 } 1201 stoplistTable.clearSelection();710 dialog.getStoplistTable().clearSelection(); 1202 711 } 1203 712 else if ("stopImporter.stoplistAdd".equals(event.getActionCommand())) 1204 713 { 1205 int insPos = stoplistTable.getSelectedRow();714 int insPos = dialog.getStoplistTable().getSelectedRow(); 1206 715 if (currentTrack != null) 1207 716 currentTrack.stoplistTM.insertRow(insPos, "00:00:00"); … … 1214 723 for (int i = currentTrack.stoplistTM.getRowCount()-1; i >=0; --i) 1215 724 { 1216 if ( stoplistTable.isRowSelected(i))725 if (dialog.getStoplistTable().isRowSelected(i)) 1217 726 { 1218 727 if ((Node)currentTrack.stoplistTM.nodes.elementAt(i) != null) … … 1231 740 else if ("stopImporter.stoplistSort".equals(event.getActionCommand())) 1232 741 { 1233 int insPos = stoplistTable.getSelectedRow();742 int insPos = dialog.getStoplistTable().getSelectedRow(); 1234 743 Vector< NodeSortEntry > nodesToSort = new Vector< NodeSortEntry >(); 1235 744 if (currentTrack == null) 1236 745 return; 1237 if ( stoplistTable.getSelectedRowCount() > 0)746 if (dialog.getStoplistTable().getSelectedRowCount() > 0) 1238 747 { 1239 748 for (int i = currentTrack.stoplistTM.getRowCount()-1; i >=0; --i) 1240 749 { 1241 if ( stoplistTable.isRowSelected(i))750 if (dialog.getStoplistTable().isRowSelected(i)) 1242 751 { 1243 752 nodesToSort.add(new NodeSortEntry … … 1245 754 (String)currentTrack.stoplistTM.getValueAt(i, 0), 1246 755 (String)currentTrack.stoplistTM.getValueAt(i, 1), 1247 parseTime(currentTrack.stopwatchStart))); 756 StopImporterDialog.parseTime(currentTrack.stopwatchStart))); 1248 757 currentTrack.stoplistTM.nodes.removeElementAt(i); 1249 758 currentTrack.stoplistTM.removeRow(i); … … 1259 768 (String)currentTrack.stoplistTM.getValueAt(i, 0), 1260 769 (String)currentTrack.stoplistTM.getValueAt(i, 1), 1261 parseTime(currentTrack.stopwatchStart))); 770 StopImporterDialog.parseTime(currentTrack.stopwatchStart))); 1262 771 } 1263 772 currentTrack.stoplistTM.clear(); … … 1281 790 return; 1282 791 1283 waypointTable.clearSelection();792 dialog.getWaypointsTable().clearSelection(); 1284 793 1285 794 for (int i = 0; i < waypointTM.getRowCount(); ++i) … … 1287 796 if ((waypointTM.nodes.elementAt(i) != null) && 1288 797 (Main.main.getCurrentDataSet().isSelected(waypointTM.nodes.elementAt(i)))) 1289 waypointTable.addRowSelectionInterval(i, i);798 dialog.getWaypointsTable().addRowSelectionInterval(i, i); 1290 799 } 1291 800 } … … 1293 802 { 1294 803 BoundingXYVisitor box = new BoundingXYVisitor(); 1295 if ( waypointTable.getSelectedRowCount() > 0)804 if (dialog.getWaypointsTable().getSelectedRowCount() > 0) 1296 805 { 1297 806 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1298 807 { 1299 if (( waypointTable.isRowSelected(i)) &&808 if ((dialog.getWaypointsTable().isRowSelected(i)) && 1300 809 (waypointTM.nodes.elementAt(i) != null)) 1301 810 { … … 1321 830 OsmPrimitive[] osmp = { null }; 1322 831 Main.main.getCurrentDataSet().setSelected(osmp); 1323 if ( waypointTable.getSelectedRowCount() > 0)832 if (dialog.getWaypointsTable().getSelectedRowCount() > 0) 1324 833 { 1325 834 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1326 835 { 1327 if (( waypointTable.isRowSelected(i)) &&836 if ((dialog.getWaypointsTable().isRowSelected(i)) && 1328 837 (waypointTM.nodes.elementAt(i) != null)) 1329 838 { … … 1343 852 else if ("stopImporter.waypointsDetach".equals(event.getActionCommand())) 1344 853 { 1345 if ( waypointTable.getSelectedRowCount() > 0)854 if (dialog.getWaypointsTable().getSelectedRowCount() > 0) 1346 855 { 1347 856 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1348 857 { 1349 if (( waypointTable.isRowSelected(i)) &&858 if ((dialog.getWaypointsTable().isRowSelected(i)) && 1350 859 (waypointTM.nodes.elementAt(i) != null)) 1351 860 { … … 1362 871 } 1363 872 } 1364 waypointTable.clearSelection();873 dialog.getWaypointsTable().clearSelection(); 1365 874 } 1366 875 else if ("stopImporter.waypointsAdd".equals(event.getActionCommand())) 1367 876 { 1368 if ( waypointTable.getSelectedRowCount() > 0)877 if (dialog.getWaypointsTable().getSelectedRowCount() > 0) 1369 878 { 1370 879 for (int i = 0; i < waypointTM.getRowCount(); ++i) 1371 880 { 1372 if (( waypointTable.isRowSelected(i)) &&881 if ((dialog.getWaypointsTable().isRowSelected(i)) && 1373 882 (waypointTM.nodes.elementAt(i) == null)) 1374 883 { … … 1393 902 for (int i = waypointTM.getRowCount()-1; i >=0; --i) 1394 903 { 1395 if ( waypointTable.isRowSelected(i))904 if (dialog.getWaypointsTable().isRowSelected(i)) 1396 905 { 1397 906 if ((Node)waypointTM.nodes.elementAt(i) != null) … … 1416 925 node.remove("highway"); 1417 926 node.remove("railway"); 1418 if ("bus".equals( (String)cbStoptype.getSelectedItem()))927 if ("bus".equals(dialog.getStoptype())) 1419 928 node.put("highway", "bus_stop"); 1420 (String)cbStoptype.getSelectedItem()))929 else if ("tram".equals(dialog.getStoptype())) 1421 930 node.put("railway", "tram_stop"); 1422 (String)cbStoptype.getSelectedItem()))931 else if ("light_rail".equals(dialog.getStoptype())) 1423 932 node.put("railway", "station"); 1424 (String)cbStoptype.getSelectedItem()))933 else if ("subway".equals(dialog.getStoptype())) 1425 934 node.put("railway", "station"); 1426 (String)cbStoptype.getSelectedItem()))935 else if ("rail".equals(dialog.getStoptype())) 1427 936 node.put("railway", "station"); 1428 937 } … … 1438 947 node.remove("highway"); 1439 948 node.remove("railway"); 1440 if ("bus".equals( (String)cbStoptype.getSelectedItem()))949 if ("bus".equals(dialog.getStoptype())) 1441 950 node.put("highway", "bus_stop"); 1442 else if ("tram".equals( (String)cbStoptype.getSelectedItem()))951 else if ("tram".equals(dialog.getStoptype())) 1443 952 node.put("railway", "tram_stop"); 1444 else if ("light_rail".equals( (String)cbStoptype.getSelectedItem()))953 else if ("light_rail".equals(dialog.getStoptype())) 1445 954 node.put("railway", "station"); 1446 else if ("subway".equals( (String)cbStoptype.getSelectedItem()))955 else if ("subway".equals(dialog.getStoptype())) 1447 956 node.put("railway", "station"); 1448 else if ("rail".equals( (String)cbStoptype.getSelectedItem()))957 else if ("rail".equals(dialog.getStoptype())) 1449 958 node.put("railway", "station"); 1450 959 } … … 1525 1034 waypointTM.addRow(waypoint); 1526 1035 } 1527 waypointTable.setModel(waypointTM);1036 dialog.getWaypointsTable().setModel(waypointTM); 1528 1037 } 1529 1038 else … … 1537 1046 } 1538 1047 1539 p rivatevoid tracksSelectionChanged()1048 public void tracksSelectionChanged(int selectedPos) 1540 1049 { 1541 int selectedPos = tracksList.getAnchorSelectionIndex(); 1542 if (tracksList.isSelectedIndex(selectedPos)) 1050 if (selectedPos >= 0) 1543 1051 { 1544 1052 currentTrack = ((TrackReference)tracksListModel.elementAt(selectedPos)); 1545 tabbedPane.setEnabledAt(1, true); 1546 tabbedPane.setEnabledAt(2, true); 1053 dialog.setTrackValid(true); 1547 1054 1548 1055 //Prepare Settings 1549 tfGPSTimeStart.setText(currentTrack.gpsSyncTime); 1550 tfStopwatchStart.setText(currentTrack.stopwatchStart); 1551 tfTimeWindow.setText(Double.toString(currentTrack.timeWindow)); 1552 tfThreshold.setText(Double.toString(currentTrack.threshold)); 1056 dialog.setSettings 1057 (currentTrack.gpsSyncTime, currentTrack.stopwatchStart, 1058 currentTrack.timeWindow, currentTrack.threshold); 1553 1059 1554 1060 //Prepare Stoplist 1555 stoplistTable.setModel1061 dialog.getStoplistTable().setModel 1556 1062 (((TrackReference)tracksListModel.elementAt(selectedPos)).stoplistTM); 1557 1063 } … … 1559 1065 { 1560 1066 currentTrack = null; 1561 tabbedPane.setEnabledAt(1, false); 1562 tabbedPane.setEnabledAt(2, false); 1067 dialog.setTrackValid(false); 1563 1068 } 1564 1069 } … … 1567 1072 { 1568 1073 Node node = new Node(latLon); 1569 if ("bus".equals( (String)cbStoptype.getSelectedItem()))1074 if ("bus".equals(dialog.getStoptype())) 1570 1075 node.put("highway", "bus_stop"); 1571 else if ("tram".equals( (String)cbStoptype.getSelectedItem()))1076 else if ("tram".equals(dialog.getStoptype())) 1572 1077 node.put("railway", "tram_stop"); 1573 else if ("light_rail".equals( (String)cbStoptype.getSelectedItem()))1078 else if ("light_rail".equals(dialog.getStoptype())) 1574 1079 node.put("railway", "station"); 1575 else if ("subway".equals( (String)cbStoptype.getSelectedItem()))1080 else if ("subway".equals(dialog.getStoptype())) 1576 1081 node.put("railway", "station"); 1577 else if ("rail".equals( (String)cbStoptype.getSelectedItem()))1082 else if ("rail".equals(dialog.getStoptype())) 1578 1083 node.put("railway", "station"); 1579 1084 node.put("name", name); … … 1592 1097 } 1593 1098 1594 private static double parseTime(String s)1595 {1596 double result = 0;1597 if ((s.charAt(2) != ':') || (s.charAt(2) != ':')1598 || (s.length() < 8))1599 return -1;1600 int hour = Integer.parseInt(s.substring(0, 2));1601 int minute = Integer.parseInt(s.substring(3, 5));1602 double second = Double.parseDouble(s.substring(6, s.length()));1603 if ((hour < 0) || (hour > 23) || (minute < 0) || (minute > 59)1604 || (second < 0) || (second >= 60.0))1605 return -1;1606 return (second + minute*60 + hour*60*60);1607 }1608 1609 1099 private static String timeOf(double t) 1610 1100 {
Note:
See TracChangeset
for help on using the changeset viewer.