コード例 #1
0
  private void drawGpsStatus(Graphics g) {
    if ((m_fix > 0) && (m_sats >= 0)) {
      // Set background to signal quality
      g.setColor(GREEN);
    } else
    // receiving data, but signal ist not good
    if ((m_fix == 0) && (m_sats >= 0)) {
      g.setColor(YELLOW);
    } else {
      g.setColor(RED);
    }

    String strSats = "Sats: -";
    if (m_sats >= 0) {
      strSats = "Sats: " + Convert.toString(m_sats) + "/" + Convert.toString(m_satsInView);
    }
    String strHdop = "HDOP: -";
    if (m_hdop >= 0) strHdop = "HDOP: " + Convert.toString(m_hdop);

    int textWidth = java.lang.Math.max(fm.getTextWidth(strSats), fm.getTextWidth(strHdop));
    int startX = location.width - (textWidth + 4);
    int startY = location.height - 2 * lineHeight;
    g.fillRect(startX, startY, location.width - startX, location.height - startY);

    g.setColor(Color.Black);
    g.drawText(strSats, startX + 2, startY);
    g.drawText(strHdop, startX + 2, startY + lineHeight);
  }
コード例 #2
0
  private void drawLuminaryData(Graphics g) {
    g.setColor(YELLOW);

    String strSunDir = "---" + " " + MyLocale.getMsg(1502, "deg");
    if (sunDir < 360 && sunDir > -360) {
      Double tmp = new Double();
      tmp.set(sunDir);
      strSunDir = tmp.toString(0, 0, 0) + " " + MyLocale.getMsg(1502, "deg");
    }

    int textWidth = java.lang.Math.max(fm.getTextWidth(m_Luminary), fm.getTextWidth(strSunDir));
    int startY = location.height - 2 * lineHeight;
    g.fillRect(0, startY, textWidth + 4, location.height - startY);

    g.setColor(Color.Black);
    g.drawText(m_Luminary, 2, startY);
    g.drawText(strSunDir, 2, startY + lineHeight);
  }
コード例 #3
0
  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);
  }
コード例 #4
0
  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);
  }
コード例 #5
0
  private void drawRosePart(
      Graphics g,
      float angle,
      Color colLeft,
      Color colRight,
      Color colBorder,
      Color colText,
      float scale,
      float innerScale,
      String strDir,
      boolean bDrawText) {
    float angleRad = angle * (float) java.lang.Math.PI / 180;
    float angleRadText = (angle + 7.5f) * (float) java.lang.Math.PI / 180;
    int centerX = location.width / 2, centerY = location.height / 2;

    float arrowLength = roseRadius * scale;
    float halfArrowWidth = arrowLength * innerScale;

    int[] pointsX = new int[3];
    int[] pointsY = new int[3];

    pointsX[0] = centerX;
    pointsY[0] = centerY;
    pointsX[1] = centerX + new Float(arrowLength * java.lang.Math.sin(angleRad)).intValue();
    pointsY[1] = centerY - new Float(arrowLength * java.lang.Math.cos(angleRad)).intValue();
    pointsX[2] =
        centerX
            + new Float(halfArrowWidth * java.lang.Math.sin(angleRad - java.lang.Math.PI / 4.0))
                .intValue();
    pointsY[2] =
        centerY
            - new Float(halfArrowWidth * java.lang.Math.cos(angleRad - java.lang.Math.PI / 4.0))
                .intValue();

    g.setPen(new Pen(colBorder, Pen.SOLID, 1));
    g.setBrush(new Brush(colLeft, Brush.SOLID));
    g.fillPolygon(pointsX, pointsY, 3);

    pointsX[2] =
        centerX
            + new Float(halfArrowWidth * java.lang.Math.sin(angleRad + java.lang.Math.PI / 4.0))
                .intValue();
    pointsY[2] =
        centerY
            - new Float(halfArrowWidth * java.lang.Math.cos(angleRad + java.lang.Math.PI / 4.0))
                .intValue();

    g.setBrush(new Brush(colRight, Brush.SOLID));
    g.fillPolygon(pointsX, pointsY, 3);

    if (bDrawText) {
      int tempFontSize = new Float(scale * mainFont.getSize()).intValue();
      Font tempFont = new Font(mainFont.getName(), Font.BOLD, tempFontSize);
      g.setFont(tempFont);
      FontMetrics tempFm = g.getFontMetrics(tempFont);
      float stringHeight = tempFm.getHeight();
      float stringWidth = tempFm.getTextWidth(strDir);
      float stringGap =
          (float) java.lang.Math.sqrt(stringHeight * stringHeight + stringWidth * stringWidth);

      float stringPosition = arrowLength - stringGap / 2.0f;
      g.setColor(colText);
      g.drawText(
          strDir,
          centerX
              + new Float(stringPosition * java.lang.Math.sin(angleRadText) - stringWidth / 2.0f)
                  .intValue(),
          centerY
              - new Float(stringPosition * java.lang.Math.cos(angleRadText) + stringHeight / 2.0f)
                  .intValue());

      g.setFont(mainFont);
    }
  }