Examples of FontMetrics


Examples of java.awt.FontMetrics

      }
      g.setFont(font);
      if (lines == 1 && !backs) {
        GraphicsUtil.drawCenteredText(g, label, x, y);
      } else {
        FontMetrics fm = g.getFontMetrics();
        int height = fm.getHeight();
        y = y - (height * lines - fm.getLeading()) / 2 + fm.getAscent();
        back = label.indexOf('\\');
        while (back >= 0 && back <= label.length() - 2) {
          char c = label.charAt(back + 1);
          if (c == 'n') {
            String line = label.substring(0, back);
View Full Code Here

Examples of java.awt.FontMetrics

    if (showState) {
      String str;
      int dispStart;
      int dispEnd;
      ArrayList<Integer> specials = new ArrayList<Integer>();
      FontMetrics fm = null;
      KeyboardData state = getKeyboardState(painter);
      synchronized(state) {
        str = state.toString();
        for (int i = state.getNextSpecial(0); i >= 0; i = state.getNextSpecial(i + 1)) {
          char c = state.getChar(i);
          specials.add(Integer.valueOf(c << 16 | i));
        }
        if (!state.isDisplayValid()) {
          fm = g.getFontMetrics(DEFAULT_FONT);
          state.updateDisplay(fm);
        }
        dispStart = state.getDisplayStart();
        dispEnd = state.getDisplayEnd();
      }
     
      if (str.length() > 0) {
        Bounds bds = painter.getBounds();
        drawBuffer(g, fm, str, dispStart, dispEnd, specials, bds);
      }
    } else {
      Bounds bds = painter.getBounds();
      int len = getBufferLength(painter.getAttributeValue(ATTR_BUFFER));
      String str = Strings.get("keybDesc", "" + len);
      FontMetrics fm = g.getFontMetrics();
      int x = bds.getX() + (WIDTH - fm.stringWidth(str)) / 2;
      int y = bds.getY() + (HEIGHT + fm.getAscent()) / 2;
      g.drawString(str, x, y);
    }
  }
View Full Code Here

Examples of java.awt.FontMetrics

   
    public void draw(InstancePainter painter) {
      KeyboardData data = getKeyboardState(painter);
      Bounds bds = painter.getInstance().getBounds();
      Graphics g = painter.getGraphics();
      FontMetrics fm = g.getFontMetrics(DEFAULT_FONT);

      String str;
      int cursor;
      int dispStart;
      synchronized(data) {
        str = data.toString();
        cursor = data.getCursorPosition();
        if (!data.isDisplayValid()) data.updateDisplay(fm);
        dispStart = data.getDisplayStart();
      }

      int asc = fm.getAscent();
      int x = bds.getX() + 8;
      if (dispStart > 0) {
        x += fm.stringWidth(str.charAt(0) + "m");
        x += fm.stringWidth(str.substring(dispStart, cursor));
      } else if (cursor >= str.length()) {
        x += fm.stringWidth(str);
      } else {
        x += fm.stringWidth(str.substring(0, cursor));
      }
      int y = bds.getY() + (bds.getHeight() + asc) / 2;
      g.drawLine(x, y - asc, x, y);
    }
View Full Code Here

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

Examples of java.awt.FontMetrics

    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

Examples of java.awt.FontMetrics

        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

Examples of java.awt.FontMetrics

  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

Examples of java.awt.FontMetrics

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

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

Examples of java.awt.FontMetrics

    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

Examples of java.awt.FontMetrics

      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
TOP
Copyright © 2018 www.massapi.com. 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.