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

📄 plot.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            Align.align(dest, area, this.backgroundImageAlignment);
            g2.drawImage(this.backgroundImage,
                         (int) dest.getX(), (int) dest.getY(),
                         (int) dest.getWidth() + 1, (int) dest.getHeight() + 1, null);
            g2.setComposite(originalComposite);
        }

    }

    /**
     * Draw the plot outline
     *
     * @param g2  the graphics device.
     * @param area  the area within which the plot should be drawn.
     */
    public void drawOutline(Graphics2D g2, Rectangle2D area) {

        if ((outlineStroke != null) && (outlinePaint != null)) {
            g2.setStroke(outlineStroke);
            g2.setPaint(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);
            FontRenderContext frc = g2.getFontRenderContext();
            Rectangle2D bounds = noDataMessageFont.getStringBounds(message, frc);
            float x = (float) (area.getX() + area.getWidth() / 2 - bounds.getWidth() / 2);
            float y = (float) (area.getMinY() + (area.getHeight() / 2) - (bounds.getHeight() / 2));
            g2.drawString(message, x, y);
        }
        g2.clip(savedClip);

    }

    /**
     * Handles a 'click' on the plot.  Since the plot does not maintain any
     * information about where it has been drawn, the plot area is supplied as
     * an argument.
     *
     * @param x  the x coordinate.
     * @param y  the y coordinate.
     * @param info  an object for collecting information about the drawing of the chart.
     */
    public void handleClick(int x, int y, ChartRenderingInfo info) {

    }

    /**
     * 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);
        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 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 == null) {
            return false;
        }

        if (obj == this) {
            return true;
        }

        if (obj instanceof Plot) {

            Plot p = (Plot) obj;

            boolean b5 = ObjectUtils.equalOrBothNull(this.noDataMessage, p.noDataMessage);
            boolean b6 = ObjectUtils.equalOrBothNull(this.noDataMessageFont, p.noDataMessageFont);
            boolean b7 = ObjectUtils.equalOrBothNull(this.noDataMessagePaint, p.noDataMessagePaint);

            boolean b8 = ObjectUtils.equalOrBothNull(this.insets, p.insets);
            boolean b9 = ObjectUtils.equalOrBothNull(this.outlineStroke, p.outlineStroke);
            boolean b10 = ObjectUtils.equalOrBothNull(this.outlinePaint, p.outlinePaint);

            boolean b11 = ObjectUtils.equalOrBothNull(this.backgroundPaint, p.backgroundPaint);
            boolean b12 = ObjectUtils.equalOrBothNull(this.backgroundImage, p.backgroundImage);
            boolean b13 = (this.backgroundImageAlignment == p.backgroundImageAlignment);

            boolean b14 = (this.foregroundAlpha == p.foregroundAlpha);
            boolean b15 = (this.backgroundAlpha == p.backgroundAlpha);

            return b5 && b6 && b7 && b8 && b9
                   && b10 && b11 && b12 && b13 && b14 && b15;

        }

        return false;

    }

    /**
     * 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.
     * @param orientation  the orientation.
     * 
     * @return The edge for the domain axis.
     */
    public static RectangleEdge resolveDomainAxisLocation(AxisLocation location, 
                                                          PlotOrientation orientation) {
        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 {
                throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
            }
        }
        else if (location == AxisLocation.TOP_OR_LEFT) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                result = RectangleEdge.LEFT;
            }
            else if (orientation == PlotOrientation.VERTICAL) {
                result = RectangleEdge.TOP;
            }
            else {
                throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
            }
        }
        else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                result = RectangleEdge.RIGHT;
            }
            else if (orientation == PlotOrientation.VERTICAL) {
                result = RectangleEdge.BOTTOM;
            }
            else {
                throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
            }
        }
        else if (location == AxisLocation.BOTTOM_OR_LEFT) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                result = RectangleEdge.LEFT;
            }
            else if (orientation == PlotOrientation.VERTICAL) {
                result = RectangleEdge.BOTTOM;
            }
            else {
                throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
            }
        }
        return result;
    }

    /**
     * Resolves a domain axis location for a given plot orientation.
     * 
     * @param location  the location.
     * @param orientation  the orientation.
     * 
     * @return The edge for the domain axis.
     */
    public static RectangleEdge resolveRangeAxisLocation(AxisLocation location, 
                                                         PlotOrientation orientation) {
        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 {
                throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
            }
        }
        else if (location == AxisLocation.TOP_OR_LEFT) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                result = RectangleEdge.TOP;
            }
            else if (orientation == PlotOrientation.VERTICAL) {
                result = RectangleEdge.LEFT;
            }
            else {
                throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
            }
        }
        else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                result = RectangleEdge.BOTTOM;
            }
            else if (orientation == PlotOrientation.VERTICAL) {
                result = RectangleEdge.RIGHT;
            }
            else {
                throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
            }
        }
        else if (location == AxisLocation.BOTTOM_OR_LEFT) {
            if (orientation == PlotOrientation.HORIZONTAL) {
                result = RectangleEdge.BOTTOM;
            }
            else if (orientation == PlotOrientation.VERTICAL) {
                result = RectangleEdge.LEFT;
            }
            else {
                throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
            }
        }
        return result;
    }

}

⌨️ 快捷键说明

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