Changeset 11496 in osm for applications/editors/josm/plugins/globalsat
- Timestamp:
- 2008-10-26T22:33:38+01:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/globalsat
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatDg100.java
r10378 r11496 3 3 * @author Stefan Kaintoch, Raphael Mack 4 4 * license: GPLv3 or any later version 5 * @version $Id: GlobalSatDg100.java 3 2007-10-30 19:40:04Z ramack $6 5 */ 7 6 package org.openstreetmap.josm.plugins.globalsat; … … 23 22 import org.kaintoch.gps.globalsat.dg100.ByteHelper; 24 23 24 import org.openstreetmap.josm.Main; 25 25 import org.openstreetmap.josm.data.gpx.GpxData; 26 26 import org.openstreetmap.josm.data.gpx.GpxTrack; … … 34 34 public class GlobalsatDg100 35 35 { 36 37 38 39 40 41 42 43 36 public class ConnectionException extends Exception{ 37 ConnectionException(Exception cause){ 38 super(cause); 39 } 40 ConnectionException(String msg){ 41 super(msg); 42 } 43 } 44 44 45 45 public static final int TIMEOUT = 2000; … … 115 115 private CommPortIdentifier portIdentifier; 116 116 private SerialPort port = null; 117 118 private boolean cancelled = false; 117 119 118 120 public GlobalsatDg100(CommPortIdentifier portId){ 119 121 this.portIdentifier = portId; 122 } 123 124 public void cancel(){ 125 cancelled = true; 120 126 } 121 127 … … 126 132 public GpxData readData() throws ConnectionException { 127 133 GpxData result = null; 134 int cnt = 0; 135 cancelled = false; 128 136 if(port == null){ 129 137 connect(); 130 138 } 131 139 Main.pleaseWaitDlg.progress.setValue(0); 140 132 141 List<FileInfoRec> fileInfoList = readFileInfoList(); 133 142 List<GpsRec> gpsRecList = readGpsRecList(fileInfoList); 143 144 Main.pleaseWaitDlg.progress.setMaximum(gpsRecList.size()); 134 145 if(gpsRecList.size() > 0){ 135 146 GpsRec last = null; … … 140 151 trk.trackSegs.add(seg); 141 152 for(GpsRec r:gpsRecList){ 153 if(cancelled){ 154 return result; 155 } 142 156 WayPoint p = wayPointFrom(r); 143 157 if(r.equals(last)){ … … 147 161 } 148 162 last = r; 163 Main.pleaseWaitDlg.progress.setValue(cnt++); 149 164 } 150 165 } … … 243 258 int len = sendCmd(src, response, -1); 244 259 return Response.parseResponse(response, len); 260 } 261 262 public boolean isCancelled(){ 263 return cancelled; 245 264 } 246 265 -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatImportDialog.java
r10378 r11496 5 5 6 6 import java.awt.GridBagLayout; 7 import java.awt.Insets; 8 import java.awt.GridBagConstraints; 7 9 import java.awt.event.ActionListener; 8 10 import java.util.ArrayList; … … 16 18 import javax.swing.JOptionPane; 17 19 import javax.swing.JPanel; 20 import javax.swing.JButton; 18 21 import javax.swing.JTabbedPane; 19 22 import javax.swing.JComboBox; … … 41 44 public class GlobalsatImportDialog extends JPanel { 42 45 43 44 45 46 47 46 // the JOptionPane that contains this dialog. required for the closeDialog() method. 47 private JOptionPane optionPane; 48 private JCheckBox delete; 49 private JComboBox portCombo; 50 private List<CommPortIdentifier> ports = new LinkedList<CommPortIdentifier>(); 48 51 49 public GlobalsatImportDialog() { 50 portCombo = new JComboBox(); 51 portCombo.setRenderer(new ListCellRenderer(){ 52 public java.awt.Component getListCellRendererComponent(JList list, Object o, int x, boolean a, boolean b){ 53 return new JLabel(((CommPortIdentifier)o).getName()); 52 public GlobalsatImportDialog() { 53 GridBagConstraints c = new GridBagConstraints(); 54 JButton refreshBtn, configBtn; 55 56 setLayout(new GridBagLayout()); 57 58 portCombo = new JComboBox(); 59 portCombo.setRenderer(new ListCellRenderer(){ 60 public java.awt.Component getListCellRendererComponent(JList list, Object o, int x, boolean a, boolean b){ 61 String value = ((CommPortIdentifier)o).getName(); 62 if(value == null){ 63 value = "null"; 54 64 } 55 }); 56 portCombo.addActionListener(new ActionListener(){ 57 public void actionPerformed(java.awt.event.ActionEvent e){ 58 Main.pref.put("globalsat.portIdentifier", ((CommPortIdentifier)portCombo.getSelectedItem()).getName()); 65 return new JLabel(value); 66 } 67 }); 68 portCombo.addActionListener(new ActionListener(){ 69 public void actionPerformed(java.awt.event.ActionEvent e){ 70 Object i = portCombo.getSelectedItem(); 71 if(i instanceof CommPortIdentifier){ 72 Main.pref.put("globalsat.portIdentifier", ((CommPortIdentifier)i).getName()); 59 73 } 60 }); 61 refreshPorts(); 62 delete = new JCheckBox(tr("delete data after import")); 63 delete.setSelected(Main.pref.getBoolean("globalsat.deleteAfterDownload", false)); 64 setLayout(new GridBagLayout()); 65 add(portCombo); 66 add(delete); 67 } 74 } 75 }); 76 77 refreshPorts(); 78 c.insets = new Insets(4,4,4,4); 79 c.gridwidth = 1; 80 c.weightx = 0.8; 81 c.fill = GridBagConstraints.HORIZONTAL; 82 c.gridx = 0; 83 c.gridy = 0; 84 add(new JLabel(tr("Port:")), c); 85 86 c.gridwidth = 1; 87 c.gridx = 1; 88 c.gridy = 0; 89 c.weightx = 1.5; 90 add(portCombo, c); 91 92 refreshBtn = new JButton(tr("Refresh")); 93 refreshBtn.addActionListener(new ActionListener(){ 94 public void actionPerformed(java.awt.event.ActionEvent e){ 95 refreshPorts(); 96 } 97 }); 98 refreshBtn.setToolTipText(tr("refresh the port list")); 99 c.gridwidth = 1; 100 c.weightx = 1.0; 101 c.fill = GridBagConstraints.HORIZONTAL; 102 c.gridx = 2; 103 c.gridy = 0; 104 add(refreshBtn, c); 105 106 configBtn = new JButton(tr("Configure")); 107 configBtn.addActionListener(new ActionListener(){ 108 public void actionPerformed(java.awt.event.ActionEvent e){ 109 System.out.println("configureing the device"); 110 } 111 }); 112 configBtn.setToolTipText(tr("configure the connected DG100")); 113 c.gridwidth = 1; 114 c.weightx = 1.0; 115 c.fill = GridBagConstraints.HORIZONTAL; 116 c.gridx = 2; 117 c.gridy = 1; 118 // add(configBtn, c); 119 120 121 delete = new JCheckBox(tr("delete data after import")); 122 delete.setSelected(Main.pref.getBoolean("globalsat.deleteAfterDownload", false)); 123 124 c.gridwidth = 3; 125 c.fill = GridBagConstraints.HORIZONTAL; 126 c.gridx = 0; 127 c.gridy = 2; 128 add(delete, c); 129 } 68 130 69 131 public void refreshPorts(){ 132 String sel = Main.pref.get("globalsat.portIdentifier"); 133 portCombo.setVisible(false); 70 134 portCombo.removeAllItems(); 71 for(Enumeration e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ){ 135 136 Enumeration e = CommPortIdentifier.getPortIdentifiers(); 137 for(e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ){ 72 138 CommPortIdentifier port = (CommPortIdentifier)e.nextElement(); 73 139 if(port.getPortType() == CommPortIdentifier.PORT_SERIAL){ 74 140 portCombo.addItem(port); 141 if(sel != null && port.getName() == sel){ 142 portCombo.setSelectedItem(port); 143 } 75 144 } 76 145 } 77 portCombo.set SelectedItem(Main.pref.get("globalsat.portIdentifier"));146 portCombo.setVisible(true); 78 147 } 79 148 … … 85 154 return (CommPortIdentifier)portCombo.getSelectedItem(); 86 155 } 87 88 89 90 91 92 93 156 /** 157 * Has to be called after this dialog has been added to a JOptionPane. 158 * @param optionPane 159 */ 160 public void setOptionPane(JOptionPane optionPane) { 161 this.optionPane = optionPane; 162 } 94 163 } -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatPlugin.java
r10439 r11496 2 2 /// @author Raphael Mack <ramack@raphael-mack.de> 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.io.IOException; 6 import org.xml.sax.SAXException; 4 7 5 8 import java.util.Enumeration; … … 16 19 import org.openstreetmap.josm.gui.layer.Layer; 17 20 import org.openstreetmap.josm.gui.layer.GpxLayer; 21 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 18 22 import org.openstreetmap.josm.plugins.Plugin; 19 23 import org.openstreetmap.josm.actions.JosmAction; … … 23 27 24 28 public class GlobalsatPlugin extends Plugin { 29 30 private static class ImportTask extends PleaseWaitRunnable { 31 public GpxData data; 32 private GlobalsatDg100 dg100; 33 public Exception eee; 34 private boolean deleteAfter; 35 36 public ImportTask(GlobalsatDg100 dg100, boolean delete){ 37 super(tr("Importing data from device.")); 38 this.dg100 = dg100; 39 deleteAfter = delete; 40 } 41 42 @Override public void realRun() throws IOException, SAXException { 43 Main.pleaseWaitDlg.progress.setValue(0); 44 Main.pleaseWaitDlg.currentAction.setText(tr("Importing data from DG100...")); 45 try{ 46 data = dg100.readData(); 47 }catch(Exception e){ 48 eee = e; 49 } 50 } 51 52 @Override protected void finish() { 53 if(deleteAfter && dg100.isCancelled() == false){ 54 Main.pref.put("globalsat.deleteAfterDownload", true); 55 try{ 56 dg100.deleteData(); 57 }catch(Exception ex){ 58 JOptionPane.showMessageDialog(Main.parent, tr("Error deleting data.") + " " + ex.toString()); 59 } 60 }else{ 61 Main.pref.put("globalsat.deleteAfterDownload", false); 62 } 63 if(data != null && data.hasTrackPoints()){ 64 Main.main.addLayer(new GpxLayer(data, tr("imported data from {0}", "DG 100"))); 65 Main.map.repaint(); 66 }else{ 67 JOptionPane.showMessageDialog(Main.parent, tr("No data found on device.")); 68 } 69 if(eee != null){ 70 eee.printStackTrace(); 71 System.out.println(eee.getMessage()); 72 JOptionPane.showMessageDialog(Main.parent, tr("Connection failed.") + " (" + eee.toString() + ")"); 73 } 74 dg100.disconnect(); 75 } 76 77 @Override protected void cancel() { 78 dg100.cancel(); 79 dg100.disconnect(); 80 } 81 } 82 83 25 84 GlobalsatImportAction importAction; 26 85 public GlobalsatPlugin() { … … 50 109 if(((Integer)pane.getValue()) == JOptionPane.OK_OPTION){ 51 110 GlobalsatDg100 dg100 = new GlobalsatDg100(dialog.getPort()); 52 try{ 53 GpxData data = dg100.readData(); 54 if(dialog.deleteFilesAfterDownload()){ 55 Main.pref.put("globalsat.deleteAfterDownload", true); 56 dg100.deleteData(); 57 }else{ 58 Main.pref.put("globalsat.deleteAfterDownload", false); 59 } 60 if(data != null && data.hasTrackPoints()){ 61 Main.main.addLayer(new GpxLayer(data, tr("imported data from {0}", "DG 100"))); 62 Main.map.repaint(); 63 }else{ 64 JOptionPane.showMessageDialog(Main.parent, tr("No data found on device.")); 65 } 66 }catch(Exception eee){ 67 eee.printStackTrace(); 68 System.out.println(eee.getMessage()); 69 JOptionPane.showMessageDialog(Main.parent, tr("Connection failed.") + " (" + eee.toString() + ")"); 70 }finally{ 71 dg100.disconnect(); 72 } 111 ImportTask task = new ImportTask(dg100, dialog.deleteFilesAfterDownload()); 112 Main.worker.execute(task); 73 113 } 74 114 dlg.dispose();
Note:
See TracChangeset
for help on using the changeset viewer.