abstractcategoryitemrenderer.java

来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,414 行 · 第 1/4 页

JAVA
1,414
字号
     * Returns the tool tip generator that will be used for ALL items in the      * dataset (the "layer 0" generator).     *      * @return A tool tip generator (possibly <code>null</code>).     */    public CategoryToolTipGenerator getToolTipGenerator() {        return this.toolTipGenerator;        }        /**     * Sets the tool tip generator for ALL series and sends a      * {@link org.jfree.chart.event.RendererChangeEvent} to all registered      * listeners.     *      * @param generator  the generator (<code>null</code> permitted).     */    public void setToolTipGenerator(CategoryToolTipGenerator generator) {        this.toolTipGenerator = generator;        notifyListeners(new RendererChangeEvent(this));    }    /**     * Returns the tool tip generator for the specified series (a "layer 1"      * generator).     *     * @param series  the series index (zero-based).     *     * @return The tool tip generator (possibly <code>null</code>).     */    public CategoryToolTipGenerator getSeriesToolTipGenerator(int series) {        return (CategoryToolTipGenerator) this.toolTipGeneratorList.get(series);    }    /**     * Sets the tool tip generator for a series and sends a      * {@link org.jfree.chart.event.RendererChangeEvent} to all registered      * listeners.     *     * @param series  the series index (zero-based).     * @param generator  the generator (<code>null</code> permitted).     */    public void setSeriesToolTipGenerator(int series,                                           CategoryToolTipGenerator generator) {        this.toolTipGeneratorList.set(series, generator);        notifyListeners(new RendererChangeEvent(this));    }    /**     * Returns the base tool tip generator (the "layer 2" generator).     *     * @return The tool tip generator (possibly <code>null</code>).     */    public CategoryToolTipGenerator getBaseToolTipGenerator() {        return this.baseToolTipGenerator;    }    /**     * Sets the base tool tip generator and sends a      * {@link org.jfree.chart.event.RendererChangeEvent} to all registered      * listeners.     *     * @param generator  the generator (<code>null</code> permitted).     */    public void setBaseToolTipGenerator(CategoryToolTipGenerator generator) {        this.baseToolTipGenerator = generator;        notifyListeners(new RendererChangeEvent(this));    }    // URL GENERATOR        /**     * Returns the URL generator for a data item.  This method just calls the     * getSeriesItemURLGenerator method, but you can override this behaviour if     * you want to.     *     * @param row  the row index (zero based).     * @param column  the column index (zero based).     *     * @return The URL generator.     */    public CategoryURLGenerator getItemURLGenerator(int row, int column) {        return getSeriesItemURLGenerator(row);    }    /**     * Returns the URL generator for a series.     *     * @param series  the series index (zero based).     *     * @return The URL generator for the series.     */    public CategoryURLGenerator getSeriesItemURLGenerator(int series) {        // return the generator for ALL series, if there is one...        if (this.itemURLGenerator != null) {            return this.itemURLGenerator;        }        // otherwise look up the generator table        CategoryURLGenerator generator            = (CategoryURLGenerator) this.itemURLGeneratorList.get(series);        if (generator == null) {            generator = this.baseItemURLGenerator;        }        return generator;    }    /**     * Sets the item URL generator for ALL series.     *     * @param generator  the generator.     */    public void setItemURLGenerator(CategoryURLGenerator generator) {        this.itemURLGenerator = generator;    }    /**     * Sets the URL generator for a series.     *     * @param series  the series index (zero based).     * @param generator  the generator.     */    public void setSeriesItemURLGenerator(int series,                                           CategoryURLGenerator generator) {        this.itemURLGeneratorList.set(series, generator);    }    /**     * Returns the base item URL generator.     *     * @return The item URL generator.     */    public CategoryURLGenerator getBaseItemURLGenerator() {        return this.baseItemURLGenerator;    }    /**     * Sets the base item URL generator.     *     * @param generator  the item URL generator.     */    public void setBaseItemURLGenerator(CategoryURLGenerator generator) {        this.baseItemURLGenerator = generator;    }    /**     * Returns the number of rows in the dataset.  This value is updated in the     * {@link AbstractCategoryItemRenderer#initialise} method.     *     * @return The row count.     */    public int getRowCount() {        return this.rowCount;    }    /**     * Returns the number of columns in the dataset.  This value is updated in      * the {@link AbstractCategoryItemRenderer#initialise} method.     *     * @return The column count.     */    public int getColumnCount() {        return this.columnCount;    }    /**     * Initialises the renderer and returns a state object that will be used      * for the remainder of the drawing process for a single chart.  The state      * object allows for the fact that the renderer may be used simultaneously      * by multiple threads (each thread will work with a separate state object).     * <P>     * Stores a reference to the {@link PlotRenderingInfo} object (which might      * be <code>null</code>), and then sets the useCategoriesPaint flag      * according to the special case conditions a) there is only one series      * and b) the categoriesPaint array is not null.     *     * @param g2  the graphics device.     * @param dataArea  the data area.     * @param plot  the plot.     * @param rendererIndex  the renderer index.     * @param info  an object for returning information about the structure of      *              the plot (<code>null</code> permitted).     *      * @return The renderer state.     *     */    public CategoryItemRendererState initialise(Graphics2D g2,                                                 Rectangle2D dataArea,                                                CategoryPlot plot,                                                 int rendererIndex,                                                PlotRenderingInfo info) {        setPlot(plot);        CategoryDataset data = plot.getDataset(rendererIndex);        if (data != null) {            this.rowCount = data.getRowCount();            this.columnCount = data.getColumnCount();        }        else {            this.rowCount = 0;            this.columnCount = 0;        }        return new CategoryItemRendererState(info);    }    /**     * Returns the range of values the renderer requires to display all the      * items from the specified dataset.     *      * @param dataset  the dataset (<code>null</code> permitted).     *      * @return The range (or <code>null</code> if the dataset is      *         <code>null</code> or empty).     */    public Range findRangeBounds(CategoryDataset dataset) {        return DatasetUtilities.findRangeBounds(dataset);       }    /**     * Draws a background for the data area.  The default implementation just      * gets the plot to draw the outline, but some renderers will override this     * behaviour.     *     * @param g2  the graphics device.     * @param plot  the plot.     * @param dataArea  the data area.     */    public void drawBackground(Graphics2D g2,                               CategoryPlot plot,                               Rectangle2D dataArea) {        plot.drawBackground(g2, dataArea);    }    /**     * Draws an outline for the data area.  The default implementation just      * gets the plot to draw the outline, but some renderers will override this     * behaviour.     *     * @param g2  the graphics device.     * @param plot  the plot.     * @param dataArea  the data area.     */    public void drawOutline(Graphics2D g2,                            CategoryPlot plot,                            Rectangle2D dataArea) {        plot.drawOutline(g2, dataArea);    }    /**     * Draws a grid line against the domain axis.     * <P>     * Note that this default implementation assumes that the horizontal axis      * is the domain axis. If this is not the case, you will need to override      * this method.     *     * @param g2  the graphics device.     * @param plot  the plot.     * @param dataArea  the area for plotting data (not yet adjusted for any      *                  3D effect).     * @param value  the Java2D value at which the grid line should be drawn.     */    public void drawDomainGridline(Graphics2D g2,                                   CategoryPlot plot,                                   Rectangle2D dataArea,                                   double value) {        Line2D line = null;        PlotOrientation orientation = plot.getOrientation();        if (orientation == PlotOrientation.HORIZONTAL) {            line = new Line2D.Double(                dataArea.getMinX(), value, dataArea.getMaxX(), value            );        }        else if (orientation == PlotOrientation.VERTICAL) {            line = new Line2D.Double(                value, dataArea.getMinY(), value, dataArea.getMaxY()            );        }        Paint paint = plot.getDomainGridlinePaint();        if (paint == null) {            paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;        }        g2.setPaint(paint);        Stroke stroke = plot.getDomainGridlineStroke();        if (stroke == null) {            stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;        }        g2.setStroke(stroke);        g2.draw(line);    }    /**     * Draws a grid line against the range axis.     *     * @param g2  the graphics device.     * @param plot  the plot.     * @param axis  the value axis.     * @param dataArea  the area for plotting data (not yet adjusted for any      *                  3D effect).     * @param value  the value at which the grid line should be drawn.     *     */    public void drawRangeGridline(Graphics2D g2,                                  CategoryPlot plot,                                  ValueAxis axis,                                  Rectangle2D dataArea,                                  double value) {        Range range = axis.getRange();        if (!range.contains(value)) {            return;        }        PlotOrientation orientation = plot.getOrientation();        double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());        Line2D line = null;        if (orientation == PlotOrientation.HORIZONTAL) {            line = new Line2D.Double(                v, dataArea.getMinY(), v, dataArea.getMaxY()            );        }        else if (orientation == PlotOrientation.VERTICAL) {            line = new Line2D.Double(                dataArea.getMinX(), v, dataArea.getMaxX(), v            );        }        Paint paint = plot.getRangeGridlinePaint();        if (paint == null) {            paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;        }        g2.setPaint(paint);        Stroke stroke = plot.getRangeGridlineStroke();        if (stroke == null) {            stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;        }        g2.setStroke(stroke);        g2.draw(line);    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?