当前位置: 首页>>代码示例>>Java>>正文


Java LineMetrics.getHeight方法代码示例

本文整理汇总了Java中java.awt.font.LineMetrics.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java LineMetrics.getHeight方法的具体用法?Java LineMetrics.getHeight怎么用?Java LineMetrics.getHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.font.LineMetrics的用法示例。


在下文中一共展示了LineMetrics.getHeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createImageWithOverlay

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Add overlay text to the image and save as a .jpg file.
 *
 * @param  image        a java.awt.Image to add the text overlay to
 * @param  overlayText  The text to overlay onto the image
 * @return
 */
public static BufferedImage createImageWithOverlay(final Image image, final String[] overlayText) {

    // Copy BufferedImage and set .jpg file name
    final BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null),
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g = (Graphics2D) bi.getGraphics();
    g.drawImage(image, 0, 0, null);
    final Font font = new Font("Monospaced", Font.PLAIN, 14);
    g.setFont(font);
    g.setColor(Color.CYAN);
    final FontRenderContext frc = g.getFontRenderContext();
    int x = 1;
    int n = 1;
    for (String s : overlayText) {
        LineMetrics lineMetrics = font.getLineMetrics(s, frc);
        float y = (lineMetrics.getHeight() + 1) * n + lineMetrics.getHeight();
        g.drawString(s, x, y);
        n++;
    }

    g.dispose();

    return bi;
}
 
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:32,代码来源:ImageArchiveServiceDecorator.java

示例2: GVTLineMetrics

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Constructs a GVTLineMetrics object based on the specified line metrics.
 *
 * @param lineMetrics The lineMetrics object that this metrics object will
 * be based upon.
 */
