📄 valueaxis.java
字号:
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;
}
/**
* 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 = TextUtilities.getTextBounds(
tick.getText(), g2, fm);
if (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;
}
/**
* Returns a flag that controls the direction of values on the axis.
* <P>
* For a regular axis, values increase from left to right (for a horizontal
* axis) and bottom to top (for a vertical axis). When the axis is
* 'inverted', the values increase in the opposite direction.
*
* @return The flag.
*
* @see #setInverted(boolean)
*/
public boolean isInverted() {
return this.inverted;
}
/**
* Sets a flag that controls the direction of values on the axis, and
* notifies registered listeners that the axis has changed.
*
* @param flag the flag.
*
* @see #isInverted()
*/
public void setInverted(boolean flag) {
if (this.inverted != flag) {
this.inverted = flag;
notifyListeners(new AxisChangeEvent(this));
}
}
/**
* Returns the flag that controls whether or not the axis range is
* automatically adjusted to fit the data values.
*
* @return The flag.
*
* @see #setAutoRange(boolean)
*/
public boolean isAutoRange() {
return this.autoRange;
}
/**
* Sets a flag that determines whether or not the axis range is
* automatically adjusted to fit the data, and notifies registered
* listeners that the axis has been modified.
*
* @param auto the new value of the flag.
*
* @see #isAutoRange()
*/
public void setAutoRange(boolean auto) {
setAutoRange(auto, true);
}
/**
* Sets the auto range attribute. If the <code>notify</code> flag is set,
* an {@link AxisChangeEvent} is sent to registered listeners.
*
* @param auto the flag.
* @param notify notify listeners?
*
* @see #isAutoRange()
*/
protected void setAutoRange(boolean auto, boolean notify) {
if (this.autoRange != auto) {
this.autoRange = auto;
if (this.autoRange) {
autoAdjustRange();
}
if (notify) {
notifyListeners(new AxisChangeEvent(this));
}
}
}
/**
* Returns the minimum size allowed for the axis range when it is
* automatically calculated.
*
* @return The minimum range.
*
* @see #setAutoRangeMinimumSize(double)
*/
public double getAutoRangeMinimumSize() {
return this.autoRangeMinimumSize;
}
/**
* Sets the auto range minimum size and sends an {@link AxisChangeEvent}
* to all registered listeners.
*
* @param size the size.
*
* @see #getAutoRangeMinimumSize()
*/
public void setAutoRangeMinimumSize(double size) {
setAutoRangeMinimumSize(size, true);
}
/**
* Sets the minimum size allowed for the axis range when it is
* automatically calculated.
* <p>
* If requested, an {@link AxisChangeEvent} is forwarded to all registered
* listeners.
*
* @param size the new minimum.
* @param notify notify listeners?
*/
public void setAutoRangeMinimumSize(double size, boolean notify) {
if (size <= 0.0) {
throw new IllegalArgumentException(
"NumberAxis.setAutoRangeMinimumSize(double): must be > 0.0.");
}
if (this.autoRangeMinimumSize != size) {
this.autoRangeMinimumSize = size;
if (this.autoRange) {
autoAdjustRange();
}
if (notify) {
notifyListeners(new AxisChangeEvent(this));
}
}
}
/**
* Returns the default auto range.
*
* @return The default auto range (never <code>null</code>).
*
* @see #setDefaultAutoRange(Range)
*
* @since 1.0.5
*/
public Range getDefaultAutoRange() {
return this.defaultAutoRange;
}
/**
* Sets the default auto range and sends an {@link AxisChangeEvent} to all
* registered listeners.
*
* @param range the range (<code>null</code> not permitted).
*
* @see #getDefaultAutoRange()
*
* @since 1.0.5
*/
public void setDefaultAutoRange(Range range) {
if (range == null) {
throw new IllegalArgumentException("Null 'range' argument.");
}
this.defaultAutoRange = range;
notifyListeners(new AxisChangeEvent(this));
}
/**
* Returns the lower margin for the axis, expressed as a percentage of the
* axis range. This controls the space added to the lower end of the axis
* when the axis range is automatically calculated (it is ignored when the
* axis range is set explicitly). The default value is 0.05 (five percent).
*
* @return The lower margin.
*
* @see #setLowerMargin(double)
*/
public double getLowerMargin() {
return this.lowerMargin;
}
/**
* Sets the lower margin for the axis (as a percentage of the axis range)
* and sends an {@link AxisChangeEvent} to all registered listeners. This
* margin is added only when the axis range is auto-calculated - if you set
* the axis range manually, the margin is ignored.
*
* @param margin the margin percentage (for example, 0.05 is five percent).
*
* @see #getLowerMargin()
* @see #setUpperMargin(double)
*/
public void setLowerMargin(double margin) {
this.lowerMargin = margin;
if (isAutoRange()) {
autoAdjustRange();
}
notifyListeners(new AxisChangeEvent(this));
}
/**
* Returns the upper margin for the axis, expressed as a percentage of the
* axis range. This controls the space added to the lower end of the axis
* when the axis range is automatically calculated (it is ignored when the
* axis range is set explicitly). The default value is 0.05 (five percent).
*
* @return The upper margin.
*
* @see #setUpperMargin(double)
*/
public double getUpperMargin() {
return this.upperMargin;
}
/**
* Sets the upper margin for the axis (as a percentage of the axis range)
* and sends an {@link AxisChangeEvent} to all registered listeners. This
* margin is added only when the axis range is auto-calculated - if you set
* the axis range manually, the margin is ignored.
*
* @param margin the margin percentage (for example, 0.05 is five percent).
*
* @see #getLowerMargin()
* @see #setLowerMargin(double)
*/
public void setUpperMargin(double margin) {
this.upperMargin = margin;
if (isAutoRange()) {
autoAdjustRange();
}
notifyListeners(new AxisChangeEvent(this));
}
/**
* Returns the fixed auto range.
*
* @return The length.
*
* @see #setFixedAutoRange(double)
*/
public double getFixedAutoRange() {
return this.fixedAutoRange;
}
/**
* Sets the fixed auto range for the axis.
*
* @param length the range length.
*
* @see #getFixedAutoRange()
*/
public void setFixedAutoRange(double length) {
this.fixedAutoRange = length;
if (isAutoRange()) {
autoAdjustRange();
}
notifyListeners(new AxisChangeEvent(this));
}
/**
* Returns the lower bound of the axis range.
*
* @return The lower bound.
*
* @see #setLowerBound(double)
*/
public double getLowerBound() {
return this.range.getLowerBound();
}
/**
* Sets the lower bound for the axis range. An {@link AxisChangeEvent} is
* sent to all registered listeners.
*
* @param min the new minimum.
*
* @see #getLowerBound()
*/
public void setLowerBound(double min) {
if (this.range.getUpperBound() > min) {
setRange(new Range(min, this.range.getUpperBound()));
}
else {
setRange(new Range(min, min + 1.0));
}
}
/**
* Returns the upper bound for the axis range.
*
* @return The upper bound.
*
* @see #setUpperBound(double)
*/
public double getUpperBound() {
return this.range.getUpperBound();
}
/**
* Sets the upper bound for the axis range, and sends an
* {@link AxisChangeEvent} to all registered listeners.
*
* @param max the new maximum.
*
* @see #getUpperBound()
*/
public void setUpperBound(double max) {
if (this.range.getLowerBound() < max) {
setRange(new Range(this.range.getLowerBound(), max));
}
else {
setRange(max - 1.0, max);
}
}
/**
* Returns the range for the axis.
*
* @return The axis range (never <code>null</code>).
*
* @see #setRange(Range)
*/
public Range getRange() {
return this.range;
}
/**
* Sets the range attribute and sends an {@link AxisChangeEvent} to all
* registered listeners. As a side-effect, the auto-range flag is set to
* <code>false</code>.
*
* @param range the range (<code>null</code> not permitted).
*
* @see #getRange()
*/
public void setRange(Range range) {
// defer argument checking
setRange(range, true, true);
}
/**
* Sets the range for the axis, if requested, sends an
* {@link AxisChangeEvent} to all registered listeners. As a side-effect,
* the auto-range flag is set to <code>false</code> (optional).
*
* @param range the range (<code>null</code> not permitted).
* @param turnOffAutoRange a flag that controls whether or not the auto
* range is turned off.
* @param notify a flag that controls whether or not listeners are
* notified.
*
* @see #getRange()
*/
public void setRange(Range range, boolean turnOffAutoRange,
boolean notify) {
if (range == null) {
throw new IllegalArgumentException("Null 'range' argument.");
}
if (turnOffAutoRange) {
this.autoRange = false;
}
this.range = range;
if (notify) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -