📄 periodaxis.java
字号:
return this.minorTickMarkStroke;
}
/**
* Sets the stroke used to display minor tick marks, if they are
* visible, and sends a {@link AxisChangeEvent} to all registered
* listeners.
*
* @param stroke the stroke (<code>null</code> not permitted).
*/
public void setMinorTickMarkStroke(Stroke stroke) {
if (stroke == null) {
throw new IllegalArgumentException("Null 'stroke' argument.");
}
this.minorTickMarkStroke = stroke;
notifyListeners(new AxisChangeEvent(this));
}
/**
* Returns the paint used to display minor tick marks, if they are
* visible.
*
* @return A paint (never <code>null</code>).
*/
public Paint getMinorTickMarkPaint() {
return this.minorTickMarkPaint;
}
/**
* Sets the paint used to display minor tick marks, if they are
* visible, and sends a {@link AxisChangeEvent} to all registered
* listeners.
*
* @param paint the paint (<code>null</code> not permitted).
*/
public void setMinorTickMarkPaint(Paint paint) {
if (paint == null) {
throw new IllegalArgumentException("Null 'paint' argument.");
}
this.minorTickMarkPaint = paint;
notifyListeners(new AxisChangeEvent(this));
}
/**
* Returns the inside length for the minor tick marks.
*
* @return The length.
*/
public float getMinorTickMarkInsideLength() {
return this.minorTickMarkInsideLength;
}
/**
* Sets the inside length of the minor tick marks and sends an
* {@link AxisChangeEvent} to all registered listeners.
*
* @param length the length.
*/
public void setMinorTickMarkInsideLength(float length) {
this.minorTickMarkInsideLength = length;
notifyListeners(new AxisChangeEvent(this));
}
/**
* Returns the outside length for the minor tick marks.
*
* @return The length.
*/
public float getMinorTickMarkOutsideLength() {
return this.minorTickMarkOutsideLength;
}
/**
* Sets the outside length of the minor tick marks and sends an
* {@link AxisChangeEvent} to all registered listeners.
*
* @param length the length.
*/
public void setMinorTickMarkOutsideLength(float length) {
this.minorTickMarkOutsideLength = length;
notifyListeners(new AxisChangeEvent(this));
}
/**
* Returns an array of label info records.
*
* @return An array.
*/
public PeriodAxisLabelInfo[] getLabelInfo() {
return this.labelInfo;
}
/**
* Sets the array of label info records.
*
* @param info the info.
*/
public void setLabelInfo(PeriodAxisLabelInfo[] info) {
this.labelInfo = info;
// FIXME: shouldn't this generate an event?
}
/**
* Returns the range for the axis.
*
* @return The axis range (never <code>null</code>).
*/
public Range getRange() {
// TODO: find a cleaner way to do this...
return new Range(this.first.getFirstMillisecond(this.calendar),
this.last.getLastMillisecond(this.calendar));
}
/**
* 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.
*/
public void setRange(Range range, boolean turnOffAutoRange,
boolean notify) {
super.setRange(range, turnOffAutoRange, false);
long upper = Math.round(range.getUpperBound());
long lower = Math.round(range.getLowerBound());
this.first = createInstance(this.autoRangeTimePeriodClass,
new Date(lower), this.timeZone);
this.last = createInstance(this.autoRangeTimePeriodClass,
new Date(upper), this.timeZone);
}
/**
* Configures the axis to work with the current plot. Override this method
* to perform any special processing (such as auto-rescaling).
*/
public void configure() {
if (this.isAutoRange()) {
autoAdjustRange();
}
}
/**
* Estimates the space (height or width) required to draw the axis.
*
* @param g2 the graphics device.
* @param plot the plot that the axis belongs to.
* @param plotArea the area within which the plot (including axes) should
* be drawn.
* @param edge the axis location.
* @param space space already reserved.
*
* @return The space required to draw the axis (including pre-reserved
* space).
*/
public AxisSpace reserveSpace(Graphics2D g2, Plot plot,
Rectangle2D plotArea, RectangleEdge edge,
AxisSpace space) {
// create a new space object if one wasn't supplied...
if (space == null) {
space = new AxisSpace();
}
// if the axis is not visible, no additional space is required...
if (!isVisible()) {
return space;
}
// if the axis has a fixed dimension, return it...
double dimension = getFixedDimension();
if (dimension > 0.0) {
space.ensureAtLeast(dimension, edge);
}
// get the axis label size and update the space object...
Rectangle2D labelEnclosure = getLabelEnclosure(g2, edge);
double labelHeight = 0.0;
double labelWidth = 0.0;
double tickLabelBandsDimension = 0.0;
for (int i = 0; i < this.labelInfo.length; i++) {
PeriodAxisLabelInfo info = this.labelInfo[i];
FontMetrics fm = g2.getFontMetrics(info.getLabelFont());
tickLabelBandsDimension
+= info.getPadding().extendHeight(fm.getHeight());
}
if (RectangleEdge.isTopOrBottom(edge)) {
labelHeight = labelEnclosure.getHeight();
space.add(labelHeight + tickLabelBandsDimension, edge);
}
else if (RectangleEdge.isLeftOrRight(edge)) {
labelWidth = labelEnclosure.getWidth();
space.add(labelWidth + tickLabelBandsDimension, edge);
}
// add space for the outer tick labels, if any...
double tickMarkSpace = 0.0;
if (isTickMarksVisible()) {
tickMarkSpace = getTickMarkOutsideLength();
}
if (this.minorTickMarksVisible) {
tickMarkSpace = Math.max(tickMarkSpace,
this.minorTickMarkOutsideLength);
}
space.add(tickMarkSpace, edge);
return space;
}
/**
* Draws the axis on a Java 2D graphics device (such as the screen or a
* printer).
*
* @param g2 the graphics device (<code>null</code> not permitted).
* @param cursor the cursor location (determines where to draw the axis).
* @param plotArea the area within which the axes and plot should be drawn.
* @param dataArea the area within which the data should be drawn.
* @param edge the axis location (<code>null</code> not permitted).
* @param plotState collects information about the plot
* (<code>null</code> permitted).
*
* @return The axis state (never <code>null</code>).
*/
public AxisState draw(Graphics2D g2,
double cursor,
Rectangle2D plotArea,
Rectangle2D dataArea,
RectangleEdge edge,
PlotRenderingInfo plotState) {
AxisState axisState = new AxisState(cursor);
if (isAxisLineVisible()) {
drawAxisLine(g2, cursor, dataArea, edge);
}
drawTickMarks(g2, axisState, dataArea, edge);
for (int band = 0; band < this.labelInfo.length; band++) {
axisState = drawTickLabels(band, g2, axisState, dataArea, edge);
}
// draw the axis label (note that 'state' is passed in *and*
// returned)...
axisState = drawLabel(getLabel(), g2, plotArea, dataArea, edge,
axisState);
return axisState;
}
/**
* Draws the tick marks for the axis.
*
* @param g2 the graphics device.
* @param state the axis state.
* @param dataArea the data area.
* @param edge the edge.
*/
protected void drawTickMarks(Graphics2D g2, AxisState state,
Rectangle2D dataArea,
RectangleEdge edge) {
if (RectangleEdge.isTopOrBottom(edge)) {
drawTickMarksHorizontal(g2, state, dataArea, edge);
}
else if (RectangleEdge.isLeftOrRight(edge)) {
drawTickMarksVertical(g2, state, dataArea, edge);
}
}
/**
* Draws the major and minor tick marks for an axis that lies at the top or
* bottom of the plot.
*
* @param g2 the graphics device.
* @param state the axis state.
* @param dataArea the data area.
* @param edge the edge.
*/
protected void drawTickMarksHorizontal(Graphics2D g2, AxisState state,
Rectangle2D dataArea,
RectangleEdge edge) {
List ticks = new ArrayList();
double x0 = dataArea.getX();
double y0 = state.getCursor();
double insideLength = getTickMarkInsideLength();
double outsideLength = getTickMarkOutsideLength();
RegularTimePeriod t = RegularTimePeriod.createInstance(
this.majorTickTimePeriodClass, this.first.getStart(),
getTimeZone());
long t0 = t.getFirstMillisecond(this.calendar);
Line2D inside = null;
Line2D outside = null;
long firstOnAxis = getFirst().getFirstMillisecond(this.calendar);
long lastOnAxis = getLast().getLastMillisecond(this.calendar);
while (t0 <= lastOnAxis) {
ticks.add(new NumberTick(new Double(t0), "", TextAnchor.CENTER,
TextAnchor.CENTER, 0.0));
x0 = valueToJava2D(t0, dataArea, edge);
if (edge == RectangleEdge.TOP) {
inside = new Line2D.Double(x0, y0, x0, y0 + insideLength);
outside = new Line2D.Double(x0, y0, x0, y0 - outsideLength);
}
else if (edge == RectangleEdge.BOTTOM) {
inside = new Line2D.Double(x0, y0, x0, y0 - insideLength);
outside = new Line2D.Double(x0, y0, x0, y0 + outsideLength);
}
if (t0 > firstOnAxis) {
g2.setPaint(getTickMarkPaint());
g2.setStroke(getTickMarkStroke());
g2.draw(inside);
g2.draw(outside);
}
// draw minor tick marks
if (this.minorTickMarksVisible) {
RegularTimePeriod tminor = RegularTimePeriod.createInstance(
this.minorTickTimePeriodClass, new Date(t0),
getTimeZone());
long tt0 = tminor.getFirstMillisecond(this.calendar);
while (tt0 < t.getLastMillisecond(this.calendar)
&& tt0 < lastOnAxis) {
double xx0 = valueToJava2D(tt0, dataArea, edge);
if (edge == RectangleEdge.TOP) {
inside = new Line2D.Double(xx0, y0, xx0,
y0 + this.minorTickMarkInsideLength);
outside = new Line2D.Double(xx0, y0, xx0,
y0 - this.minorTickMarkOutsideLength);
}
else if (edge == RectangleEdge.BOTTOM) {
inside = new Line2D.Double(xx0, y0, xx0,
y0 - this.minorTickMarkInsideLength);
outside = new Line2D.Double(xx0, y0, xx0,
y0 + this.minorTickMarkOutsideLength);
}
if (tt0 >= firstOnAxis) {
g2.setPaint(this.minorTickMarkPaint);
g2.setStroke(this.minorTickMarkStroke);
g2.draw(inside);
g2.draw(outside);
}
tminor = tminor.next();
tt0 = tminor.getFirstMillisecond(this.calendar);
}
}
t = t.next();
t0 = t.getFirstMillisecond(this.calendar);
}
if (edge == RectangleEdge.TOP) {
state.cursorUp(Math.max(outsideLength,
this.minorTickMarkOutsideLength));
}
else if (edge == RectangleEdge.BOTTOM) {
state.cursorDown(Math.max(outsideLength,
this.minorTickMarkOutsideLength));
}
state.setTicks(ticks);
}
/**
* Draws the tick marks for a vertical axis.
*
* @param g2 the graphics device.
* @param state the axis state.
* @param dataArea the data area.
* @param edge the edge.
*/
protected void drawTickMarksVertical(Graphics2D g2, AxisState state,
Rectangle2D dataArea,
RectangleEdge edge) {
// FIXME: implement this...
}
/**
* Draws the tick labels for one "band" of time periods.
*
* @param band the band index (zero-based).
* @param g2 the graphics device.
* @param state the axis state.
* @param dataArea the data area.
* @param edge the edge where the axis is located.
*
* @return The updated axis state.
*/
protected AxisState drawTickLabels(int band, Graphics2D g2, AxisState state,
Rectangle2D dataArea,
RectangleEdge edge) {
// work out the initial gap
double delta1 = 0.0;
FontMetrics fm = g2.getFontMetrics(this.labelInfo[band].getLabelFont());
if (edge == RectangleEdge.BOTTOM) {
delta1 = this.labelInfo[band].getPadding().calculateTopOutset(
fm.getHeight());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -