Examples of FontMetrics


Examples of java.awt.FontMetrics

        model_ = new BinaryModel();
        updateUI();
    }

    public Dimension getPreferredSize() {
        FontMetrics fm = getFontMetrics(getFont());
        return new Dimension(
            fm.charWidth('0')*68,
            fm.getHeight()*(model_.getLength()+15)/16
        );
    }
View Full Code Here

Examples of java.awt.FontMetrics

        return model_;
    }

    public void paintComponent(Graphics g) {
        Rectangle clipRect = g.getClipBounds();
        FontMetrics fm = getFontMetrics(getFont());

        g.setColor(getBackground());
        g.fillRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
        g.setColor(getForeground());

        int startLine = clipRect.y / fm.getHeight();
        int endLine = Math.min(
            (clipRect.y + clipRect.height) / fm.getHeight() + 1,
            (model_.getLength()+15) / 16
        );
        byte[] bytes = new byte[16];
        char[] chars = new char[69];

        // for each visible line
        for ( ; startLine < endLine; startLine++) {
            Arrays.fill(chars, ' ');

            int offset = 1;

            // write the line address
            int address = startLine*16;
            for (int i=0; i < 8; i++) {
                chars[offset++] = HEX[address >>> 28];
                address <<= 4;
            }
            offset += 2;
            chars[9] = '>';

            int len = model_.getBytes(startLine*16,16,bytes);
            for(int i=0; i<len; i++) {
                // write the data as hexadecimal digits
                chars[offset++] = HEX[ (bytes[i] >>> 4) & 0x0f];
                chars[offset++] = HEX[bytes[i] & 0x0f];

                // write the data as characters
                char ch = (char) (bytes[i] & 0xff);
                chars[i + 48 + i / 4] = Character.isISOControl(ch) ? '.' : ch;

                if (i % 4 == 3) {
                    offset++;
                }

            }

            g.drawString(
                new String(chars),
                0,
                startLine*fm.getHeight()+fm.getAscent()
            );
        }
    }
View Full Code Here

Examples of java.awt.FontMetrics

     
      Circuit circ = circuits.get(pageIndex);
      CircuitState circState = proj.getCircuitState(circ);
      Graphics g = base.create();
      Graphics2D g2 = g instanceof Graphics2D ? (Graphics2D) g : null;
      FontMetrics fm = g.getFontMetrics();
      String head = (header != null && !header.equals(""))
        ? format(header, pageIndex + 1, circuits.size(),
            circ.getName())
        : null;
      int headHeight = (head == null ? 0 : fm.getHeight());

      // Compute image size
      double imWidth = format.getImageableWidth();
      double imHeight = format.getImageableHeight();
     
      // Correct coordinate system for page, including
      // translation and possible rotation.
      Bounds bds = circ.getBounds(g).expand(4);
      double scale = Math.min(imWidth / bds.getWidth(),
          (imHeight - headHeight) / bds.getHeight());
      if (g2 != null) {
        g2.translate(format.getImageableX(), format.getImageableY());
        if (rotateToFit && scale < 1.0 / 1.1) {
          double scale2 = Math.min(imHeight / bds.getWidth(),
              (imWidth - headHeight) / bds.getHeight());
          if (scale2 >= scale * 1.1) { // will rotate
            scale = scale2;
            if (imHeight > imWidth) { // portrait -> landscape
              g2.translate(0, imHeight);
              g2.rotate(-Math.PI / 2);
            } else { // landscape -> portrait
              g2.translate(imWidth, 0);
              g2.rotate(Math.PI / 2);
            }
            double t = imHeight;
            imHeight = imWidth;
            imWidth = t;
          }
        }
      }
     
      // Draw the header line if appropriate
      if (head != null) {
        g.drawString(head,
            (int) Math.round((imWidth - fm.stringWidth(head)) / 2),
            fm.getAscent());
        if (g2 != null) {
          imHeight -= headHeight;
          g2.translate(0, headHeight);
        }
      }
