Package java.awt

Examples of java.awt.FontMetrics


    int lineY = top + cellHeight + HEADER_SEP / 2;
    g.drawLine(left, lineY, left + tableWidth, lineY);
   
    g.setColor(Color.BLACK);
    g.setFont(HEAD_FONT);
    FontMetrics headerMetric = g.getFontMetrics();
    int x = left;
    int y = top + headerMetric.getAscent() + 1;
    for (int i = 0; i < columns; i++) {
      x = paintHeader(sel.get(i).toShortString(), x, y, g, headerMetric);
    }
   
    g.setFont(BODY_FONT);
    FontMetrics bodyMetric = g.getFontMetrics();
    Rectangle clip = g.getClipBounds();
    int firstRow = Math.max(0, (clip.y - y) / cellHeight - 1);
    int lastRow = Math.min(rowCount, 2 + (clip.y + clip.height - y) / cellHeight);
    int y0 = top + cellHeight + HEADER_SEP;
    x = left;
    for (int col = 0; col < columns; col++) {
      SelectionItem item = sel.get(col);
      ValueLog log = model.getValueLog(item);
      int radix = item.getRadix();
      int offs = rowCount - log.size();
      y = y0 + Math.max(offs, firstRow) * cellHeight;
      for (int row = Math.max(offs, firstRow); row < lastRow; row++) {
        Value val = log.get(row - offs);
        String label = val.toDisplayString(radix);
        int width = bodyMetric.stringWidth(label);
        g.drawString(label, x + (cellWidth - width) / 2,
            y + bodyMetric.getAscent());
        y += cellHeight;
      }
      x += cellWidth + COLUMN_SEP;
    }
  }
View Full Code Here


    Graphics g = getGraphics();
    if (g == null) {
      cellHeight = 16;
      cellWidth = 24;
    } else {
      FontMetrics fm = g.getFontMetrics(HEAD_FONT);
      cellHeight = fm.getHeight();
      cellWidth = 24;
      for (int i = 0; i < columns; i++) {
        String header = sel.get(i).toShortString();
        cellWidth = Math.max(cellWidth, fm.stringWidth(header));
      }
    }
   
    tableWidth = (cellWidth + COLUMN_SEP) * columns - COLUMN_SEP;
    tableHeight = cellHeight * (1 + rowCount) + HEADER_SEP;
View Full Code Here

        curCol = state.getCursorColumn();
      }

      g.setFont(DEFAULT_FONT);
      g.setColor(painter.getAttributeValue(Io.ATTR_COLOR));
      FontMetrics fm = g.getFontMetrics();
      int x = bds.getX() + BORDER;
      int y = bds.getY() + BORDER + (ROW_HEIGHT + fm.getAscent()) / 2;
      for (int i = 0; i < rows; i++) {
        g.drawString(rowData[i], x, y);
        if (i == curRow) {
          int x0 = x + fm.stringWidth(rowData[i].substring(0, curCol));
          g.drawLine(x0, y - fm.getAscent(), x0, y);
        }
        y += ROW_HEIGHT;
      }
    } else {
      String str = Strings.get("ttyDesc", "" + rows, "" + cols);
      FontMetrics fm = g.getFontMetrics();
      int strWidth = fm.stringWidth(str);
      if (strWidth + BORDER > bds.getWidth()) {
        str = Strings.get("ttyDescShort");
        strWidth = fm.stringWidth(str);
      }
      int x = bds.getX() + (bds.getWidth() - strWidth) / 2;
      int y = bds.getY() + (bds.getHeight() + fm.getAscent()) / 2;
      g.drawString(str, x, y);
    }
  }
View Full Code Here

  public static int getStringWidth(Font font, String str) {
    if (str == null) {
      return 0;
    }

    FontMetrics metrics = HELPER_LABEL.getFontMetrics(font);
    return metrics.stringWidth(str);
  }
View Full Code Here

      int length) {
    if (chars == null) {
      return 0;
    }

    FontMetrics metrics = HELPER_LABEL.getFontMetrics(font);
    return metrics.charsWidth(chars, offset, length);
  }
View Full Code Here

    setUI(toolTipUI);
  }

  private class IconToolTipUI extends MetalToolTipUI {
    public void paint(Graphics g, JComponent c) {
      FontMetrics metrics = c.getFontMetrics(c.getFont());
      Dimension size = c.getSize();
      g.setColor(c.getBackground());
      g.fillRect(0, 0, size.width, size.height);
      int x = 3;
      if (icon != null) {
        icon.paintIcon(c, g, 1, 1);
        x += icon.getIconWidth() + 1;
      }
      g.setColor(c.getForeground());
      String text = ((JToolTip) c).getTipText();
      if (text != null && text.length() > 0) {
        g.drawString(text, x, metrics.getHeight());
      }
    }
View Full Code Here

      String tipText = ((JToolTip) c).getTipText();
      // avoid painting by returning empty dimension for no text and no icon
      if (icon == null && (tipText == null || tipText.length() == 0)) {
        return new Dimension(0, 0);
      }
      FontMetrics metrics = c.getFontMetrics(c.getFont());
      if (tipText == null) {
        tipText = "";
      }
      int width = SwingUtilities.computeStringWidth(metrics, tipText);
      int height = metrics.getHeight() + 4;
      if (icon != null) {
        width += icon.getIconWidth() + 2;
        int iconHeight = icon.getIconHeight() + 2;
        if (iconHeight > height) {
          height = iconHeight;
View Full Code Here

public TextFieldWidget(SectionWidget sw, Field field) {
    super(sw, field);

    // Calculate line height.
    Font f = field.getFormat().getFont();
    FontMetrics fm = swingField.getComponent().getFontMetrics(f);
    lineHeight = fm.getHeight();
}
View Full Code Here

  else formatted = getDateFormatterFor(fmtStr).format((Date)value);
    }
    else {
  formatted = value.toString();
  if (format.isWrap()) {
      FontMetrics fm =
        getWrappingCalcsLabel().getFontMetrics(format.getFont());
      formatted =
    StringUtils.join(StringUtils.wrap(formatted, fm,
              (int)field.getBounds().width),
         "\n");
View Full Code Here

      }
    }

    // draw everything onto an image before drawing to avoid flicker
    Graphics og = offscreen.getGraphics();
    FontMetrics fm = og.getFontMetrics();

    // clear background color
    og.setColor(bgColor);
    og.fillRect(0, 0, offscreen.getWidth(null), offscreen.getHeight(null));

    og.setColor(fgColor);
    String message = getDescriptionForState();

    // if we had a failure of some sort, notify the user
    if (fatalError) {
      String[] errorMessage = (certificateRefused) ? certificateRefusedMessage : genericErrorMessage;

      for(int i=0; i<errorMessage.length; i++) {
        if(errorMessage[i] != null) {
          int messageX = (offscreen.getWidth(null) - fm.stringWidth(errorMessage[i])) / 2;
          int messageY = (offscreen.getHeight(null) - (fm.getHeight() * errorMessage.length)) / 2;

          og.drawString(errorMessage[i], messageX, messageY + i*fm.getHeight());
        }
      }
    } else {
      og.setColor(fgColor);

      painting = true;

      // get position at the middle of the offscreen buffer
      int x = offscreen.getWidth(null)/2;
      int y = offscreen.getHeight(null)/2;

      // draw logo
      if (logo != null) {
        og.drawImage(logoBuffer, x-logo.getWidth(null)/2, y-logo.getHeight(null)/2, this);
      }

      // draw message
      int messageX = (offscreen.getWidth(null) - fm.stringWidth(message)) / 2;
      int messageY = y + 20;

      if (logo != null) messageY += logo.getHeight(null)/2;
      else if (progressbar != null) messageY += progressbar.getHeight(null)/2;

      og.drawString(message, messageX, messageY);

      // draw subtaskmessage, if any
      if(subtaskMessage.length() > 0) {
        messageX = (offscreen.getWidth(null) - fm.stringWidth(subtaskMessage)) / 2;
        og.drawString(subtaskMessage, messageX, messageY+20);
      }

      // draw loading bar, clipping it depending on percentage done
      if (progressbar != null) {
View Full Code Here

TOP

Related Classes of java.awt.FontMetrics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.