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

📄 standardxyitemrenderer.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void setDefaultShapesFilled(Boolean flag) {
        this.defaultShapesFilled = flag;
    }

    /**
     * Returns true if lines are being plotted by the renderer.
     *
     * @return <code>true</code> if lines are being plotted by the renderer.
     */
    public boolean getPlotLines() {
        return this.plotLines;
    }

    /**
     * Sets the flag that controls whether or not a line is plotted between each data point.
     *
     * @param flag  the flag.
     */
    public void setPlotLines(boolean flag) {
        if (this.plotLines != flag) {
            Object oldValue = new Boolean(this.plotLines);
            this.plotLines = flag;
            firePropertyChanged("renderer.PlotLines", oldValue, new Boolean(flag));
        }
    }

    /**
     * Returns the gap threshold for discontinuous lines.
     *
     * @return the gap threshold.
     */
    public double getGapThreshold() {
        return this.gapThreshold;
    }

    /**
     * Sets the gap threshold for discontinuous lines.
     *
     * @param t  the threshold.
     */
    public void setGapThreshold(double t) {
        Object oldValue = new Double(this.gapThreshold);
        this.gapThreshold = t;
        firePropertyChanged("renderer.GapThreshold", oldValue, new Double(t));
    }

    /**
     * Returns true if images are being plotted by the renderer.
     *
     * @return <code>true</code> if images are being plotted by the renderer.
     */
    public boolean getPlotImages() {
        return this.plotImages;
    }

    /**
     * Sets the flag that controls whether or not an image is drawn at each data point.
     *
     * @param flag  the flag.
     */
    public void setPlotImages(boolean flag) {
        if (this.plotImages != flag) {
            Object oldValue = new Boolean(this.plotImages);
            this.plotImages = flag;
            firePropertyChanged("renderer.PlotImages", oldValue, new Boolean(flag));
        }
    }

    /**
     * Returns true if lines should be discontinuous.
     *
     * @return <code>true</code> if images are being plotted by the renderer.
     */
    public boolean getPlotDiscontinuous() {
        return this.plotDiscontinuous;
    }

    /**
     * Draws the visual representation of a single data item.
     *
     * @param g2  the graphics device.
     * @param dataArea  the area within which the data is being drawn.
     * @param info  collects information about the drawing.
     * @param plot  the plot (can be used to obtain standard color information etc).
     * @param domainAxis  the domain axis.
     * @param rangeAxis  the range axis.
     * @param dataset  the dataset.
     * @param series  the series index (zero-based).
     * @param item  the item index (zero-based).
     * @param crosshairInfo  information about crosshairs on a plot.
     * @param pass  the pass index.
     */
    public void drawItem(Graphics2D g2,
                         Rectangle2D dataArea,
                         ChartRenderingInfo info,
                         XYPlot plot,
                         ValueAxis domainAxis,
                         ValueAxis rangeAxis,
                         XYDataset dataset,
                         int series,
                         int item,
                         CrosshairInfo crosshairInfo,
                         int pass) {

        // setup for collecting optional entity info...
        Shape entityArea = null;
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getEntityCollection();
        }

        Paint paint = getItemPaint(series, item);
        Stroke seriesStroke = getItemStroke(series, item);
        g2.setPaint(paint);
        g2.setStroke(seriesStroke);

        // get the data point...
        Number x1n = dataset.getXValue(series, item);
        Number y1n = dataset.getYValue(series, item);
        if (y1n == null) {
            return;
        }

        double x1 = x1n.doubleValue();
        double y1 = y1n.doubleValue();
        final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
        final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
        double transX1 = domainAxis.translateValueToJava2D(x1, dataArea, xAxisLocation);
        double transY1 = rangeAxis.translateValueToJava2D(y1, dataArea, yAxisLocation);

        if (this.plotLines) {

            if (item > 0) {
                // get the previous data point...
                Number x0n = dataset.getXValue(series, item - 1);
                Number y0n = dataset.getYValue(series, item - 1);
                if (y0n != null) {
                    double x0 = x0n.doubleValue();
                    double y0 = y0n.doubleValue();
                    boolean drawLine = true;
                    if (this.plotDiscontinuous) {
                        // only draw a line if the gap between the current and previous data
                        // point is within the threshold
                        int numX = dataset.getItemCount(series);
                        double minX = dataset.getXValue(series, 0).doubleValue();
                        double maxX = dataset.getXValue(series, numX - 1).doubleValue();
                        drawLine = (x1 - x0) <= ((maxX - minX) / numX * this.gapThreshold);
                    }
                    if (drawLine) {
                        double transX0 
                            = domainAxis.translateValueToJava2D(x0, dataArea, xAxisLocation);
                        double transY0 
                            = rangeAxis.translateValueToJava2D(y0, dataArea, yAxisLocation);

                        PlotOrientation orientation = plot.getOrientation();
                        if (orientation == PlotOrientation.HORIZONTAL) {
                            line.setLine(transY0, transX0, transY1, transX1);
                        }
                        else if (orientation == PlotOrientation.VERTICAL) {
                            line.setLine(transX0, transY0, transX1, transY1);
                        }

                        if (line.intersects(dataArea)) {
                            g2.draw(line);
                        }
                    }
                }
            }
        }

        if (this.plotShapes) {

            Shape shape = getItemShape(series, item);
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL) {
                shape = createTransformedShape(shape, transY1, transX1);
            }
            else if (orientation == PlotOrientation.VERTICAL) {
                shape = createTransformedShape(shape, transX1, transY1);
            }
            if (shape.intersects(dataArea)) {
                if (getItemShapeFilled(series, item)) {
                    g2.fill(shape);
                }
                else {
                    g2.draw(shape);
                }
            }
            entityArea = shape;

        }

        if (this.plotImages) {
            // use shape scale with transform??
            //double scale = getShapeScale(plot, series, item, transX1, transY1);
            Image image = getImage(plot, series, item, transX1, transY1);
            if (image != null) {
                Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
                g2.drawImage(image,
                             (int) (transX1 - hotspot.getX()),
                             (int) (transY1 - hotspot.getY()), (ImageObserver) null);
                entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(),
                                                    transY1 - hotspot.getY(),
                                                    image.getWidth(null),
                                                    image.getHeight(null));
            }

        }

        // add an entity for the item...
        if (entities != null) {
            if (entityArea == null) {
                entityArea = new Rectangle2D.Double(transX1 - 2, transY1 - 2, 4, 4);
            }
            String tip = null;
            if (getToolTipGenerator() != null) {
                tip = getToolTipGenerator().generateToolTip(dataset, series, item);
            }
            String url = null;
            if (getURLGenerator() != null) {
                url = getURLGenerator().generateURL(dataset, series, item);
            }
            XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, url);
            entities.addEntity(entity);
        }

        // do we need to update the crosshair values?
        if (plot.isDomainCrosshairLockedOnData()) {
            if (plot.isRangeCrosshairLockedOnData()) {
                // both axes
                crosshairInfo.updateCrosshairPoint(x1, y1);
            }
            else {
                // just the horizontal axis...
                crosshairInfo.updateCrosshairX(x1);
            }
        }
        else {
            if (plot.isRangeCrosshairLockedOnData()) {
                // just the vertical axis...
                crosshairInfo.updateCrosshairY(y1);
            }
        }

    }

    /**
     * Tests this renderer 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 StandardXYItemRenderer) {
            StandardXYItemRenderer r = (StandardXYItemRenderer) obj;
            if (super.equals(obj)) {
                boolean b0 = (this.plotShapes == r.plotShapes);
                boolean b1 = (this.plotLines == r.plotLines);
                boolean b2 = (this.plotImages == r.plotImages);
                boolean b3 = (this.plotDiscontinuous == r.plotDiscontinuous);
                boolean b4 = (this.gapThreshold == r.gapThreshold);
                //boolean b5 = (this.defaultShapeFilled == r.defaultShapeFilled);
                return b0 && b1 && b2 && b3 && b4;
            }
        }

        return false;

    }

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // PROTECTED METHODS
    // These provide the opportunity to subclass the standard renderer and create custom effects.
    ////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * Returns the image used to draw a single data item.
     *
     * @param plot  the plot (can be used to obtain standard color information etc).
     * @param series  the series index.
     * @param item  the item index.
     * @param x  the x value of the item.
     * @param y  the y value of the item.
     *
     * @return the image.
     */
    protected Image getImage(Plot plot, int series, int item, double x, double y) {
        // should this be added to the plot as well ?
        // return plot.getShape(series, item, x, y, scale);
        // or should this be left to the user - like this:
        return null;
    }

    /**
     * Returns the hotspot of the image used to draw a single data item.
     * The hotspot is the point relative to the top left of the image
     * that should indicate the data item. The default is the center of the
     * image.
     *
     * @param plot  the plot (can be used to obtain standard color information etc).
     * @param image  the image (can be used to get size information about the image)
     * @param series  the series index
     * @param item  the item index
     * @param x  the x value of the item
     * @param y  the y value of the item
     *
     * @return the hotspot used to draw the data item.
     */
    protected Point getImageHotspot(Plot plot, int series, int item,
                                    double x, double y, Image image) {

        int height = image.getHeight(null);
        int width = image.getWidth(null);
        return new Point(width / 2, height / 2);

    }

}

⌨️ 快捷键说明

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