Changeset 30532 in osm for applications/editors/josm/plugins/globalsat/src
- Timestamp:
- 2014-07-14T04:18:06+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/globalsat/src/org
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/globalsat/src/org/kaintoch/gps/globalsat/dg100/Response.java
r29854 r30532 12 12 * 13 13 */ 14 public class Response 14 public class Response<E> 15 15 { 16 16 final static public byte typeFileInfo = (byte)0xBB; … … 23 23 private int nextIdx = 0; 24 24 private Dg100Config config = null; 25 private List data = new ArrayList(100);25 private List<E> data = new ArrayList<>(100); 26 26 private long id = 0; 27 27 … … 35 35 * @param resp 36 36 */ 37 static public Response parseResponse(byte resp[], int len)37 static public Response<?> parseResponse(byte resp[], int len) 38 38 { 39 39 ByteBuffer buf = ByteBuffer.wrap(resp); 40 40 byte respType = buf.get(4); 41 Response response = new Response(respType);42 41 buf.position(5); 43 42 if (respType == typeFileInfo) // file info 44 43 { 44 Response<FileInfoRec> response = new Response<>(respType); 45 45 int cntInfoCur = buf.getShort(); 46 46 int nextIdx = buf.getShort(); … … 52 52 response.addRec(fileInfoRec); 53 53 } 54 return response; 54 55 } 55 56 else if (respType == typeGpsRec) // gps recs 56 57 { 58 Response<GpsRec> response = new Response<>(respType); 57 59 int recType = 2; 58 60 // read part 1 … … 85 87 recType = gpsRec.getDg100TypeOfNextRec(); 86 88 } 89 return response; 87 90 } 88 91 else if (respType == typeConfig) // config 89 92 { 93 Response<?> response = new Response<>(respType); 90 94 Dg100Config config = new Dg100Config(buf); 91 95 response.config = config; 96 return response; 92 97 } 93 98 else if (respType == typeId) // id 94 99 { 100 Response<?> response = new Response<>(respType); 95 101 response.id = 0; 96 102 for (int ii = 0 ; ii < 8 ; ++ii) … … 99 105 response.id = response.id * 10 + digit; 100 106 } 107 return response; 101 108 } 102 109 else 103 110 { 111 return new Response<>(respType); 104 112 } 105 return response;106 113 } 107 114 108 private void addRec( Objectobj)115 private void addRec(E obj) 109 116 { 110 117 data.add(obj); 111 118 } 112 119 113 public List getRecs()120 public List<E> getRecs() 114 121 { 115 122 return data; -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatConfigDialog.java
r29854 r30532 5 5 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 import gnu.io.CommPortIdentifier;8 7 9 8 import java.awt.Dimension; … … 13 12 import java.awt.event.ActionListener; 14 13 import java.awt.event.KeyEvent; 15 import java.util.LinkedList;16 import java.util.List;17 14 18 15 import javax.swing.BoxLayout; 19 16 import javax.swing.ButtonGroup; 20 17 import javax.swing.JCheckBox; 21 import javax.swing.JComboBox;22 18 import javax.swing.JLabel; 23 19 import javax.swing.JOptionPane; … … 28 24 import org.kaintoch.gps.globalsat.dg100.Dg100Config; 29 25 import org.openstreetmap.josm.Main; 30 31 26 32 27 /** … … 55 50 } 56 51 57 58 59 // the JOptionPane that contains this dialog. required for the closeDialog() method.60 private JOptionPane optionPane;61 private JCheckBox delete;62 private JComboBox portCombo;63 52 private JRadioButton formatPosOnly = new JRadioButton(tr("Position only")); 64 53 private JRadioButton formatPosTDS = new JRadioButton(tr("Position, Time, Date, Speed")); … … 79 68 private JTextField cMeters = new IntegerTextField(); 80 69 81 private JLabel memUsage = new JLabel();82 83 70 private JCheckBox disableLogDist, disableLogSpeed; 84 71 private JTextField minLogDist, minLogSpeed; 85 72 86 private List<CommPortIdentifier> ports = new LinkedList<CommPortIdentifier>();87 88 73 private Dg100Config conf; 89 90 74 91 75 public GlobalsatConfigDialog(Dg100Config config) { … … 326 310 327 311 /** 328 * Has to be called after this dialog has been added to a JOptionPane.329 * @param optionPane330 */331 public void setOptionPane(JOptionPane optionPane) {332 this.optionPane = optionPane;333 }334 335 /**336 312 * Get the selected configuration. 337 313 */ -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatDg100.java
r26509 r30532 50 50 51 51 /** delete file: A0 A2 00 02 BC 01 00 BD B0 B3 */ 52 private static byte dg100CmdSwitch2Nmea[] =52 /*private static byte dg100CmdSwitch2Nmea[] = 53 53 { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x18, (byte) 0x81, 54 54 (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x01, … … 58 58 (byte) 0x00, (byte) 0x25, (byte) 0x80, (byte) 0x00, (byte) 0x00, 59 59 (byte) 0xB0, (byte) 0xB3 60 }; 60 };*/ 61 61 /** delete file: A0 A2 00 02 BC 01 00 BD B0 B3 */ 62 private static byte dg100CmdEnterGMouse[] =62 /*private static byte dg100CmdEnterGMouse[] = 63 63 { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x02, (byte) 0xBC 64 64 , (byte) 0x01, (byte) 0x00, (byte) 0xBD, (byte) 0xB0, (byte) 0xB3 65 }; 65 };*/ 66 66 /** delete file: A0 A2 00 03 BA FF FF 02 B8 B0 B3 */ 67 67 private static byte dg100CmdDelFile[] = … … 104 104 }; 105 105 /** read config: A0 A2 00 01 BF 00 BF B0 B3 */ 106 private static byte dg100CmdGetId[] =106 /*private static byte dg100CmdGetId[] = 107 107 { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x01, (byte) 0xBF 108 , (byte) 0x00, (byte) 0xBF, (byte) 0xB0, (byte) 0xB3 }; 108 , (byte) 0x00, (byte) 0xBF, (byte) 0xB0, (byte) 0xB3 };*/ 109 109 /** read config: A0 A2 00 01 BF 00 BF B0 B3 */ 110 private static byte dg100CmdSetId[] =110 /*private static byte dg100CmdSetId[] = 111 111 { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x09, (byte) 0xC0 112 112 , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 113 113 , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 114 , (byte) 0x00, (byte) 0xC0, (byte) 0xB0, (byte) 0xB3}; 114 , (byte) 0x00, (byte) 0xC0, (byte) 0xB0, (byte) 0xB3};*/ 115 115 116 116 private byte[] response = new byte[65536]; … … 187 187 } 188 188 try{ 189 Response response =sendCmdDelFiles();189 sendCmdDelFiles(); 190 190 }catch(Exception e){ 191 191 throw new ConnectionException(e); … … 220 220 try{ 221 221 do{ 222 Response response = sendCmdGetFileInfo(nextIdx);222 Response<FileInfoRec> response = sendCmdGetFileInfo(nextIdx); 223 223 nextIdx = response.getNextIdx(); 224 224 result.addAll(response.getRecs()); … … 232 232 public List<GpsRec> readGpsRecList(List<FileInfoRec> fileInfoList) throws ConnectionException 233 233 { 234 int cnt = 0;235 234 List<GpsRec> result = new ArrayList<GpsRec>(200); 236 235 237 236 try{ 238 237 for(FileInfoRec fileInfoRec:fileInfoList){ 239 cnt++; 240 Response response = sendCmdGetGpsRecs(fileInfoRec.getIdx()); 238 Response<GpsRec> response = sendCmdGetGpsRecs(fileInfoRec.getIdx()); 241 239 result.addAll(response.getRecs()); 242 240 } … … 247 245 } 248 246 249 private Response sendCmdDelFiles() throws IOException, UnsupportedCommOperationException247 private Response<?> sendCmdDelFiles() throws IOException, UnsupportedCommOperationException 250 248 { 251 249 System.out.println("deleting data..."); … … 254 252 } 255 253 256 private Response sendCmdGetFileInfo(int idx) throws IOException, UnsupportedCommOperationException 254 @SuppressWarnings("unchecked") 255 private Response<FileInfoRec> sendCmdGetFileInfo(int idx) throws IOException, UnsupportedCommOperationException 257 256 { 258 257 byte[] src = dg100CmdGetFileInfo; … … 262 261 updateCheckSum(buf); 263 262 int len = sendCmd(src, response, -1); 264 return Response.parseResponse(response, len);265 } 266 267 private Response sendCmdGetConfig() throws IOException, UnsupportedCommOperationException263 return (Response<FileInfoRec>) Response.parseResponse(response, len); 264 } 265 266 private Response<?> sendCmdGetConfig() throws IOException, UnsupportedCommOperationException 268 267 { 269 268 byte[] src = dg100CmdGetConfig; … … 277 276 connect(); 278 277 } 279 Response response = sendCmdGetConfig(); 280 return response.getConfig(); 278 return sendCmdGetConfig().getConfig(); 281 279 }catch(Exception e){ 282 280 throw new ConnectionException(e); 283 281 } 284 282 } 285 286 283 287 284 private void sendCmdSetConfig(Dg100Config config) throws IOException, UnsupportedCommOperationException … … 310 307 } 311 308 312 private Response sendCmdGetGpsRecs(int idx) throws IOException, UnsupportedCommOperationException 309 @SuppressWarnings("unchecked") 310 private Response<GpsRec> sendCmdGetGpsRecs(int idx) throws IOException, UnsupportedCommOperationException 313 311 { 314 312 byte[] src = dg100CmdGetGpsRecs; … … 318 316 updateCheckSum(buf); 319 317 int len = sendCmd(src, response, 2074); 320 return Response.parseResponse(response, len);318 return (Response<GpsRec>) Response.parseResponse(response, len); 321 319 } 322 320 -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatImportDialog.java
r29854 r30532 10 10 import java.awt.event.ActionListener; 11 11 import java.util.Enumeration; 12 import java.util.LinkedList;13 import java.util.List;14 12 15 13 import javax.swing.JButton; … … 33 31 public class GlobalsatImportDialog extends JPanel { 34 32 35 // the JOptionPane that contains this dialog. required for the closeDialog() method.36 private JOptionPane optionPane;37 33 private JCheckBox delete; 38 private JComboBox portCombo; 39 private List<CommPortIdentifier> ports = new LinkedList<CommPortIdentifier>(); 34 private JComboBox<CommPortIdentifier> portCombo; 40 35 41 36 public GlobalsatImportDialog() { … … 45 40 setLayout(new GridBagLayout()); 46 41 47 portCombo = new JComboBox ();48 portCombo.setRenderer(new ListCellRenderer (){49 public java.awt.Component getListCellRendererComponent(JList list, Objecto, int x, boolean a, boolean b){50 String value = ((CommPortIdentifier)o).getName();42 portCombo = new JComboBox<>(); 43 portCombo.setRenderer(new ListCellRenderer<CommPortIdentifier>(){ 44 public java.awt.Component getListCellRendererComponent(JList<? extends CommPortIdentifier> list, CommPortIdentifier o, int x, boolean a, boolean b){ 45 String value = o.getName(); 51 46 if(value == null){ 52 47 value = "null"; … … 103 98 JOptionPane pane = new JOptionPane(dialog, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 104 99 JDialog dlg = pane.createDialog(Main.parent, tr("Configure Device")); 105 dialog.setOptionPane(pane);106 100 dlg.setVisible(true); 107 101 if(((Integer)pane.getValue()) == JOptionPane.OK_OPTION){ … … 140 134 portCombo.removeAllItems(); 141 135 142 Enumeration e = CommPortIdentifier.getPortIdentifiers();136 Enumeration<?> e = CommPortIdentifier.getPortIdentifiers(); 143 137 for(e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ){ 144 138 CommPortIdentifier port = (CommPortIdentifier)e.nextElement(); … … 163 157 return (CommPortIdentifier)portCombo.getSelectedItem(); 164 158 } 165 /**166 * Has to be called after this dialog has been added to a JOptionPane.167 * @param optionPane168 */169 public void setOptionPane(JOptionPane optionPane) {170 this.optionPane = optionPane;171 }172 159 } -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatPlugin.java
r27852 r30532 7 7 import java.awt.event.KeyEvent; 8 8 import java.io.IOException; 9 import java.util.Enumeration;10 9 11 10 import javax.swing.JDialog; … … 86 85 } 87 86 88 89 87 GlobalsatImportAction importAction; 90 88 public GlobalsatPlugin(PluginInformation info) { … … 92 90 boolean error = false; 93 91 try{ 94 Enumeration e =CommPortIdentifier.getPortIdentifiers();92 CommPortIdentifier.getPortIdentifiers(); 95 93 }catch(java.lang.UnsatisfiedLinkError e){ 96 94 error = true; … … 114 112 JOptionPane pane = new JOptionPane(dialog, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 115 113 JDialog dlg = pane.createDialog(Main.parent, tr("Import")); 116 dialog.setOptionPane(pane);117 114 dlg.setVisible(true); 118 115 if(((Integer)pane.getValue()) == JOptionPane.OK_OPTION){
Note:
See TracChangeset
for help on using the changeset viewer.