Changeset 20741 in osm for applications


Ignore:
Timestamp:
2010-03-30T08:28:06+02:00 (15 years ago)
Author:
roland
Message:

Public Transport Plugin: Refactoring StopImporter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/public_transport/src/public_transport/StopImporterAction.java

    r20730 r20741  
    6161public class StopImporterAction extends JosmAction
    6262
    63 
    64   private class TracksLSL implements ListSelectionListener
    65   {
    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  
    7963  private class TrackReference
    8064    implements Comparable< TrackReference >, TableModelListener
     
    150134      if (e.getType() == TableModelEvent.UPDATE)
    151135      {
    152         double time = parseTime
     136        double time = StopImporterDialog.parseTime
    153137            ((String)stoplistTM.getValueAt(e.getFirstRow(), 0));
    154138        if (time < 0)
     
    183167    public LatLon computeCoor(double time)
    184168    {
    185       double gpsSyncTime = parseTime(this.gpsSyncTime);
    186       double dGpsStartTime = parseTime(gpsStartTime);
     169      double gpsSyncTime = StopImporterDialog.parseTime(this.gpsSyncTime);
     170      double dGpsStartTime = StopImporterDialog.parseTime(gpsStartTime);
    187171      if (gpsSyncTime < dGpsStartTime - 12*60*60)
    188172        gpsSyncTime += 24*60*60;
    189       double timeDelta = gpsSyncTime - parseTime(stopwatchStart);
     173      double timeDelta = gpsSyncTime - StopImporterDialog.parseTime(stopwatchStart);
    190174      time += timeDelta;
    191175       
     
    202186          wayPoint = witer.next();
    203187          String startTime = wayPoint.getString("time");
    204           wayPointTime = parseTime(startTime.substring(11, 19));
     188          wayPointTime = StopImporterDialog.parseTime(startTime.substring(11, 19));
    205189          if (startTime.substring(11, 19).compareTo(gpsStartTime.substring(11, 19)) == -1)
    206190            wayPointTime += 24*60*60;
     
    242226          continue;
    243227       
    244         double time = parseTime
     228        double time = StopImporterDialog.parseTime
    245229              ((String)stoplistTM.getValueAt(i, 0));
    246230        LatLon latLon = computeCoor(time);
     
    270254      int i = 0;
    271255      double time = -48*60*60;
    272       double dGpsStartTime = parseTime(gpsStartTime);
     256      double dGpsStartTime = StopImporterDialog.parseTime(gpsStartTime);
    273257      while ((i < wayPoints.size()) && (time < dGpsStartTime + timeWindow/2))
    274258      {
    275259        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));
    277262        if (time < dGpsStartTime)
    278263          time += 24*60*60;
     
    288273          --j;
    289274          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));
    291277          if (time2 < dGpsStartTime)
    292278            time2 += 24*60*60;
     
    297283        {
    298284          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));
    300287          if (time2 < dGpsStartTime)
    301288            time2 += 24*60*60;
     
    319306       
    320307        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));
    322310        if (time < dGpsStartTime)
    323311          time += 24*60*60;
     
    356344        if (wayPoints.elementAt(i).getString("time") != null)
    357345        {
    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);
    360349          if (gpsSyncTime < dGpsStartTime - 12*60*60)
    361350            gpsSyncTime += 24*60*60;
    362           double timeDelta = gpsSyncTime - parseTime(stopwatchStart);
     351          double timeDelta = gpsSyncTime - StopImporterDialog.parseTime(stopwatchStart);
    363352          time -= timeDelta;
    364353          stoplistTM.insertRow(-1, timeOf(time));
     
    388377    public int compareTo(NodeSortEntry nse)
    389378    {
    390       double time = parseTime(this.time);
     379      double time = StopImporterDialog.parseTime(this.time);
    391380      if (time - startTime > 12*60*60)
    392381        time -= 24*60*60;
    393382     
    394       double nseTime = parseTime(nse.time);
     383      double nseTime = StopImporterDialog.parseTime(nse.time);
    395384      if (nseTime - startTime > 12*60*60)
    396385        nseTime -= 24*60*60;
     
    541530  };
    542531 
    543   private static JDialog jDialog = null;
    544   private static JTabbedPane tabbedPane = null;
     532  private static StopImporterDialog dialog = null;
    545533  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;
    554534  private static GpxData data = null;
    555535  private static TrackReference currentTrack = null;
     
    562542  }
    563543
     544  public DefaultListModel getTracksListModel()
     545  {
     546    if (tracksListModel == null)
     547      tracksListModel = new DefaultListModel();
     548    return tracksListModel;
     549  }
     550 
    564551  public void actionPerformed(ActionEvent event)
    565552  {
    566     Frame frame = JOptionPane.getFrameForComponent(Main.parent);
    567553    DataSet mainDataSet = Main.main.getCurrentDataSet();
    568554   
    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);
    1027559
    1028560    if (tr("Create Stops from GPX ...").equals(event.getActionCommand()))
     
    1047579     
    1048580      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       }*/
    1066581    }
    1067582    else if ("stopImporter.settingsGPSTimeStart"
    1068583      .equals(event.getActionCommand()))
    1069584    {
    1070       if (parseTime(tfGPSTimeStart.getText()) >= 0)
     585      if (dialog.gpsTimeStartValid())
    1071586      {
    1072587        if (currentTrack != null)
    1073588        {
    1074           currentTrack.gpsSyncTime = tfGPSTimeStart.getText();
     589          currentTrack.gpsSyncTime = dialog.getGpsTimeStart();
    1075590          currentTrack.relocateNodes();
    1076591        }
    1077       }
    1078       else
    1079       {
    1080         JOptionPane.showMessageDialog
    1081         (null, "Can't parse a time from this string.", "Invalid value",
    1082          JOptionPane.ERROR_MESSAGE);
    1083592      }
    1084593    }
     
    1086595      .equals(event.getActionCommand()))
    1087596    {
    1088       if (parseTime(tfStopwatchStart.getText()) >= 0)
     597      if (dialog.stopwatchStartValid())
    1089598      {
    1090599        if (currentTrack != null)
    1091600        {
    1092           currentTrack.stopwatchStart = tfStopwatchStart.getText();
     601          currentTrack.stopwatchStart = dialog.getStopwatchStart();
    1093602          currentTrack.relocateNodes();
    1094603        }
     
    1102611    {
    1103612      if (currentTrack != null)
    1104         currentTrack.timeWindow = Double.parseDouble(tfTimeWindow.getText());
     613        currentTrack.timeWindow = dialog.getTimeWindow();
    1105614    }
    1106615    else if ("stopImporter.settingsThreshold".equals(event.getActionCommand()))
    1107616    {
    1108617      if (currentTrack != null)
    1109         currentTrack.threshold = Double.parseDouble(tfThreshold.getText());
     618        currentTrack.threshold = dialog.getThreshold();
    1110619    }
    1111620    else if ("stopImporter.settingsSuggestStops".equals(event.getActionCommand()))
     
    1118627        return;
    1119628     
    1120       stoplistTable.clearSelection();
     629      dialog.getStoplistTable().clearSelection();
    1121630     
    1122631      for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)
     
    1124633        if ((currentTrack.stoplistTM.nodes.elementAt(i) != null) &&
    1125634                    (Main.main.getCurrentDataSet().isSelected(currentTrack.stoplistTM.nodes.elementAt(i))))
    1126           stoplistTable.addRowSelectionInterval(i, i);
     635          dialog.getStoplistTable().addRowSelectionInterval(i, i);
    1127636      }
    1128637    }
     
    1130639    {
    1131640      BoundingXYVisitor box = new BoundingXYVisitor();
    1132       if (stoplistTable.getSelectedRowCount() > 0)
     641      if (dialog.getStoplistTable().getSelectedRowCount() > 0)
    1133642      {
    1134643        for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)
    1135644        {
    1136           if ((stoplistTable.isRowSelected(i)) &&
     645          if ((dialog.getStoplistTable().isRowSelected(i)) &&
    1137646                      (currentTrack.stoplistTM.nodes.elementAt(i) != null))
    1138647          {
     
    1158667      OsmPrimitive[] osmp = { null };
    1159668      Main.main.getCurrentDataSet().setSelected(osmp);
    1160       if (stoplistTable.getSelectedRowCount() > 0)
     669      if (dialog.getStoplistTable().getSelectedRowCount() > 0)
    1161670      {
    1162671        for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)
    1163672        {
    1164           if ((stoplistTable.isRowSelected(i)) &&
     673          if ((dialog.getStoplistTable().isRowSelected(i)) &&
    1165674            (currentTrack.stoplistTM.nodes.elementAt(i) != null))
    1166675          {
     
    1180689    else if ("stopImporter.stoplistDetach".equals(event.getActionCommand()))
    1181690    {
    1182       if (stoplistTable.getSelectedRowCount() > 0)
     691      if (dialog.getStoplistTable().getSelectedRowCount() > 0)
    1183692      {
    1184693        for (int i = 0; i < currentTrack.stoplistTM.getRowCount(); ++i)
    1185694        {
    1186           if ((stoplistTable.isRowSelected(i)) &&
     695          if ((dialog.getStoplistTable().isRowSelected(i)) &&
    1187696                      (currentTrack.stoplistTM.nodes.elementAt(i) != null))
    1188697          {
     
    1199708        }
    1200709      }
    1201       stoplistTable.clearSelection();
     710      dialog.getStoplistTable().clearSelection();
    1202711    }
    1203712    else if ("stopImporter.stoplistAdd".equals(event.getActionCommand()))
    1204713    {
    1205       int insPos = stoplistTable.getSelectedRow();
     714      int insPos = dialog.getStoplistTable().getSelectedRow();
    1206715      if (currentTrack != null)
    1207716        currentTrack.stoplistTM.insertRow(insPos, "00:00:00");
     
    1214723      for (int i = currentTrack.stoplistTM.getRowCount()-1; i >=0; --i)
    1215724      {
    1216         if (stoplistTable.isRowSelected(i))
     725        if (dialog.getStoplistTable().isRowSelected(i))
    1217726        {
    1218727          if ((Node)currentTrack.stoplistTM.nodes.elementAt(i) != null)
     
    1231740    else if ("stopImporter.stoplistSort".equals(event.getActionCommand()))
    1232741    {
    1233       int insPos = stoplistTable.getSelectedRow();
     742      int insPos = dialog.getStoplistTable().getSelectedRow();
    1234743      Vector< NodeSortEntry > nodesToSort = new Vector< NodeSortEntry >();
    1235744      if (currentTrack == null)
    1236745        return;
    1237       if (stoplistTable.getSelectedRowCount() > 0)
     746      if (dialog.getStoplistTable().getSelectedRowCount() > 0)
    1238747      {
    1239748        for (int i = currentTrack.stoplistTM.getRowCount()-1; i >=0; --i)
    1240749        {
    1241           if (stoplistTable.isRowSelected(i))
     750          if (dialog.getStoplistTable().isRowSelected(i))
    1242751          {
    1243752            nodesToSort.add(new NodeSortEntry
     
    1245754                 (String)currentTrack.stoplistTM.getValueAt(i, 0),
    1246755                  (String)currentTrack.stoplistTM.getValueAt(i, 1),
    1247                    parseTime(currentTrack.stopwatchStart)));
     756                   StopImporterDialog.parseTime(currentTrack.stopwatchStart)));
    1248757            currentTrack.stoplistTM.nodes.removeElementAt(i);
    1249758            currentTrack.stoplistTM.removeRow(i);
     
    1259768               (String)currentTrack.stoplistTM.getValueAt(i, 0),
    1260769                (String)currentTrack.stoplistTM.getValueAt(i, 1),
    1261                  parseTime(currentTrack.stopwatchStart)));
     770                 StopImporterDialog.parseTime(currentTrack.stopwatchStart)));
    1262771        }
    1263772        currentTrack.stoplistTM.clear();
     
    1281790        return;
    1282791     
    1283       waypointTable.clearSelection();
     792      dialog.getWaypointsTable().clearSelection();
    1284793     
    1285794      for (int i = 0; i < waypointTM.getRowCount(); ++i)
     
    1287796        if ((waypointTM.nodes.elementAt(i) != null) &&
    1288797                    (Main.main.getCurrentDataSet().isSelected(waypointTM.nodes.elementAt(i))))
    1289           waypointTable.addRowSelectionInterval(i, i);
     798          dialog.getWaypointsTable().addRowSelectionInterval(i, i);
    1290799      }
    1291800    }
     
    1293802    {
    1294803      BoundingXYVisitor box = new BoundingXYVisitor();
    1295       if (waypointTable.getSelectedRowCount() > 0)
     804      if (dialog.getWaypointsTable().getSelectedRowCount() > 0)
    1296805      {
    1297806        for (int i = 0; i < waypointTM.getRowCount(); ++i)
    1298807        {
    1299           if ((waypointTable.isRowSelected(i)) &&
     808          if ((dialog.getWaypointsTable().isRowSelected(i)) &&
    1300809                      (waypointTM.nodes.elementAt(i) != null))
    1301810          {
     
    1321830      OsmPrimitive[] osmp = { null };
    1322831      Main.main.getCurrentDataSet().setSelected(osmp);
    1323       if (waypointTable.getSelectedRowCount() > 0)
     832      if (dialog.getWaypointsTable().getSelectedRowCount() > 0)
    1324833      {
    1325834        for (int i = 0; i < waypointTM.getRowCount(); ++i)
    1326835        {
    1327           if ((waypointTable.isRowSelected(i)) &&
     836          if ((dialog.getWaypointsTable().isRowSelected(i)) &&
    1328837                      (waypointTM.nodes.elementAt(i) != null))
    1329838          {
     
    1343852    else if ("stopImporter.waypointsDetach".equals(event.getActionCommand()))
    1344853    {
    1345       if (waypointTable.getSelectedRowCount() > 0)
     854      if (dialog.getWaypointsTable().getSelectedRowCount() > 0)
    1346855      {
    1347856        for (int i = 0; i < waypointTM.getRowCount(); ++i)
    1348857        {
    1349           if ((waypointTable.isRowSelected(i)) &&
     858          if ((dialog.getWaypointsTable().isRowSelected(i)) &&
    1350859                      (waypointTM.nodes.elementAt(i) != null))
    1351860          {
     
    1362871        }
    1363872      }
    1364       waypointTable.clearSelection();
     873      dialog.getWaypointsTable().clearSelection();
    1365874    }
    1366875    else if ("stopImporter.waypointsAdd".equals(event.getActionCommand()))
    1367876    {
    1368       if (waypointTable.getSelectedRowCount() > 0)
     877      if (dialog.getWaypointsTable().getSelectedRowCount() > 0)
    1369878      {
    1370879        for (int i = 0; i < waypointTM.getRowCount(); ++i)
    1371880        {
    1372           if ((waypointTable.isRowSelected(i)) &&
     881          if ((dialog.getWaypointsTable().isRowSelected(i)) &&
    1373882                      (waypointTM.nodes.elementAt(i) == null))
    1374883          {
     
    1393902      for (int i = waypointTM.getRowCount()-1; i >=0; --i)
    1394903      {
    1395         if (waypointTable.isRowSelected(i))
     904        if (dialog.getWaypointsTable().isRowSelected(i))
    1396905        {
    1397906          if ((Node)waypointTM.nodes.elementAt(i) != null)
     
    1416925          node.remove("highway");
    1417926          node.remove("railway");
    1418           if ("bus".equals((String)cbStoptype.getSelectedItem()))
     927          if ("bus".equals(dialog.getStoptype()))
    1419928            node.put("highway", "bus_stop");
    1420           else if ("tram".equals((String)cbStoptype.getSelectedItem()))
     929          else if ("tram".equals(dialog.getStoptype()))
    1421930            node.put("railway", "tram_stop");
    1422           else if ("light_rail".equals((String)cbStoptype.getSelectedItem()))
     931          else if ("light_rail".equals(dialog.getStoptype()))
    1423932            node.put("railway", "station");
    1424           else if ("subway".equals((String)cbStoptype.getSelectedItem()))
     933          else if ("subway".equals(dialog.getStoptype()))
    1425934            node.put("railway", "station");
    1426           else if ("rail".equals((String)cbStoptype.getSelectedItem()))
     935          else if ("rail".equals(dialog.getStoptype()))
    1427936            node.put("railway", "station");
    1428937        }
     
    1438947            node.remove("highway");
    1439948            node.remove("railway");
    1440             if ("bus".equals((String)cbStoptype.getSelectedItem()))
     949            if ("bus".equals(dialog.getStoptype()))
    1441950              node.put("highway", "bus_stop");
    1442             else if ("tram".equals((String)cbStoptype.getSelectedItem()))
     951            else if ("tram".equals(dialog.getStoptype()))
    1443952              node.put("railway", "tram_stop");
    1444             else if ("light_rail".equals((String)cbStoptype.getSelectedItem()))
     953            else if ("light_rail".equals(dialog.getStoptype()))
    1445954              node.put("railway", "station");
    1446             else if ("subway".equals((String)cbStoptype.getSelectedItem()))
     955            else if ("subway".equals(dialog.getStoptype()))
    1447956              node.put("railway", "station");
    1448             else if ("rail".equals((String)cbStoptype.getSelectedItem()))
     957            else if ("rail".equals(dialog.getStoptype()))
    1449958              node.put("railway", "station");
    1450959          }
     
    15251034        waypointTM.addRow(waypoint);
    15261035      }
    1527       waypointTable.setModel(waypointTM);
     1036      dialog.getWaypointsTable().setModel(waypointTM);
    15281037    }
    15291038    else
     
    15371046  }
    15381047 
    1539   private void tracksSelectionChanged()
     1048  public void tracksSelectionChanged(int selectedPos)
    15401049  {
    1541     int selectedPos = tracksList.getAnchorSelectionIndex();
    1542     if (tracksList.isSelectedIndex(selectedPos))
     1050    if (selectedPos >= 0)
    15431051    {
    15441052      currentTrack = ((TrackReference)tracksListModel.elementAt(selectedPos));
    1545       tabbedPane.setEnabledAt(1, true);
    1546       tabbedPane.setEnabledAt(2, true);
     1053      dialog.setTrackValid(true);
    15471054     
    15481055      //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);
    15531059     
    15541060      //Prepare Stoplist
    1555       stoplistTable.setModel
     1061      dialog.getStoplistTable().setModel
    15561062          (((TrackReference)tracksListModel.elementAt(selectedPos)).stoplistTM);
    15571063    }
     
    15591065    {
    15601066      currentTrack = null;
    1561       tabbedPane.setEnabledAt(1, false);
    1562       tabbedPane.setEnabledAt(2, false);
     1067      dialog.setTrackValid(false);
    15631068    }
    15641069  }
     
    15671072  {
    15681073    Node node = new Node(latLon);
    1569     if ("bus".equals((String)cbStoptype.getSelectedItem()))
     1074    if ("bus".equals(dialog.getStoptype()))
    15701075      node.put("highway", "bus_stop");
    1571     else if ("tram".equals((String)cbStoptype.getSelectedItem()))
     1076    else if ("tram".equals(dialog.getStoptype()))
    15721077      node.put("railway", "tram_stop");
    1573     else if ("light_rail".equals((String)cbStoptype.getSelectedItem()))
     1078    else if ("light_rail".equals(dialog.getStoptype()))
    15741079      node.put("railway", "station");
    1575     else if ("subway".equals((String)cbStoptype.getSelectedItem()))
     1080    else if ("subway".equals(dialog.getStoptype()))
    15761081      node.put("railway", "station");
    1577     else if ("rail".equals((String)cbStoptype.getSelectedItem()))
     1082    else if ("rail".equals(dialog.getStoptype()))
    15781083      node.put("railway", "station");
    15791084    node.put("name", name);
     
    15921097  }
    15931098   
    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  
    16091099  private static String timeOf(double t)
    16101100  {
Note: See TracChangeset for help on using the changeset viewer.