Changeset 32649 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-07-13T08:41:57+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/globalsat
Files:
2 added
6 edited

Legend:

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

    r32286 r32649  
    1616                        </arguments>
    1717                </buildCommand>
     18                <buildCommand>
     19                        <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
     20                        <arguments>
     21                        </arguments>
     22                </buildCommand>
    1823        </buildSpec>
    1924        <natures>
    2025                <nature>org.eclipse.jdt.core.javanature</nature>
     26                <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
    2127        </natures>
    2228</projectDescription>
  • applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatConfigDialog.java

    r30532 r32649  
    1 // License: GPL v2 or later (v3 preferred). Copyright 2008 by Raphael Mack
     1// License: GPL. For details, see LICENSE file.
    22
    33//TODO: check input for numbers in text fields
     
    2828 * Configuration download dialog.
    2929 *
    30  * @author Raphael Mack <ramack@raphael-mack.de>
    31  *
     30 * @author Raphael Mack &lt;ramack@raphael-mack.de&gt;
    3231 */
    3332public class GlobalsatConfigDialog extends JPanel {
    3433
    35 
    3634    public class IntegerTextField extends JTextField {
    3735
    38         final static String badchars = "-`~!@#$%^&*()_+=\\|\"':;?/>.<, ";
    39 
     36        static final String badchars = "-`~!@#$%^&*()_+=\\|\"':;?/>.<, ";
     37
     38        @Override
    4039        public void processKeyEvent(KeyEvent ev) {
    4140
    4241            char c = ev.getKeyChar();
    43             if((Character.isLetter(c) && !ev.isAltDown())
     42            if ((Character.isLetter(c) && !ev.isAltDown())
    4443               || badchars.indexOf(c) > -1) {
    4544                ev.consume();
     
    7978
    8079        Dimension xx = aSeconds.getPreferredSize();
    81         aSeconds.setPreferredSize(new Dimension((int)xx.getWidth() + 50, (int)xx.getHeight()));
     80        aSeconds.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight()));
    8281        aSeconds.setHorizontalAlignment(JTextField.RIGHT);
    83         aMeters.setPreferredSize(new Dimension((int)xx.getWidth() + 50, (int)xx.getHeight()));
     82        aMeters.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight()));
    8483        aMeters.setHorizontalAlignment(JTextField.RIGHT);
    85         bSeconds.setPreferredSize(new Dimension((int)xx.getWidth() + 50, (int)xx.getHeight()));
     84        bSeconds.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight()));
    8685        bSeconds.setHorizontalAlignment(JTextField.RIGHT);
    87         bMeters.setPreferredSize(new Dimension((int)xx.getWidth() + 50, (int)xx.getHeight()));
     86        bMeters.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight()));
    8887        bMeters.setHorizontalAlignment(JTextField.RIGHT);
    89         cSeconds.setPreferredSize(new Dimension((int)xx.getWidth() + 50, (int)xx.getHeight()));
     88        cSeconds.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight()));
    9089        cSeconds.setHorizontalAlignment(JTextField.RIGHT);
    91         cMeters.setPreferredSize(new Dimension((int)xx.getWidth() + 50, (int)xx.getHeight()));
     90        cMeters.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight()));
    9291        cMeters.setHorizontalAlignment(JTextField.RIGHT);
    9392
     
    106105        logPanel.add(formatPosTDSA);
    107106
    108         c.insets = new Insets(4,4,0,4);
     107        c.insets = new Insets(4, 4, 0, 4);
    109108        c.gridwidth = 1;
    110109        c.weightx = 1.8;
     
    116115
    117116        disableLogSpeed = new JCheckBox(tr("Disable data logging if speed falls below"));
    118         c.insets = new Insets(4,4,0,4);
     117        c.insets = new Insets(4, 4, 0, 4);
    119118        c.gridwidth = 1;
    120119        c.weightx = 0.8;
     
    127126        minLogSpeed = new IntegerTextField();
    128127        minLogSpeed.setHorizontalAlignment(JTextField.RIGHT);
    129         c.insets = new Insets(4,4,0,4);
     128        c.insets = new Insets(4, 4, 0, 4);
    130129        c.gridwidth = 1;
    131130        c.weightx = 1.5;
     
    135134        add(minLogSpeed, c);
    136135
    137         disableLogSpeed.addActionListener(new ActionListener(){
    138                 public void actionPerformed(java.awt.event.ActionEvent e){
     136        disableLogSpeed.addActionListener(new ActionListener() {
     137                @Override
     138                public void actionPerformed(java.awt.event.ActionEvent e) {
    139139                    minLogSpeed.setEnabled(disableLogSpeed.isSelected());
    140140                }
     
    142142
    143143        disableLogDist = new JCheckBox(tr("Disable data logging if distance falls below"));
    144         c.insets = new Insets(0,4,4,4);
     144        c.insets = new Insets(0, 4, 4, 4);
    145145        c.gridwidth = 1;
    146146        c.weightx = 0.8;
     
    152152        minLogDist = new IntegerTextField();
    153153        minLogDist.setHorizontalAlignment(JTextField.RIGHT);
    154         c.insets = new Insets(0,4,4,4);
     154        c.insets = new Insets(0, 4, 4, 4);
    155155        c.gridwidth = 1;
    156156        c.weightx = 1.5;
     
    160160        add(minLogDist, c);
    161161        Dimension x = minLogDist.getPreferredSize();
    162         minLogDist.setPreferredSize(new Dimension((int)x.getWidth() + 50, (int)x.getHeight()));
    163 
    164         disableLogDist.addActionListener(new ActionListener(){
    165                 public void actionPerformed(java.awt.event.ActionEvent e){
     162        minLogDist.setPreferredSize(new Dimension((int) x.getWidth() + 50, (int) x.getHeight()));
     163
     164        disableLogDist.addActionListener(new ActionListener() {
     165                @Override
     166                public void actionPerformed(java.awt.event.ActionEvent e) {
    166167                    minLogDist.setEnabled(disableLogDist.isSelected());
    167168                }
     
    180181        group.add(aDist);
    181182
    182         c.insets = new Insets(4,4,0,4);
     183        c.insets = new Insets(4, 4, 0, 4);
    183184        c.gridwidth = 1;
    184185        c.weightx = 1;
     
    187188        c.gridy = 3;
    188189        add(aTime, c);
    189         c.insets = new Insets(0,4,4,4);
     190        c.insets = new Insets(0, 4, 4, 4);
    190191        c.gridy = 4;
    191192        add(aDist, c);
    192193
    193         c.insets = new Insets(4,4,0,4);
     194        c.insets = new Insets(4, 4, 0, 4);
    194195        c.gridwidth = 1;
    195196        c.weightx = 1;
     
    198199        c.gridy = 3;
    199200        add(aSeconds, c);
    200         c.insets = new Insets(0,4,4,4);
     201        c.insets = new Insets(0, 4, 4, 4);
    201202        c.gridy = 4;
    202203        add(aMeters, c);
     
    206207        group.add(bDist);
    207208
    208         c.insets = new Insets(4,4,0,4);
     209        c.insets = new Insets(4, 4, 0, 4);
    209210        c.gridwidth = 1;
    210211        c.weightx = 1;
     
    213214        c.gridy = 5;
    214215        add(bTime, c);
    215         c.insets = new Insets(0,4,4,4);
     216        c.insets = new Insets(0, 4, 4, 4);
    216217        c.gridy = 6;
    217218        add(bDist, c);
    218219
    219         c.insets = new Insets(4,4,0,4);
     220        c.insets = new Insets(4, 4, 0, 4);
    220221        c.gridwidth = 1;
    221222        c.weightx = 1;
     
    224225        c.gridy = 5;
    225226        add(bSeconds, c);
    226         c.insets = new Insets(0,4,4,4);
     227        c.insets = new Insets(0, 4, 4, 4);
    227228        c.gridy = 6;
    228229        add(bMeters, c);
     
    232233        group.add(cDist);
    233234
    234         c.insets = new Insets(4,4,0,4);
     235        c.insets = new Insets(4, 4, 0, 4);
    235236        c.gridwidth = 1;
    236237        c.weightx = 1;
     
    239240        c.gridy = 7;
    240241        add(cTime, c);
    241         c.insets = new Insets(0,4,4,4);
     242        c.insets = new Insets(0, 4, 4, 4);
    242243        c.gridy = 8;
    243244        add(cDist, c);
    244245
    245         c.insets = new Insets(4,4,0,4);
     246        c.insets = new Insets(4, 4, 0, 4);
    246247        c.gridwidth = 1;
    247248        c.weightx = 1;
     
    250251        c.gridy = 7;
    251252        add(cSeconds, c);
    252         c.insets = new Insets(0,4,4,4);
     253        c.insets = new Insets(0, 4, 4, 4);
    253254        c.gridy = 8;
    254255        add(cMeters, c);
     
    258259        //add ID textbox
    259260
    260 
    261 
    262         switch(conf.getLogFormat()){
     261        switch(conf.getLogFormat()) {
    263262        case 0:
    264263            formatPosOnly.setSelected(true);
     
    274273        }
    275274
    276         if(conf.getSwATimeOrDist() == 0){
     275        if (conf.getSwATimeOrDist() == 0) {
    277276            aTime.setSelected(true);
    278277            aDist.setSelected(false);
    279         }else{
     278        } else {
    280279            aTime.setSelected(false);
    281280            aDist.setSelected(true);
    282281        }
    283282
    284         if(conf.getSwBTimeOrDist() == 0){
     283        if (conf.getSwBTimeOrDist() == 0) {
    285284            bTime.setSelected(true);
    286285            bDist.setSelected(false);
    287         }else{
     286        } else {
    288287            bTime.setSelected(false);
    289288            bDist.setSelected(true);
    290289        }
    291290
    292         if(conf.getSwCTimeOrDist() == 0){
     291        if (conf.getSwCTimeOrDist() == 0) {
    293292            cTime.setSelected(true);
    294293            cDist.setSelected(false);
    295         }else{
     294        } else {
    296295            cTime.setSelected(false);
    297296            cDist.setSelected(true);
     
    306305        cSeconds.setText("" + conf.getSwCTime() / 1000);
    307306        cMeters.setText("" + conf.getSwCDist());
    308 
    309307    }
    310308
     
    312310     * Get the selected configuration.
    313311     */
    314     public Dg100Config getConfig(){
     312    public Dg100Config getConfig() {
    315313        conf.setDisableLogDist(disableLogDist.isSelected());
    316314        conf.setDisableLogSpeed(disableLogSpeed.isSelected());
     
    318316        conf.setSpeedThres(Integer.parseInt(minLogSpeed.getText()));
    319317
    320         if(formatPosOnly.isSelected()){
    321             conf.setLogFormat((byte)0);
    322         }else if(formatPosTDS.isSelected()){
    323             conf.setLogFormat((byte)1);
    324         }else if(formatPosTDSA.isSelected()){
    325             conf.setLogFormat((byte)2);
    326         }
    327 
    328         conf.setSwATimeOrDist((byte)(aDist.isSelected() ? 1 : 0));
    329         conf.setSwBTimeOrDist((byte)(bDist.isSelected() ? 1 : 0));
    330         conf.setSwCTimeOrDist((byte)(cDist.isSelected() ? 1 : 0));
     318        if (formatPosOnly.isSelected()) {
     319            conf.setLogFormat((byte) 0);
     320        } else if (formatPosTDS.isSelected()) {
     321            conf.setLogFormat((byte) 1);
     322        } else if (formatPosTDSA.isSelected()) {
     323            conf.setLogFormat((byte) 2);
     324        }
     325
     326        conf.setSwATimeOrDist((byte) (aDist.isSelected() ? 1 : 0));
     327        conf.setSwBTimeOrDist((byte) (bDist.isSelected() ? 1 : 0));
     328        conf.setSwCTimeOrDist((byte) (cDist.isSelected() ? 1 : 0));
    331329
    332330        conf.setSwATime(Integer.parseInt(aSeconds.getText()) * 1000);
  • applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatDg100.java

    r30737 r32649  
     1// License: GPL. For details, see LICENSE file.
    12/**
    23 * Communicate with a GlobalSat DG-100 GPS mouse and data logger.
     
    56 */
    67package org.openstreetmap.josm.plugins.globalsat;
    7 
    8 import gnu.io.CommPortIdentifier;
    9 import gnu.io.PortInUseException;
    10 import gnu.io.SerialPort;
    11 import gnu.io.UnsupportedCommOperationException;
    128
    139import java.io.IOException;
     
    3127import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    3228
     29import gnu.io.CommPortIdentifier;
     30import gnu.io.PortInUseException;
     31import gnu.io.SerialPort;
     32import gnu.io.UnsupportedCommOperationException;
     33
    3334/**
    3435 * @author ramack
    3536 *
    3637 */
    37 public class GlobalsatDg100
    38 {
    39     public class ConnectionException extends Exception{
    40         ConnectionException(Exception cause){
     38public class GlobalsatDg100 {
     39
     40    public class ConnectionException extends Exception {
     41        ConnectionException(Exception cause) {
    4142            super(cause);
    4243        }
    43         ConnectionException(String msg){
     44
     45        ConnectionException(String msg) {
    4446            super(msg);
    4547        }
     
    6567    };*/
    6668    /** delete file: A0 A2 00 03 BA FF FF 02 B8 B0 B3 */
    67     private static byte dg100CmdDelFile[] =
    68     { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xBA
    69       , (byte) 0xFF, (byte) 0xFF, (byte) 0x02, (byte) 0xB8, (byte) 0xB0, (byte) 0xB3
     69    private static byte[] dg100CmdDelFile =
     70    {(byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xBA,
     71     (byte) 0xFF, (byte) 0xFF, (byte) 0x02, (byte) 0xB8, (byte) 0xB0, (byte) 0xB3
    7072    };
    7173    /** get file info: A0 A2 00 03 BB 00 00 00 BB B0 B3 */
    72     private static byte dg100CmdGetFileInfo[] =
    73     { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xBB
    74       , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xBB, (byte) 0xB0, (byte) 0xB3
     74    private static byte[] dg100CmdGetFileInfo =
     75    {(byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xBB,
     76     (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xBB, (byte) 0xB0, (byte) 0xB3
    7577    };
    7678    /** get gps recs: A0 A2 00 03 B5 00 02 00 B7 B0 B3 */
    77     private static byte dg100CmdGetGpsRecs[] =
    78     { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xB5
    79       , (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0xB7, (byte) 0xB0, (byte) 0xB3
     79    private static byte[] dg100CmdGetGpsRecs =
     80    {(byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xB5,
     81     (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0xB7, (byte) 0xB0, (byte) 0xB3
    8082    };
    8183    /** read config: A0 A2 00 01 B7 00 B7 B0 B3 */
    82     private static byte dg100CmdGetConfig[] =
    83     { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x01, (byte) 0xB7
    84       , (byte) 0x00, (byte) 0xB7, (byte) 0xB0, (byte) 0xB3 };
     84    private static byte[] dg100CmdGetConfig =
     85    {(byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x01, (byte) 0xB7,
     86     (byte) 0x00, (byte) 0xB7, (byte) 0xB0, (byte) 0xB3 };
    8587    /** set config: A0 A2 00 2A B8 jj kk ll ll ll ll mm nn nn nn nn
    8688        aa aa aa aa bb bb bb bb cc cc cc cc 00 00 gg hh
    8789        ii dd dd dd dd ee ee ee ee ff ff ff ff 01 xx xx
    8890        B0 B3 */
    89     private static byte dg100CmdSetConfig[] =
    90     { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x2A, (byte) 0xB8
    91       , (byte) 0x02
    92       , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
    93       , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
    94       , (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE8
    95       , (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE8
    96       , (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE8
    97       , (byte) 0x00, (byte) 0x00
    98       , (byte) 0x00, (byte) 0x00, (byte) 0x00
    99       , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
    100       , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
    101       , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
    102       , (byte) 0x01
    103       , (byte) 0x00, (byte) 0x00, (byte) 0xB0, (byte) 0xB3
     91    private static byte[] dg100CmdSetConfig =
     92    {(byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x2A, (byte) 0xB8,
     93     (byte) 0x02,
     94     (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
     95     (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
     96     (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE8,
     97     (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE8,
     98     (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE8,
     99     (byte) 0x00, (byte) 0x00,
     100     (byte) 0x00, (byte) 0x00, (byte) 0x00,
     101     (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
     102     (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
     103     (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
     104     (byte) 0x01,
     105     (byte) 0x00, (byte) 0x00, (byte) 0xB0, (byte) 0xB3
    104106    };
    105107    /** read config: A0 A2 00 01 BF 00 BF B0 B3 */
     
    121123    private boolean canceled = false;
    122124
    123     public GlobalsatDg100(CommPortIdentifier portId){
     125    public GlobalsatDg100(CommPortIdentifier portId) {
    124126        this.portIdentifier = portId;
    125127    }
    126128
    127     public void cancel(){
     129    public void cancel() {
    128130        canceled = true;
    129131        disconnect();
     
    139141            GpxData result = null;
    140142            canceled = false;
    141             if(port == null){
     143            if (port == null) {
    142144                connect();
    143145            }
     
    147149
    148150            progressMonitor.setTicksCount(gpsRecList.size());
    149             if(gpsRecList.size() > 0){
     151            if (gpsRecList.size() > 0) {
    150152                GpsRec last = null;
    151153                result = new GpxData();
    152154                Collection<WayPoint> seg = new ArrayList<>(100);
    153                 for(GpsRec r:gpsRecList){
    154                     if(canceled){
     155                for (GpsRec r:gpsRecList) {
     156                    if (canceled) {
    155157                        return result;
    156158                    }
    157159                    WayPoint p = wayPointFrom(r);
    158                     if(r.equals(last)){
     160                    if (r.equals(last)) {
    159161                        result.waypoints.add(p);
    160                     }else{
     162                    } else {
    161163                        seg.add(p);
    162164                    }
     
    172174    }
    173175
    174     private WayPoint wayPointFrom(GpsRec r){
     176    private WayPoint wayPointFrom(GpsRec r) {
    175177        LatLon l = new LatLon(r.getLatitude(), r.getLongitude());
    176178        WayPoint result = new WayPoint(l);
    177179        result.attr.put("time", "" + r.getStringZuluTime());
    178180        result.attr.put("speed", "" + r.getSpeed());
    179         if(r.getDg100TypeOfCurRec() > 1)
     181        if (r.getDg100TypeOfCurRec() > 1)
    180182            result.attr.put("ele", "" + r.getAltitude());
    181183        return result;
    182184    }
    183185
    184     public void deleteData() throws ConnectionException{
    185         if(port == null){
     186    public void deleteData() throws ConnectionException {
     187        if (port == null) {
    186188            connect();
    187189        }
    188         try{
     190        try {
    189191            sendCmdDelFiles();
    190         }catch(Exception e){
    191             throw new ConnectionException(e);
    192         }
    193     }
    194 
    195     public void disconnect(){
    196         if(port != null){
     192        } catch (Exception e) {
     193            throw new ConnectionException(e);
     194        }
     195    }
     196
     197    public void disconnect() {
     198        if (port != null) {
    197199            port.close();
    198200            port = null;
     
    200202    }
    201203
    202     private void connect() throws ConnectionException{
    203         try{
    204             port = (SerialPort)portIdentifier.open("DG100", TIMEOUT);
     204    private void connect() throws ConnectionException {
     205        try {
     206            port = (SerialPort) portIdentifier.open("DG100", TIMEOUT);
    205207            port.setSerialPortParams(115200, SerialPort.DATABITS_8,
    206208                                     SerialPort.STOPBITS_2, SerialPort.PARITY_NONE);
    207209            port.notifyOnOutputEmpty(false);
    208210
    209         }catch(PortInUseException e){
    210             throw new ConnectionException(e);
    211         }catch(UnsupportedCommOperationException e){
    212             throw new ConnectionException(e);
    213         }
    214     }
    215 
    216     private List<FileInfoRec> readFileInfoList() throws ConnectionException
    217     {
     211        } catch (PortInUseException e) {
     212            throw new ConnectionException(e);
     213        } catch (UnsupportedCommOperationException e) {
     214            throw new ConnectionException(e);
     215        }
     216    }
     217
     218    private List<FileInfoRec> readFileInfoList() throws ConnectionException {
    218219        int nextIdx = 0;
    219220        List<FileInfoRec> result = new ArrayList<>(64);
    220         try{
    221             do{
     221        try {
     222            do {
    222223                Response<FileInfoRec> response = sendCmdGetFileInfo(nextIdx);
    223224                nextIdx = response.getNextIdx();
     
    225226            } while (nextIdx > 0);
    226227            return result;
    227         }catch(Exception e){
    228             throw new ConnectionException(e);
    229         }
    230     }
    231 
    232     public List<GpsRec> readGpsRecList(List<FileInfoRec> fileInfoList) throws ConnectionException
    233     {
     228        } catch (Exception e) {
     229            throw new ConnectionException(e);
     230        }
     231    }
     232
     233    public List<GpsRec> readGpsRecList(List<FileInfoRec> fileInfoList) throws ConnectionException {
    234234        List<GpsRec> result = new ArrayList<>(200);
    235235
    236         try{
    237             for(FileInfoRec fileInfoRec:fileInfoList){
     236        try {
     237            for (FileInfoRec fileInfoRec:fileInfoList) {
    238238                Response<GpsRec> response = sendCmdGetGpsRecs(fileInfoRec.getIdx());
    239239                result.addAll(response.getRecs());
    240240            }
    241241            return result;
    242         }catch(Exception e){
    243             throw new ConnectionException(e);
    244         }
    245     }
    246 
    247     private Response<?> sendCmdDelFiles() throws IOException, UnsupportedCommOperationException
    248     {
     242        } catch (Exception e) {
     243            throw new ConnectionException(e);
     244        }
     245    }
     246
     247    private Response<?> sendCmdDelFiles() throws IOException, UnsupportedCommOperationException {
    249248        System.out.println("deleting data...");
    250249        int len = sendCmd(dg100CmdDelFile, response, -1);
     
    253252
    254253    @SuppressWarnings("unchecked")
    255     private Response<FileInfoRec> sendCmdGetFileInfo(int idx) throws IOException, UnsupportedCommOperationException
    256     {
     254    private Response<FileInfoRec> sendCmdGetFileInfo(int idx) throws IOException, UnsupportedCommOperationException {
    257255        byte[] src = dg100CmdGetFileInfo;
    258256        ByteBuffer buf = ByteBuffer.wrap(src);
    259257        buf.position(5);
    260         buf.putShort((short)idx); // index of first file info rec to be read
     258        buf.putShort((short) idx); // index of first file info rec to be read
    261259        updateCheckSum(buf);
    262260        int len = sendCmd(src, response, -1);
     
    264262    }
    265263
    266     private Response<?> sendCmdGetConfig() throws IOException, UnsupportedCommOperationException
    267     {
     264    private Response<?> sendCmdGetConfig() throws IOException, UnsupportedCommOperationException {
    268265        byte[] src = dg100CmdGetConfig;
    269266        int len = sendCmd(src, response, -1);
     
    271268    }
    272269
    273     public Dg100Config getConfig() throws ConnectionException{
    274         try{
    275             if(port == null){
     270    public Dg100Config getConfig() throws ConnectionException {
     271        try {
     272            if (port == null) {
    276273                connect();
    277274            }
    278275            return sendCmdGetConfig().getConfig();
    279         }catch(Exception e){
    280             throw new ConnectionException(e);
    281         }
    282     }
    283 
    284     private void sendCmdSetConfig(Dg100Config config) throws IOException, UnsupportedCommOperationException
    285     {
     276        } catch (Exception e) {
     277            throw new ConnectionException(e);
     278        }
     279    }
     280
     281    private void sendCmdSetConfig(Dg100Config config) throws IOException, UnsupportedCommOperationException {
    286282        byte[] src = dg100CmdSetConfig;
    287283        ByteBuffer buf = ByteBuffer.wrap(src);
    288         if (config != null){
     284        if (config != null) {
    289285            config.write(buf);
    290286        }
     
    295291    }
    296292
    297     public void setConfig(Dg100Config conf) throws ConnectionException{
    298         try{
     293    public void setConfig(Dg100Config conf) throws ConnectionException {
     294        try {
    299295            sendCmdSetConfig(conf);
    300         }catch(Exception e){
    301             throw new ConnectionException(e);
    302         }
    303     }
    304 
    305     public boolean isCanceled(){
     296        } catch (Exception e) {
     297            throw new ConnectionException(e);
     298        }
     299    }
     300
     301    public boolean isCanceled() {
    306302        return canceled;
    307303    }
    308304
    309305    @SuppressWarnings("unchecked")
    310     private Response<GpsRec> sendCmdGetGpsRecs(int idx) throws IOException, UnsupportedCommOperationException
    311     {
     306    private Response<GpsRec> sendCmdGetGpsRecs(int idx) throws IOException, UnsupportedCommOperationException {
    312307        byte[] src = dg100CmdGetGpsRecs;
    313308        ByteBuffer buf = ByteBuffer.wrap(src);
    314309        buf.position(5);
    315         buf.putShort((short)idx); // index of first chunk of gps recs to be read
     310        buf.putShort((short) idx); // index of first chunk of gps recs to be read
    316311        updateCheckSum(buf);
    317312        int len = sendCmd(src, response, 2074);
     
    319314    }
    320315
    321     /**
    322      *
    323      * @param buf
    324      */
    325     private void updateCheckSum(ByteBuffer buf)
    326     {
     316    private void updateCheckSum(ByteBuffer buf) {
    327317        buf.position(2);
    328318        short len = buf.getShort();
    329319        int sum = 0;
    330         for (int ii = 0 ; ii < len ; ++ii){
     320        for (int ii = 0; ii < len; ++ii) {
    331321            sum += ByteHelper.byte2IntUnsigned(buf.get());
    332322        }
    333323        sum = sum & 0x7FFF;
    334         buf.putShort((short)sum);
    335     }
    336 
    337     private int sendCmd(byte cmdAndArgs[], byte response[], int bytesToRead) throws IOException, UnsupportedCommOperationException
    338     {
     324        buf.putShort((short) sum);
     325    }
     326
     327    private int sendCmd(byte[] cmdAndArgs, byte[] response, int bytesToRead) throws IOException, UnsupportedCommOperationException {
    339328
    340329        int cntBytTot = 0;
     
    349338    }
    350339
    351 
    352     private int readResponse(byte[] response, int bytesToRead) throws IOException, UnsupportedCommOperationException
    353     {
     340    private int readResponse(byte[] response, int bytesToRead) throws IOException, UnsupportedCommOperationException {
    354341        byte[] readBuffer = new byte[200];
    355342        int responsePos = 0;
     
    359346        int cntBytTot = 0;
    360347        InputStream inputStream = port.getInputStream();
    361         if (inputStream != null){
     348        if (inputStream != null) {
    362349            ByteBuffer buf = ByteBuffer.wrap(response);
    363350            port.enableReceiveThreshold(2); // read at least 2 byte
    364351            boolean a0A2Received = false;
    365             while (! a0A2Received){
     352            while (!a0A2Received) {
    366353                response[0] = response[1];
    367354                int rcvd = inputStream.read(response, 1, 1);
    368                 if (rcvd == 0){
     355                if (rcvd == 0) {
    369356                    return 0;
    370357                }
    371                 a0A2Received = (response[0] == (byte)0xa0 && response[1] == (byte)0xa2);
     358                a0A2Received = (response[0] == (byte) 0xa0 && response[1] == (byte) 0xa2);
    372359            }
    373360            // we already have read 2 bytes
     
    376363            // read interesting data
    377364            port.enableReceiveThreshold(2); // read at least 2 bytes
    378             while (bytesToRead < 0 || (bytesToRead >= 0 && cntBytTot < bytesToRead)){
     365            while (bytesToRead < 0 || (bytesToRead >= 0 && cntBytTot < bytesToRead)) {
    379366                int cntBytAct = 0;
    380367                cntBytAct = inputStream.read(readBuffer);
     
    382369                // copy readBuffer to response
    383370                responsePos = ByteHelper.copyByteArr2ByteArr(readBuffer, 0, cntBytAct, response, responsePos);
    384                 if (!headerReceived && cntBytTot >= 4){
     371                if (!headerReceived && cntBytTot >= 4) {
    385372                    // do we have enough bytes to extract bytesToRead
    386                     if (bytesToRead == -1){
     373                    if (bytesToRead == -1) {
    387374                        // get bytesToRead from response
    388375                        buf.position(2); // here starts length of payload
     
    392379                    headerReceived = true;
    393380                }
    394                 if (cntBytAct == 0){
     381                if (cntBytAct == 0) {
    395382                    break;
    396383                }
  • applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatImportDialog.java

    r30532 r32649  
    1 // License: GPL v2 or later. Copyright 2007 by Raphael Mack, Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.globalsat;
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    5 import gnu.io.CommPortIdentifier;
    65
    76import java.awt.GridBagConstraints;
     
    2322import org.openstreetmap.josm.Main;
    2423
     24import gnu.io.CommPortIdentifier;
     25
    2526/**
    2627 * Main download dialog.
    2728 *
    28  * @author Raphael Mack <ramack@raphael-mack.de>
     29 * @author Raphael Mack &lt;ramack@raphael-mack.de&gt;
    2930 *
    3031 */
     
    4142
    4243        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){
     44        portCombo.setRenderer(new ListCellRenderer<CommPortIdentifier>() {
     45                @Override
     46                public java.awt.Component getListCellRendererComponent(JList<? extends CommPortIdentifier> list,
     47                        CommPortIdentifier o, int x, boolean a, boolean b) {
    4548                    String value = o.getName();
    46                     if(value == null){
     49                    if (value == null) {
    4750                        value = "null";
    4851                    }
     
    5053                }
    5154            });
    52         portCombo.addActionListener(new ActionListener(){
    53                 public void actionPerformed(java.awt.event.ActionEvent e){
     55        portCombo.addActionListener(new ActionListener() {
     56                @Override
     57                public void actionPerformed(java.awt.event.ActionEvent e) {
    5458                    Object i = portCombo.getSelectedItem();
    55                     if(i instanceof CommPortIdentifier){
    56                         GlobalsatPlugin.setPortIdent((CommPortIdentifier)i);
    57                         Main.pref.put("globalsat.portIdentifier", ((CommPortIdentifier)i).getName());
     59                    if (i instanceof CommPortIdentifier) {
     60                        GlobalsatPlugin.setPortIdent((CommPortIdentifier) i);
     61                        Main.pref.put("globalsat.portIdentifier", ((CommPortIdentifier) i).getName());
    5862                    }
    5963                }
     
    6165
    6266        refreshPorts();
    63         c.insets = new Insets(4,4,4,4);
     67        c.insets = new Insets(4, 4, 4, 4);
    6468        c.gridwidth = 1;
    6569        c.weightx = 0.8;
     
    7680
    7781        refreshBtn = new JButton(tr("Refresh"));
    78         refreshBtn.addActionListener(new ActionListener(){
    79                 public void actionPerformed(java.awt.event.ActionEvent e){
     82        refreshBtn.addActionListener(new ActionListener() {
     83                @Override
     84                public void actionPerformed(java.awt.event.ActionEvent e) {
    8085                    refreshPorts();
    8186                }
     
    9095
    9196        configBtn = new JButton(tr("Configure"));
    92         configBtn.addActionListener(new ActionListener(){
    93                 public void actionPerformed(java.awt.event.ActionEvent e){
     97        configBtn.addActionListener(new ActionListener() {
     98                @Override
     99                public void actionPerformed(java.awt.event.ActionEvent e) {
    94100                    System.out.println("configureing the device");
    95                     try{
     101                    try {
    96102
    97103                        GlobalsatConfigDialog dialog = new GlobalsatConfigDialog(GlobalsatPlugin.dg100().getConfig());
     
    99105                        JDialog dlg = pane.createDialog(Main.parent, tr("Configure Device"));
    100106                        dlg.setVisible(true);
    101                         if(((Integer)pane.getValue()) == JOptionPane.OK_OPTION){
     107                        if (((Integer) pane.getValue()) == JOptionPane.OK_OPTION) {
    102108                            GlobalsatPlugin.dg100().setConfig(dialog.getConfig());
    103109                        }
    104110                        dlg.dispose();
    105111
    106                     }catch(GlobalsatDg100.ConnectionException ex){
     112                    } catch (GlobalsatDg100.ConnectionException ex) {
    107113                        JOptionPane.showMessageDialog(Main.parent, tr("Connection Error.") + " " + ex.toString());
    108114                    }
     
    129135    }
    130136
    131     public void refreshPorts(){
     137    public void refreshPorts() {
    132138        String sel = Main.pref.get("globalsat.portIdentifier");
    133139        portCombo.setVisible(false);
     
    135141
    136142        Enumeration<?> e = CommPortIdentifier.getPortIdentifiers();
    137         for(e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ){
    138             CommPortIdentifier port = (CommPortIdentifier)e.nextElement();
    139             if(port.getPortType() == CommPortIdentifier.PORT_SERIAL){
     143        for (e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements();) {
     144            CommPortIdentifier port = (CommPortIdentifier) e.nextElement();
     145            if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    140146                portCombo.addItem(port);
    141                 if(sel != null && port.getName() == sel){
     147                if (sel != null && port.getName() == sel) {
    142148                    portCombo.setSelectedItem(port);
    143149                    GlobalsatPlugin.setPortIdent(port);
     
    150156    }
    151157
    152     public boolean deleteFilesAfterDownload(){
     158    public boolean deleteFilesAfterDownload() {
    153159        return delete.isSelected();
    154160    }
    155161
    156     public CommPortIdentifier getPort(){
    157         return (CommPortIdentifier)portCombo.getSelectedItem();
     162    public CommPortIdentifier getPort() {
     163        return (CommPortIdentifier) portCombo.getSelectedItem();
    158164    }
    159165}
  • applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatPlugin.java

    r32486 r32649  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.globalsat;
    23/// @author Raphael Mack <ramack@raphael-mack.de>
    34import static org.openstreetmap.josm.tools.I18n.tr;
    4 import gnu.io.CommPortIdentifier;
    55
    66import java.awt.GraphicsEnvironment;
     
    2323import org.xml.sax.SAXException;
    2424
     25import gnu.io.CommPortIdentifier;
     26
    2527public class GlobalsatPlugin extends Plugin {
    2628    private static GlobalsatDg100 device = null;
    27     public static GlobalsatDg100 dg100(){
     29    public static GlobalsatDg100 dg100() {
    2830        return device;
    2931    }
    3032
    31     public static void setPortIdent(CommPortIdentifier port){
    32         if(device != null){
     33    public static void setPortIdent(CommPortIdentifier port) {
     34        if (device != null) {
    3335            device.disconnect();
    3436        }
     
    4143        private boolean deleteAfter;
    4244
    43         public ImportTask(boolean delete){
     45        ImportTask(boolean delete) {
    4446            super(tr("Importing data from device."));
    4547            deleteAfter = delete;
     
    4850        @Override public void realRun() throws IOException, SAXException {
    4951            progressMonitor.subTask(tr("Importing data from DG100..."));
    50             try{
     52            try {
    5153                data = GlobalsatPlugin.dg100().readData(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, true));
    52             }catch(Exception e){
     54            } catch (Exception e) {
    5355                eee = e;
    5456            }
     
    5658
    5759        @Override protected void finish() {
    58             if(deleteAfter && GlobalsatPlugin.dg100().isCanceled() == false){
     60            if (deleteAfter && GlobalsatPlugin.dg100().isCanceled() == false) {
    5961                Main.pref.put("globalsat.deleteAfterDownload", true);
    60                 try{
     62                try {
    6163                    GlobalsatPlugin.dg100().deleteData();
    62                 }catch(Exception ex){
     64                } catch (Exception ex) {
    6365                    JOptionPane.showMessageDialog(Main.parent, tr("Error deleting data.") + " " + ex.toString());
    6466                }
    65             }else{
     67            } else {
    6668                Main.pref.put("globalsat.deleteAfterDownload", false);
    6769            }
    68             if(data != null && data.hasTrackPoints()){
     70            if (data != null && data.hasTrackPoints()) {
    6971                Main.getLayerManager().addLayer(new GpxLayer(data, tr("imported data from {0}", "DG 100")));
    7072                Main.map.repaint();
    71             }else{
     73            } else {
    7274                JOptionPane.showMessageDialog(Main.parent, tr("No data found on device."));
    7375            }
    74             if(eee != null){
     76            if (eee != null) {
    7577                eee.printStackTrace();
    7678                System.out.println(eee.getMessage());
     
    9496        } catch (UnsatisfiedLinkError e) {
    9597            error = true;
     98            // CHECKSTYLE.OFF: LineLength
    9699            String msg = tr("Cannot load library rxtxSerial. If you need support to install it try Globalsat homepage at http://www.raphael-mack.de/josm-globalsat-gpx-import-plugin/");
     100            // CHECKSTYLE.ON: LineLength
    97101            Main.error(msg);
    98102            if (!GraphicsEnvironment.isHeadless()) {
    99                 JOptionPane.showMessageDialog(Main.parent, "<html>" + msg + "</html>");
     103                JOptionPane.showMessageDialog(Main.parent, "<html>" + msg + "</html>");
    100104            }
    101105        }
     
    106110    }
    107111
    108     class GlobalsatImportAction extends JosmAction{
    109         public GlobalsatImportAction(){
     112    class GlobalsatImportAction extends JosmAction {
     113        GlobalsatImportAction() {
    110114            super(tr("Globalsat Import"), "globalsatImport",
    111115            tr("Import Data from Globalsat Datalogger DG100 into GPX layer."),
     
    113117            KeyEvent.VK_G, Shortcut.ALT_CTRL), false);
    114118        }
    115         public void actionPerformed(ActionEvent e){
     119
     120        @Override
     121        public void actionPerformed(ActionEvent e) {
    116122            GlobalsatImportDialog dialog = new GlobalsatImportDialog();
    117123            JOptionPane pane = new JOptionPane(dialog, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    118124            JDialog dlg = pane.createDialog(Main.parent, tr("Import"));
    119125            dlg.setVisible(true);
    120             if(((Integer)pane.getValue()) == JOptionPane.OK_OPTION){
     126            if (((Integer) pane.getValue()) == JOptionPane.OK_OPTION) {
    121127                setPortIdent(dialog.getPort());
    122128                ImportTask task = new ImportTask(dialog.deleteFilesAfterDownload());
  • applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/SingleSegmentGpxTrack.java

    r29222 r32649  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.globalsat;
    23
     
    1920    }
    2021
     22    @Override
    2123    public Map<String, Object> getAttributes() {
    2224        return attr;
    2325    }
    2426
     27    @Override
    2528    public Bounds getBounds() {
    2629        return trackSegment.getBounds();
    2730    }
    2831
     32    @Override
    2933    public Collection<GpxTrackSegment> getSegments() {
    3034        return Collections.singleton(trackSegment);
    3135    }
    3236
     37    @Override
    3338    public double length() {
    3439        return trackSegment.length();
Note: See TracChangeset for help on using the changeset viewer.