lineandshaperenderer.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 686 行 · 第 1/2 页
JAVA
686 行
/** * Sets the 'shapes filled' flag for a series. * * @param series the series index (zero-based). * @param filled the flag. */ public void setSeriesShapesFilled(int series, Boolean filled) { this.seriesShapesFilled.setBoolean(series, filled); } /** * Sets the 'shapes filled' flag for a series. * * @param series the series index (zero-based). * @param filled the flag. */ public void setSeriesShapesFilled(int series, boolean filled) { this.seriesShapesFilled.setBoolean( series, BooleanUtilities.valueOf(filled) ); } /** * Returns the default 'shape filled' attribute. * * @return The default flag. */ public boolean getDefaultShapesFilled() { return this.defaultShapesFilled; } /** * Sets the default 'shapes filled' flag. * * @param flag the flag. */ public void setDefaultShapesFilled(boolean flag) { this.defaultShapesFilled = flag; } /** * Returns <code>true</code> if the renderer should use the fill paint * setting to fill shapes, and <code>false</code> if it should just * use the regular paint. * * @return A boolean. */ public boolean getUseFillPaint() { return this.useFillPaint; } /** * Sets the flag that controls whether the fill paint is used to fill * shapes, and sends a {@link RendererChangeEvent} to all * registered listeners. * * @param flag the flag. */ public void setUseFillPaint(boolean flag) { this.useFillPaint = flag; notifyListeners(new RendererChangeEvent(this)); } /** * Returns a legend item for a series. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return The legend item. */ public LegendItem getLegendItem(int datasetIndex, int series) { CategoryPlot cp = getPlot(); if (cp == null) { return null; } if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) { CategoryDataset dataset; dataset = cp.getDataset(datasetIndex); String label = getLegendItemLabelGenerator().generateLabel( dataset, series ); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series ); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel( dataset, series ); } Shape shape = getSeriesShape(series); Paint paint = getSeriesPaint(series); Paint fillPaint = (this.useFillPaint ? getItemFillPaint(series, 0) : paint); boolean shapeOutlineVisible = this.drawOutlines; Paint outlinePaint = (this.useOutlinePaint ? getItemOutlinePaint(series, 0) : paint); Stroke outlineStroke = getSeriesOutlineStroke(series); return new LegendItem( label, description, toolTipText, urlText, isShapesVisible(), shape, getItemShapeFilled(series, 0), fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, isLinesVisible(), new Line2D.Double(-7.0, 0.0, 7.0, 0.0), getItemStroke(series, 0), getItemPaint(series, 0) ); } return null; } /** * This renderer uses two passes to draw the data. * * @return The pass count (<code>2</code> for this renderer). */ public int getPassCount() { return 2; } /** * Draw a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area in which the data is drawn. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass index. */ public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // do nothing if item is not visible if (!getItemVisible(row, column)) { return; } // nothing is drawn for null... Number v = dataset.getValue(row, column); if (v == null) { return; } PlotOrientation orientation = plot.getOrientation(); // current data point... double x1 = domainAxis.getCategoryMiddle( column, getColumnCount(), dataArea, plot.getDomainAxisEdge() ); double value = v.doubleValue(); double y1 = rangeAxis.valueToJava2D( value, dataArea, plot.getRangeAxisEdge() ); if (pass == 0 && isLinesVisible()) { if (column != 0) { Number previousValue = dataset.getValue(row, column - 1); if (previousValue != null) { // previous data point... double previous = previousValue.doubleValue(); double x0 = domainAxis.getCategoryMiddle( column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge() ); double y0 = rangeAxis.valueToJava2D( previous, dataArea, plot.getRangeAxisEdge() ); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(y0, x0, y1, x1); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(x0, y0, x1, y1); } g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); g2.draw(line); } } } if (pass == 1) { Shape shape = getItemShape(row, column); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, y1, x1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, x1, y1); } if (isShapesVisible()) { if (getItemShapeFilled(row, column)) { if (this.useFillPaint) { g2.setPaint(getItemFillPaint(row, column)); } else { g2.setPaint(getItemPaint(row, column)); } g2.fill(shape); } if (this.drawOutlines) { if (this.useOutlinePaint) { g2.setPaint(getItemOutlinePaint(row, column)); } else { g2.setPaint(getItemPaint(row, column)); } g2.setStroke(getItemOutlineStroke(row, column)); g2.draw(shape); } } // draw the item label if there is one... if (isItemLabelVisible(row, column)) { if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel( g2, orientation, dataset, row, column, y1, x1, (value < 0.0) ); } else if (orientation == PlotOrientation.VERTICAL) { drawItemLabel( g2, orientation, dataset, row, column, x1, y1, (value < 0.0) ); } } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getInfo().getOwner().getEntityCollection(); if (entities != null && shape != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator( row, column ); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL( dataset, row, column ); } CategoryItemEntity entity = new CategoryItemEntity( shape, tip, url, dataset, row, dataset.getColumnKey(column), column ); entities.add(entity); } } } } /** * Tests this renderer for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ public boolean equals(Object obj) { if (obj == this) { return true; } if (!super.equals(obj)) { return false; } if (!(obj instanceof LineAndShapeRenderer)) { return false; } LineAndShapeRenderer that = (LineAndShapeRenderer) obj; if (this.linesVisible != that.linesVisible) { return false; } if (this.shapesVisible != that.shapesVisible) { return false; } if (!ObjectUtilities.equal(this.shapesFilled, that.shapesFilled)) { return false; } if (!ObjectUtilities.equal( this.seriesShapesFilled, that.seriesShapesFilled) ) { return false; } if (this.defaultShapesFilled != that.defaultShapesFilled) { return false; } if (this.useOutlinePaint != that.useOutlinePaint) { return false; } return true; } /** * Returns an independent copy of the renderer. * * @return A clone. * * @throws CloneNotSupportedException should not happen. */ public Object clone() throws CloneNotSupportedException { LineAndShapeRenderer clone = (LineAndShapeRenderer) super.clone(); clone.seriesShapesFilled = (BooleanList) this.seriesShapesFilled.clone(); return clone; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?