Package java.awt

Examples of java.awt.FontMetrics


    grp.setClip(clipBounds);

    // Paint the copyright notices
    grp.setColor(Settings.propProgramPanelForegroundColor.getColor());
    Channel[] channelArr = mModel.getShownChannels();
    FontMetrics metric = grp.getFontMetrics();
    for (Channel channel : channelArr) {
      String msg = channel.getCopyrightNotice();
      // repeatedly reduce the font size while the copyright notice is wider than the column
      while (metric.stringWidth(msg) > mColumnWidth) {
        Font font = grp.getFont();
        grp.setFont(font.deriveFont((float)(font.getSize()-1)));
        metric = grp.getFontMetrics();
      }
    }
View Full Code Here


  rep = "None";
      }
      java.awt.Font originalFont = gfx.getFont();
      gfx.setFont(originalFont.deriveFont(java.awt.Font.BOLD));

      FontMetrics fm = gfx.getFontMetrics();
      int vpad = (box.height - fm.getHeight());
      gfx.drawString(rep, 2, fm.getAscent() + vpad);
      int repwidth = fm.stringWidth(rep);

      gfx.setFont(originalFont);
      if ((m_Object instanceof OptionHandler) && !(m_Object instanceof CustomDisplayStringProvider)) {
  gfx.drawString(" " + Utils.joinOptions(((OptionHandler)m_Object).getOptions()),
                 repwidth + 2, fm.getAscent() + vpad);
      }
    }
  }
View Full Code Here

   * @param gfx the graphics context to use
   * @param box the area we are allowed to paint into
   */
  public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box) {

    FontMetrics fm = gfx.getFontMetrics();
    int vpad = (box.height - fm.getHeight()) / 2;
    String rep = m_ListModel.getSize() + " " + m_ElementClass.getName();
    gfx.drawString(rep, 2, fm.getAscent() + vpad + 2);
  }
View Full Code Here

    }
   
    public Dimension getPreferredSize() {

      Font f = this.getFont();
      FontMetrics fm = this.getFontMetrics(f);
      return new Dimension(0, fm.getHeight());
    }
  };
      } catch (Exception ex) {
  return null;
      }
View Full Code Here

  public Dimension getPreferredSize() {
    if(mPreferredSize != null) {
      return mPreferredSize;
    }
   
    FontMetrics fmBold = getFontMetrics(mBoldFont);
    FontMetrics fmPlain = getFontMetrics(mPlainFont);
   
    int height = mIconHeight;
    int width = fmPlain.stringWidth(mProgram.getTitle().length() > 70 ? mProgram.getTitle().substring(0,67) + "..." : mProgram.getTitle()) + mInsets.left + mInsets.right + 10;
   
    if(height != 0) {
      width += mIcon.getIconWidth() + getIconTextGap();
    } else {
      width += 30;
    }
   
    if(mShowName) {
      width += Settings.propTrayChannelWidth.getInt() + getIconTextGap();
    }
    if(mShowStartTime) {
      width += TIME_WIDTH;
    }
    if(mShowDate) {
      width += DATE_WIDTH;
    }
   
    if(height == 0) {
      if(mShowStartTime || mShowDate) {
        height = fmBold.getHeight();
      } else {
        height = fmPlain.getHeight();
      }
     
      height += mInsets.top + mInsets.bottom;
    } else {
      height += 2;
View Full Code Here

        g2d.drawRoundRect((int) rect.getX(), (int) rect.getY(),
                (int) rect.getWidth(), (int) rect.getHeight(), arc, arc);

        g2d.clip(rect);
        if (text != null) {
            FontMetrics metrics = g2d.getFontMetrics(g2d.getFont());
            ArrayList<TextLayout> layouts = breakLines((int) rect.getWidth() - textWidthOffset * 2,
                    text, metrics);

            int textHeight = metrics.getHeight();
            int top = textHeight;
            for (TextLayout layout : layouts) {
                layout.draw(g2d, (float) rect.getX() + textWidthOffset, (float) rect.getY() + top);
                top += textHeight;
            }
View Full Code Here

    return tip;
  }

  @Override
  public Point getToolTipLocation(MouseEvent event) {
    FontMetrics metrics = this.getFontMetrics(this.getFont());
    int stringWidth = SwingUtilities.computeStringWidth(metrics, this.getText());
    int x = 0;
    Icon icon = this.getIcon();

    int iconWidth = getIcon().getIconWidth();
View Full Code Here

        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

        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

     
      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

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.