abstractcategoryitemrenderer.java

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

JAVA
1,414
字号
        if (!ObjectUtilities.equal(this.itemLabelGenerator,                 that.itemLabelGenerator)) {            return false;        }        if (!ObjectUtilities.equal(            this.itemLabelGeneratorList, that.itemLabelGeneratorList        )) {            return false;        }        if (!ObjectUtilities.equal(            this.baseItemLabelGenerator, that.baseItemLabelGenerator        )) {            return false;        }        if (!ObjectUtilities.equal(            this.toolTipGenerator, that.toolTipGenerator        )) {            return false;        }        if (!ObjectUtilities.equal(            this.toolTipGeneratorList, that.toolTipGeneratorList        )) {            return false;        }        if (!ObjectUtilities.equal(            this.baseToolTipGenerator, that.baseToolTipGenerator         )) {            return false;        }        if (!ObjectUtilities.equal(            this.itemURLGenerator, that.itemURLGenerator        )) {            return false;        }        if (!ObjectUtilities.equal(            this.itemURLGeneratorList, that.itemURLGeneratorList        )) {            return false;        }        if (!ObjectUtilities.equal(            this.baseItemURLGenerator, that.baseItemURLGenerator        )) {            return false;        }        return true;    }        /**     * Returns a hash code for the renderer.     *      * @return The hash code.     */    public int hashCode() {        int result = super.hashCode();        return result;    }    /**     * Returns the drawing supplier from the plot.     *     * @return The drawing supplier (possibly <code>null</code>).     */    public DrawingSupplier getDrawingSupplier() {        DrawingSupplier result = null;        CategoryPlot cp = getPlot();        if (cp != null) {            result = cp.getDrawingSupplier();        }        return result;    }    /**     * Draws an item label.     *     * @param g2  the graphics device.     * @param orientation  the orientation.     * @param dataset  the dataset.     * @param row  the row.     * @param column  the column.     * @param x  the x coordinate (in Java2D space).     * @param y  the y coordinate (in Java2D space).     * @param negative  indicates a negative value (which affects the item      *                  label position).     */    protected void drawItemLabel(Graphics2D g2,                                  PlotOrientation orientation,                                 CategoryDataset dataset,                                  int row, int column,                                 double x, double y,                                  boolean negative) {                                             CategoryItemLabelGenerator generator             = getItemLabelGenerator(row, column);        if (generator != null) {            Font labelFont = getItemLabelFont(row, column);            Paint paint = getItemLabelPaint(row, column);            g2.setFont(labelFont);            g2.setPaint(paint);            String label = generator.generateLabel(dataset, row, column);            ItemLabelPosition position = null;            if (!negative) {                position = getPositiveItemLabelPosition(row, column);            }            else {                position = getNegativeItemLabelPosition(row, column);            }            Point2D anchorPoint = calculateLabelAnchorPoint(                position.getItemLabelAnchor(), x, y, orientation            );            TextUtilities.drawRotatedString(                label, g2,                 (float) anchorPoint.getX(), (float) anchorPoint.getY(),                position.getTextAnchor(),                 position.getAngle(), position.getRotationAnchor()            );        }    }        /**     * Returns an independent copy of the renderer.  The <code>plot</code>      * reference is shallow copied.     *      * @return A clone.     *      * @throws CloneNotSupportedException  can be thrown if one of the objects      *         belonging to the renderer does not support cloning (for example,     *         an item label generator).     */    public Object clone() throws CloneNotSupportedException {                AbstractCategoryItemRenderer clone             = (AbstractCategoryItemRenderer) super.clone();        if (this.itemLabelGenerator != null) {            if (this.itemLabelGenerator instanceof PublicCloneable) {                PublicCloneable pc = (PublicCloneable) this.itemLabelGenerator;                clone.itemLabelGenerator                     = (CategoryItemLabelGenerator) pc.clone();            }            else {                throw new CloneNotSupportedException(                    "ItemLabelGenerator not cloneable."                );            }        }        if (this.itemLabelGeneratorList != null) {            clone.itemLabelGeneratorList                 = (ObjectList) this.itemLabelGeneratorList.clone();        }                if (this.baseItemLabelGenerator != null) {            if (this.baseItemLabelGenerator instanceof PublicCloneable) {                PublicCloneable pc                     = (PublicCloneable) this.baseItemLabelGenerator;                clone.baseItemLabelGenerator                     = (CategoryItemLabelGenerator) pc.clone();            }            else {                throw new CloneNotSupportedException(                    "ItemLabelGenerator not cloneable."                );            }        }                if (this.toolTipGenerator != null) {            if (this.toolTipGenerator instanceof PublicCloneable) {                PublicCloneable pc = (PublicCloneable) this.toolTipGenerator;                clone.toolTipGenerator = (CategoryToolTipGenerator) pc.clone();            }            else {                throw new CloneNotSupportedException(                    "Tool tip generator not cloneable."                );            }        }        if (this.toolTipGeneratorList != null) {            clone.toolTipGeneratorList                 = (ObjectList) this.toolTipGeneratorList.clone();        }                if (this.baseToolTipGenerator != null) {            if (this.baseToolTipGenerator instanceof PublicCloneable) {                PublicCloneable pc                     = (PublicCloneable) this.baseToolTipGenerator;                clone.baseToolTipGenerator                     = (CategoryToolTipGenerator) pc.clone();            }            else {                throw new CloneNotSupportedException(                    "Base tool tip generator not cloneable."                );            }        }                if (this.itemURLGenerator != null) {            if (this.itemURLGenerator instanceof PublicCloneable) {                PublicCloneable pc = (PublicCloneable) this.itemURLGenerator;                clone.itemURLGenerator = (CategoryURLGenerator) pc.clone();            }            else {                throw new CloneNotSupportedException(                    "Item URL generator not cloneable."                );            }        }        if (this.itemURLGeneratorList != null) {            clone.itemURLGeneratorList                 = (ObjectList) this.itemURLGeneratorList.clone();        }        if (this.baseItemURLGenerator != null) {            if (this.baseItemURLGenerator instanceof PublicCloneable) {                PublicCloneable pc                     = (PublicCloneable) this.baseItemURLGenerator;                   clone.baseItemURLGenerator = (CategoryURLGenerator) pc.clone();            }            else {                throw new CloneNotSupportedException(                    "Base item URL generator not cloneable."                );               }        }                return clone;    }    /**     * Returns a domain axis for a plot.     *      * @param plot  the plot.     * @param index  the axis index.     *      * @return A domain axis.     */    protected CategoryAxis getDomainAxis(CategoryPlot plot, int index) {        CategoryAxis result = plot.getDomainAxis(index);        if (result == null) {            result = plot.getDomainAxis();        }        return result;    }    /**     * Returns a range axis for a plot.     *      * @param plot  the plot.     * @param index  the axis index (<code>null</code> for the primary axis).     *      * @return A range axis.     */    protected ValueAxis getRangeAxis(CategoryPlot plot, int index) {        ValueAxis result = plot.getRangeAxis(index);        if (result == null) {            result = plot.getRangeAxis();        }        return result;    }        /**     * Returns a (possibly empty) collection of legend items for the series     * that this renderer is responsible for drawing.     *     * @return The legend item collection (never <code>null</code>).     */    public LegendItemCollection getLegendItems() {        if (this.plot == null) {            return new LegendItemCollection();        }        LegendItemCollection result = new LegendItemCollection();        int index = this.plot.getIndexOf(this);        CategoryDataset dataset = this.plot.getDataset(index);        if (dataset != null) {            int seriesCount = dataset.getRowCount();            for (int i = 0; i < seriesCount; i++) {                LegendItem item = getLegendItem(index, i);                if (item != null) {                    result.add(item);                }            }           }        return result;    }        /**     * Returns the legend item label generator.     *      * @return The label generator (never <code>null</code>).     */    public CategorySeriesLabelGenerator getLegendItemLabelGenerator() {        return this.legendItemLabelGenerator;    }        /**     * Sets the legend item label generator.     *      * @param generator  the generator (<code>null</code> not permitted).     */    public void setLegendItemLabelGenerator(            CategorySeriesLabelGenerator generator) {        if (generator == null) {            throw new IllegalArgumentException("Null 'generator' argument.");        }        this.legendItemLabelGenerator = generator;    }        /**     * Returns the legend item tool tip generator.     *      * @return The tool tip generator (possibly <code>null</code>).     */    public CategorySeriesLabelGenerator getLegendItemToolTipGenerator() {        return this.legendItemToolTipGenerator;    }        /**     * Sets the legend item tool tip generator.     *      * @param generator  the generator (<code>null</code> permitted).     */    public void setLegendItemToolTipGenerator(            CategorySeriesLabelGenerator generator) {        this.legendItemToolTipGenerator = generator;    }    /**     * Returns the legend item URL generator.     *      * @return The URL generator (possibly <code>null</code>).     */    public CategorySeriesLabelGenerator getLegendItemURLGenerator() {        return this.legendItemURLGenerator;    }        /**     * Sets the legend item URL generator.     *      * @param generator  the generator (<code>null</code> permitted).     */    public void setLegendItemURLGenerator(            CategorySeriesLabelGenerator generator) {        this.legendItemURLGenerator = generator;    }}

⌨️ 快捷键说明

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