categoryplottests.java

来自「java开发中使用Jfreechart进行画图的源码」· Java 代码 · 共 934 行 · 第 1/3 页

JAVA
934
字号
        // anchorValue        plot1.setAnchorValue(100.0);        assertFalse(plot1.equals(plot2));        plot2.setAnchorValue(100.0);        assertTrue(plot1.equals(plot2));        // rangeCrosshairVisible        plot1.setRangeCrosshairVisible(true);        assertFalse(plot1.equals(plot2));        plot2.setRangeCrosshairVisible(true);        assertTrue(plot1.equals(plot2));        // rangeCrosshairValue        plot1.setRangeCrosshairValue(100.0);        assertFalse(plot1.equals(plot2));        plot2.setRangeCrosshairValue(100.0);        assertTrue(plot1.equals(plot2));        // rangeCrosshairStroke        plot1.setRangeCrosshairStroke(stroke);        assertFalse(plot1.equals(plot2));        plot2.setRangeCrosshairStroke(stroke);        assertTrue(plot1.equals(plot2));        // rangeCrosshairPaint        plot1.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.white,                3.0f, 4.0f, Color.yellow));        assertFalse(plot1.equals(plot2));        plot2.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.white,                3.0f, 4.0f, Color.yellow));        assertTrue(plot1.equals(plot2));        // rangeCrosshairLockedOnData        plot1.setRangeCrosshairLockedOnData(false);        assertFalse(plot1.equals(plot2));        plot2.setRangeCrosshairLockedOnData(false);        assertTrue(plot1.equals(plot2));        // foreground domain markers        plot1.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND);        assertFalse(plot1.equals(plot2));        plot2.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND);        assertTrue(plot1.equals(plot2));        // background domain markers        plot1.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND);        assertFalse(plot1.equals(plot2));        plot2.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND);        assertTrue(plot1.equals(plot2));        // range markers - no longer separate fields but test anyway...        plot1.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND);        assertFalse(plot1.equals(plot2));        plot2.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND);        assertTrue(plot1.equals(plot2));        plot1.addRangeMarker(new ValueMarker(5.0), Layer.BACKGROUND);        assertFalse(plot1.equals(plot2));        plot2.addRangeMarker(new ValueMarker(5.0), Layer.BACKGROUND);        assertTrue(plot1.equals(plot2));        // foreground range markers...        plot1.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);        assertFalse(plot1.equals(plot2));        plot2.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);        assertTrue(plot1.equals(plot2));        // background range markers...        plot1.addRangeMarker(1, new ValueMarker(5.0), Layer.BACKGROUND);        assertFalse(plot1.equals(plot2));        plot2.addRangeMarker(1, new ValueMarker(5.0), Layer.BACKGROUND);        assertTrue(plot1.equals(plot2));        // annotations        plot1.addAnnotation(new CategoryTextAnnotation("Text", "Category",                43.0));        assertFalse(plot1.equals(plot2));        plot2.addAnnotation(new CategoryTextAnnotation("Text", "Category",                43.0));        assertTrue(plot1.equals(plot2));        // weight        plot1.setWeight(3);        assertFalse(plot1.equals(plot2));        plot2.setWeight(3);        assertTrue(plot1.equals(plot2));        // fixed domain axis space...        plot1.setFixedDomainAxisSpace(new AxisSpace());        assertFalse(plot1.equals(plot2));        plot2.setFixedDomainAxisSpace(new AxisSpace());        assertTrue(plot1.equals(plot2));        // fixed range axis space...        plot1.setFixedRangeAxisSpace(new AxisSpace());        assertFalse(plot1.equals(plot2));        plot2.setFixedRangeAxisSpace(new AxisSpace());        assertTrue(plot1.equals(plot2));        // fixed legend items        plot1.setFixedLegendItems(new LegendItemCollection());        assertFalse(plot1.equals(plot2));        plot2.setFixedLegendItems(new LegendItemCollection());        assertTrue(plot1.equals(plot2));        // crosshairDatasetIndex        plot1.setCrosshairDatasetIndex(99);        assertFalse(plot1.equals(plot2));        plot2.setCrosshairDatasetIndex(99);        assertTrue(plot1.equals(plot2));        // domainCrosshairColumnKey        plot1.setDomainCrosshairColumnKey("A");        assertFalse(plot1.equals(plot2));        plot2.setDomainCrosshairColumnKey("A");        assertTrue(plot1.equals(plot2));        // domainCrosshairRowKey        plot1.setDomainCrosshairRowKey("B");        assertFalse(plot1.equals(plot2));        plot2.setDomainCrosshairRowKey("B");        assertTrue(plot1.equals(plot2));        // domainCrosshairVisible        plot1.setDomainCrosshairVisible(true);        assertFalse(plot1.equals(plot2));        plot2.setDomainCrosshairVisible(true);        assertTrue(plot1.equals(plot2));        // domainCrosshairPaint        plot1.setDomainCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.red,                3.0f, 4.0f, Color.blue));        assertFalse(plot1.equals(plot2));        plot2.setDomainCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.red,                3.0f, 4.0f, Color.blue));        assertTrue(plot1.equals(plot2));        // domainCrosshairStroke        plot1.setDomainCrosshairStroke(new BasicStroke(1.23f));        assertFalse(plot1.equals(plot2));        plot2.setDomainCrosshairStroke(new BasicStroke(1.23f));        assertTrue(plot1.equals(plot2));    }    /**     * Confirm that cloning works.     */    public void testCloning() {        CategoryPlot p1 = new CategoryPlot();        p1.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.white,                3.0f, 4.0f, Color.yellow));        CategoryPlot p2 = null;        try {            p2 = (CategoryPlot) p1.clone();        }        catch (CloneNotSupportedException e) {            e.printStackTrace();            System.err.println("Failed to clone.");        }        assertTrue(p1 != p2);        assertTrue(p1.getClass() == p2.getClass());        assertTrue(p1.equals(p2));        // check independence        p1.addAnnotation(new CategoryLineAnnotation("C1", 1.0, "C2", 2.0,                Color.red, new BasicStroke(1.0f)));        assertFalse(p1.equals(p2));        p2.addAnnotation(new CategoryLineAnnotation("C1", 1.0, "C2", 2.0,                Color.red, new BasicStroke(1.0f)));        assertTrue(p1.equals(p2));        p1.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND);        assertFalse(p1.equals(p2));        p2.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND);        assertTrue(p1.equals(p2));        p1.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND);        assertFalse(p1.equals(p2));        p2.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND);        assertTrue(p1.equals(p2));        p1.addRangeMarker(new ValueMarker(1.0), Layer.FOREGROUND);        assertFalse(p1.equals(p2));        p2.addRangeMarker(new ValueMarker(1.0), Layer.FOREGROUND);        assertTrue(p1.equals(p2));        p1.addRangeMarker(new ValueMarker(2.0), Layer.BACKGROUND);        assertFalse(p1.equals(p2));        p2.addRangeMarker(new ValueMarker(2.0), Layer.BACKGROUND);        assertTrue(p1.equals(p2));    }    /**     * Some more cloning checks.     */    public void testCloning2() {        AxisSpace da1 = new AxisSpace();        AxisSpace ra1 = new AxisSpace();        CategoryPlot p1 = new CategoryPlot();        p1.setFixedDomainAxisSpace(da1);        p1.setFixedRangeAxisSpace(ra1);        CategoryPlot p2 = null;        try {            p2 = (CategoryPlot) p1.clone();        }        catch (CloneNotSupportedException e) {            e.printStackTrace();        }        assertTrue(p1 != p2);        assertTrue(p1.getClass() == p2.getClass());        assertTrue(p1.equals(p2));        da1.setBottom(99.0);        assertFalse(p1.equals(p2));        p2.getFixedDomainAxisSpace().setBottom(99.0);        assertTrue(p1.equals(p2));        ra1.setBottom(11.0);        assertFalse(p1.equals(p2));        p2.getFixedRangeAxisSpace().setBottom(11.0);        assertTrue(p1.equals(p2));    }    /**     * Some more cloning checks.     */    public void testCloning3() {        LegendItemCollection c1 = new LegendItemCollection();        CategoryPlot p1 = new CategoryPlot();        p1.setFixedLegendItems(c1);        CategoryPlot p2 = null;        try {            p2 = (CategoryPlot) p1.clone();        }        catch (CloneNotSupportedException e) {            e.printStackTrace();        }        assertTrue(p1 != p2);        assertTrue(p1.getClass() == p2.getClass());        assertTrue(p1.equals(p2));        c1.add(new LegendItem("X", "XX", "tt", "url", true,                new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red,                true, Color.yellow, new BasicStroke(1.0f), true,                new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(1.0f),                Color.green));        assertFalse(p1.equals(p2));        p2.getFixedLegendItems().add(new LegendItem("X", "XX", "tt", "url",                true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true,                Color.red, true, Color.yellow, new BasicStroke(1.0f), true,                new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(1.0f),                Color.green));        assertTrue(p1.equals(p2));    }    /**     * Serialize an instance, restore it, and check for equality.     */    public void testSerialization() {        DefaultCategoryDataset dataset = new DefaultCategoryDataset();        CategoryAxis domainAxis = new CategoryAxis("Domain");        NumberAxis rangeAxis = new NumberAxis("Range");        BarRenderer renderer = new BarRenderer();        CategoryPlot p1 = new CategoryPlot(dataset, domainAxis, rangeAxis,                renderer);        p1.setOrientation(PlotOrientation.HORIZONTAL);        CategoryPlot 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 = (CategoryPlot) in.readObject();            in.close();        }        catch (Exception e) {            e.printStackTrace();        }        assertTrue(p1.equals(p2));    }    /**     * Serialize an instance, restore it, and check for equality.     */    public void testSerialization2() {        DefaultCategoryDataset data = new DefaultCategoryDataset();        CategoryAxis domainAxis = new CategoryAxis("Domain");        NumberAxis rangeAxis = new NumberAxis("Range");        BarRenderer renderer = new BarRenderer();        CategoryPlot p1 = new CategoryPlot(data, domainAxis, rangeAxis,                renderer);        p1.setOrientation(PlotOrientation.VERTICAL);        CategoryPlot 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 = (CategoryPlot) in.readObject();            in.close();        }        catch (Exception e) {

⌨️ 快捷键说明

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