當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。