source: osm/applications/editors/josm/plugins/public_transport/src/public_transport/StopImporterDialog.java@ 26168

Last change on this file since 26168 was 26168, checked in by stoecker, 13 years ago

fix i18n

File size: 23.8 KB
Line 
1package public_transport;
2
3import static org.openstreetmap.josm.tools.I18n.marktr;
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Container;
7import java.awt.Frame;
8import java.awt.GridBagConstraints;
9import java.awt.GridBagLayout;
10import java.awt.event.ActionEvent;
11import java.io.File;
12import java.io.FileInputStream;
13import java.io.FileNotFoundException;
14import java.io.InputStream;
15import java.io.IOException;
16import java.text.DecimalFormat;
17import java.text.Format;
18import java.util.Collections;
19import java.util.Iterator;
20import java.util.Vector;
21import java.util.zip.GZIPInputStream;
22
23import javax.swing.DefaultCellEditor;
24import javax.swing.DefaultListModel;
25import javax.swing.JButton;
26import javax.swing.JComboBox;
27import javax.swing.JComponent;
28import javax.swing.JDialog;
29import javax.swing.JFileChooser;
30import javax.swing.JLabel;
31import javax.swing.JList;
32import javax.swing.JOptionPane;
33import javax.swing.JPanel;
34import javax.swing.JScrollPane;
35import javax.swing.JTabbedPane;
36import javax.swing.JTable;
37import javax.swing.JTextField;
38import javax.swing.KeyStroke;
39import javax.swing.ListSelectionModel;
40import javax.swing.event.ListSelectionEvent;
41import javax.swing.event.ListSelectionListener;
42import javax.swing.event.TableModelEvent;
43import javax.swing.event.TableModelListener;
44import javax.swing.table.DefaultTableModel;
45
46import org.openstreetmap.josm.Main;
47import org.openstreetmap.josm.actions.JosmAction;
48import org.openstreetmap.josm.command.Command;
49import org.openstreetmap.josm.command.ChangeCommand;
50import org.openstreetmap.josm.command.DeleteCommand;
51import org.openstreetmap.josm.data.coor.LatLon;
52import org.openstreetmap.josm.data.gpx.GpxData;
53import org.openstreetmap.josm.data.gpx.GpxTrack;
54import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
55import org.openstreetmap.josm.data.gpx.WayPoint;
56import org.openstreetmap.josm.data.osm.DataSet;
57import org.openstreetmap.josm.data.osm.Node;
58import org.openstreetmap.josm.data.osm.OsmPrimitive;
59import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
60import org.openstreetmap.josm.io.GpxReader;
61
62import org.xml.sax.SAXException;
63
64public class StopImporterDialog
65{
66 private JDialog jDialog = null;
67 private JTabbedPane tabbedPane = null;
68 private JComboBox cbStoptype = null;
69 private JList tracksList = null;
70 private JTextField tfGPSTimeStart = null;
71 private JTextField tfStopwatchStart = null;
72 private JTextField tfTimeWindow = null;
73 private JTextField tfThreshold = null;
74 private JTable stoplistTable = null;
75 private JTable waypointTable = null;
76
77 private final String[] stoptypes = new String[]{marktr("bus"), marktr("tram"), marktr("light_rail"), marktr("subway"), marktr("rail")};
78
79 public StopImporterDialog(StopImporterAction controller)
80 {
81 Frame frame = JOptionPane.getFrameForComponent(Main.parent);
82 jDialog = new JDialog(frame, tr("Create Stops from GPX"), false);
83 tabbedPane = new JTabbedPane();
84 JPanel tabTracks = new JPanel();
85 tabbedPane.addTab(tr("Tracks"), tabTracks);
86 JPanel tabSettings = new JPanel();
87 tabbedPane.addTab(tr("Settings"), tabSettings);
88 JPanel tabStops = new JPanel();
89 tabbedPane.addTab(tr("Stops"), tabStops);
90 JPanel tabWaypoints = new JPanel();
91 tabbedPane.addTab(tr("Waypoints"), tabWaypoints);
92 tabbedPane.setEnabledAt(0, true);
93 tabbedPane.setEnabledAt(1, true);
94 tabbedPane.setEnabledAt(2, false);
95 tabbedPane.setEnabledAt(3, true);
96 jDialog.add(tabbedPane);
97
98 //Tracks Tab
99 JPanel contentPane = tabTracks;
100 GridBagLayout gridbag = new GridBagLayout();
101 GridBagConstraints layoutCons = new GridBagConstraints();
102 contentPane.setLayout(gridbag);
103
104 JLabel label = new JLabel(tr("Tracks in this GPX file:"));
105
106 layoutCons.gridx = 0;
107 layoutCons.gridy = 0;
108 layoutCons.gridwidth = 3;
109 layoutCons.weightx = 0.0;
110 layoutCons.weighty = 0.0;
111 layoutCons.fill = GridBagConstraints.BOTH;
112 gridbag.setConstraints(label, layoutCons);
113 contentPane.add(label);
114
115 DefaultListModel tracksListModel = controller.getTracksListModel();
116 tracksList = new JList(tracksListModel);
117 JScrollPane rpListSP = new JScrollPane(tracksList);
118 String[] data = {"1", "2", "3", "4", "5", "6"};
119 tracksListModel.copyInto(data);
120 tracksList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
121 tracksList.addListSelectionListener(new TracksLSL(controller));
122
123 layoutCons.gridx = 0;
124 layoutCons.gridy = 1;
125 layoutCons.gridwidth = 3;
126 layoutCons.weightx = 1.0;
127 layoutCons.weighty = 1.0;
128 layoutCons.fill = GridBagConstraints.BOTH;
129 gridbag.setConstraints(rpListSP, layoutCons);
130 contentPane.add(rpListSP);
131
132 //Settings Tab
133 contentPane = tabSettings;
134 gridbag = new GridBagLayout();
135 layoutCons = new GridBagConstraints();
136 contentPane.setLayout(gridbag);
137
138 label = new JLabel(tr("Type of stops to add"));
139
140 layoutCons.gridx = 0;
141 layoutCons.gridy = 0;
142 layoutCons.gridwidth = 2;
143 layoutCons.weightx = 0.0;
144 layoutCons.weighty = 0.0;
145 layoutCons.fill = GridBagConstraints.BOTH;
146 gridbag.setConstraints(label, layoutCons);
147 contentPane.add(label);
148
149 cbStoptype = new JComboBox();
150 cbStoptype.setEditable(false);
151 for(String type : stoptypes)
152 cbStoptype.addItem(new TransText(type));
153 cbStoptype.setActionCommand("stopImporter.settingsStoptype");
154 cbStoptype.addActionListener(controller);
155
156 layoutCons.gridx = 0;
157 layoutCons.gridy = 1;
158 layoutCons.gridwidth = 1;
159 layoutCons.weightx = 0.0;
160 layoutCons.weighty = 0.0;
161 layoutCons.fill = GridBagConstraints.BOTH;
162 gridbag.setConstraints(cbStoptype, layoutCons);
163 contentPane.add(cbStoptype);
164
165 label = new JLabel(tr("Time on your GPS device"));
166
167 layoutCons.gridx = 0;
168 layoutCons.gridy = 2;
169 layoutCons.gridwidth = 2;
170 layoutCons.weightx = 0.0;
171 layoutCons.weighty = 0.0;
172 layoutCons.fill = GridBagConstraints.BOTH;
173 gridbag.setConstraints(label, layoutCons);
174 contentPane.add(label);
175
176 tfGPSTimeStart = new JTextField("00:00:00", 15);
177 tfGPSTimeStart.setActionCommand("stopImporter.settingsGPSTimeStart");
178 tfGPSTimeStart.addActionListener(controller);
179
180 layoutCons.gridx = 0;
181 layoutCons.gridy = 3;
182 layoutCons.gridwidth = 1;
183 layoutCons.weightx = 0.0;
184 layoutCons.weighty = 0.0;
185 layoutCons.fill = GridBagConstraints.BOTH;
186 gridbag.setConstraints(tfGPSTimeStart, layoutCons);
187 contentPane.add(tfGPSTimeStart);
188
189 label = new JLabel(tr("HH:MM:SS.sss"));
190
191 layoutCons.gridx = 1;
192 layoutCons.gridy = 3;
193 layoutCons.gridwidth = 1;
194 layoutCons.weightx = 0.0;
195 layoutCons.weighty = 0.0;
196 layoutCons.fill = GridBagConstraints.BOTH;
197 gridbag.setConstraints(label, layoutCons);
198 contentPane.add(label);
199
200 label = new JLabel(tr("Time on your stopwatch"));
201
202 layoutCons.gridx = 0;
203 layoutCons.gridy = 4;
204 layoutCons.gridwidth = 2;
205 layoutCons.weightx = 0.0;
206 layoutCons.weighty = 0.0;
207 layoutCons.fill = GridBagConstraints.BOTH;
208 gridbag.setConstraints(label, layoutCons);
209 contentPane.add(label);
210
211 tfStopwatchStart = new JTextField("00:00:00", 15);
212 tfStopwatchStart.setActionCommand("stopImporter.settingsStopwatchStart");
213 tfStopwatchStart.addActionListener(controller);
214
215 layoutCons.gridx = 0;
216 layoutCons.gridy = 5;
217 layoutCons.gridwidth = 1;
218 layoutCons.weightx = 0.0;
219 layoutCons.weighty = 0.0;
220 layoutCons.fill = GridBagConstraints.BOTH;
221 gridbag.setConstraints(tfStopwatchStart, layoutCons);
222 contentPane.add(tfStopwatchStart);
223
224 label = new JLabel(tr("HH:MM:SS.sss"));
225
226 layoutCons.gridx = 1;
227 layoutCons.gridy = 5;
228 layoutCons.gridwidth = 1;
229 layoutCons.weightx = 0.0;
230 layoutCons.weighty = 0.0;
231 layoutCons.fill = GridBagConstraints.BOTH;
232 gridbag.setConstraints(label, layoutCons);
233 contentPane.add(label);
234
235 label = new JLabel(tr("Time window"));
236
237 layoutCons.gridx = 0;
238 layoutCons.gridy = 6;
239 layoutCons.gridwidth = 2;
240 layoutCons.weightx = 0.0;
241 layoutCons.weighty = 0.0;
242 layoutCons.fill = GridBagConstraints.BOTH;
243 gridbag.setConstraints(label, layoutCons);
244 contentPane.add(label);
245
246 tfTimeWindow = new JTextField("15", 4);
247 tfTimeWindow.setActionCommand("stopImporter.settingsTimeWindow");
248 tfTimeWindow.addActionListener(controller);
249
250 layoutCons.gridx = 0;
251 layoutCons.gridy = 7;
252 layoutCons.gridwidth = 1;
253 layoutCons.weightx = 0.0;
254 layoutCons.weighty = 0.0;
255 layoutCons.fill = GridBagConstraints.BOTH;
256 gridbag.setConstraints(tfTimeWindow, layoutCons);
257 contentPane.add(tfTimeWindow);
258
259 label = new JLabel(tr("seconds"));
260
261 layoutCons.gridx = 1;
262 layoutCons.gridy = 7;
263 layoutCons.gridwidth = 1;
264 layoutCons.weightx = 0.0;
265 layoutCons.weighty = 0.0;
266 layoutCons.fill = GridBagConstraints.BOTH;
267 gridbag.setConstraints(label, layoutCons);
268 contentPane.add(label);
269
270 label = new JLabel(tr("Move Threshold"));
271
272 layoutCons.gridx = 0;
273 layoutCons.gridy = 8;
274 layoutCons.gridwidth = 2;
275 layoutCons.weightx = 0.0;
276 layoutCons.weighty = 0.0;
277 layoutCons.fill = GridBagConstraints.BOTH;
278 gridbag.setConstraints(label, layoutCons);
279 contentPane.add(label);
280
281 tfThreshold = new JTextField("20", 4);
282 tfThreshold.setActionCommand("stopImporter.settingsThreshold");
283 tfThreshold.addActionListener(controller);
284
285 layoutCons.gridx = 0;
286 layoutCons.gridy = 9;
287 layoutCons.gridwidth = 1;
288 layoutCons.weightx = 0.0;
289 layoutCons.weighty = 0.0;
290 layoutCons.fill = GridBagConstraints.BOTH;
291 gridbag.setConstraints(tfThreshold, layoutCons);
292 contentPane.add(tfThreshold);
293
294 label = new JLabel(tr("meters"));
295
296 layoutCons.gridx = 1;
297 layoutCons.gridy = 9;
298 layoutCons.gridwidth = 1;
299 layoutCons.weightx = 0.0;
300 layoutCons.weighty = 0.0;
301 layoutCons.fill = GridBagConstraints.BOTH;
302 gridbag.setConstraints(label, layoutCons);
303 contentPane.add(label);
304
305 JButton bSuggestStops = new JButton(tr("Suggest Stops"));
306 bSuggestStops.setActionCommand("stopImporter.settingsSuggestStops");
307 bSuggestStops.addActionListener(controller);
308
309 layoutCons.gridx = 0;
310 layoutCons.gridy = 10;
311 layoutCons.gridwidth = 3;
312 layoutCons.weightx = 1.0;
313 layoutCons.weighty = 0.0;
314 layoutCons.fill = GridBagConstraints.BOTH;
315 gridbag.setConstraints(bSuggestStops, layoutCons);
316 contentPane.add(bSuggestStops);
317
318 //Stops Tab
319 contentPane = tabStops;
320 gridbag = new GridBagLayout();
321 layoutCons = new GridBagConstraints();
322 contentPane.setLayout(gridbag);
323 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put
324 (KeyStroke.getKeyStroke("alt N"), "stopImporter.focusName");
325 contentPane.getActionMap().put
326 ("stopImporter.focusName", controller.getFocusTrackStoplistNameAction());
327 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put
328 (KeyStroke.getKeyStroke("alt S"), "stopImporter.focusShelterYes");
329 contentPane.getActionMap().put
330 ("stopImporter.focusShelterYes",
331 controller.getFocusTrackStoplistShelterAction("yes"));
332 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put
333 (KeyStroke.getKeyStroke("alt T"), "stopImporter.focusShelterNo");
334 contentPane.getActionMap().put
335 ("stopImporter.focusShelterNo",
336 controller.getFocusTrackStoplistShelterAction("no"));
337 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put
338 (KeyStroke.getKeyStroke("alt U"), "stopImporter.focusShelterImplicit");
339 contentPane.getActionMap().put
340 ("stopImporter.focusShelterImplicit",
341 controller.getFocusTrackStoplistShelterAction("implicit"));
342 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put
343 (KeyStroke.getKeyStroke("alt D"), "stopImporter.stoplistDelete");
344 contentPane.getActionMap().put
345 ("stopImporter.stoplistDelete",
346 controller.getFocusStoplistDeleteAction());
347
348 stoplistTable = new JTable();
349 JScrollPane tableSP = new JScrollPane(stoplistTable);
350
351 layoutCons.gridx = 0;
352 layoutCons.gridy = 0;
353 layoutCons.gridwidth = 4;
354 layoutCons.weightx = 1.0;
355 layoutCons.weighty = 1.0;
356 layoutCons.fill = GridBagConstraints.BOTH;
357 gridbag.setConstraints(tableSP, layoutCons);
358 contentPane.add(tableSP);
359
360 JButton bFind = new JButton(tr("Find"));
361 bFind.setActionCommand("stopImporter.stoplistFind");
362 bFind.addActionListener(controller);
363
364 layoutCons.gridx = 0;
365 layoutCons.gridy = 1;
366 layoutCons.gridwidth = 1;
367 layoutCons.weightx = 1.0;
368 layoutCons.weighty = 0.0;
369 layoutCons.fill = GridBagConstraints.BOTH;
370 gridbag.setConstraints(bFind, layoutCons);
371 contentPane.add(bFind);
372
373 JButton bShow = new JButton(tr("Show"));
374 bShow.setActionCommand("stopImporter.stoplistShow");
375 bShow.addActionListener(controller);
376
377 layoutCons.gridx = 0;
378 layoutCons.gridy = 2;
379 layoutCons.gridwidth = 1;
380 layoutCons.weightx = 1.0;
381 layoutCons.weighty = 0.0;
382 layoutCons.fill = GridBagConstraints.BOTH;
383 gridbag.setConstraints(bShow, layoutCons);
384 contentPane.add(bShow);
385
386 JButton bMark = new JButton(tr("Mark"));
387 bMark.setActionCommand("stopImporter.stoplistMark");
388 bMark.addActionListener(controller);
389
390 layoutCons.gridx = 1;
391 layoutCons.gridy = 1;
392 layoutCons.gridheight = 1;
393 layoutCons.gridwidth = 1;
394 layoutCons.weightx = 1.0;
395 layoutCons.weighty = 0.0;
396 layoutCons.fill = GridBagConstraints.BOTH;
397 gridbag.setConstraints(bMark, layoutCons);
398 contentPane.add(bMark);
399
400 JButton bDetach = new JButton(tr("Detach"));
401 bDetach.setActionCommand("stopImporter.stoplistDetach");
402 bDetach.addActionListener(controller);
403
404 layoutCons.gridx = 1;
405 layoutCons.gridy = 2;
406 layoutCons.gridheight = 1;
407 layoutCons.gridwidth = 1;
408 layoutCons.weightx = 1.0;
409 layoutCons.weighty = 0.0;
410 layoutCons.fill = GridBagConstraints.BOTH;
411 gridbag.setConstraints(bDetach, layoutCons);
412 contentPane.add(bDetach);
413
414 JButton bAdd = new JButton(tr("Add"));
415 bAdd.setActionCommand("stopImporter.stoplistAdd");
416 bAdd.addActionListener(controller);
417
418 layoutCons.gridx = 2;
419 layoutCons.gridy = 1;
420 layoutCons.gridheight = 1;
421 layoutCons.gridwidth = 1;
422 layoutCons.weightx = 1.0;
423 layoutCons.weighty = 0.0;
424 layoutCons.fill = GridBagConstraints.BOTH;
425 gridbag.setConstraints(bAdd, layoutCons);
426 contentPane.add(bAdd);
427
428 JButton bDelete = new JButton(tr("Delete"));
429 bDelete.setActionCommand("stopImporter.stoplistDelete");
430 bDelete.addActionListener(controller);
431
432 layoutCons.gridx = 2;
433 layoutCons.gridy = 2;
434 layoutCons.gridwidth = 1;
435 layoutCons.weightx = 1.0;
436 layoutCons.weighty = 0.0;
437 layoutCons.fill = GridBagConstraints.BOTH;
438 gridbag.setConstraints(bDelete, layoutCons);
439 contentPane.add(bDelete);
440
441 JButton bSort = new JButton(tr("Sort"));
442 bSort.setActionCommand("stopImporter.stoplistSort");
443 bSort.addActionListener(controller);
444
445 layoutCons.gridx = 3;
446 layoutCons.gridy = 1;
447 layoutCons.gridheight = 2;
448 layoutCons.gridwidth = 1;
449 layoutCons.weightx = 1.0;
450 layoutCons.weighty = 0.0;
451 layoutCons.fill = GridBagConstraints.BOTH;
452 gridbag.setConstraints(bSort, layoutCons);
453 contentPane.add(bSort);
454
455 //Waypoints Tab
456 contentPane = tabWaypoints;
457 gridbag = new GridBagLayout();
458 layoutCons = new GridBagConstraints();
459 contentPane.setLayout(gridbag);
460 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put
461 (KeyStroke.getKeyStroke("alt N"), "stopImporter.focusName");
462 contentPane.getActionMap().put
463 ("stopImporter.focusName", controller.getFocusWaypointNameAction());
464 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put
465 (KeyStroke.getKeyStroke("alt S"), "stopImporter.focusShelterYes");
466 contentPane.getActionMap().put
467 ("stopImporter.focusShelterYes",
468 controller.getFocusWaypointShelterAction("yes"));
469 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put
470 (KeyStroke.getKeyStroke("alt T"), "stopImporter.focusShelterNo");
471 contentPane.getActionMap().put
472 ("stopImporter.focusShelterNo",
473 controller.getFocusWaypointShelterAction("no"));
474 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put
475 (KeyStroke.getKeyStroke("alt U"), "stopImporter.focusShelterImplicit");
476 contentPane.getActionMap().put
477 ("stopImporter.focusShelterImplicit",
478 controller.getFocusWaypointShelterAction("implicit"));
479 contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put
480 (KeyStroke.getKeyStroke("alt D"), "stopImporter.waypointsDelete");
481 contentPane.getActionMap().put
482 ("stopImporter.waypointsDelete",
483 controller.getFocusWaypointDeleteAction());
484
485 waypointTable = new JTable();
486 tableSP = new JScrollPane(waypointTable);
487
488 layoutCons.gridx = 0;
489 layoutCons.gridy = 0;
490 layoutCons.gridwidth = 3;
491 layoutCons.weightx = 1.0;
492 layoutCons.weighty = 1.0;
493 layoutCons.fill = GridBagConstraints.BOTH;
494 gridbag.setConstraints(tableSP, layoutCons);
495 contentPane.add(tableSP);
496
497 bFind = new JButton(tr("Find"));
498 bFind.setActionCommand("stopImporter.waypointsFind");
499 bFind.addActionListener(controller);
500
501 layoutCons.gridx = 0;
502 layoutCons.gridy = 1;
503 layoutCons.gridwidth = 1;
504 layoutCons.weightx = 1.0;
505 layoutCons.weighty = 0.0;
506 layoutCons.fill = GridBagConstraints.BOTH;
507 gridbag.setConstraints(bFind, layoutCons);
508 contentPane.add(bFind);
509
510 bShow = new JButton(tr("Show"));
511 bShow.setActionCommand("stopImporter.waypointsShow");
512 bShow.addActionListener(controller);
513
514 layoutCons.gridx = 0;
515 layoutCons.gridy = 2;
516 layoutCons.gridwidth = 1;
517 layoutCons.weightx = 1.0;
518 layoutCons.weighty = 0.0;
519 layoutCons.fill = GridBagConstraints.BOTH;
520 gridbag.setConstraints(bShow, layoutCons);
521 contentPane.add(bShow);
522
523 bMark = new JButton(tr("Mark"));
524 bMark.setActionCommand("stopImporter.waypointsMark");
525 bMark.addActionListener(controller);
526
527 layoutCons.gridx = 1;
528 layoutCons.gridy = 1;
529 layoutCons.gridheight = 1;
530 layoutCons.gridwidth = 1;
531 layoutCons.weightx = 1.0;
532 layoutCons.weighty = 0.0;
533 layoutCons.fill = GridBagConstraints.BOTH;
534 gridbag.setConstraints(bMark, layoutCons);
535 contentPane.add(bMark);
536
537 bDetach = new JButton(tr("Detach"));
538 bDetach.setActionCommand("stopImporter.waypointsDetach");
539 bDetach.addActionListener(controller);
540
541 layoutCons.gridx = 1;
542 layoutCons.gridy = 2;
543 layoutCons.gridheight = 1;
544 layoutCons.gridwidth = 1;
545 layoutCons.weightx = 1.0;
546 layoutCons.weighty = 0.0;
547 layoutCons.fill = GridBagConstraints.BOTH;
548 gridbag.setConstraints(bDetach, layoutCons);
549 contentPane.add(bDetach);
550
551 bAdd = new JButton(tr("Enable"));
552 bAdd.setActionCommand("stopImporter.waypointsAdd");
553 bAdd.addActionListener(controller);
554
555 layoutCons.gridx = 2;
556 layoutCons.gridy = 1;
557 layoutCons.gridheight = 1;
558 layoutCons.gridwidth = 1;
559 layoutCons.weightx = 1.0;
560 layoutCons.weighty = 0.0;
561 layoutCons.fill = GridBagConstraints.BOTH;
562 gridbag.setConstraints(bAdd, layoutCons);
563 contentPane.add(bAdd);
564
565 bDelete = new JButton(tr("Disable"));
566 bDelete.setActionCommand("stopImporter.waypointsDelete");
567 bDelete.addActionListener(controller);
568
569 layoutCons.gridx = 2;
570 layoutCons.gridy = 2;
571 layoutCons.gridwidth = 1;
572 layoutCons.weightx = 1.0;
573 layoutCons.weighty = 0.0;
574 layoutCons.fill = GridBagConstraints.BOTH;
575 gridbag.setConstraints(bDelete, layoutCons);
576 contentPane.add(bDelete);
577
578 jDialog.pack();
579 jDialog.setLocationRelativeTo(frame);
580 }
581
582 public void setTrackValid(boolean valid)
583 {
584 tabbedPane.setEnabledAt(2, valid);
585 }
586
587 public void setVisible(boolean visible)
588 {
589 jDialog.setVisible(visible);
590 }
591
592 public void setSettings
593 (String gpsSyncTime, String stopwatchStart,
594 double timeWindow, double threshold)
595 {
596 tfGPSTimeStart.setText(gpsSyncTime);
597 tfStopwatchStart.setText(stopwatchStart);
598 tfTimeWindow.setText(Double.toString(timeWindow));
599 tfThreshold.setText(Double.toString(threshold));
600 }
601
602 public String getStoptype()
603 {
604 return ((TransText)cbStoptype.getSelectedItem()).text;
605 }
606
607 public boolean gpsTimeStartValid()
608 {
609 if (parseTime(tfGPSTimeStart.getText()) >= 0)
610 {
611 return true;
612 }
613 else
614 {
615 JOptionPane.showMessageDialog
616 (null, tr("Can't parse a time from this string."), tr("Invalid value"),
617 JOptionPane.ERROR_MESSAGE);
618 return false;
619 }
620 }
621
622 public String getGpsTimeStart()
623 {
624 return tfGPSTimeStart.getText();
625 }
626
627 public void setGpsTimeStart(String s)
628 {
629 tfGPSTimeStart.setText(s);
630 }
631
632 public boolean stopwatchStartValid()
633 {
634 if (parseTime(tfStopwatchStart.getText()) >= 0)
635 {
636 return true;
637 }
638 else
639 {
640 JOptionPane.showMessageDialog
641 (null, tr("Can't parse a time from this string."), tr("Invalid value"),
642 JOptionPane.ERROR_MESSAGE);
643 return false;
644 }
645 }
646
647 public String getStopwatchStart()
648 {
649 return tfStopwatchStart.getText();
650 }
651
652 public void setStopwatchStart(String s)
653 {
654 tfStopwatchStart.setText(s);
655 }
656
657 public double getTimeWindow()
658 {
659 return Double.parseDouble(tfTimeWindow.getText());
660 }
661
662 public double getThreshold()
663 {
664 return Double.parseDouble(tfThreshold.getText());
665 }
666
667 public JTable getStoplistTable()
668 {
669 return stoplistTable;
670 }
671
672 public void setStoplistTableModel(TrackStoplistTableModel model)
673 {
674 stoplistTable.setModel(model);
675 JComboBox comboBox = new JComboBox();
676 comboBox.addItem(new TransText(null));
677 comboBox.addItem(new TransText(marktr("yes")));
678 comboBox.addItem(new TransText(marktr("no")));
679 comboBox.addItem(new TransText(marktr("implicit")));
680 stoplistTable.getColumnModel().getColumn(2)
681 .setCellEditor(new DefaultCellEditor(comboBox));
682 int width = stoplistTable.getPreferredSize().width;
683 stoplistTable.getColumnModel().getColumn(0).setPreferredWidth((int)(width * 0.4));
684 stoplistTable.getColumnModel().getColumn(1).setPreferredWidth((int)(width * 0.5));
685 stoplistTable.getColumnModel().getColumn(2).setPreferredWidth((int)(width * 0.1));
686 }
687
688 public JTable getWaypointsTable()
689 {
690 return waypointTable;
691 }
692
693 public void setWaypointsTableModel(WaypointTableModel model)
694 {
695 waypointTable.setModel(model);
696 JComboBox comboBox = new JComboBox();
697 comboBox.addItem(new TransText(null));
698 comboBox.addItem(new TransText(marktr("yes")));
699 comboBox.addItem(new TransText(marktr("no")));
700 comboBox.addItem(new TransText(marktr("implicit")));
701 waypointTable.getColumnModel().getColumn(2)
702 .setCellEditor(new DefaultCellEditor(comboBox));
703 int width = waypointTable.getPreferredSize().width;
704 waypointTable.getColumnModel().getColumn(0).setPreferredWidth((int)(width * 0.4));
705 waypointTable.getColumnModel().getColumn(1).setPreferredWidth((int)(width * 0.5));
706 waypointTable.getColumnModel().getColumn(2).setPreferredWidth((int)(width * 0.1));
707 }
708
709 public static double parseTime(String s)
710 {
711 double result = 0;
712 if ((s.charAt(2) != ':') || (s.charAt(2) != ':')
713 || (s.length() < 8))
714 return -1;
715 int hour = Integer.parseInt(s.substring(0, 2));
716 int minute = Integer.parseInt(s.substring(3, 5));
717 double second = Double.parseDouble(s.substring(6, s.length()));
718 if ((hour < 0) || (hour > 23) || (minute < 0) || (minute > 59)
719 || (second < 0) || (second >= 60.0))
720 return -1;
721 return (second + minute*60 + hour*60*60);
722 }
723
724 private class TracksLSL implements ListSelectionListener
725 {
726 StopImporterAction root = null;
727
728 public TracksLSL(StopImporterAction sia)
729 {
730 root = sia;
731 }
732
733 public void valueChanged(ListSelectionEvent e)
734 {
735 int selectedPos = tracksList.getAnchorSelectionIndex();
736 if (tracksList.isSelectedIndex(selectedPos))
737 root.tracksSelectionChanged(selectedPos);
738 else
739 root.tracksSelectionChanged(-1);
740 }
741 };
742}
Note: See TracBrowser for help on using the repository browser.