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

📄 abstractxyitemrenderer.java

📁 这是一个segy数据显示程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    marker.getLabelTextAnchor()                );            }        }    }    /**     * Calculates the (x, y) coordinates for drawing a marker label.     *     * @param g2  the graphics device.     * @param orientation  the plot orientation.     * @param dataArea  the data area.     * @param markerArea  the rectangle surrounding the marker area.     * @param markerOffset  the marker label offset     * @param anchor  the label anchor.     * @param inset  a flag that controls whether the marker label offset is inside or outside the     *               marker area.     *     * @return the coordinates for drawing the marker label.     */    private double[] calculateDomainMarkerTextAnchorPoint(Graphics2D g2,            PlotOrientation orientation,            Rectangle2D dataArea,            Rectangle2D markerArea,            RectangleInsets markerOffset,            RectangleAnchor anchor,            boolean inset) {        double[] result = null;        if (orientation == PlotOrientation.HORIZONTAL) {            Rectangle2D anchorRect = null;            if (inset) {                anchorRect = markerOffset.createInsetRectangle(markerArea, false, true);            }            else {                anchorRect = markerOffset.createOutsetRectangle(markerArea, false, true);            }            result = RectangleAnchor.coordinates(anchorRect, anchor);        }        else if (orientation == PlotOrientation.VERTICAL) {            Rectangle2D anchorRect = null;            if (inset) {                anchorRect = markerOffset.createInsetRectangle(markerArea, false, true);            }            else {                anchorRect = markerOffset.createOutsetRectangle(markerArea, false, true);            }            result = RectangleAnchor.coordinates(anchorRect, anchor);        }        return result;    }    /**     * Draws a horizontal line across the chart to represent a 'range marker'.     *     * @param g2  the graphics device.     * @param plot  the plot.     * @param rangeAxis  the range axis.     * @param marker  the marker line.     * @param dataArea  the axis data area.     */    public void drawRangeMarker(Graphics2D g2,                                XYPlot plot,                                ValueAxis rangeAxis,                                Marker marker,                                Rectangle2D dataArea) {        if (marker instanceof ValueMarker) {            ValueMarker vm = (ValueMarker) marker;            double value = vm.getValue();            Range range = rangeAxis.getRange();            if (!range.contains(value)) {                return;            }            double v = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());            PlotOrientation orientation = plot.getOrientation();            Line2D line = null;            if (orientation == PlotOrientation.HORIZONTAL) {                line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());            }            else if (orientation == PlotOrientation.VERTICAL) {                line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);            }            g2.setPaint(marker.getPaint());            g2.setStroke(marker.getStroke());            g2.draw(line);            String label = marker.getLabel();            RectangleAnchor anchor = marker.getLabelAnchor();            if (label != null) {                Font labelFont = marker.getLabelFont();                g2.setFont(labelFont);                g2.setPaint(marker.getLabelPaint());                double[] coordinates = calculateRangeMarkerTextAnchorPoint(                    g2, orientation, dataArea, line.getBounds2D(), marker.getLabelOffset(), anchor                );                RefineryUtilities.drawAlignedString(                    label, g2, (float) coordinates[0], (float) coordinates[1],                     marker.getLabelTextAnchor()                );            }        }        else if (marker instanceof IntervalMarker) {                        IntervalMarker im = (IntervalMarker) marker;            double start = im.getStartValue();            double end = im.getEndValue();            Range range = rangeAxis.getRange();            if (!(range.intersects(start, end))) {                return;            }            // don't draw beyond the axis range...            start = range.constrain(start);            end = range.constrain(end);                        double v0 = rangeAxis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge());            double v1 = rangeAxis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge());            PlotOrientation orientation = plot.getOrientation();            Rectangle2D rect = null;            if (orientation == PlotOrientation.HORIZONTAL) {                rect = new Rectangle2D.Double(                    Math.min(v0, v1), dataArea.getMinY(), Math.abs(v1 - v0), dataArea.getHeight()                );            }            else if (orientation == PlotOrientation.VERTICAL) {                rect = new Rectangle2D.Double(                    dataArea.getMinX(), Math.min(v0, v1), dataArea.getWidth(), Math.abs(v0 - v1)                );            }            g2.setPaint(marker.getPaint());            g2.fill(rect);            String label = marker.getLabel();            RectangleAnchor anchor = marker.getLabelAnchor();            if (label != null) {                Font labelFont = marker.getLabelFont();                g2.setFont(labelFont);                g2.setPaint(marker.getLabelPaint());                double[] coordinates = calculateDomainMarkerTextAnchorPoint(                    g2, orientation, dataArea, rect, marker.getLabelOffset(), anchor, true                );                RefineryUtilities.drawAlignedString(                    label, g2, (float) coordinates[0], (float) coordinates[1],                     marker.getLabelTextAnchor()                );            }        }     }    /**     * Calculates the (x, y) coordinates for drawing a marker label.     *     * @param g2  the graphics device.     * @param orientation  the plot orientation.     * @param dataArea  the data area.     * @param markerArea  the marker area.     * @param markerOffset  the marker offset.     * @param anchor  the label anchor.     *     * @return the coordinates for drawing the marker label.     */    private double[] calculateRangeMarkerTextAnchorPoint(Graphics2D g2,                                                         PlotOrientation orientation,                                                         Rectangle2D dataArea,                                                         Rectangle2D markerArea,                                                         RectangleInsets markerOffset,                                                         RectangleAnchor anchor) {        double[] result = null;        if (orientation == PlotOrientation.HORIZONTAL) {            Rectangle2D anchorRect = markerOffset.createOutsetRectangle(markerArea, true, false);            result = RectangleAnchor.coordinates(anchorRect, anchor);        }        else if (orientation == PlotOrientation.VERTICAL) {            Rectangle2D anchorRect = markerOffset.createOutsetRectangle(markerArea, false, true);            result = RectangleAnchor.coordinates(anchorRect, anchor);        }        return result;    }    /**     * Returns a clone of the renderer.     *     * @return A clone.     *     * @throws CloneNotSupportedException if the renderer does not support cloning.     */    protected Object clone() throws CloneNotSupportedException {        AbstractXYItemRenderer clone = (AbstractXYItemRenderer) super.clone();        // 'plot' : just retain reference, not a deep copy        if (this.itemLabelGenerator != null && this.itemLabelGenerator instanceof PublicCloneable) {            PublicCloneable pc = (PublicCloneable) this.itemLabelGenerator;            clone.itemLabelGenerator = (XYLabelGenerator) pc.clone();        }        return clone;    }    /**     * 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 AbstractXYItemRenderer)) {            return false;        }        AbstractXYItemRenderer renderer = (AbstractXYItemRenderer) obj;        if (!super.equals(obj)) {            return false;        }        if (!ObjectUtils.equal(this.itemLabelGenerator, renderer.itemLabelGenerator)) {            return false;        }        if (!ObjectUtils.equal(this.urlGenerator, renderer.urlGenerator)) {            return false;        }        return true;    }    /**     * Returns the drawing supplier from the plot.     *     * @return The drawing supplier (possibly <code>null</code>).     */    public DrawingSupplier getDrawingSupplier() {        DrawingSupplier result = null;        XYPlot p = getPlot();        if (p != null) {            result = p.getDrawingSupplier();        }        return result;    }    /**     * Considers the current (x, y) coordinate and updates the crosshair point if it meets the     * criteria (usually means the (x, y) coordinate is the closest to the anchor point so far).     *     * @param crosshairState  the crosshair state (<code>null</code> permitted, but the method does      *                        nothing in that case).     * @param x  the x-value (in data space).     * @param y  the y-value (in data space).     * @param transX  the x-value translated to Java2D space.     * @param transY  the y-value translated to Java2D space.     * @param orientation  the plot orientation (<code>null</code> not permitted).     */    protected void updateCrosshairValues(CrosshairState crosshairState,                                         double x, double y, double transX, double transY,                                         PlotOrientation orientation) {        if (orientation == null) {            throw new IllegalArgumentException("Null 'orientation' argument.");        }        if (crosshairState != null) {            // do we need to update the crosshair values?            if (this.plot.isDomainCrosshairLockedOnData()) {                if (this.plot.isRangeCrosshairLockedOnData()) {                    // both axes                    crosshairState.updateCrosshairPoint(x, y, transX, transY, orientation);                }                else {                    // just the domain axis...                    crosshairState.updateCrosshairX(x);                }            }            else {                if (this.plot.isRangeCrosshairLockedOnData()) {                    // just the range axis...                    crosshairState.updateCrosshairY(y);                }            }        }    }        /**     * Draws an item label.     *     * @param g2  the graphics device.     * @param orientation  the orientation.     * @param dataset  the dataset.     * @param series  the series index (zero-based).     * @param item  the item index (zero-based).     * @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,                                 XYDataset dataset,                                  int series,                                  int item,                                 double x,                                  double y,                                  boolean negative) {                                             XYLabelGenerator generator = getLabelGenerator(series, item);        if (generator != null) {            Font labelFont = getItemLabelFont(series, item);            Paint paint = getItemLabelPaint(series, item);            g2.setFont(labelFont);            g2.setPaint(paint);            String label = generator.generateLabel(dataset, series, item);            // get the label position..            ItemLabelPosition position = null;            if (!negative) {                position = getPositiveItemLabelPosition(series, item);            }            else {                position = getNegativeItemLabelPosition(series, item);            }            // work out the label anchor point...            Point2D anchorPoint = calculateLabelAnchorPoint(                position.getItemLabelAnchor(), x, y, orientation            );            RefineryUtilities.drawRotatedString(                label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(),                position.getTextAnchor(), position.getRotationAnchor(), position.getAngle()            );        }    }}

⌨️ 快捷键说明

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