Changeset 30


Ignore:
Timestamp:
07/27/07 19:16:10 (6 years ago)
Author:
saua
Message:

display length of current track (fixes #11)

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • bbtracker/trunk/src/org/bbtracker/mobile/gui/StatusTile.java

    r14 r30  
    1010 
    1111public class StatusTile extends Tile { 
    12         public static final String MAX_DEGREE_STRING = "99" + Utils.DEGREE + "99" + Utils.MINUTE + "99.99" + Utils.SECOND + 
     12        private static final String MAX_DEGREE_STRING = "99" + Utils.DEGREE + "99" + Utils.MINUTE + "99.99" + Utils.SECOND + 
    1313                        "W"; 
     14 
     15        private static final String MAX_SPEED_STRING = "888.8 km/h"; 
     16 
     17        private static final String MAX_COURSE_STRING = "399" + Utils.DEGREE; 
     18 
     19        private static final String MAX_ELEVATION_STRING = "8888m"; 
    1420 
    1521        private static final int MARGIN = 2; 
     
    2329        private final int latWidth; 
    2430 
     31        private final int speedWidth; 
     32 
     33        private final int courseWidth; 
     34 
     35        private final int elevationWidth; 
     36 
    2537        public StatusTile(final TrackManager manager) { 
    2638                this.manager = manager; 
    2739                font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL); 
    2840                latWidth = font.stringWidth(MAX_DEGREE_STRING); 
     41                System.out.println(latWidth); 
     42                speedWidth = font.stringWidth(MAX_SPEED_STRING); 
     43                System.out.println(speedWidth); 
     44                courseWidth = font.stringWidth(MAX_COURSE_STRING); 
     45                System.out.println(courseWidth); 
     46                elevationWidth = font.stringWidth(MAX_ELEVATION_STRING); 
     47                System.out.println(elevationWidth); 
    2948        } 
    3049 
     
    6382                        elevation = "-m"; 
    6483                } 
     84                final String length; 
     85                if (track != null) { 
     86                        length = Utils.distanceToString(track.getLength()); 
     87                } else { 
     88                        length = "-m"; 
     89                } 
    6590 
    6691                int y = MARGIN; 
    6792 
    68                 final int leftColumn = MARGIN + latWidth; 
    69                 final int middleColumn = MARGIN + latWidth * 2 + GAP; 
    70                 final int rightBorder = width - MARGIN; 
     93                final int lonPos = MARGIN + latWidth; 
     94                final int latPos = MARGIN + latWidth * 2 + GAP; 
     95                final int rightPos = width - MARGIN; 
    7196 
    72                 g.drawString(lon, leftColumn, y, Graphics.TOP | Graphics.RIGHT); 
    73                 g.drawString(lat, middleColumn, y, Graphics.TOP | Graphics.RIGHT); 
    74                 g.drawString(elevation, rightBorder, y, Graphics.TOP | Graphics.RIGHT); 
     97                g.drawString(lon, lonPos, y, Graphics.TOP | Graphics.RIGHT); 
     98                g.drawString(lat, latPos, y, Graphics.TOP | Graphics.RIGHT); 
     99                g.drawString(length, rightPos, y, Graphics.TOP | Graphics.RIGHT); 
    75100                y += font.getHeight(); 
    76                 g.drawString(speed, leftColumn, y, Graphics.TOP | Graphics.RIGHT); 
    77                 g.drawString(course, middleColumn, y, Graphics.TOP | Graphics.RIGHT); 
    78                 g.drawString(point, rightBorder, y, Graphics.TOP | Graphics.RIGHT); 
     101                g.drawString(speed, lonPos, y, Graphics.TOP | Graphics.RIGHT); 
     102                g.drawString(course, lonPos + GAP + GAP + courseWidth, y, Graphics.TOP | Graphics.RIGHT); 
     103                g.drawString(elevation, latPos, y, Graphics.TOP | Graphics.RIGHT); 
     104                g.drawString(point, rightPos, y, Graphics.TOP | Graphics.RIGHT); 
    79105        } 
    80106 
  • bbtracker_common/trunk/src/org/bbtracker/Track.java

    r7 r30  
    9999        public double getMinLongitude() { 
    100100                return minLongitude; 
     101        } 
     102 
     103        public double getLength() { 
     104                final Enumeration e = segments.elements(); 
     105                double length = 0d; 
     106                while (e.hasMoreElements()) { 
     107                        length += ((TrackSegment) e.nextElement()).getLength(); 
     108                } 
     109                return length; 
    101110        } 
    102111 
  • bbtracker_common/trunk/src/org/bbtracker/TrackSegment.java

    r4 r30  
    1717 
    1818        transient double maxLongitude = Double.MIN_VALUE; 
     19 
     20        transient double length = 0; 
    1921 
    2022        TrackSegment() { 
     
    4648                        boundsChanged = true; 
    4749                } 
     50                if (points.size() > 0) { 
     51                        final TrackPoint prevPoint = (TrackPoint) points.elementAt(points.size() - 1); 
     52                        final double dist = Utils.distance(prevPoint.getLatitude(), prevPoint.getLongitude(), lat, lon); 
     53                        length += dist; 
     54                } 
    4855                points.addElement(point); 
    4956                return boundsChanged; 
     
    5663        public int getPointCount() { 
    5764                return points.size(); 
     65        } 
     66 
     67        public double getLength() { 
     68                return length; 
    5869        } 
    5970 
  • bbtracker_common/trunk/src/org/bbtracker/Utils.java

    r18 r30  
    206206                return ((int) elevation) + "m"; 
    207207        } 
     208 
     209        public static String distanceToString(final double length) { 
     210                if (length < 1000) { 
     211                        return ((int) length) + "m"; 
     212                } else { 
     213                        return String.valueOf(((int) (length / 100)) / 10f) + "km"; 
     214                } 
     215        } 
    208216} 
Note: See TracChangeset for help on using the changeset viewer.