Changeset 31995 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-01-17T16:05:35+01:00 (9 years ago)
Author:
donvip
Message:

[josm_public_transport] reduce code duplication

Location:
applications/editors/josm/plugins/public_transport
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/public_transport/.project

    r29661 r31995  
    1111                        </arguments>
    1212                </buildCommand>
     13                <buildCommand>
     14                        <name>org.sonarlint.eclipse.core.sonarlintBuilder</name>
     15                        <arguments>
     16                        </arguments>
     17                </buildCommand>
    1318        </buildSpec>
    1419        <natures>
     20                <nature>org.sonarlint.eclipse.core.sonarlintNature</nature>
    1521                <nature>org.eclipse.jdt.core.javanature</nature>
    1622        </natures>
  • applications/editors/josm/plugins/public_transport/src/public_transport/GTFSImporterDialog.java

    r30532 r31995  
    11package public_transport;
    22
    3 import static org.openstreetmap.josm.tools.I18n.marktr;
    43import static org.openstreetmap.josm.tools.I18n.tr;
    54
    6 import java.awt.Frame;
    75import java.awt.GridBagConstraints;
    86import java.awt.GridBagLayout;
    97
    108import javax.swing.JButton;
    11 import javax.swing.JComboBox;
    129import javax.swing.JComponent;
    13 import javax.swing.JDialog;
    1410import javax.swing.JLabel;
    15 import javax.swing.JList;
    16 import javax.swing.JOptionPane;
    1711import javax.swing.JPanel;
    1812import javax.swing.JScrollPane;
    19 import javax.swing.JTabbedPane;
    2013import javax.swing.JTable;
    21 import javax.swing.JTextField;
    2214import javax.swing.KeyStroke;
    2315
    24 import org.openstreetmap.josm.Main;
    25 
    26 public class GTFSImporterDialog
     16public class GTFSImporterDialog extends AbstractImporterDialog<GTFSImporterAction>
    2717{
    28   private JDialog jDialog = null;
    29   private JTabbedPane tabbedPane = null;
    30   private JComboBox<TransText> cbStoptype = null;
    31   private JList tracksList = null;
    32   private JTextField tfGPSTimeStart = null;
    33   private JTextField tfStopwatchStart = null;
    34   private JTextField tfTimeWindow = null;
    35   private JTextField tfThreshold = null;
    36   private JTable stoplistTable = null;
    3718  private JTable gtfsStopTable = null;
    38   private final String[] stoptypes = new String[]{marktr("bus"), marktr("tram"), marktr("light_rail"), marktr("subway"), marktr("rail")};
    3919
    4020  public GTFSImporterDialog(GTFSImporterAction controller)
    4121  {
    42     Frame frame = JOptionPane.getFrameForComponent(Main.parent);
    43     jDialog = new JDialog(frame, tr("Create Stops from GTFS"), false);
    44     tabbedPane = new JTabbedPane();
     22      super(controller, tr("Create Stops from GTFS"), "gtfsImporter");
     23  }
     24 
     25  @Override
     26  protected void initDialog(GTFSImporterAction controller) {
    4527    JPanel tabSettings = new JPanel();
    4628    tabbedPane.addTab(tr("Settings"), tabSettings);
     
    4931    tabbedPane.setEnabledAt(0, false);
    5032    tabbedPane.setEnabledAt(1, true);
    51     jDialog.add(tabbedPane);
    5233
    5334    //Settings Tab
     
    6849    contentPane.add(label);
    6950
    70     cbStoptype = new JComboBox<>();
    71     cbStoptype.setEditable(false);
    72     for(String type : stoptypes)
    73         cbStoptype.addItem(new TransText(type));
    74     cbStoptype.setActionCommand("gtfsImporter.settingsStoptype");
    75     cbStoptype.addActionListener(controller);
    76 
    7751    layoutCons.gridx = 0;
    7852    layoutCons.gridy = 1;
     
    9569    contentPane.add(label);
    9670
    97     tfGPSTimeStart = new JTextField("00:00:00", 15);
    98     tfGPSTimeStart.setActionCommand("gtfsImporter.settingsGPSTimeStart");
    99     tfGPSTimeStart.addActionListener(controller);
    100 
    10171    layoutCons.gridx = 0;
    10272    layoutCons.gridy = 3;
     
    131101    contentPane.add(label);
    132102
    133     tfStopwatchStart = new JTextField("00:00:00", 15);
    134     tfStopwatchStart.setActionCommand("gtfsImporter.settingsStopwatchStart");
    135     tfStopwatchStart.addActionListener(controller);
    136 
    137103    layoutCons.gridx = 0;
    138104    layoutCons.gridy = 5;
     
    167133    contentPane.add(label);
    168134
    169     tfTimeWindow = new JTextField("15", 4);
    170     tfTimeWindow.setActionCommand("gtfsImporter.settingsTimeWindow");
    171     tfTimeWindow.addActionListener(controller);
    172 
    173135    layoutCons.gridx = 0;
    174136    layoutCons.gridy = 7;
     
    201163    gridbag.setConstraints(label, layoutCons);
    202164    contentPane.add(label);
    203 
    204     tfThreshold = new JTextField("20", 4);
    205     tfThreshold.setActionCommand("gtfsImporter.settingsThreshold");
    206     tfThreshold.addActionListener(controller);
    207165
    208166    layoutCons.gridx = 0;
     
    375333    gridbag.setConstraints(bDelete, layoutCons);
    376334    contentPane.add(bDelete);
    377 
    378     jDialog.pack();
    379     jDialog.setLocationRelativeTo(frame);
    380   }
    381 
    382   public void setTrackValid(boolean valid)
    383   {
    384     tabbedPane.setEnabledAt(2, valid);
    385   }
    386 
    387   public void setVisible(boolean visible)
    388   {
    389     jDialog.setVisible(visible);
    390   }
    391 
    392   public void setSettings
    393       (String gpsSyncTime, String stopwatchStart,
    394        double timeWindow, double threshold)
    395   {
    396     tfGPSTimeStart.setText(gpsSyncTime);
    397     tfStopwatchStart.setText(stopwatchStart);
    398     tfTimeWindow.setText(Double.toString(timeWindow));
    399     tfThreshold.setText(Double.toString(threshold));
    400   }
    401 
    402   public String getStoptype()
    403   {
    404     return ((TransText)cbStoptype.getSelectedItem()).text;
    405   }
    406 
    407   public boolean gpsTimeStartValid()
    408   {
    409     if (parseTime(tfGPSTimeStart.getText()) >= 0)
    410     {
    411       return true;
    412     }
    413     else
    414     {
    415       JOptionPane.showMessageDialog
    416       (null, tr("Can''t parse a time from this string."), tr("Invalid value"),
    417        JOptionPane.ERROR_MESSAGE);
    418       return false;
    419     }
    420   }
    421 
    422   public String getGpsTimeStart()
    423   {
    424     return tfGPSTimeStart.getText();
    425   }
    426 
    427   public void setGpsTimeStart(String s)
    428   {
    429     tfGPSTimeStart.setText(s);
    430   }
    431 
    432   public boolean stopwatchStartValid()
    433   {
    434     if (parseTime(tfStopwatchStart.getText()) >= 0)
    435     {
    436       return true;
    437     }
    438     else
    439     {
    440       JOptionPane.showMessageDialog
    441       (null, tr("Can''t parse a time from this string."), tr("Invalid value"),
    442        JOptionPane.ERROR_MESSAGE);
    443       return false;
    444     }
    445   }
    446 
    447   public String getStopwatchStart()
    448   {
    449     return tfStopwatchStart.getText();
    450   }
    451 
    452   public void setStopwatchStart(String s)
    453   {
    454     tfStopwatchStart.setText(s);
    455   }
    456 
    457   public double getTimeWindow()
    458   {
    459     return Double.parseDouble(tfTimeWindow.getText());
    460   }
    461 
    462   public double getThreshold()
    463   {
    464     return Double.parseDouble(tfThreshold.getText());
    465335  }
    466336
     
    477347    gtfsStopTable.getColumnModel().getColumn(1).setPreferredWidth((int)(width * 0.6));
    478348    gtfsStopTable.getColumnModel().getColumn(2).setPreferredWidth((int)(width * 0.1));
    479   }
    480 
    481   public static double parseTime(String s)
    482   {
    483     if ((s.charAt(2) != ':') || (s.charAt(2) != ':')
    484      || (s.length() < 8))
    485       return -1;
    486     int hour = Integer.parseInt(s.substring(0, 2));
    487     int minute = Integer.parseInt(s.substring(3, 5));
    488     double second = Double.parseDouble(s.substring(6, s.length()));
    489     if ((hour < 0) || (hour > 23) || (minute < 0) || (minute > 59)
    490      || (second < 0) || (second >= 60.0))
    491       return -1;
    492     return (second + minute*60 + hour*60*60);
    493349  }
    494350
  • applications/editors/josm/plugins/public_transport/src/public_transport/StopImporterDialog.java

    r30532 r31995  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.Frame;
    76import java.awt.GridBagConstraints;
    87import java.awt.GridBagLayout;
     
    1312import javax.swing.JComboBox;
    1413import javax.swing.JComponent;
    15 import javax.swing.JDialog;
    1614import javax.swing.JLabel;
    1715import javax.swing.JList;
    18 import javax.swing.JOptionPane;
    1916import javax.swing.JPanel;
    2017import javax.swing.JScrollPane;
    21 import javax.swing.JTabbedPane;
    2218import javax.swing.JTable;
    23 import javax.swing.JTextField;
    2419import javax.swing.KeyStroke;
    2520import javax.swing.ListSelectionModel;
     
    2722import javax.swing.event.ListSelectionListener;
    2823
    29 import org.openstreetmap.josm.Main;
    30 
    31 public class StopImporterDialog
     24public class StopImporterDialog extends AbstractImporterDialog<StopImporterAction>
    3225{
    33   private JDialog jDialog = null;
    34   private JTabbedPane tabbedPane = null;
    35   private JComboBox<TransText> cbStoptype = null;
    3626  private JList<TrackReference> tracksList = null;
    37   private JTextField tfGPSTimeStart = null;
    38   private JTextField tfStopwatchStart = null;
    39   private JTextField tfTimeWindow = null;
    40   private JTextField tfThreshold = null;
    4127  private JTable stoplistTable = null;
    4228  private JTable waypointTable = null;
    4329
    44   private final String[] stoptypes = new String[]{marktr("bus"), marktr("tram"), marktr("light_rail"), marktr("subway"), marktr("rail")};
    45 
    4630  public StopImporterDialog(StopImporterAction controller)
    4731  {
    48     Frame frame = JOptionPane.getFrameForComponent(Main.parent);
    49     jDialog = new JDialog(frame, tr("Create Stops from GPX"), false);
    50     tabbedPane = new JTabbedPane();
     32      super(controller, tr("Create Stops from GPX"), "stopImporter");
     33  }
     34 
     35  @Override
     36  protected void initDialog(StopImporterAction controller) {
    5137    JPanel tabTracks = new JPanel();
    5238    tabbedPane.addTab(tr("Tracks"), tabTracks);
     
    6147    tabbedPane.setEnabledAt(2, false);
    6248    tabbedPane.setEnabledAt(3, true);
    63     jDialog.add(tabbedPane);
    6449
    6550    //Tracks Tab
     
    11499    contentPane.add(label);
    115100
    116     cbStoptype = new JComboBox<>();
    117     cbStoptype.setEditable(false);
    118     for(String type : stoptypes)
    119         cbStoptype.addItem(new TransText(type));
    120     cbStoptype.setActionCommand("stopImporter.settingsStoptype");
    121     cbStoptype.addActionListener(controller);
    122 
    123101    layoutCons.gridx = 0;
    124102    layoutCons.gridy = 1;
     
    141119    contentPane.add(label);
    142120
    143     tfGPSTimeStart = new JTextField("00:00:00", 15);
    144     tfGPSTimeStart.setActionCommand("stopImporter.settingsGPSTimeStart");
    145     tfGPSTimeStart.addActionListener(controller);
    146 
    147121    layoutCons.gridx = 0;
    148122    layoutCons.gridy = 3;
     
    176150    contentPane.add(label);
    177151
    178     tfStopwatchStart = new JTextField("00:00:00", 15);
    179     tfStopwatchStart.setActionCommand("stopImporter.settingsStopwatchStart");
    180     tfStopwatchStart.addActionListener(controller);
    181 
    182152    layoutCons.gridx = 0;
    183153    layoutCons.gridy = 5;
     
    211181    contentPane.add(label);
    212182
    213     tfTimeWindow = new JTextField("15", 4);
    214     tfTimeWindow.setActionCommand("stopImporter.settingsTimeWindow");
    215     tfTimeWindow.addActionListener(controller);
    216 
    217183    layoutCons.gridx = 0;
    218184    layoutCons.gridy = 7;
     
    245211    gridbag.setConstraints(label, layoutCons);
    246212    contentPane.add(label);
    247 
    248     tfThreshold = new JTextField("20", 4);
    249     tfThreshold.setActionCommand("stopImporter.settingsThreshold");
    250     tfThreshold.addActionListener(controller);
    251213
    252214    layoutCons.gridx = 0;
     
    542504    gridbag.setConstraints(bDelete, layoutCons);
    543505    contentPane.add(bDelete);
    544 
    545     jDialog.pack();
    546     jDialog.setLocationRelativeTo(frame);
    547   }
    548 
    549   public void setTrackValid(boolean valid)
    550   {
    551     tabbedPane.setEnabledAt(2, valid);
    552   }
    553 
    554   public void setVisible(boolean visible)
    555   {
    556     jDialog.setVisible(visible);
    557   }
    558 
    559   public void setSettings
    560       (String gpsSyncTime, String stopwatchStart,
    561        double timeWindow, double threshold)
    562   {
    563     tfGPSTimeStart.setText(gpsSyncTime);
    564     tfStopwatchStart.setText(stopwatchStart);
    565     tfTimeWindow.setText(Double.toString(timeWindow));
    566     tfThreshold.setText(Double.toString(threshold));
    567   }
    568 
    569   public String getStoptype()
    570   {
    571     return ((TransText)cbStoptype.getSelectedItem()).text;
    572   }
    573 
    574   public boolean gpsTimeStartValid()
    575   {
    576     if (parseTime(tfGPSTimeStart.getText()) >= 0)
    577     {
    578       return true;
    579     }
    580     else
    581     {
    582       JOptionPane.showMessageDialog
    583       (null, tr("Can''t parse a time from this string."), tr("Invalid value"),
    584        JOptionPane.ERROR_MESSAGE);
    585       return false;
    586     }
    587   }
    588 
    589   public String getGpsTimeStart()
    590   {
    591     return tfGPSTimeStart.getText();
    592   }
    593 
    594   public void setGpsTimeStart(String s)
    595   {
    596     tfGPSTimeStart.setText(s);
    597   }
    598 
    599   public boolean stopwatchStartValid()
    600   {
    601     if (parseTime(tfStopwatchStart.getText()) >= 0)
    602     {
    603       return true;
    604     }
    605     else
    606     {
    607       JOptionPane.showMessageDialog
    608       (null, tr("Can''t parse a time from this string."), tr("Invalid value"),
    609        JOptionPane.ERROR_MESSAGE);
    610       return false;
    611     }
    612   }
    613 
    614   public String getStopwatchStart()
    615   {
    616     return tfStopwatchStart.getText();
    617   }
    618 
    619   public void setStopwatchStart(String s)
    620   {
    621     tfStopwatchStart.setText(s);
    622   }
    623 
    624   public double getTimeWindow()
    625   {
    626     return Double.parseDouble(tfTimeWindow.getText());
    627   }
    628 
    629   public double getThreshold()
    630   {
    631     return Double.parseDouble(tfThreshold.getText());
    632506  }
    633507
     
    674548  }
    675549
    676   public static double parseTime(String s)
    677   {
    678     if ((s.charAt(2) != ':') || (s.charAt(2) != ':')
    679      || (s.length() < 8))
    680       return -1;
    681     int hour = Integer.parseInt(s.substring(0, 2));
    682     int minute = Integer.parseInt(s.substring(3, 5));
    683     double second = Double.parseDouble(s.substring(6, s.length()));
    684     if ((hour < 0) || (hour > 23) || (minute < 0) || (minute > 59)
    685      || (second < 0) || (second >= 60.0))
    686       return -1;
    687     return (second + minute*60 + hour*60*60);
    688   }
    689 
    690550  private class TracksLSL implements ListSelectionListener
    691551  {
     
    697557    }
    698558
     559    @Override
    699560    public void valueChanged(ListSelectionEvent e)
    700561    {
Note: See TracChangeset for help on using the changeset viewer.