⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractcategoryitemrenderer.java

📁 jfreechart-1
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        )) {
            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;
    }
    
    /**
     * Adds an entity with the specified hotspot, but only if an entity 
     * collection is accessible via the renderer state.
     * 
     * @param entities  the entity collection.
     * @param dataset  the dataset.
     * @param row  the row index.
     * @param column  the column index.
     * @param hotspot  the hotspot.
     */
    protected void addItemEntity(EntityCollection entities, 
                                 CategoryDataset dataset, int row, int column,
                                 Shape hotspot) {

        String tip = null;
        CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
        if (tipster != null) {
            tip = tipster.generateToolTip(dataset, row, column);
        }
        String url = null;
        CategoryURLGenerator urlster = getItemURLGenerator(row, column);
        if (urlster != null) {
            url = urlster.generateURL(dataset, row, column);
        }
        CategoryItemEntity entity = new CategoryItemEntity(
            hotspot, tip, url, dataset, row, 
            dataset.getColumnKey(column), column
        );
        entities.add(entity);
    
    }

}

⌨️ 快捷键说明

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