org.jfree.chart.util.AttrStringUtils Java Examples
The following examples show how to use
org.jfree.chart.util.AttrStringUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValueAxis.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * 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(); g2.setFont(font); 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds( tick.getText(), g2, fm); } if (labelBounds != null && 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; }
Example #2
Source File: LogAxis.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * 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. * * @since 1.0.7 */ 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... Range range = getRange(); double lower = range.getLowerBound(); double upper = range.getUpperBound(); AttributedString lowerStr = createTickLabel(lower); AttributedString upperStr = createTickLabel(upper); double w1 = AttrStringUtils.getTextBounds(lowerStr, g2).getWidth(); double w2 = AttrStringUtils.getTextBounds(upperStr, g2).getWidth(); result += Math.max(w1, w2); } return result; }
Example #3
Source File: ValueAxis.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * 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) { RectangleInsets 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm); } if (labelBounds != null && labelBounds.getWidth() + insets.getLeft() + insets.getRight() > maxWidth) { maxWidth = labelBounds.getWidth() + insets.getLeft() + insets.getRight(); } } } else { LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext()); maxWidth = metrics.getHeight() + insets.getTop() + insets.getBottom(); } return maxWidth; }
Example #4
Source File: ValueAxis.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * 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(); g2.setFont(font); 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds( tick.getText(), g2, fm); } if (labelBounds != null && 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; }
Example #5
Source File: LogAxis.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * 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. * * @since 1.0.7 */ 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... Range range = getRange(); double lower = range.getLowerBound(); double upper = range.getUpperBound(); AttributedString lowerStr = createTickLabel(lower); AttributedString upperStr = createTickLabel(upper); double w1 = AttrStringUtils.getTextBounds(lowerStr, g2).getWidth(); double w2 = AttrStringUtils.getTextBounds(upperStr, g2).getWidth(); result += Math.max(w1, w2); } return result; }
Example #6
Source File: ValueAxis.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * 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) { RectangleInsets 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm); } if (labelBounds != null && labelBounds.getWidth() + insets.getLeft() + insets.getRight() > maxWidth) { maxWidth = labelBounds.getWidth() + insets.getLeft() + insets.getRight(); } } } else { LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext()); maxWidth = metrics.getHeight() + insets.getTop() + insets.getBottom(); } return maxWidth; }
Example #7
Source File: ValueAxis.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * 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(); g2.setFont(font); 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds( tick.getText(), g2, fm); } if (labelBounds != null && 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; }
Example #8
Source File: LogAxis.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * 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. * * @since 1.0.7 */ 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... Range range = getRange(); double lower = range.getLowerBound(); double upper = range.getUpperBound(); AttributedString lowerStr = createTickLabel(lower); AttributedString upperStr = createTickLabel(upper); double w1 = AttrStringUtils.getTextBounds(lowerStr, g2).getWidth(); double w2 = AttrStringUtils.getTextBounds(upperStr, g2).getWidth(); result += Math.max(w1, w2); } return result; }
Example #9
Source File: ValueAxis.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * 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) { RectangleInsets 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm); } if (labelBounds != null && labelBounds.getWidth() + insets.getLeft() + insets.getRight() > maxWidth) { maxWidth = labelBounds.getWidth() + insets.getLeft() + insets.getRight(); } } } else { LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext()); maxWidth = metrics.getHeight() + insets.getTop() + insets.getBottom(); } return maxWidth; }
Example #10
Source File: ValueAxis.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * 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(); g2.setFont(font); 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds( tick.getText(), g2, fm); } if (labelBounds != null && 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; }
Example #11
Source File: LogAxis.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * 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. * * @since 1.0.7 */ 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... Range range = getRange(); double lower = range.getLowerBound(); double upper = range.getUpperBound(); AttributedString lowerStr = createTickLabel(lower); AttributedString upperStr = createTickLabel(upper); double w1 = AttrStringUtils.getTextBounds(lowerStr, g2).getWidth(); double w2 = AttrStringUtils.getTextBounds(upperStr, g2).getWidth(); result += Math.max(w1, w2); } return result; }
Example #12
Source File: ValueAxis.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * 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) { RectangleInsets 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm); } if (labelBounds != null && labelBounds.getWidth() + insets.getLeft() + insets.getRight() > maxWidth) { maxWidth = labelBounds.getWidth() + insets.getLeft() + insets.getRight(); } } } else { LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext()); maxWidth = metrics.getHeight() + insets.getTop() + insets.getBottom(); } return maxWidth; }
Example #13
Source File: ValueAxis.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * 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(); g2.setFont(font); 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds( tick.getText(), g2, fm); } if (labelBounds != null && 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; }
Example #14
Source File: LogAxis.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * 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. * * @since 1.0.7 */ 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... Range range = getRange(); double lower = range.getLowerBound(); double upper = range.getUpperBound(); AttributedString lowerStr = createTickLabel(lower); AttributedString upperStr = createTickLabel(upper); double w1 = AttrStringUtils.getTextBounds(lowerStr, g2).getWidth(); double w2 = AttrStringUtils.getTextBounds(upperStr, g2).getWidth(); result += Math.max(w1, w2); } return result; }
Example #15
Source File: ValueAxis.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * 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) { RectangleInsets 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm); } if (labelBounds != null && labelBounds.getWidth() + insets.getLeft() + insets.getRight() > maxWidth) { maxWidth = labelBounds.getWidth() + insets.getLeft() + insets.getRight(); } } } else { LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext()); maxWidth = metrics.getHeight() + insets.getTop() + insets.getBottom(); } return maxWidth; }
Example #16
Source File: ValueAxis.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * 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(); g2.setFont(font); 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds( tick.getText(), g2, fm); } if (labelBounds != null && 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; }
Example #17
Source File: LogAxis.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * 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. * * @since 1.0.7 */ 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... Range range = getRange(); double lower = range.getLowerBound(); double upper = range.getUpperBound(); AttributedString lowerStr = createTickLabel(lower); AttributedString upperStr = createTickLabel(upper); double w1 = AttrStringUtils.getTextBounds(lowerStr, g2).getWidth(); double w2 = AttrStringUtils.getTextBounds(upperStr, g2).getWidth(); result += Math.max(w1, w2); } return result; }
Example #18
Source File: ValueAxis.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * 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) { RectangleInsets 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 = null; if (tick instanceof LogTick) { LogTick lt = (LogTick) tick; if (lt.getAttributedLabel() != null) { labelBounds = AttrStringUtils.getTextBounds( lt.getAttributedLabel(), g2); } } else if (tick.getText() != null) { labelBounds = TextUtilities.getTextBounds(tick.getText(), g2, fm); } if (labelBounds != null && labelBounds.getWidth() + insets.getLeft() + insets.getRight() > maxWidth) { maxWidth = labelBounds.getWidth() + insets.getLeft() + insets.getRight(); } } } else { LineMetrics metrics = font.getLineMetrics("ABCxyz", g2.getFontRenderContext()); maxWidth = metrics.getHeight() + insets.getTop() + insets.getBottom(); } return maxWidth; }