View Full Code Here

Examples of java.awt.FontMetrics

      int index = -1;
      for (CreditsLine line : lines) {
        index++;
        if (index == initialLines) initialHeight = y;
        if (line.type == 0) y += 10;
        FontMetrics fm = fms[line.type];
        line.y = y + fm.getAscent();
        y += fm.getHeight();
      }
      linesHeight = y;
    }
   
    Paint[] paint = paintSteady;
View Full Code Here

Examples of java.awt.FontMetrics

      if (AppPreferences.SHOW_TICK_RATE.getBoolean()) {
        String hz = tickCounter.getTickRate();
        if (hz != null && !hz.equals("")) {
          g.setColor(TICK_RATE_COLOR);
          g.setFont(TICK_RATE_FONT);
          FontMetrics fm = g.getFontMetrics();
          int x = getWidth() - fm.stringWidth(hz) - 5;
          int y = fm.getAscent() + 5;
          g.drawString(hz, x, y);
        }
      }

      GraphicsUtil.switchToWidth(g, 1);
View Full Code Here

Examples of java.awt.FontMetrics

    }
   
    private void paintString(Graphics g, String msg) {
      Font old = g.getFont();
      g.setFont(old.deriveFont(Font.BOLD).deriveFont(18.0f));
      FontMetrics fm = g.getFontMetrics();
      int x = (getWidth() - fm.stringWidth(msg)) / 2;
      if (x < 0) x = 0;
      g.drawString(msg, x, getHeight() - 23);
      g.setFont(old);
      return;
    }
View Full Code Here

Examples of java.awt.FontMetrics

    private static int toDim(int offs) {
      return offs * 3 / 2;
    }
     
    private void drawText(Graphics g, int x, int y) {
      FontMetrics fm;
      String str;
     
      g.setColor(headerColor);
      g.setFont(headerFont);
      g.drawString("Logisim", x, y + 45);
      g.setFont(copyrightFont); fm = g.getFontMetrics();
      str = "\u00a9 " + Main.COPYRIGHT_YEAR;
      g.drawString(str, x + IMAGE_WIDTH - fm.stringWidth(str), y + 16);
      g.setFont(versionFont); fm = g.getFontMetrics();
      str = "Version " + Main.VERSION_NAME;
      g.drawString(str, x + IMAGE_WIDTH - fm.stringWidth(str), y + 75);
    }
View Full Code Here

Examples of java.awt.FontMetrics

    int w;
    int border = EditableLabelField.FIELD_BORDER;
    if (dimsKnown) {
      w = width + 1 + 2 * border;
    } else {
      FontMetrics fm = field.getFontMetrics(font);
      ascent = fm.getAscent();
      descent = fm.getDescent();
      w = 0;
    }
   
    int x0 = x;
    int y0 = getBaseY() - ascent;
View Full Code Here

Examples of java.awt.FontMetrics

  }

  public Bounds getBounds(Graphics g) {
    int x = this.x;
    int y = this.y;
    FontMetrics fm;
    if (font == null)   fm = g.getFontMetrics();
    else                fm = g.getFontMetrics(font);
    int width = fm.stringWidth(text);
    int ascent = fm.getAscent();
    int descent = fm.getDescent();
    switch (halign) {
    case TextField.H_CENTER:    x -= width / 2; break;
    case TextField.H_RIGHT:  x -= width; break;
    default:                    break;
    }
View Full Code Here

Examples of java.awt.FontMetrics

    Font old = g.getFont();
    if (font != null) g.setFont(font);

    int x = this.x;
    int y = this.y;
    FontMetrics fm = g.getFontMetrics();
    int width = fm.stringWidth(text);
    int ascent = fm.getAscent();
    int descent = fm.getDescent();
    switch (halign) {
    case TextField.H_CENTER:    x -= width / 2; break;
    case TextField.H_RIGHT:  x -= width; break;
    default:                    break;
    }
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.