pieplot.java

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

JAVA
1,886
字号
     *     * ...and this bug report in the Java Bug Parade:     *     * http://developer.java.sun.com/developer/bugParade/bugs/4836495.html     */    private double minimumArcAngleToDraw;    /** The resourceBundle for the localization. */    protected static ResourceBundle localizationResources =        ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle");    /**     * Creates a new plot.  The dataset is initially set to <code>null</code>.     */    public PiePlot() {        this(null);    }    /**     * Creates a plot that will draw a pie chart for the specified dataset.     *     * @param dataset  the dataset (<code>null</code> permitted).     */    public PiePlot(PieDataset dataset) {        super();        this.dataset = dataset;        if (dataset != null) {            dataset.addChangeListener(this);        }        this.pieIndex = 0;                this.interiorGap = DEFAULT_INTERIOR_GAP;        this.circular = true;        this.startAngle = DEFAULT_START_ANGLE;        this.direction = Rotation.CLOCKWISE;        this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;                this.sectionPaint = null;        this.sectionPaintList = new PaintList();        this.baseSectionPaint = null;        this.sectionOutlinePaint = null;        this.sectionOutlinePaintList = new PaintList();        this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;        this.sectionOutlineStroke = null;        this.sectionOutlineStrokeList = new StrokeList();        this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;                this.explodePercentages = new ObjectList();        this.labelGenerator = new StandardPieItemLabelGenerator();        this.labelFont = DEFAULT_LABEL_FONT;        this.labelPaint = DEFAULT_LABEL_PAINT;        this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;        this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;        this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;        this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;        this.labelLinksVisible = true;                this.toolTipGenerator = null;        this.urlGenerator = null;        this.legendLabelGenerator = new StandardPieSectionLabelGenerator();        this.legendLabelToolTipGenerator = null;        this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;                this.ignoreNullValues = false;        this.ignoreZeroValues = false;    }    /**     * Returns the dataset.     *     * @return The dataset (possibly <code>null</code>).     */    public PieDataset getDataset() {        return this.dataset;    }    /**     * Sets the dataset and sends a {@link DatasetChangeEvent} to 'this'.     *     * @param dataset  the dataset (<code>null</code> permitted).     */    public void setDataset(PieDataset dataset) {        // if there is an existing dataset, remove the plot from the list of         // change listeners...        PieDataset existing = this.dataset;        if (existing != null) {            existing.removeChangeListener(this);        }        // set the new dataset, and register the chart as a change listener...        this.dataset = dataset;        if (dataset != null) {            setDatasetGroup(dataset.getGroup());            dataset.addChangeListener(this);        }        // send a dataset change event to self...        DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);        datasetChanged(event);    }        /**     * Returns the pie index (this is used by the {@link MultiplePiePlot} class     * to track subplots).     *      * @return The pie index.     */    public int getPieIndex() {        return this.pieIndex;    }        /**     * Sets the pie index (this is used by the {@link MultiplePiePlot} class to      * track subplots).     *      * @param index  the index.     */    public void setPieIndex(int index) {        this.pieIndex = index;    }        /**     * Returns the start angle for the first pie section.  This is measured in      * degrees starting from 3 o'clock and measuring anti-clockwise.     *     * @return The start angle.     */    public double getStartAngle() {        return this.startAngle;    }    /**     * Sets the starting angle and sends a {@link PlotChangeEvent} to all      * registered listeners.  The initial default value is 90 degrees, which      * corresponds to 12 o'clock.  A value of zero corresponds to 3 o'clock...     * this is the encoding used by Java's Arc2D class.     *     * @param angle  the angle (in degrees).     */    public void setStartAngle(double angle) {        this.startAngle = angle;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the direction in which the pie sections are drawn (clockwise or      * anti-clockwise).     *     * @return The direction (never <code>null</code>).     */    public Rotation getDirection() {        return this.direction;    }    /**     * Sets the direction in which the pie sections are drawn and sends a      * {@link PlotChangeEvent} to all registered listeners.     *     * @param direction  the direction (<code>null</code> not permitted).     */    public void setDirection(Rotation direction) {        if (direction == null) {            throw new IllegalArgumentException("Null 'direction' argument.");        }        this.direction = direction;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the interior gap, measured as a percentage of the available      * drawing space.     *     * @return The gap (as a percentage of the available drawing space).     */    public double getInteriorGap() {        return this.interiorGap;    }    /**     * Sets the interior gap and sends a {@link PlotChangeEvent} to all      * registered listeners.  This controls the space between the edges of the      * pie plot and the plot area itself (the region where the section labels      * appear).     *     * @param percent  the gap (as a percentage of the available drawing space).     */    public void setInteriorGap(double percent) {        // check arguments...        if ((percent < 0.0) || (percent > MAX_INTERIOR_GAP)) {            throw new IllegalArgumentException(                "Invalid 'percent' (" + percent + ") argument.");        }        // make the change...        if (this.interiorGap != percent) {            this.interiorGap = percent;            notifyListeners(new PlotChangeEvent(this));        }    }    /**     * Returns a flag indicating whether the pie chart is circular, or     * stretched into an elliptical shape.     *     * @return A flag indicating whether the pie chart is circular.     */    public boolean isCircular() {        return this.circular;    }    /**     * A flag indicating whether the pie chart is circular, or stretched into     * an elliptical shape.     *     * @param flag  the new value.     */    public void setCircular(boolean flag) {        setCircular(flag, true);    }    /**     * Sets the circular attribute and, if requested, sends a      * {@link PlotChangeEvent} to all registered listeners.     *     * @param circular  the new value of the flag.     * @param notify  notify listeners?     */    public void setCircular(boolean circular, boolean notify) {        this.circular = circular;        if (notify) {            notifyListeners(new PlotChangeEvent(this));           }    }    /**     * Returns the flag that controls whether <code>null</code> values in the      * dataset are ignored.       *      * @return A boolean.     */    public boolean getIgnoreNullValues() {        return this.ignoreNullValues;       }        /**     * Sets a flag that controls whether <code>null</code> values are ignored,      * and sends a {@link PlotChangeEvent} to all registered listeners.  At      * present, this only affects whether or not the key is presented in the      * legend.     *      * @param flag  the flag.     */    public void setIgnoreNullValues(boolean flag) {        this.ignoreNullValues = flag;        notifyListeners(new PlotChangeEvent(this));    }        /**     * Returns the flag that controls whether zero values in the      * dataset are ignored.       *      * @return A boolean.     */    public boolean getIgnoreZeroValues() {        return this.ignoreZeroValues;       }        /**     * Sets a flag that controls whether zero values are ignored,      * and sends a {@link PlotChangeEvent} to all registered listeners.  This      * only affects whether or not a label appears for the non-visible     * pie section.     *      * @param flag  the flag.     */    public void setIgnoreZeroValues(boolean flag) {        this.ignoreZeroValues = flag;        notifyListeners(new PlotChangeEvent(this));    }        //// SECTION PAINT ////////////////////////////////////////////////////////    /**     * Returns the paint for ALL sections in the plot.     *     * @return The paint (possibly <code>null</code>).     */    public Paint getSectionPaint() {        return this.sectionPaint;    }    /**     * Sets the paint for ALL sections in the plot.  If this is set to     * </code>null</code>, then a list of paints is used instead (to allow     * different colors to be used for each section).     *     * @param paint  the paint (<code>null</code> permitted).     */    public void setSectionPaint(Paint paint) {        this.sectionPaint = paint;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the paint for the specified section.     *      * @param section  the section index (zero-based).     *      * @return The paint (never <code>null</code>).     */    public Paint getSectionPaint(int section) {                // return the override, if there is one...        if (this.sectionPaint != null) {            return this.sectionPaint;        }        // otherwise look up the paint list        Paint result = this.sectionPaintList.getPaint(section);        if (result == null) {            DrawingSupplier supplier = getDrawingSupplier();            if (supplier != null) {                Paint p = supplier.getNextPaint();                this.sectionPaintList.setPaint(section, p);                result = p;            }            else {                result = this.baseSectionPaint;            }        }        return result;           }        /**     * Sets the paint used to fill a section of the pie and sends a      * {@link PlotChangeEvent} to all registered listeners.     *     * @param section  the section index (zero-based).     * @param paint  the paint (<code>null</code> permitted).     */    public void setSectionPaint(int section, Paint paint) {        this.sectionPaintList.setPaint(section, paint);        notifyListeners(new PlotChangeEvent(this));    }        /**     * Returns the base section paint.  This is used when no other paint is      * available.     *      * @return The paint (never <code>null</code>).     */    public Paint getBaseSectionPaint() {        return this.baseSectionPaint;       }        /**     * Sets the base section paint.     *      * @param paint  the paint (<code>null</code> not permitted).     */    public void setBaseSectionPaint(Paint paint) {        if (paint == null) {            throw new IllegalArgumentException("Null 'paint' argument.");           }        this.baseSectionPaint = paint;        notifyListeners(new PlotChangeEvent(this));    }        //// SECTION OUTLINE PAINT ////////////////////////////////////////////////    /**

⌨️ 快捷键说明

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