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

📄 xyplottests.java

📁 用于制作报表的中间件控件,纯java编写,还附带有数据库操作的源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        plot2.setWeight(3);        assertTrue(plot1.equals(plot2));                // quadrant origin        plot1.setQuadrantOrigin(new Point2D.Double(12.3, 45.6));        assertFalse(plot1.equals(plot2));        plot2.setQuadrantOrigin(new Point2D.Double(12.3, 45.6));        assertTrue(plot1.equals(plot2));                // quadrant paint        plot1.setQuadrantPaint(0, new GradientPaint(1.0f, 2.0f, Color.red,                3.0f, 4.0f, Color.blue));        assertFalse(plot1.equals(plot2));        plot2.setQuadrantPaint(0, new GradientPaint(1.0f, 2.0f, Color.red,                3.0f, 4.0f, Color.blue));        assertTrue(plot1.equals(plot2));        plot1.setQuadrantPaint(1, new GradientPaint(2.0f, 3.0f, Color.red,                4.0f, 5.0f, Color.blue));        assertFalse(plot1.equals(plot2));        plot2.setQuadrantPaint(1, new GradientPaint(2.0f, 3.0f, Color.red,                4.0f, 5.0f, Color.blue));        assertTrue(plot1.equals(plot2));        plot1.setQuadrantPaint(2, new GradientPaint(3.0f, 4.0f, Color.red,                5.0f, 6.0f, Color.blue));        assertFalse(plot1.equals(plot2));        plot2.setQuadrantPaint(2, new GradientPaint(3.0f, 4.0f, Color.red,                5.0f, 6.0f, Color.blue));        assertTrue(plot1.equals(plot2));        plot1.setQuadrantPaint(3, new GradientPaint(4.0f, 5.0f, Color.red,                6.0f, 7.0f, Color.blue));        assertFalse(plot1.equals(plot2));        plot2.setQuadrantPaint(3, new GradientPaint(4.0f, 5.0f, Color.red,                6.0f, 7.0f, Color.blue));        assertTrue(plot1.equals(plot2));                  plot1.setDomainTickBandPaint(Color.red);        assertFalse(plot1.equals(plot2));        plot2.setDomainTickBandPaint(Color.red);        assertTrue(plot1.equals(plot2));                plot1.setRangeTickBandPaint(Color.blue);        assertFalse(plot1.equals(plot2));        plot2.setRangeTickBandPaint(Color.blue);        assertTrue(plot1.equals(plot2));            }    /**     * Confirm that basic cloning works.     */    public void testCloning() {        XYPlot p1 = new XYPlot();        XYPlot p2 = null;        try {            p2 = (XYPlot) p1.clone();        }        catch (CloneNotSupportedException e) {            e.printStackTrace();        }        assertTrue(p1 != p2);        assertTrue(p1.getClass() == p2.getClass());        assertTrue(p1.equals(p2));    }        /**     * Tests cloning for a more complex plot.     */    public void testCloning2() {        XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),                 new NumberAxis("Range Axis"), new StandardXYItemRenderer());        p1.setRangeAxis(1, new NumberAxis("Range Axis 2"));        p1.setRenderer(1, new XYBarRenderer());        XYPlot p2 = null;        try {            p2 = (XYPlot) p1.clone();        }        catch (CloneNotSupportedException e) {            e.printStackTrace();        }        assertTrue(p1 != p2);        assertTrue(p1.getClass() == p2.getClass());        assertTrue(p1.equals(p2));    }        /**     * Confirm that cloning captures the quadrantOrigin field.     */    public void testCloning_QuadrantOrigin() {        XYPlot p1 = new XYPlot();        Point2D p = new Point2D.Double(1.2, 3.4);        p1.setQuadrantOrigin(p);        XYPlot p2 = null;        try {            p2 = (XYPlot) p1.clone();        }        catch (CloneNotSupportedException e) {            e.printStackTrace();        }        assertTrue(p1 != p2);        assertTrue(p1.getClass() == p2.getClass());        assertTrue(p1.equals(p2));        assertTrue(p2.getQuadrantOrigin() != p);    }        /**     * Confirm that cloning captures the quadrantOrigin field.     */    public void testCloning_QuadrantPaint() {        XYPlot p1 = new XYPlot();        p1.setQuadrantPaint(3, new GradientPaint(1.0f, 2.0f, Color.red,                 3.0f, 4.0f, Color.blue));        XYPlot p2 = null;        try {            p2 = (XYPlot) p1.clone();        }        catch (CloneNotSupportedException e) {            e.printStackTrace();        }        assertTrue(p1 != p2);        assertTrue(p1.getClass() == p2.getClass());        assertTrue(p1.equals(p2));                // check for independence        p1.setQuadrantPaint(1, Color.red);        assertFalse(p1.equals(p2));        p2.setQuadrantPaint(1, Color.red);        assertTrue(p1.equals(p2));    }        /**     * Tests the independence of the clones.     */    public void testCloneIndependence() {        XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),                 new NumberAxis("Range Axis"), new StandardXYItemRenderer());        p1.setDomainAxis(1, new NumberAxis("Domain Axis 2"));        p1.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);        p1.setRangeAxis(1, new NumberAxis("Range Axis 2"));        p1.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT);        p1.setRenderer(1, new XYBarRenderer());        XYPlot p2 = null;                try {            p2 = (XYPlot) p1.clone();        }        catch (CloneNotSupportedException e) {            e.printStackTrace();            System.err.println("Failed to clone.");        }        assertTrue(p1.equals(p2));                p1.getDomainAxis().setLabel("Label");        assertFalse(p1.equals(p2));        p2.getDomainAxis().setLabel("Label");        assertTrue(p1.equals(p2));                p1.getDomainAxis(1).setLabel("S1");        assertFalse(p1.equals(p2));        p2.getDomainAxis(1).setLabel("S1");        assertTrue(p1.equals(p2));                p1.setDomainAxisLocation(1, AxisLocation.TOP_OR_RIGHT);        assertFalse(p1.equals(p2));        p2.setDomainAxisLocation(1, AxisLocation.TOP_OR_RIGHT);        assertTrue(p1.equals(p2));                p1.mapDatasetToDomainAxis(2, 1);        assertFalse(p1.equals(p2));        p2.mapDatasetToDomainAxis(2, 1);        assertTrue(p1.equals(p2));        p1.getRangeAxis().setLabel("Label");        assertFalse(p1.equals(p2));        p2.getRangeAxis().setLabel("Label");        assertTrue(p1.equals(p2));                p1.getRangeAxis(1).setLabel("S1");        assertFalse(p1.equals(p2));        p2.getRangeAxis(1).setLabel("S1");        assertTrue(p1.equals(p2));                p1.setRangeAxisLocation(1, AxisLocation.TOP_OR_LEFT);        assertFalse(p1.equals(p2));        p2.setRangeAxisLocation(1, AxisLocation.TOP_OR_LEFT);        assertTrue(p1.equals(p2));                p1.mapDatasetToRangeAxis(2, 1);        assertFalse(p1.equals(p2));        p2.mapDatasetToRangeAxis(2, 1);        assertTrue(p1.equals(p2));        p1.getRenderer().setOutlinePaint(Color.cyan);        assertFalse(p1.equals(p2));        p2.getRenderer().setOutlinePaint(Color.cyan);        assertTrue(p1.equals(p2));                p1.getRenderer(1).setOutlinePaint(Color.red);        assertFalse(p1.equals(p2));        p2.getRenderer(1).setOutlinePaint(Color.red);        assertTrue(p1.equals(p2));            }        /**     * Setting a null renderer should be allowed, but is generating a null      * pointer exception in 0.9.7.     */    public void testSetNullRenderer() {        boolean failed = false;        try {            XYPlot plot = new XYPlot(null, new NumberAxis("X"),                     new NumberAxis("Y"), null);            plot.setRenderer(null);        }        catch (Exception e) {            failed = true;        }        assertTrue(!failed);    }    /**     * Serialize an instance, restore it, and check for equality.     */    public void testSerialization1() {        XYDataset data = new XYSeriesCollection();        NumberAxis domainAxis = new NumberAxis("Domain");        NumberAxis rangeAxis = new NumberAxis("Range");        StandardXYItemRenderer renderer = new StandardXYItemRenderer();        XYPlot p1 = new XYPlot(data, domainAxis, rangeAxis, renderer);        XYPlot p2 = null;        try {            ByteArrayOutputStream buffer = new ByteArrayOutputStream();            ObjectOutput out = new ObjectOutputStream(buffer);            out.writeObject(p1);            out.close();            ObjectInput in = new ObjectInputStream(                new ByteArrayInputStream(buffer.toByteArray())            );            p2 = (XYPlot) in.readObject();            in.close();        }        catch (Exception e) {            fail(e.toString());        }        assertEquals(p1, p2);    }    /**     * Serialize an instance, restore it, and check for equality.  This test      * uses a {@link DateAxis} and a {@link StandardXYToolTipGenerator}.     */    public void testSerialization2() {        IntervalXYDataset data1 = createDataset1();        XYItemRenderer renderer1 = new XYBarRenderer(0.20);        renderer1.setToolTipGenerator(            StandardXYToolTipGenerator.getTimeSeriesInstance()        );        XYPlot p1 = new XYPlot(data1, new DateAxis("Date"), null, renderer1);        XYPlot p2 = null;        try {            ByteArrayOutputStream buffer = new ByteArrayOutputStream();            ObjectOutput out = new ObjectOutputStream(buffer);            out.writeObject(p1);            out.close();            ObjectInput in = new ObjectInputStream(                new ByteArrayInputStream(buffer.toByteArray())            );            p2 = (XYPlot) in.readObject();            in.close();        }        catch (Exception e) {            fail(e.toString());        }        assertEquals(p1, p2);    }    /**     * Problem to reproduce a bug in serialization.  The bug (first reported      * against the {@link org.jfree.chart.plot.CategoryPlot} class) is a null      * pointer exception that occurs when drawing a plot after deserialization.     * It is caused by four temporary storage structures (axesAtTop,      * axesAtBottom, axesAtLeft and axesAtRight - all initialized as empty      * lists in the constructor) not being initialized by the readObject()      * method following deserialization.  This test has been written to      * reproduce the bug (now fixed).     */    public void testSerialization3() {                XYSeriesCollection dataset = new XYSeriesCollection();        JFreeChart chart = ChartFactory.createXYLineChart(            "Test Chart",            "Domain Axis",            "Range Axis",            dataset,            PlotOrientation.VERTICAL,            true,            true,            false        );        JFreeChart chart2 = null;                // serialize and deserialize the chart....        try {            ByteArrayOutputStream buffer = new ByteArrayOutputStream();            ObjectOutput out = new ObjectOutputStream(buffer);            out.writeObject(chart);            out.close();            ObjectInput in = new ObjectInputStream(                new ByteArrayInputStream(buffer.toByteArray())            );            chart2 = (JFreeChart) in.readObject();            in.close();        }        catch (Exception e) {            fail(e.toString());        }        assertEquals(chart, chart2);        boolean passed = true;        try {            chart2.createBufferedImage(300, 200);        }        catch (Exception e) {            passed = false;              e.printStackTrace();                    }        assertTrue(passed);    }        /**     * A test to reproduce a bug in serialization: the domain and/or range     * markers for a plot are not being serialized.     */

⌨️ 快捷键说明

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