📄 minmaxcategoryrenderer.java
字号:
float lead = lm.getLeading();
double width = labelBounds.getWidth();
double height = labelBounds.getHeight();
float labelx;
float labely;
int position = labelPosition;
if (rotate) {
if (position == LineAndShapeRenderer.TOP) {
labelx = (float) (x + height / 2 - lm.getDescent());
labely = (float) (y - shapeScale);
}
else if (position == LineAndShapeRenderer.BOTTOM) {
labelx = (float) (x + height / 2 - lm.getDescent());
labely = (float) (y + shapeScale + width);
}
else if (position == LineAndShapeRenderer.LEFT) {
labelx = (float) (x - shapeScale / 2 - lead - lm.getDescent());
labely = (float) (y + width / 2);
}
else {
labelx = (float) (x + shapeScale / 2 + lead + lm.getAscent());
labely = (float) (y + width / 2);
}
RefineryUtilities.drawRotatedString(label, g2, labelx, labely, -Math.PI / 2);
}
else {
if (position == LineAndShapeRenderer.TOP) {
labelx = (float) (x - width / 2);
labely = (float) (y - shapeScale / 2 - lm.getDescent() - lead);
}
else if (position == LineAndShapeRenderer.BOTTOM) {
labelx = (float) (x - width / 2);
labely = (float) (y + shapeScale / 2 + lm.getAscent() + lead);
}
else if (position == LineAndShapeRenderer.LEFT) {
labelx = (float) (x - shapeScale - width);
labely = (float) (y + height / 2 - lm.getDescent());
}
else {
labelx = (float) (x + shapeScale);
labely = (float) (y + height / 2 - lm.getDescent());
}
g2.drawString(label, labelx, labely);
}
}
/**
* Draws a horizontal line across the chart to represent the marker.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param axis the value axis.
* @param marker the marker line.
* @param axisDataArea the axis data area.
* @param dataClipRegion the data clip region.
*/
public void drawRangeMarker (Graphics2D g2, CategoryPlot plot, ValueAxis axis,
Marker marker, Rectangle2D axisDataArea, Shape dataClipRegion) {
double value = marker.getValue();
Range range = axis.getRange();
if (!range.contains(value)) {
return;
}
double y = axis.translateValueToJava2D(marker.getValue(), axisDataArea,
plot.getRangeAxisEdge());
Line2D line = new Line2D.Double(axisDataArea.getMinX(), y, axisDataArea.getMaxX(), y);
g2.setPaint(marker.getOutlinePaint());
g2.draw(line);
}
/**
* Sets whether or not lines are drawn between category points.
*
* @param drawLines if true, then line will be drawn between sequenced categories.
*/
public void setDrawLines (boolean drawLines) {
this.plotLines = drawLines;
}
/**
* Gets whether or not lines are drawn between category points.
*
* @return boolean true if line will be drawn between sequenced categories, otherwise false.
*/
public boolean isDrawLines () {
return plotLines;
}
/**
* Sets the paint of the line between the minimum value and the maximum value.
*
* @param groupPaint the new paint.
*/
public void setGroupPaint (Paint groupPaint) {
this.groupPaint = groupPaint;
}
/**
* Gets the paint of the line between the minimum value and the maximum value.
*
* @return the paint.
*/
public Paint getGroupPaint () {
return groupPaint;
}
/**
* Sets the stroke of the line between the minimum value and the maximum value.
*
* @param groupStroke The new stroke
*/
public void setGroupStroke (Stroke groupStroke) {
this.groupStroke = groupStroke;
}
/**
* Gets the stroke of the line between the minimum value and the maximum value.
*
* @return Stroke The current stroke.
*/
public Stroke getGroupStroke () {
return groupStroke;
}
/**
* Sets the icon used to indicate the values.
*
* @param objectIcon the icon.
*/
public void setObjectIcon (Icon objectIcon) {
this.objectIcon = objectIcon;
}
/**
* Gets the icon used to indicate the values.
*
* @return the icon.
*/
public Icon getObjectIcon () {
return objectIcon;
}
/**
* Sets the icon used to indicate the maximum value.
*
* @param maxIcon the max icon.
*/
public void setMaxIcon (Icon maxIcon) {
this.maxIcon = maxIcon;
}
/**
* Gets the icon used to indicate the maximum value.
*
* @return the icon
*/
public Icon getMaxIcone () {
return maxIcon;
}
/**
* Sets the icon used to indicate the minimum value.
*
* @param minIcon the min icon.
*/
public void setMinIcon (Icon minIcon) {
this.minIcon = minIcon;
}
/**
* Gets the icon used to indicate the minimum value.
*
* @return Icon
*/
public Icon getMinIcon () {
return minIcon;
}
/**
* Returns an icon.
*
* @param shape the shape.
* @param fillPaint the fill paint.
* @param outlinePaint the outline paint.
*
* @return the icon.
*/
private Icon getIcon(Shape shape, final Paint fillPaint, final Paint outlinePaint) {
final int width = shape.getBounds().width;
final int height = shape.getBounds().height;
final GeneralPath path = new GeneralPath(shape);
return new Icon() {
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D) g;
path.transform(AffineTransform.getTranslateInstance(x, y));
if (fillPaint != null) {
g2.setPaint(fillPaint);
g2.fill(path);
}
if (outlinePaint != null) {
g2.setPaint(outlinePaint);
g2.draw(path);
}
path.transform(AffineTransform.getTranslateInstance(-x, -y));
}
public int getIconWidth() {
return width;
}
public int getIconHeight() {
return height;
}
};
}
/**
* Returns an icon.
*
* @param shape the shape.
* @param fill the fill flag.
* @param outline the outline flag.
*
* @return the icon.
*/
private Icon getIcon(Shape shape, final boolean fill, final boolean outline) {
final int width = shape.getBounds().width;
final int height = shape.getBounds().height;
final GeneralPath path = new GeneralPath(shape);
return new Icon() {
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D) g;
path.transform(AffineTransform.getTranslateInstance(x, y));
if (fill) {
g2.fill(path);
}
if (outline) {
g2.draw(path);
}
path.transform(AffineTransform.getTranslateInstance(-x, -y));
}
public int getIconWidth() {
return width;
}
public int getIconHeight() {
return height;
}
};
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -