Ignore:
Timestamp:
2009-01-01T18:28:53+01:00 (16 years ago)
Author:
stoecker
Message:

removed tab stop usage

Location:
applications/editors/josm/plugins/livegps/livegps
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/livegps/livegps/LiveGpsAcquirer.java

    r6709 r12778  
    1818
    1919public class LiveGpsAcquirer implements Runnable {
    20         Socket gpsdSocket;
    21         BufferedReader gpsdReader;
    22         boolean connected = false;
    23         String gpsdHost = "localhost";
    24         int gpsdPort = 2947;
    25         String configFile = "liveGPS.conf";
    26         boolean shutdownFlag = false;
     20    Socket gpsdSocket;
     21    BufferedReader gpsdReader;
     22    boolean connected = false;
     23    String gpsdHost = "localhost";
     24    int gpsdPort = 2947;
     25    String configFile = "liveGPS.conf";
     26    boolean shutdownFlag = false;
    2727    private List<PropertyChangeListener> propertyChangeListener = new ArrayList<PropertyChangeListener>();
    2828    private PropertyChangeEvent lastStatusEvent;
    2929    private PropertyChangeEvent lastDataEvent;
    30        
    31         public LiveGpsAcquirer(String pluginDir) {
    32                                
    33                 Properties liveGPSconfig = new Properties();
    34                
    35                 FileInputStream fis = null;
    36                                
    37                 try {
    38                         fis = new FileInputStream(pluginDir + configFile);
    39                 } catch (FileNotFoundException e) {
    40                         System.err.println("No liveGPS.conf found, using defaults");
    41                 }
    42                
    43                 if(fis != null)
    44                 {               
    45                         try {
    46                                 liveGPSconfig.load(fis);
    47                                 this.gpsdHost = liveGPSconfig.getProperty("host");
    48                                 this.gpsdPort = Integer.parseInt(liveGPSconfig.getProperty("port"));
    49                                
    50                         } catch (IOException e) {
    51                                 System.err.println("Error while loading liveGPS.conf, using defaults");
    52                         }
    53                        
    54                         if(this.gpsdHost == null || this.gpsdPort == 0)
    55                         {
    56                                 System.err.println("Error in liveGPS.conf, using defaults");
    57                                 this.gpsdHost = "localhost";
    58                                 this.gpsdPort = 2947;
    59                         }
    60                 }
    61                
    62         }
    63    
    64     /**
    65      * Adds a property change listener to the acquirer. 
     30
     31    public LiveGpsAcquirer(String pluginDir) {
     32
     33        Properties liveGPSconfig = new Properties();
     34
     35        FileInputStream fis = null;
     36
     37        try {
     38            fis = new FileInputStream(pluginDir + configFile);
     39        } catch (FileNotFoundException e) {
     40            System.err.println("No liveGPS.conf found, using defaults");
     41        }
     42
     43        if(fis != null)
     44        {
     45            try {
     46                liveGPSconfig.load(fis);
     47                this.gpsdHost = liveGPSconfig.getProperty("host");
     48                this.gpsdPort = Integer.parseInt(liveGPSconfig.getProperty("port"));
     49
     50            } catch (IOException e) {
     51                System.err.println("Error while loading liveGPS.conf, using defaults");
     52            }
     53
     54            if(this.gpsdHost == null || this.gpsdPort == 0)
     55            {
     56                System.err.println("Error in liveGPS.conf, using defaults");
     57                this.gpsdHost = "localhost";
     58                this.gpsdPort = 2947;
     59            }
     60        }
     61
     62    }
     63
     64    /**
     65     * Adds a property change listener to the acquirer.
    6666     * @param listener the new listener
    6767     */
     
    7171        }
    7272    }
    73    
     73
    7474    /**
    7575     * Fire a gps status change event. Fires events with key "gpsstatus" and a {@link LiveGpsStatus}
     
    8787
    8888    /**
    89      * Fire a gps data change event to all listeners. Fires events with key "gpsdata" and a 
     89     * Fire a gps data change event to all listeners. Fires events with key "gpsdata" and a
    9090     * {@link LiveGpsData} object as values.
    9191     * @param oldData the old gps data.
     
    9999        }
    100100    }
    101    
     101
    102102    /**
    103103     * Fires the given event to all listeners.
     
    107107        for (PropertyChangeListener listener : propertyChangeListener) {
    108108            listener.propertyChange(event);
    109         }       
    110     }
    111 
    112         public void run() {     
    113             LiveGpsData oldGpsData = null;
    114             LiveGpsData gpsData = null;
     109        }
     110    }
     111
     112    public void run() {
     113        LiveGpsData oldGpsData = null;
     114        LiveGpsData gpsData = null;
    115115        shutdownFlag = false;
    116                 while(!shutdownFlag) {
    117                         double lat = 0;
    118                         double lon = 0;
     116        while(!shutdownFlag) {
     117            double lat = 0;
     118            double lon = 0;
    119119            float speed = 0;
    120120            float course = 0;
    121                         boolean haveFix = false;
    122 
    123                         try
    124                         {
    125                                 if (!connected)
    126                                 {
    127                                     System.out.println("LiveGps tries to connect to gpsd");
     121            boolean haveFix = false;
     122
     123            try
     124            {
     125                if (!connected)
     126                {
     127                    System.out.println("LiveGps tries to connect to gpsd");
    128128                    fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.CONNECTING, tr("Connecting"));
    129                                         InetAddress[] addrs = InetAddress.getAllByName(gpsdHost);
    130                                         for (int i=0; i < addrs.length && gpsdSocket == null; i++) {
    131                                                 try {
    132                                                         gpsdSocket = new Socket(addrs[i], gpsdPort);
    133                                                         break;
    134                                                 } catch (Exception e) {
    135                                                         System.out.println("LiveGps: Could not open connection to gpsd: " + e);
    136                                                         gpsdSocket = null;
    137                                                 }
    138                                         }
    139                                        
    140                                         if (gpsdSocket != null)
    141                                         {
    142                                                 gpsdReader = new BufferedReader(new InputStreamReader(gpsdSocket.getInputStream()));
    143                                                 gpsdSocket.getOutputStream().write(new byte[] { 'w', 13, 10 });
     129                    InetAddress[] addrs = InetAddress.getAllByName(gpsdHost);
     130                    for (int i=0; i < addrs.length && gpsdSocket == null; i++) {
     131                        try {
     132                            gpsdSocket = new Socket(addrs[i], gpsdPort);
     133                            break;
     134                        } catch (Exception e) {
     135                            System.out.println("LiveGps: Could not open connection to gpsd: " + e);
     136                            gpsdSocket = null;
     137                        }
     138                    }
     139
     140                    if (gpsdSocket != null)
     141                    {
     142                        gpsdReader = new BufferedReader(new InputStreamReader(gpsdSocket.getInputStream()));
     143                        gpsdSocket.getOutputStream().write(new byte[] { 'w', 13, 10 });
    144144                        fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.CONNECTING, tr("Connecting"));
    145                                                 connected = true;
    146                                         System.out.println("LiveGps: Connected to gpsd");
    147                                         }
    148                                 }
     145                        connected = true;
     146                    System.out.println("LiveGps: Connected to gpsd");
     147                    }
     148                }
    149149
    150150
     
    153153                    // TODO this read is blocking if gps is connected but has no fix, so gpsd does not send positions
    154154                    String line = gpsdReader.readLine();
    155                     // </FIXXME> 
     155                    // </FIXXME>
    156156                    if (line == null) break;
    157157                    String words[] = line.split(",");
     
    189189                            }
    190190                            break;
    191                         case 'P':       
     191                        case 'P':
    192192                            // position report, tab delimited.
    193193                            String[] pos = value.split("\\s+");
     
    217217                    try { Thread.sleep(1000); } catch (InterruptedException ignore) {};
    218218                }
    219                         } catch(IOException iox) {
    220                                 connected = false;
    221                                 if(gpsData != null) {
    222                                     gpsData.setFix(false);
    223                                     fireGpsDataChangeEvent(oldGpsData, gpsData);
    224                                 }
     219            } catch(IOException iox) {
     220                connected = false;
     221                if(gpsData != null) {
     222                    gpsData.setFix(false);
     223                    fireGpsDataChangeEvent(oldGpsData, gpsData);
     224                }
    225225                fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.CONNECTION_FAILED, tr("Connection Failed"));
    226                                 try { Thread.sleep(1000); } catch (InterruptedException ignore) {};
    227                                 // send warning to layer
    228 
    229                         }
    230                 }
    231    
     226                try { Thread.sleep(1000); } catch (InterruptedException ignore) {};
     227                // send warning to layer
     228
     229            }
     230        }
     231
    232232    fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.DISCONNECTED, tr("Not connected"));
    233                 if (gpsdSocket != null) {
    234       try { 
    235         gpsdSocket.close(); 
     233        if (gpsdSocket != null) {
     234      try {
     235        gpsdSocket.close();
    236236        gpsdSocket = null;
    237                         System.out.println("LiveGps: Disconnected from gpsd");
    238       } 
     237            System.out.println("LiveGps: Disconnected from gpsd");
     238      }
    239239      catch (Exception e) {
    240240        System.out.println("LiveGps: Unable to close socket; reconnection may not be possible");
    241241      };
    242           }
     242      }
    243243  }
    244        
    245         public void shutdown()
    246         {
    247                 shutdownFlag = true;
    248         }
     244
     245    public void shutdown()
     246    {
     247        shutdownFlag = true;
     248    }
    249249}
  • applications/editors/josm/plugins/livegps/livegps/LiveGpsData.java

    r3336 r12778  
    11/**
    2  * 
     2 *
    33 */
    44package livegps;
     
    2222    private String wayString;
    2323    private Way way;
    24    
     24
    2525    /**
    2626     * @param latitude
     
    3838    }
    3939    /**
    40      * 
     40     *
    4141     */
    4242    public LiveGpsData() {
     
    9191        this.speed = speed;
    9292    }
    93    
     93
    9494    /**
    9595     * @return the latlon
     
    9898        return this.latLon;
    9999    }
    100    
     100
    101101    /**
    102102     * @param latLon
     
    105105        this.latLon = latLon;
    106106    }
    107    
     107
    108108    public String toString() {
    109         return getClass().getSimpleName() + "[fix=" + fix + ", lat=" + latLon.lat() 
     109        return getClass().getSimpleName() + "[fix=" + fix + ", lat=" + latLon.lat()
    110110        + ", long=" + latLon.lon() + ", speed=" + speed + ", course=" + course + "]";
    111        
    112     }
    113    
     111
     112    }
     113
    114114    /**
    115115     * Returns the name of the way that is closest to the current coordinates or an
    116116     * empty string if no way is around.
    117      * 
     117     *
    118118     * @return the name of the way that is closest to the current coordinates.
    119119     */
     
    156156        return wayString;
    157157    }
    158    
     158
    159159    /**
    160160     * Returns the closest way to this position.
     
    163163    public Way getWay() {
    164164        if(way == null) {
    165             EastNorth eastnorth = Main.proj.latlon2eastNorth(getLatLon()); 
    166             Point xy = Main.map.mapView.getPoint(eastnorth); 
     165            EastNorth eastnorth = Main.proj.latlon2eastNorth(getLatLon());
     166            Point xy = Main.map.mapView.getPoint(eastnorth);
    167167            way = Main.map.mapView.getNearestWay(xy);
    168168        }
    169169        return way;
    170        
    171     }
    172    
     170
     171    }
     172
    173173    /* (non-Javadoc)
    174174     * @see java.lang.Object#hashCode()
     
    207207    }
    208208
    209    
    210    
     209
     210
    211211}
  • applications/editors/josm/plugins/livegps/livegps/LiveGpsDialog.java

    r11974 r12778  
    11/**
    2  * 
     2 *
    33 */
    44package livegps;
     
    6262        add(new JScrollPane(panel), BorderLayout.CENTER);
    6363    }
    64    
     64
    6565    /* (non-Javadoc)
    6666     * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
     
    7979                speedLabel.setText((Math.round(mySpeed*100)/100) + "km/h"); // m(s to km/h
    8080                courseLabel.setText(data.getCourse() + "deg");
    81                
     81
    8282                String wayString = data.getWayInfo();
    8383                if(wayString.length() > 0) {
     
    8686                    wayLabel.setText("unknown");
    8787                }
    88                
     88
    8989            } else {
    9090//                fixLabel.setText("no fix");
     
    101101                panel.setBackground(Color.RED);
    102102            } else {
    103                 panel.setBackground(Color.WHITE);               
     103                panel.setBackground(Color.WHITE);
    104104            }
    105105        }
    106        
     106
    107107    }
    108 
    109 
    110 
    111108}
  • applications/editors/josm/plugins/livegps/livegps/LiveGpsLayer.java

    r11934 r12778  
    2525    public static final String LAYER_NAME = tr("LiveGPS layer");
    2626    public static final String KEY_LIVEGPS_COLOR ="color.livegps.position";
    27         LatLon lastPos;
    28         WayPoint lastPoint;
    29         GpxTrack trackBeingWritten;
    30         Collection<WayPoint> trackSegment;
    31         float speed;
    32         float course;
    33         String status;
    34         //JLabel lbl;
    35         boolean autocenter;
    36         private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    37        
    38         public LiveGpsLayer(GpxData data)
    39         {
    40                 super (data, LAYER_NAME);
    41                 trackBeingWritten = new GpxTrack();
    42                 trackBeingWritten.attr.put("desc", "josm live gps");
    43                 trackSegment = new ArrayList<WayPoint>();
    44                 trackBeingWritten.trackSegs.add(trackSegment);
    45                 data.tracks.add(trackBeingWritten);
    46         }
    47        
    48         void setCurrentPosition(double lat, double lon)
    49         {
    50             //System.out.println("adding pos " + lat + "," + lon);
    51                 LatLon thisPos = new LatLon(lat, lon);
    52                 if ((lastPos != null) && (thisPos.equalsEpsilon(lastPos))) {
    53                         // no change in position
    54                         // maybe show a "paused" cursor or some such
    55                         return;
    56                 }
    57                        
    58                 lastPos = thisPos;
    59                 lastPoint = new WayPoint(thisPos);
    60                 lastPoint.attr.put("time", dateFormat.format(new Date()));
    61                 // synchronize when adding data, as otherwise the autosave action
    62                 // needs concurrent access and this results in an exception!
    63                 synchronized (LiveGpsLock.class) {
    64                     trackSegment.add(lastPoint);           
     27    LatLon lastPos;
     28    WayPoint lastPoint;
     29    GpxTrack trackBeingWritten;
     30    Collection<WayPoint> trackSegment;
     31    float speed;
     32    float course;
     33    String status;
     34    //JLabel lbl;
     35    boolean autocenter;
     36    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
     37
     38    public LiveGpsLayer(GpxData data)
     39    {
     40        super (data, LAYER_NAME);
     41        trackBeingWritten = new GpxTrack();
     42        trackBeingWritten.attr.put("desc", "josm live gps");
     43        trackSegment = new ArrayList<WayPoint>();
     44        trackBeingWritten.trackSegs.add(trackSegment);
     45        data.tracks.add(trackBeingWritten);
     46    }
     47
     48    void setCurrentPosition(double lat, double lon)
     49    {
     50        //System.out.println("adding pos " + lat + "," + lon);
     51        LatLon thisPos = new LatLon(lat, lon);
     52        if ((lastPos != null) && (thisPos.equalsEpsilon(lastPos))) {
     53            // no change in position
     54            // maybe show a "paused" cursor or some such
     55            return;
    6556        }
    66                 if (autocenter) {
    67                     center();
    68                 }
    69                
    70                 //Main.map.repaint();
    71         }
    7257
    73         public void center()
    74         {
    75                 if (lastPoint != null)
    76                         Main.map.mapView.zoomTo(lastPoint.eastNorth, Main.map.mapView.getScale());
    77         }
    78        
    79 //      void setStatus(String status)
    80 //      {
    81 //              this.status = status;
    82 //              Main.map.repaint();
     58        lastPos = thisPos;
     59        lastPoint = new WayPoint(thisPos);
     60        lastPoint.attr.put("time", dateFormat.format(new Date()));
     61        // synchronize when adding data, as otherwise the autosave action
     62        // needs concurrent access and this results in an exception!
     63        synchronized (LiveGpsLock.class) {
     64            trackSegment.add(lastPoint);
     65        }
     66        if (autocenter) {
     67            center();
     68        }
     69
     70        //Main.map.repaint();
     71    }
     72
     73    public void center()
     74    {
     75        if (lastPoint != null)
     76            Main.map.mapView.zoomTo(lastPoint.eastNorth, Main.map.mapView.getScale());
     77    }
     78
     79//  void setStatus(String status)
     80//  {
     81//      this.status = status;
     82//      Main.map.repaint();
    8383//        System.out.println("LiveGps status: " + status);
    84 //      }
    85        
    86         void setSpeed(float metresPerSecond)
    87         {
    88                 speed = metresPerSecond;
    89                 //Main.map.repaint();
    90         }
     84//  }
    9185
    92         void setCourse(float degrees)
    93         {
    94                 course = degrees;
    95                 //Main.map.repaint();
    96         }
    97        
    98         public void setAutoCenter(boolean ac)
    99         {
    100                 autocenter = ac;
    101         }
     86    void setSpeed(float metresPerSecond)
     87    {
     88        speed = metresPerSecond;
     89        //Main.map.repaint();
     90    }
    10291
    103         @Override public void paint(Graphics g, MapView mv)
    104         {
    105             //System.out.println("in paint");
    106             synchronized (LiveGpsLock.class) {
    107                 //System.out.println("in synced paint");
    108                 super.paint(g, mv);
    109 //              int statusHeight = 50;
    110 //              Rectangle mvs = mv.getBounds();
    111 //              mvs.y = mvs.y + mvs.height - statusHeight;
    112 //              mvs.height = statusHeight;
    113 //              g.setColor(new Color(1.0f, 1.0f, 1.0f, 0.8f));
    114 //              g.fillRect(mvs.x, mvs.y, mvs.width, mvs.height);
     92    void setCourse(float degrees)
     93    {
     94        course = degrees;
     95        //Main.map.repaint();
     96    }
    11597
    116                 if (lastPoint != null)
    117                 {
    118                     Point screen = mv.getPoint(lastPoint.eastNorth);
    119                     g.setColor(Main.pref.getColor(KEY_LIVEGPS_COLOR, Color.RED));
    120                     g.drawOval(screen.x-10, screen.y-10,20,20);
    121                     g.drawOval(screen.x-9, screen.y-9,18,18);
    122                 }
     98    public void setAutoCenter(boolean ac)
     99    {
     100        autocenter = ac;
     101    }
    123102
    124 //              lbl.setText("gpsd: "+status+" Speed: " + speed + " Course: "+course);
    125 //              lbl.setBounds(0, 0, mvs.width-10, mvs.height-10);
    126 //              Graphics sub = g.create(mvs.x+5, mvs.y+5, mvs.width-10, mvs.height-10);
    127 //              lbl.paint(sub);
     103    @Override public void paint(Graphics g, MapView mv)
     104    {
     105        //System.out.println("in paint");
     106        synchronized (LiveGpsLock.class) {
     107            //System.out.println("in synced paint");
     108            super.paint(g, mv);
     109//          int statusHeight = 50;
     110//          Rectangle mvs = mv.getBounds();
     111//          mvs.y = mvs.y + mvs.height - statusHeight;
     112//          mvs.height = statusHeight;
     113//          g.setColor(new Color(1.0f, 1.0f, 1.0f, 0.8f));
     114//          g.fillRect(mvs.x, mvs.y, mvs.width, mvs.height);
    128115
    129 //              if(status != null) {
    130 //              g.setColor(Color.WHITE);
    131 //              g.drawString("gpsd: " + status, 5, mv.getBounds().height - 15); // lower left corner
    132 //              }
    133             }
    134         }
    135    
     116            if (lastPoint != null)
     117            {
     118                Point screen = mv.getPoint(lastPoint.eastNorth);
     119                g.setColor(Main.pref.getColor(KEY_LIVEGPS_COLOR, Color.RED));
     120                g.drawOval(screen.x-10, screen.y-10,20,20);
     121                g.drawOval(screen.x-9, screen.y-9,18,18);
     122            }
     123
     124//          lbl.setText("gpsd: "+status+" Speed: " + speed + " Course: "+course);
     125//          lbl.setBounds(0, 0, mvs.width-10, mvs.height-10);
     126//          Graphics sub = g.create(mvs.x+5, mvs.y+5, mvs.width-10, mvs.height-10);
     127//          lbl.paint(sub);
     128
     129//          if(status != null) {
     130//          g.setColor(Color.WHITE);
     131//          g.drawString("gpsd: " + status, 5, mv.getBounds().height - 15); // lower left corner
     132//          }
     133        }
     134    }
     135
    136136    /* (non-Javadoc)
    137137     * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
     
    154154            }
    155155        }
    156        
     156
    157157    }
    158158
  • applications/editors/josm/plugins/livegps/livegps/LiveGpsLock.java

    r3073 r12778  
    11/**
    2  * 
     2 *
    33 */
    44package livegps;
     
    88 * read or write live gps data must synchronize to this class. Especially the save action
    99 * takes quite long, so concurrency problems occur.
    10  * 
     10 *
    1111 * @author cdaller
    1212 *
  • applications/editors/josm/plugins/livegps/livegps/LiveGpsPlugin.java

    r11974 r12778  
    2424public class LiveGpsPlugin extends Plugin
    2525{
    26         private LiveGpsAcquirer acquirer = null;
    27         private Thread acquirerThread = null;
     26    private LiveGpsAcquirer acquirer = null;
     27    private Thread acquirerThread = null;
    2828    private JMenu lgpsmenu;
    2929    private JCheckBoxMenuItem lgpscapture;
     
    3232    private LiveGpsDialog lgpsdialog;
    3333    List<PropertyChangeListener>listenerQueue;
    34        
    35         private GpxData data = new GpxData();
     34
     35    private GpxData data = new GpxData();
    3636    private LiveGpsLayer lgpslayer;
    37    
    38        
     37
     38
    3939    public class CaptureAction extends JosmAction {
    4040        public CaptureAction() {
     
    7777    }
    7878
    79     public LiveGpsPlugin() 
     79    public LiveGpsPlugin()
    8080    {
    8181        MainMenu menu = Main.main.menu;
     
    111111        }
    112112    }
    113    
     113
    114114    /**
    115115     * Returns <code>true</code> if autocenter is selected.
     
    119119        return lgpsautocenter.isSelected();
    120120    }
    121    
     121
    122122    /**
    123123     * Enable or disable gps tracking
     
    155155        }
    156156    }
    157    
    158    
     157
     158
    159159    /**
    160160     * Add a listener for gps events.
  • applications/editors/josm/plugins/livegps/livegps/LiveGpsStatus.java

    r3073 r12778  
    11/**
    2  * 
     2 *
    33 */
    44package livegps;
Note: See TracChangeset for help on using the changeset viewer.