defaultdrawingsupplier.java

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

JAVA
507
字号
        // square        result[0] = new Rectangle2D.Double(-delta, -delta, size, size);        // circle        result[1] = new Ellipse2D.Double(-delta, -delta, size, size);        // up-pointing triangle        xpoints = intArray(0.0, delta, -delta);        ypoints = intArray(-delta, delta, delta);        result[2] = new Polygon(xpoints, ypoints, 3);        // diamond        xpoints = intArray(0.0, delta, 0.0, -delta);        ypoints = intArray(-delta, 0.0, delta, 0.0);        result[3] = new Polygon(xpoints, ypoints, 4);        // horizontal rectangle        result[4] = new Rectangle2D.Double(-delta, -delta / 2, size, size / 2);        // down-pointing triangle        xpoints = intArray(-delta, +delta, 0.0);        ypoints = intArray(-delta, -delta, delta);        result[5] = new Polygon(xpoints, ypoints, 3);        // horizontal ellipse        result[6] = new Ellipse2D.Double(-delta, -delta / 2, size, size / 2);        // right-pointing triangle        xpoints = intArray(-delta, delta, -delta);        ypoints = intArray(-delta, 0.0, delta);        result[7] = new Polygon(xpoints, ypoints, 3);        // vertical rectangle        result[8] = new Rectangle2D.Double(-delta / 2, -delta, size / 2, size);        // left-pointing triangle        xpoints = intArray(-delta, delta, delta);        ypoints = intArray(0.0, -delta, +delta);        result[9] = new Polygon(xpoints, ypoints, 3);        return result;    }    /**     * Tests this object for equality with another object.     *     * @param obj  the object (<code>null</code> permitted).     *     * @return A boolean.     */    public boolean equals(Object obj) {        if (obj == this) {            return true;        }        if (!(obj instanceof DefaultDrawingSupplier)) {            return false;        }        DefaultDrawingSupplier that = (DefaultDrawingSupplier) obj;        if (!Arrays.equals(this.paintSequence, that.paintSequence)) {            return false;        }        if (this.paintIndex != that.paintIndex) {            return false;           }        if (!Arrays.equals(this.outlinePaintSequence,                 that.outlinePaintSequence)) {            return false;        }        if (this.outlinePaintIndex != that.outlinePaintIndex) {            return false;        }        if (!Arrays.equals(this.strokeSequence, that.strokeSequence)) {            return false;        }        if (this.strokeIndex != that.strokeIndex) {            return false;           }        if (!Arrays.equals(this.outlineStrokeSequence,                 that.outlineStrokeSequence)) {            return false;        }        if (this.outlineStrokeIndex != that.outlineStrokeIndex) {            return false;           }        if (!equalShapes(this.shapeSequence, that.shapeSequence)) {            return false;        }        if (this.shapeIndex != that.shapeIndex) {            return false;        }        return true;    }        /**     * A utility method for testing the equality of two arrays of shapes.     *      * @param s1  the first array (<code>null</code> permitted).     * @param s2  the second array (<code>null</code> permitted).     *      * @return A boolean.     */    private boolean equalShapes(Shape[] s1, Shape[] s2) {        if (s1 == null) {            return s2 == null;           }        if (s2 == null) {            return false;           }        if (s1.length != s2.length) {            return false;           }        for (int i = 0; i < s1.length; i++) {            if (!ShapeUtilities.equal(s1[i], s2[i])) {                return false;               }        }        return true;    }    /**     * Handles serialization.     *     * @param stream  the output stream.     *     * @throws IOException if there is an I/O problem.     */    private void writeObject(ObjectOutputStream stream) throws IOException {        stream.defaultWriteObject();        int paintCount = this.paintSequence.length;        stream.writeInt(paintCount);        for (int i = 0; i < paintCount; i++) {            SerialUtilities.writePaint(this.paintSequence[i], stream);        }        int outlinePaintCount = this.outlinePaintSequence.length;        stream.writeInt(outlinePaintCount);        for (int i = 0; i < outlinePaintCount; i++) {            SerialUtilities.writePaint(this.outlinePaintSequence[i], stream);        }        int strokeCount = this.strokeSequence.length;        stream.writeInt(strokeCount);        for (int i = 0; i < strokeCount; i++) {            SerialUtilities.writeStroke(this.strokeSequence[i], stream);        }        int outlineStrokeCount = this.outlineStrokeSequence.length;        stream.writeInt(outlineStrokeCount);        for (int i = 0; i < outlineStrokeCount; i++) {            SerialUtilities.writeStroke(this.outlineStrokeSequence[i], stream);        }        int shapeCount = this.shapeSequence.length;        stream.writeInt(shapeCount);        for (int i = 0; i < shapeCount; i++) {            SerialUtilities.writeShape(this.shapeSequence[i], stream);        }    }    /**     * Restores a serialized object.     *     * @param stream  the input stream.     *     * @throws IOException if there is an I/O problem.     * @throws ClassNotFoundException if there is a problem loading a class.     */    private void readObject(ObjectInputStream stream)         throws IOException, ClassNotFoundException {        stream.defaultReadObject();        int paintCount = stream.readInt();        this.paintSequence = new Paint[paintCount];        for (int i = 0; i < paintCount; i++) {            this.paintSequence[i] = SerialUtilities.readPaint(stream);        }        int outlinePaintCount = stream.readInt();        this.outlinePaintSequence = new Paint[outlinePaintCount];        for (int i = 0; i < outlinePaintCount; i++) {            this.outlinePaintSequence[i] = SerialUtilities.readPaint(stream);        }        int strokeCount = stream.readInt();        this.strokeSequence = new Stroke[strokeCount];        for (int i = 0; i < strokeCount; i++) {            this.strokeSequence[i] = SerialUtilities.readStroke(stream);        }        int outlineStrokeCount = stream.readInt();        this.outlineStrokeSequence = new Stroke[outlineStrokeCount];        for (int i = 0; i < outlineStrokeCount; i++) {            this.outlineStrokeSequence[i] = SerialUtilities.readStroke(stream);        }        int shapeCount = stream.readInt();        this.shapeSequence = new Shape[shapeCount];        for (int i = 0; i < shapeCount; i++) {            this.shapeSequence[i] = SerialUtilities.readShape(stream);        }    }    /**     * Helper method to avoid lots of explicit casts in getShape().  Returns     * an array containing the provided doubles cast to ints.     *     * @param a  x     * @param b  y     * @param c  z     *     * @return int[3] with converted params.     */    private static int[] intArray(double a, double b, double c) {        return new int[] {(int) a, (int) b, (int) c};    }    /**     * Helper method to avoid lots of explicit casts in getShape().  Returns     * an array containing the provided doubles cast to ints.     *     * @param a  x     * @param b  y     * @param c  z     * @param d  t     *     * @return int[3] with converted params.     */    private static int[] intArray(double a, double b, double c, double d) {        return new int[] {(int) a, (int) b, (int) c, (int) d};    }    /**     * Returns a clone.     *      * @return A clone.     *      * @throws CloneNotSupportedException if a component of the supplier does      *                                    not support cloning.     */    public Object clone() throws CloneNotSupportedException {        DefaultDrawingSupplier clone = (DefaultDrawingSupplier) super.clone();         return clone;    }}

⌨️ 快捷键说明

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