plot.java

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

JAVA
1,228
字号
     * renderers used by certain subclasses. You shouldn't need to call this      * method directly.     *      * @param g2  the graphics device.     * @param area  the area within which the plot should be drawn.     */    public void drawOutline(Graphics2D g2, Rectangle2D area) {        if ((this.outlineStroke != null) && (this.outlinePaint != null)) {            g2.setStroke(this.outlineStroke);            g2.setPaint(this.outlinePaint);            g2.draw(area);        }    }    /**     * Draws a message to state that there is no data to plot.     *     * @param g2  the graphics device.     * @param area  the area within which the plot should be drawn.     */    protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {        Shape savedClip = g2.getClip();        g2.clip(area);        String message = this.noDataMessage;        if (message != null) {            g2.setFont(this.noDataMessageFont);            g2.setPaint(this.noDataMessagePaint);            TextBlock block = TextUtilities.createTextBlock(                this.noDataMessage, this.noDataMessageFont,                 this.noDataMessagePaint,                 0.9f * (float) area.getWidth(), new G2TextMeasurer(g2)            );            block.draw(                g2, (float) area.getCenterX(), (float) area.getCenterY(),                 TextBlockAnchor.CENTER            );        }        g2.setClip(savedClip);    }    /**     * Handles a 'click' on the plot.  Since the plot does not maintain any     * information about where it has been drawn, the plot rendering info is      * supplied as an argument.     *     * @param x  the x coordinate (in Java2D space).     * @param y  the y coordinate (in Java2D space).     * @param info  an object containing information about the dimensions of      *              the plot.     */    public void handleClick(int x, int y, PlotRenderingInfo info) {        // provides a 'no action' default    }    /**     * Performs a zoom on the plot.  Subclasses should override if zooming is      * appropriate for the type of plot.     *     * @param percent  the zoom percentage.     */    public void zoom(double percent) {        // do nothing by default.    }    /**     * Receives notification of a change to one of the plot's axes.     *     * @param event  information about the event (not used here).     */    public void axisChanged(AxisChangeEvent event) {        notifyListeners(new PlotChangeEvent(this));    }    /**     * Receives notification of a change to the plot's dataset.     * <P>     * The plot reacts by passing on a plot change event to all registered      * listeners.     *     * @param event  information about the event (not used here).     */    public void datasetChanged(DatasetChangeEvent event) {        PlotChangeEvent newEvent = new PlotChangeEvent(this);        newEvent.setType(ChartChangeEventType.DATASET_UPDATED);        notifyListeners(newEvent);    }    /**     * Adjusts the supplied x-value.     *     * @param x  the x-value.     * @param w1  width 1.     * @param w2  width 2.     * @param edge  the edge (left or right).     *     * @return The adjusted x-value.     */    protected double getRectX(double x, double w1, double w2,                               RectangleEdge edge) {        double result = x;        if (edge == RectangleEdge.LEFT) {            result = result + w1;        }        else if (edge == RectangleEdge.RIGHT) {            result = result + w2;        }        return result;    }    /**     * Adjusts the supplied y-value.     *     * @param y  the x-value.     * @param h1  height 1.     * @param h2  height 2.     * @param edge  the edge (top or bottom).     *     * @return The adjusted y-value.     */    protected double getRectY(double y, double h1, double h2,                               RectangleEdge edge) {        double result = y;        if (edge == RectangleEdge.TOP) {            result = result + h1;        }        else if (edge == RectangleEdge.BOTTOM) {            result = result + h2;        }        return result;    }    /**     * Returns the data area ratio.     *     * @return The ratio.     */    public double getDataAreaRatio() {        return this.dataAreaRatio;    }    /**     * Sets the data area ratio.     *     * @param ratio  the ratio.     */    public void setDataAreaRatio(double ratio) {        this.dataAreaRatio = ratio;    }    /**     * Tests this plot for equality with another object.     *     * @param obj  the object.     *     * @return <code>true</code> or <code>false</code>.     */    public boolean equals(Object obj) {        if (obj == this) {            return true;        }        if (!(obj instanceof Plot)) {            return false;        }        Plot that = (Plot) obj;        if (!ObjectUtilities.equal(this.noDataMessage, that.noDataMessage)) {            return false;        }        if (!ObjectUtilities.equal(            this.noDataMessageFont, that.noDataMessageFont        )) {            return false;        }        if (!ObjectUtilities.equal(            this.noDataMessagePaint, that.noDataMessagePaint        )) {            return false;        }        if (!ObjectUtilities.equal(this.insets, that.insets)) {            return false;        }        if (!ObjectUtilities.equal(this.outlineStroke, that.outlineStroke)) {            return false;        }        if (!ObjectUtilities.equal(this.outlinePaint, that.outlinePaint)) {            return false;        }        if (!ObjectUtilities.equal(            this.backgroundPaint, that.backgroundPaint        )) {            return false;        }        if (!ObjectUtilities.equal(            this.backgroundImage, that.backgroundImage        )) {            return false;        }        if (this.backgroundImageAlignment != that.backgroundImageAlignment) {            return false;        }        if (this.foregroundAlpha != that.foregroundAlpha) {            return false;        }        if (this.backgroundAlpha != that.backgroundAlpha) {            return false;        }        return true;    }    /**     * Creates a clone of the plot.     *     * @return A clone.     *     * @throws CloneNotSupportedException if some component of the plot does not     *         support cloning.     */    public Object clone() throws CloneNotSupportedException {        Plot clone = (Plot) super.clone();        // private Plot parent <-- don't clone the parent plot, but take care         // childs in combined plots instead        if (this.datasetGroup != null) {            clone.datasetGroup                 = (DatasetGroup) ObjectUtilities.clone(this.datasetGroup);        }        clone.drawingSupplier             = (DrawingSupplier) ObjectUtilities.clone(this.drawingSupplier);        clone.listenerList = new EventListenerList();        return clone;    }    /**     * Provides serialization support.     *     * @param stream  the output stream.     *     * @throws IOException  if there is an I/O error.     */    private void writeObject(ObjectOutputStream stream) throws IOException {        stream.defaultWriteObject();        SerialUtilities.writePaint(this.noDataMessagePaint, stream);        SerialUtilities.writeStroke(this.outlineStroke, stream);        SerialUtilities.writePaint(this.outlinePaint, stream);        // backgroundImage        SerialUtilities.writePaint(this.backgroundPaint, stream);    }    /**     * Provides serialization support.     *     * @param stream  the input stream.     *     * @throws IOException  if there is an I/O error.     * @throws ClassNotFoundException  if there is a classpath problem.     */    private void readObject(ObjectInputStream stream)         throws IOException, ClassNotFoundException {        stream.defaultReadObject();        this.noDataMessagePaint = SerialUtilities.readPaint(stream);        this.outlineStroke = SerialUtilities.readStroke(stream);        this.outlinePaint = SerialUtilities.readPaint(stream);        // backgroundImage        this.backgroundPaint = SerialUtilities.readPaint(stream);        this.listenerList = new EventListenerList();    }    /**     * Resolves a domain axis location for a given plot orientation.     *     * @param location  the location (<code>null</code> not permitted).     * @param orientation  the orientation (<code>null</code> not permitted).     *     * @return The edge (never <code>null</code>).     */    public static RectangleEdge resolveDomainAxisLocation(            AxisLocation location, PlotOrientation orientation) {                if (location == null) {            throw new IllegalArgumentException("Null 'location' argument.");           }        if (orientation == null) {            throw new IllegalArgumentException("Null 'orientation' argument.");        }        RectangleEdge result = null;                if (location == AxisLocation.TOP_OR_RIGHT) {            if (orientation == PlotOrientation.HORIZONTAL) {                result = RectangleEdge.RIGHT;            }            else if (orientation == PlotOrientation.VERTICAL) {                result = RectangleEdge.TOP;            }        }        else if (location == AxisLocation.TOP_OR_LEFT) {            if (orientation == PlotOrientation.HORIZONTAL) {                result = RectangleEdge.LEFT;            }            else if (orientation == PlotOrientation.VERTICAL) {                result = RectangleEdge.TOP;            }        }        else if (location == AxisLocation.BOTTOM_OR_RIGHT) {            if (orientation == PlotOrientation.HORIZONTAL) {                result = RectangleEdge.RIGHT;            }            else if (orientation == PlotOrientation.VERTICAL) {                result = RectangleEdge.BOTTOM;            }        }        else if (location == AxisLocation.BOTTOM_OR_LEFT) {            if (orientation == PlotOrientation.HORIZONTAL) {                result = RectangleEdge.LEFT;            }            else if (orientation == PlotOrientation.VERTICAL) {                result = RectangleEdge.BOTTOM;            }        }        // the above should cover all the options...        if (result == null) {            throw new IllegalStateException("resolveDomainAxisLocation()");        }        return result;            }    /**     * Resolves a range axis location for a given plot orientation.     *     * @param location  the location (<code>null</code> not permitted).     * @param orientation  the orientation (<code>null</code> not permitted).     *     * @return The edge (never <code>null</code>).     */    public static RectangleEdge resolveRangeAxisLocation(            AxisLocation location, PlotOrientation orientation) {        if (location == null) {            throw new IllegalArgumentException("Null 'location' argument.");           }        if (orientation == null) {            throw new IllegalArgumentException("Null 'orientation' argument.");        }        RectangleEdge result = null;                if (location == AxisLocation.TOP_OR_RIGHT) {            if (orientation == PlotOrientation.HORIZONTAL) {                result = RectangleEdge.TOP;            }            else if (orientation == PlotOrientation.VERTICAL) {                result = RectangleEdge.RIGHT;            }        }        else if (location == AxisLocation.TOP_OR_LEFT) {            if (orientation == PlotOrientation.HORIZONTAL) {                result = RectangleEdge.TOP;            }            else if (orientation == PlotOrientation.VERTICAL) {                result = RectangleEdge.LEFT;            }        }        else if (location == AxisLocation.BOTTOM_OR_RIGHT) {            if (orientation == PlotOrientation.HORIZONTAL) {                result = RectangleEdge.BOTTOM;            }            else if (orientation == PlotOrientation.VERTICAL) {                result = RectangleEdge.RIGHT;            }        }        else if (location == AxisLocation.BOTTOM_OR_LEFT) {            if (orientation == PlotOrientation.HORIZONTAL) {                result = RectangleEdge.BOTTOM;            }            else if (orientation == PlotOrientation.VERTICAL) {                result = RectangleEdge.LEFT;            }        }        // the above should cover all the options...        if (result == null) {            throw new IllegalStateException("resolveRangeAxisLocation()");        }        return result;            }}

⌨️ 快捷键说明

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