xylineandshaperenderer.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,233 行 · 第 1/3 页
JAVA
1,233 行
* * @param visible the flag. */ public void setShapesVisible(boolean visible) { setShapesVisible(BooleanUtilities.valueOf(visible)); } /** * Returns the flag used to control whether or not the shapes for a series * are visible. * * @param series the series index (zero-based). * * @return A boolean. */ public Boolean getSeriesShapesVisible(int series) { return this.seriesShapesVisible.getBoolean(series); } /** * Sets the 'shapes visible' flag for a series and sends a * {@link RendererChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * @param visible the flag. */ public void setSeriesShapesVisible(int series, boolean visible) { setSeriesShapesVisible(series, BooleanUtilities.valueOf(visible)); } /** * Sets the 'shapes visible' flag for a series and sends a * {@link RendererChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * @param flag the flag. */ public void setSeriesShapesVisible(int series, Boolean flag) { this.seriesShapesVisible.setBoolean(series, flag); notifyListeners(new RendererChangeEvent(this)); } /** * Returns the default 'shape visible' attribute. * * @return The default flag. */ public boolean getDefaultShapesVisible() { return this.defaultShapesVisible; } /** * Sets the default 'shapes visible' flag. * * @param flag the flag. */ public void setDefaultShapesVisible(boolean flag) { this.defaultShapesVisible = flag; notifyListeners(new RendererChangeEvent(this)); } // SHAPES FILLED /** * Returns the flag used to control whether or not the shape for an item * is filled. * <p> * The default implementation passes control to the * <code>getSeriesShapesFilled</code> method. You can override this method * if you require different behaviour. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return A boolean. */ public boolean getItemShapeFilled(int series, int item) { Boolean flag = this.shapesFilled; if (flag == null) { flag = getSeriesShapesFilled(series); } if (flag != null) { return flag.booleanValue(); } else { return this.defaultShapesFilled; } } /** * Sets the 'shapes filled' for ALL series and sends a * {@link RendererChangeEvent} to all registered listeners. * * @param filled the flag. */ public void setShapesFilled(boolean filled) { setShapesFilled(BooleanUtilities.valueOf(filled)); } /** * Sets the 'shapes filled' for ALL series and sends a * {@link RendererChangeEvent} to all registered listeners. * * @param filled the flag (<code>null</code> permitted). */ public void setShapesFilled(Boolean filled) { this.shapesFilled = filled; notifyListeners(new RendererChangeEvent(this)); } /** * Returns the flag used to control whether or not the shapes for a series * are filled. * * @param series the series index (zero-based). * * @return A boolean. */ public Boolean getSeriesShapesFilled(int series) { return this.seriesShapesFilled.getBoolean(series); } /** * Sets the 'shapes filled' flag for a series. * * @param series the series index (zero-based). * @param flag the flag. */ public void setSeriesShapesFilled(int series, boolean flag) { setSeriesShapesFilled(series, BooleanUtilities.valueOf(flag)); } /** * Sets the 'shapes filled' flag for a series. * * @param series the series index (zero-based). * @param flag the flag. */ public void setSeriesShapesFilled(int series, Boolean flag) { this.seriesShapesFilled.setBoolean(series, flag); notifyListeners(new RendererChangeEvent(this)); } /** * 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; notifyListeners(new RendererChangeEvent(this)); } /** * Returns <code>true</code> if outlines should be drawn for shapes, and * <code>false</code> otherwise. * * @return A boolean. */ public boolean getDrawOutlines() { return this.drawOutlines; } /** * Sets the flag that controls whether outlines are drawn for * shapes, and sends a {@link RendererChangeEvent} to all registered * listeners. * <P> * In some cases, shapes look better if they do NOT have an outline, but * this flag allows you to set your own preference. * * @param flag the flag. */ public void setDrawOutlines(boolean flag) { this.drawOutlines = flag; notifyListeners(new RendererChangeEvent(this)); } /** * 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 <code>true</code> if the renderer should use the outline paint * setting to draw shape outlines, and <code>false</code> if it should just * use the regular paint. * * @return A boolean. */ public boolean getUseOutlinePaint() { return this.useOutlinePaint; } /** * Sets the flag that controls whether the outline paint is used to draw * shape outlines, and sends a {@link RendererChangeEvent} to all * registered listeners. * * @param flag the flag. */ public void setUseOutlinePaint(boolean flag) { this.useOutlinePaint = flag; notifyListeners(new RendererChangeEvent(this)); } /** * Records the state for the renderer. This is used to preserve state * information between calls to the drawItem() method for a single chart * drawing. */ public static class State extends XYItemRendererState { /** The path for the current series. */ public GeneralPath seriesPath; /** * A flag that indicates if the last (x, y) point was 'good' * (non-null). */ private boolean lastPointGood; /** * Creates a new state instance. * * @param info the plot rendering info. */ public State(PlotRenderingInfo info) { super(info); } /** * Returns a flag that indicates if the last point drawn (in the * current series) was 'good' (non-null). * * @return A boolean. */ public boolean isLastPointGood() { return this.lastPointGood; } /** * Sets a flag that indicates if the last point drawn (in the current * series) was 'good' (non-null). * * @param good the flag. */ public void setLastPointGood(boolean good) { this.lastPointGood = good; } } /** * Initialises the renderer. * <P> * This method will be called before the first item is rendered, giving the * renderer an opportunity to initialise any state information it wants to * maintain. The renderer can do nothing if it chooses. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * @param plot the plot. * @param data the data. * @param info an optional info collection object to return data back to * the caller. * * @return The renderer state. */ public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset data, PlotRenderingInfo info) { State state = new State(info); state.seriesPath = new GeneralPath(); return state; } /** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // do nothing if item is not visible if (!getItemVisible(series, item)) { return; } // first pass draws the background (lines, for instance) if (isLinePass(pass)) { if (item == 0) { if (this.drawSeriesLineAsPath) { State s = (State) state; s.seriesPath.reset(); s.lastPointGood = false; } } if (getItemLineVisible(series, item)) { if (this.drawSeriesLineAsPath) { drawPrimaryLineAsPath( state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis, dataArea ); } else { drawPrimaryLine( state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis, dataArea ); } } } // second pass adds shapes where the items are .. else if (isItemPass(pass)) { // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } drawSecondaryPass( g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis, crosshairState, entities ); } } /** * Returns <code>true</code> if the specified pass is the one for drawing * lines. * * @param pass the pass. * * @return A boolean. */ protected boolean isLinePass(int pass) { return pass == 0; } /** * Returns <code>true</code> if the specified pass is the one for drawing * items. * * @param pass the pass. * * @return A boolean. */ protected boolean isItemPass(int pass) { return pass == 1; } /** * Draws the item (first pass). This method draws the lines * connecting the items.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?