private void drawGpsData(Graphics g) { g.setColor(RED); String strHeadline = MyLocale.getMsg(1501, "Current"); Double tmp = new Double(); String strSpeed = null; String unit = null; // Allow for different metric systems if (Global.getPref().metricSystem == Metrics.IMPERIAL) { tmp.set(Metrics.convertUnit(m_speed, Metrics.KILOMETER, Metrics.MILES)); unit = " mph"; strSpeed = "- mph"; } else { tmp.set(m_speed); unit = " km/h"; strSpeed = "- km/h"; } if (tmp.value >= 0) { if (tmp.value >= 100) { strSpeed = MyLocale.formatDouble(tmp, "0") + unit; } else { strSpeed = MyLocale.formatDouble(tmp, "0.0") + unit; } } tmp.set(moveDir); String strMoveDir = "---" + " " + MyLocale.getMsg(1502, "deg"); if ((tmp.value <= 360) && (tmp.value >= -360)) strMoveDir = tmp.toString(0, 0, 0) + " " + MyLocale.getMsg(1502, "deg"); int textWidth = java.lang.Math.max(fm.getTextWidth(strSpeed), fm.getTextWidth(strMoveDir)); textWidth = java.lang.Math.max(textWidth, fm.getTextWidth(strHeadline)); int startX = location.width - (textWidth + 4); g.fillRect(startX, 0, location.width - startX, lineHeight); g.setColor(Color.Black); g.drawText(strHeadline, startX + 2, 0); g.drawText(strSpeed, startX + 2, lineHeight); g.drawText(strMoveDir, startX + 2, 2 * lineHeight); }
private void drawWayPointData(Graphics g) { String strTemp = MyLocale.getMsg(1512, "Waypoint"); g.setColor(Color.DarkBlue); g.fillRect(0, 0, fm.getTextWidth(strTemp) + 4, lineHeight); g.setColor(Color.White); g.drawText(strTemp, 2, 0); g.setColor(Color.Black); int metricSystem = Global.getPref().metricSystem; Double tmp = new Double(); strTemp = ""; double newDistance = 0; int bigUnit = -1; int smallUnit = -1; double threshold = -1; // Allow for different metric systems if (metricSystem == Metrics.IMPERIAL) { // Why these values? See: http://tinyurl.com/b4nn9m bigUnit = Metrics.MILES; smallUnit = Metrics.FEET; threshold = 0.1; newDistance = Metrics.convertUnit(distance, Metrics.KILOMETER, Metrics.MILES); } else { bigUnit = Metrics.KILOMETER; smallUnit = Metrics.METER; threshold = 1.0; newDistance = distance; } if (newDistance >= 0.0f) { tmp.set(newDistance); if (tmp.value >= threshold) { strTemp = MyLocale.formatDouble(tmp, "0.000") + " " + Metrics.getUnit(bigUnit); } else { tmp.set(Metrics.convertUnit(tmp.value, bigUnit, smallUnit)); strTemp = tmp.toString(3, 0, 0) + " " + Metrics.getUnit(smallUnit); } } else strTemp = "--- " + Metrics.getUnit(bigUnit); g.drawText(strTemp, 2, lineHeight); tmp.set(gotoDir); if ((tmp.value <= 360) && (tmp.value >= -360)) strTemp = tmp.toString(0, 0, 0) + " " + MyLocale.getMsg(1502, "deg"); else strTemp = "---" + " " + MyLocale.getMsg(1502, "deg"); g.drawText(strTemp, 2, 2 * lineHeight); }