public GVTLineMetrics(LineMetrics lineMetrics) {
    this.ascent = lineMetrics.getAscent();
    this.baselineIndex = lineMetrics.getBaselineIndex();
    this.baselineOffsets = lineMetrics.getBaselineOffsets();
    this.descent = lineMetrics.getDescent();
    this.height = lineMetrics.getHeight();
    this.leading = lineMetrics.getLeading();
    this.numChars = lineMetrics.getNumChars();
    this.strikethroughOffset = lineMetrics.getStrikethroughOffset();
    this.strikethroughThickness = lineMetrics.getStrikethroughThickness();
    this.underlineOffset = lineMetrics.getUnderlineOffset();
    this.underlineThickness = lineMetrics.getUnderlineThickness();
    this.overlineOffset = -this.ascent;
    this.overlineThickness = this.underlineThickness;
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:22,代码来源:GVTLineMetrics.java

示例3: paintLabel

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
private void paintLabel(Graphics g, int cell, Rectangle cellBounds, @Nullable String label, int thumbnailHeight) {
  if (!StringUtil.isEmpty(label)) {
    final Color fg;
    if (hasFocus() && cell == mySelectedIndex && (getImage(cell) != null || UIUtil.isUnderDarcula())) {
      fg = UIUtil.getTreeSelectionForeground();
    }
    else {
      fg = UIUtil.getTreeForeground();
    }
    GraphicsUtil.setupAntialiasing(g);
    g.setColor(fg);
    FontMetrics fontMetrics = g.getFontMetrics();
    LineMetrics metrics = fontMetrics.getLineMetrics(label, g);
    int width = fontMetrics.stringWidth(label);

    int textBoxTop = myCellMargin.top + thumbnailHeight;
    int cellBottom = cellBounds.height - myCellMargin.bottom;

    int textY = cellBounds.y + (cellBottom + textBoxTop + (int)(metrics.getHeight() - metrics.getDescent())) / 2 ;
    int textX = (cellBounds.width - myCellMargin.left - myCellMargin.right - width) / 2 + cellBounds.x + myCellMargin.left;
    g.drawString(label, textX, textY);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:ASGallery.java

示例4: createLegendItem

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Creates a legend item
 *
 * @param graphics  the graphics device.
 * @param item  the legend item.
 * @param x  the x coordinate.
 * @param y  the y coordinate.
 *
 * @return the legend item.
 */
private DrawableLegendItem createLegendItem(Graphics graphics,
                                            LegendItem item, double x, double y) {

    int innerGap = 2;
    FontMetrics fm = graphics.getFontMetrics();
    LineMetrics lm = fm.getLineMetrics(item.getLabel(), graphics);
    float textHeight = lm.getHeight();

    DrawableLegendItem drawable = new DrawableLegendItem(item);

    float xloc = (float) (x + innerGap + 1.15f * textHeight);
    float yloc = (float) (y + innerGap + (textHeight - lm.getLeading() - lm.getDescent()));

    drawable.setLabelPosition(new Point2D.Float(xloc, yloc));

    float boxDim = textHeight * 0.70f;
    xloc = (float) (x + innerGap + 0.15f * textHeight);
    yloc = (float) (y + innerGap + 0.15f * textHeight);

    drawable.setMarker(new Rectangle2D.Float(xloc, yloc, boxDim, boxDim));

    float width = (float) (drawable.getLabelPosition().getX() - x
                           + fm.stringWidth(item.getLabel()) + 0.5 * textHeight);

    float height = 2 * innerGap + textHeight;
    drawable.setBounds(x, y, width, height);
    return drawable;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:40,代码来源:MeterLegend.java

示例5: estimateMaximumTickLabelWidth

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Estimates the maximum width of the tick labels, assuming the specified tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we just look at two
 * values: the lower bound and the upper bound for the axis.  These two values will usually
 * be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return the estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelWidth(Graphics2D g2, DateTickUnit unit) {

    Insets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.left + tickLabelInsets.right;

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr = null;
        String upperStr = null;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:50,代码来源:DateAxis.java

示例6: estimateMaximumTickLabelHeight

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Estimates the maximum width of the tick labels, assuming the specified tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we just look at two
 * values: the lower bound and the upper bound for the axis.  These two values will usually
 * be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return the estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelHeight(Graphics2D g2, DateTickUnit unit) {

    Insets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.top + tickLabelInsets.bottom;

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (!isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr = null;
        String upperStr = null;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:50,代码来源:DateAxis.java

示例7: estimateMaximumTickLabelWidth

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Estimates the maximum width of the tick labels, assuming the specified tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we just look at two
 * values: the lower bound and the upper bound for the axis.  These two values will usually
 * be representative.
 *
 * @param g2  the graphics device.
 * @param tickUnit  the tick unit to use for calculation.
 *
 * @return the estimated maximum width of the tick labels.
 */
protected double estimateMaximumTickLabelWidth(Graphics2D g2, TickUnit tickUnit) {

    Insets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.left + tickLabelInsets.right;

    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of the font)...
        FontRenderContext frc = g2.getFontRenderContext();
        LineMetrics lm = getTickLabelFont().getLineMetrics("0", frc);
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        FontMetrics fm = g2.getFontMetrics(getTickLabelFont());
        Range range = getRange();
        double lower = range.getLowerBound();
        double upper = range.getUpperBound();
        String lowerStr = tickUnit.valueToString(lower);
        String upperStr = tickUnit.valueToString(upper);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:40,代码来源:NumberAxis.java

示例8: getHeight

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Returns the height of the band.
 *
 * @param g2  the graphics device.
 *
 * @return the height of the band.
 */
public double getHeight(Graphics2D g2) {

    double result = 0.0;
    if (this.markers.size() > 0) {
        LineMetrics metrics = this.font.getLineMetrics("123g", g2.getFontRenderContext());
        result = this.topOuterGap + this.topInnerGap + metrics.getHeight()
                 + this.bottomInnerGap + this.bottomOuterGap;
    }
    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:19,代码来源:MarkerAxisBand.java

示例9: findMaximumTickLabelHeight

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * A utility method for determining the height of the tallest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels are 'vertical'.
 *
 * @return the height of the tallest tick label.
 */
protected double findMaximumTickLabelHeight(List ticks,
                                            Graphics2D g2, 
                                            Rectangle2D drawArea, 
                                            boolean vertical) {
                                                
    Insets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    double maxHeight = 0.0;
    if (vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm);
            if (labelBounds.getWidth() + insets.top + insets.bottom > maxHeight) {
                maxHeight = labelBounds.getWidth() + insets.top + insets.bottom;
            }
        }
    }
    else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext());
        maxHeight = metrics.getHeight() + insets.top + insets.bottom;
    }
    return maxHeight;
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:37,代码来源:ValueAxis.java

示例10: findMaximumTickLabelWidth

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * A utility method for determining the width of the widest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels are 'vertical'.
 *
 * @return the width of the tallest tick label.
 */
protected double findMaximumTickLabelWidth(List ticks, 
                                           Graphics2D g2, 
                                           Rectangle2D drawArea, 
                                           boolean vertical) {
                                               
    Insets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    double maxWidth = 0.0;
    if (!vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm);
            if (labelBounds.getWidth() + insets.left + insets.right > maxWidth) {
                maxWidth = labelBounds.getWidth() + insets.left + insets.right;
            }
        }
    }
    else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext());
        maxWidth = metrics.getHeight() + insets.top + insets.bottom;
    }
    return maxWidth;
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:37,代码来源:ValueAxis.java

示例11: estimateMaximumTickLabelWidth

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Estimates the maximum width of the tick labels, assuming the specified 
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the 
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelWidth(Graphics2D g2, 
                                             DateTickUnit unit) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of 
        // the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr = null;
        String upperStr = null;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:53,代码来源:DateAxis.java

示例12: estimateMaximumTickLabelHeight

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Estimates the maximum width of the tick labels, assuming the specified 
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we 
 * just look at two values: the lower bound and the upper bound for the 
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelHeight(Graphics2D g2, 
                                              DateTickUnit unit) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();

    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (!isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of 
        // the font)...
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr = null;
        String upperStr = null;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:53,代码来源:DateAxis.java

示例13: estimateMaximumTickLabelWidth

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Estimates the maximum width of the tick labels, assuming the specified 
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we 
 * just look at two values: the lower bound and the upper bound for the 
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
protected double estimateMaximumTickLabelWidth(Graphics2D g2, 
                                               TickUnit unit) {

    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();

    if (isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of the 
        // font)...
        FontRenderContext frc = g2.getFontRenderContext();
        LineMetrics lm = getTickLabelFont().getLineMetrics("0", frc);
        result += lm.getHeight();
    }
    else {
        // look at lower and upper bounds...
        FontMetrics fm = g2.getFontMetrics(getTickLabelFont());
        Range range = getRange();
        double lower = range.getLowerBound();
        double upper = range.getUpperBound();
        String lowerStr = "";
        String upperStr = "";
        NumberFormat formatter = getNumberFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        }
        else {
            lowerStr = unit.valueToString(lower);
            upperStr = unit.valueToString(upper);                
        }
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }

    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:52,代码来源:NumberAxis.java

示例14: getHeight

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * Returns the height of the band.
 *
 * @param g2  the graphics device.
 *
 * @return The height of the band.
 */
public double getHeight(Graphics2D g2) {

    double result = 0.0;
    if (this.markers.size() > 0) {
        LineMetrics metrics = this.font.getLineMetrics(
            "123g", g2.getFontRenderContext()
        );
        result = this.topOuterGap + this.topInnerGap + metrics.getHeight()
                 + this.bottomInnerGap + this.bottomOuterGap;
    }
    return result;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:21,代码来源:MarkerAxisBand.java

示例15: findMaximumTickLabelHeight

import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
 * A utility method for determining the height of the tallest tick label.
 *
 * @param ticks  the ticks.
 * @param g2  the graphics device.
 * @param drawArea  the area within which the plot and axes should be drawn.
 * @param vertical  a flag that indicates whether or not the tick labels 
 *                  are 'vertical'.
 *
 * @return The height of the tallest tick label.
 */
protected double findMaximumTickLabelHeight(List ticks,
                                            Graphics2D g2, 
                                            Rectangle2D drawArea, 
                                            boolean vertical) {
                                                
    RectangleInsets insets = getTickLabelInsets();
    Font font = getTickLabelFont();
    double maxHeight = 0.0;
    if (vertical) {
        FontMetrics fm = g2.getFontMetrics(font);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            Tick tick = (Tick) iterator.next();
            Rectangle2D labelBounds = TextUtilities.getTextBounds(
                    tick.getText(), g2, fm);
            if (labelBounds.getWidth() + insets.getTop() 
                    + insets.getBottom() > maxHeight) {
                maxHeight = labelBounds.getWidth() 
                            + insets.getTop() + insets.getBottom();
            }
        }
    }
    else {
        LineMetrics metrics = font.getLineMetrics("ABCxyz", 
                g2.getFontRenderContext());
        maxHeight = metrics.getHeight() 
                    + insets.getTop() + insets.getBottom();
    }
    return maxHeight;
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:43,代码来源:ValueAxis.java


注:本文中的java.awt.font.LineMetrics.getHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。