Package java.awt

Examples of java.awt.FontMetrics


        slider = new JSlider(JSlider.VERTICAL, modelMin, modelMax, modelValue);
        valueLabel = new JLabel() {
            @Override
            public Dimension getPreferredSize() {
                FontMetrics fm = getFontMetrics(getFont());
                return new Dimension(fm.stringWidth("-20.00dB"), fm.getHeight());
            }
        };

        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
View Full Code Here


    /* tick-labels */
    if (drawTicks) {
      g.setColor(LABEL_COLOR);
      Font font = new Font(LBL_FONT_NAME, Font.PLAIN, LBL_FONT_SIZE);
      g.setFont(font);
      FontMetrics fm = g.getFontMetrics();
      int yFontOffset = fm.getMaxAscent();
      FontRenderContext frc = fm.getFontRenderContext();
      {
        double dx = envelope.getViewXMax() - envelope.getViewXMin();
        double step = Tools.FTOI(dx / (double) xnum);
        if (step < 1.0)
          step = 1.0;
View Full Code Here

            break;
        }
        res.font = new Font(this.fontName, fontStyle, this.fontSize);
      }
      g.setFont(res.font);
      FontMetrics fm = g.getFontMetrics();
      res.yOffset = fm.getMaxAscent();
      FontRenderContext frc = fm.getFontRenderContext();
      for (TextRow row : pRows) {
        Rectangle2D rect = res.font.getStringBounds(row.text, frc);
        row.width = (int) (rect.getWidth() + 0.5);
        row.height = (int) (rect.getHeight() + 0.5);
        if (this.mode == Mode.OUTLINE) {
View Full Code Here

    }

    public FontMetrics getFontMetrics(Font f) {
        Graphics2D g2d = getBogusGraphics2D();

        FontMetrics fontMetrics = g2d.getFontMetrics(f);

        g2d.dispose();

        return fontMetrics;
    }
View Full Code Here

    }

    public FontMetrics getFontMetrics(Font f) {
        Graphics2D g2d = getBogusGraphics2D(true);

        FontMetrics fontMetrics = g2d.getFontMetrics(f);

        g2d.dispose();

        return fontMetrics;
    }
View Full Code Here

    final String text = getText() + ' ';
    final String[] textSplited = text.split("\n"); //$NON-NLS-1$
    Rectangle2D rec;
    double width   = 0.;
    double height   = 0.;
    final FontMetrics fm   = getFontMetrics(getFont());
    final double heightInc   = fm.getHeight();

    if(textSplited.length>0) // Removing the space added at the beginning of the method.
      textSplited[textSplited.length-1] = textSplited[textSplited.length-1].substring(0, textSplited[textSplited.length-1].length()-1);

    for(final String str : textSplited) {
      rec = fm.getStringBounds(str, null);
      if(rec.getWidth()>width)
        width = rec.getWidth();
      height += heightInc;
    }

    setBounds(getX(), getY(), (int)width+10, (int)height);

    if(!msg.getText().isEmpty())
      msg.setBounds(getX(), getY()+getHeight(), (int)fm.getStringBounds(msg.getText(), null).getWidth()+2, (int)heightInc+2);
  }
View Full Code Here

    final boolean isXLabelSouth = shape.isXLabelSouth();
    final boolean isYLabelWest   = shape.isYLabelWest();
    final double originX     = shape.getOriginX();
    final double originY     = shape.getOriginY();
    final Color gridLabelsColor = shape.getGridLabelsColour();
    final FontMetrics fontMetrics = FontDesignMetrics.getMetrics(new Font(null, Font.PLAIN, shape.getLabelsSize()));
    final float labelHeight   = fontMetrics.getAscent();
    final float labelWidth     = fontMetrics.stringWidth(String.valueOf((int)maxX));
    final double xorigin = xStep*originX;
    final double yorigin = isXLabelSouth  ? yStep*originY+labelHeight : yStep*originY-2;
    final double width=gridWidth/2.;
    final double tmp = isXLabelSouth ? width : -width;
    final SVGElement texts = new SVGGElement(document);
    SVGElement text;
    String label;
    double i;
    double j;

    texts.setAttribute(SVGAttributes.SVG_FONT_SIZE, String.valueOf(shape.getLabelsSize()));
    texts.setAttribute(SVGAttributes.SVG_STROKE, CSSColors.INSTANCE.getColorName(gridLabelsColor, true));
    texts.setAttribute(prefix+LNamespace.XML_TYPE, LNamespace.XML_TYPE_TEXT);

    for(i=tlx + (isYLabelWest ? width+gridLabelsSize/4. : -width-labelWidth-gridLabelsSize/4.), j=minX; j<=maxX; i+=absStep, j++) {
      text = new SVGTextElement(document);
      text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int)i));
      text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int)(yorigin+tmp)));
      text.setTextContent(String.valueOf((int)j));
      texts.appendChild(text);
    }

    if(isYLabelWest)
      for(i=tly + (isXLabelSouth ? -width-gridLabelsSize/4. : width+labelHeight), j=maxY ; j>=minY; i+=absStep, j--) {
        label = String.valueOf((int)j);
        text = new SVGTextElement(document);
        text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int)(xorigin-fontMetrics.stringWidth(label)-gridLabelsSize/4.-width)));
        text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int)i));
        text.setTextContent(label);
        texts.appendChild(text);
      }
    else
View Full Code Here

            final Rectangle2D textBounds) {

        final float[] result = new float[3];
        final FontRenderContext frc = g2.getFontRenderContext();
        final Font f = g2.getFont();
        final FontMetrics fm = g2.getFontMetrics(f);
        final Rectangle2D bounds = TextUtilities.getTextBounds(text, g2, fm);
        final LineMetrics metrics = f.getLineMetrics(text, frc);
        final float ascent = metrics.getAscent();
        result[2] = -ascent;
        final float halfAscent = ascent / 2.0f;
View Full Code Here

            final String text, final TextAnchor anchor) {

        final float[] result = new float[2];
        final FontRenderContext frc = g2.getFontRenderContext();
        final Font f = g2.getFont();
        final FontMetrics fm = g2.getFontMetrics(f);
        final Rectangle2D bounds = TextUtilities.getTextBounds(text, g2, fm);
        final LineMetrics metrics = f.getLineMetrics(text, frc);
        final float ascent = metrics.getAscent();
        final float halfAscent = ascent / 2.0f;
        final float descent = metrics.getDescent();
View Full Code Here

            final String text, final TextAnchor anchor) {

        final float[] result = new float[2];
        final FontRenderContext frc = g2.getFontRenderContext();
        final LineMetrics metrics = g2.getFont().getLineMetrics(text, frc);
        final FontMetrics fm = g2.getFontMetrics();
        final Rectangle2D bounds = TextUtilities.getTextBounds(text, g2, fm);
        final float ascent = metrics.getAscent();
        final float halfAscent = ascent / 2.0f;
        final float descent = metrics.getDescent();
        final float leading = metrics.getLeading();
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.