Changeset 50
- Timestamp:
- 08/07/07 18:19:01 (6 years ago)
- Location:
- bbtracker/trunk/src/org/bbtracker/mobile/gui
- Files:
-
- 2 edited
-
MainCanvas.java (modified) (1 diff)
-
StatusTile.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bbtracker/trunk/src/org/bbtracker/mobile/gui/MainCanvas.java
r33 r50 52 52 super.sizeChanged(w, h); 53 53 54 final int statusHeight = statusTile.getPreferredHeight( );54 final int statusHeight = statusTile.getPreferredHeight(w); 55 55 trackTile.resize(0, 0, w, h - (statusHeight + 1)); 56 56 statusTile.resize(0, h - statusHeight, w, statusHeight); -
bbtracker/trunk/src/org/bbtracker/mobile/gui/StatusTile.java
r36 r50 12 12 13 13 public class StatusTile extends Tile { 14 15 /* 16 * The MAX_* constants represent the string values that each field can take that take up the maximum amount of 17 * horizontal space. 18 */ 14 19 private static final String MAX_DEGREE_STRING = "99" + Utils.DEGREE + "99" + Utils.MINUTE + "99.99" + Utils.SECOND + 15 20 "W"; … … 17 22 private static final String MAX_COURSE_STRING = "399" + Utils.DEGREE; 18 23 24 private static final String MAX_SPEED_STRING = "999.9km/h"; 25 26 private static final String MAX_ELEVATION_STRING = "9999m"; 27 28 private static final String MAX_LENGTH_STRING = "9999.9km"; 29 30 private static final String MAX_POINT_STRING = "9999/9999"; 31 19 32 private static final int MARGIN = 2; 20 33 21 private static final int GAP = 5;34 private static final int MINIMAL_GAP = 5; 22 35 23 36 private final TrackManager manager; 24 37 25 private finalFont font;38 private Font font; 26 39 27 private finalint latWidth;40 private int latWidth; 28 41 29 private final int courseWidth; 42 private int courseWidth; 43 44 private int speedWidth; 45 46 private int elevationWidth; 47 48 private int lengthWidth; 49 50 private int pointWidth; 51 52 private boolean twoLineLayout = true; 30 53 31 54 public StatusTile(final TrackManager manager) { 32 55 this.manager = manager; 33 font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL); 56 setFontSize(Font.SIZE_MEDIUM); 57 } 58 59 private void setFontSize(final int fontSize) { 60 font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, fontSize); 34 61 latWidth = font.stringWidth(MAX_DEGREE_STRING); 35 62 courseWidth = font.stringWidth(MAX_COURSE_STRING); 63 speedWidth = font.stringWidth(MAX_SPEED_STRING); 64 elevationWidth = font.stringWidth(MAX_ELEVATION_STRING); 65 lengthWidth = font.stringWidth(MAX_LENGTH_STRING); 66 pointWidth = font.stringWidth(MAX_POINT_STRING); 67 twoLineLayout = fitsTwoLineLayout(width); 68 } 69 70 protected void onResize() { 71 twoLineLayout = fitsTwoLineLayout(width); 72 } 73 74 protected boolean fitsTwoLineLayout(final int width) { 75 final int twoLineWidth = (MARGIN + MINIMAL_GAP + latWidth) * 2 + lengthWidth; 76 return width >= twoLineWidth; 36 77 } 37 78 … … 78 119 final String length = unit.distanceToString(lengthValue); 79 120 80 int y = MARGIN; 121 final int line1 = MARGIN; 122 final int line2 = line1 + font.getHeight(); 123 final int latLonWidth; // the space available for latitude and longitude combined, it's also used for 124 // speed/course/elevation 125 if (twoLineLayout) { 126 final int spareSpace = width - (MARGIN * 2 + latWidth * 2 + Math.max(lengthWidth, pointWidth)); 127 latLonWidth = latWidth * 2 + spareSpace / 2; 128 } else { 129 latLonWidth = width - 2 * MARGIN; 130 } 81 131 82 final int lonPos = MARGIN + latWidth;83 final int latPos = MARGIN + latWidth * 2 + GAP;84 final int rightPos = width - MARGIN;132 // longitude / latitude (always on line 1) 133 g.drawString(lon, MARGIN + latLonWidth / 2, line1, Graphics.TOP | Graphics.RIGHT); 134 g.drawString(lat, MARGIN + latLonWidth, line1, Graphics.TOP | Graphics.RIGHT); 85 135 86 g.drawString(lon, lonPos, y, Graphics.TOP | Graphics.RIGHT); 87 g.drawString(lat, latPos, y, Graphics.TOP | Graphics.RIGHT); 88 g.drawString(length, rightPos, y, Graphics.TOP | Graphics.RIGHT); 89 y += font.getHeight(); 90 g.drawString(speed, lonPos, y, Graphics.TOP | Graphics.RIGHT); 91 g.drawString(course, lonPos + GAP + GAP + courseWidth, y, Graphics.TOP | Graphics.RIGHT); 92 g.drawString(elevation, latPos, y, Graphics.TOP | Graphics.RIGHT); 93 g.drawString(point, rightPos, y, Graphics.TOP | Graphics.RIGHT); 136 final int spaceForCourse = latLonWidth - speedWidth - elevationWidth; 137 final int courseX = MARGIN + speedWidth + (spaceForCourse + courseWidth) / 2; 138 139 // speed / course / elevation (always on line 2) 140 g.drawString(speed, MARGIN + speedWidth, line2, Graphics.TOP | Graphics.RIGHT); 141 g.drawString(course, courseX, line2, Graphics.TOP | Graphics.RIGHT); 142 g.drawString(elevation, MARGIN + latLonWidth, line2, Graphics.TOP | Graphics.RIGHT); 143 144 final int lengthX; 145 int lengthY; 146 final int pointX; 147 int pointY; 148 149 if (twoLineLayout) { 150 lengthX = width - MARGIN; 151 lengthY = line1; 152 pointX = lengthX; 153 pointY = line2; 154 } else { 155 lengthX = width / 2; 156 lengthY = line2 + font.getHeight(); 157 pointX = width - MARGIN; 158 pointY = lengthY; 159 } 160 g.drawString(length, lengthX, lengthY, Graphics.TOP | Graphics.RIGHT); 161 g.drawString(point, pointX, pointY, Graphics.TOP | Graphics.RIGHT); 94 162 } 95 163 96 public int getPreferredHeight() { 97 return (MARGIN + font.getHeight()) * 2; 164 public void showNotify() { 165 // nothing to do 166 } 167 168 public int getPreferredHeight(final int width) { 169 final int lineCount = fitsTwoLineLayout(width) ? 2 : 3; 170 return MARGIN + font.getHeight() * lineCount + MARGIN; 98 171 } 99 172 }
Note: See TracChangeset
for help on using the changeset viewer.