コード例 #1
0
  protected void paint(AbstractTnGraphics graphics) {
    NavBottomStatusBarHelper.getInstance().drawBackground(graphics, this, false);

    if (isDisabled) {
      return;
    }

    int width = this.getWidth();
    int height = this.getHeight();

    AbstractTnFont fontNumber =
        UiStyleManager.getInstance().getFont(UiStyleManager.FONT_SPEED_LIMIT_NUMBER);
    AbstractTnFont fontUnit = UiStyleManager.getInstance().getFont(UiStyleManager.FONT_SPEED_LIMIT);

    int gap = (height - fontNumber.getHeight() - fontUnit.getHeight()) / 3;
    int xNumber = (width - fontNumber.stringWidth(speedStr)) / 2;
    int yNumber = (height - fontNumber.getHeight() - fontUnit.getHeight() - gap) / 2;

    int xUnit = (width - fontUnit.stringWidth(unitStr)) / 2;
    int yUnit = yNumber + fontNumber.getHeight() + gap;

    graphics.setColor(UiStyleManager.getInstance().getColor(UiStyleManager.TEXT_COLOR_WH));
    graphics.setFont(fontNumber);
    graphics.drawString(
        speedStr, xNumber, yNumber, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP);
    graphics.setFont(fontUnit);
    graphics.drawString(unitStr, xUnit, yUnit, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP);
  }
コード例 #2
0
  protected void paint(AbstractTnGraphics g) {
    // g.setColor(isFocused ? bgFocusedColor : bgUnFocusedColor);
    // g.fillRect(0, 0, this.getPreferredWidth(), this.getPreferredHeight());
    super.paint(g);
    boolean isTitleAvailable = (title != null && title.length() > 0);
    boolean isValueAvailable = (value != null && value.length() > 0);

    int titleY = topGap;

    AbstractTnFont titleFont = getTitleFont();
    if (titleFont == null) {
      titleFont = g.getFont();
    }

    AbstractTnFont valueFont = getValueFont();
    if (valueFont == null) {
      valueFont = g.getFont();
    }

    if (isTitleAvailable) {
      if (isValueAvailable) {
        titleY = topGap;
      } else {
        titleY = (this.getPreferredHeight() - titleFont.getHeight()) / 2;
      }
      g.setColor(isFocused ? titleFocusedColor : this.titleUnFocuedColor);
      g.setFont(titleFont);
      g.drawString(
          title, this.getLeftPadding(), titleY, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP);
    }

    if (isValueAvailable) {
      int ValueY;
      if (isTitleAvailable) {
        ValueY = titleY + LINE_GAP + titleFont.getHeight();
      } else {
        ValueY = (this.getPreferredHeight() - valueFont.getHeight()) / 2;
      }

      g.setColor(isFocused ? valueFocusedColor : this.valueUnFocusedColor);
      g.setFont(valueFont);
      if (valueFont.stringWidth(value) < this.getPreferredWidth() - 2 * leftPadding) {
        g.drawString(
            value, this.getLeftPadding(), ValueY, AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP);
      } else {
        String tempValue = value;
        while (valueFont.stringWidth(tempValue + "...")
            > this.getPreferredWidth() - 2 * this.getLeftPadding()) {
          tempValue = tempValue.substring(0, tempValue.length() - 1);
        }
        g.drawString(
            tempValue + "...",
            this.getLeftPadding(),
            ValueY,
            AbstractTnGraphics.LEFT | AbstractTnGraphics.TOP);
      }
    }
  }