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

📄 categoryplottests.java

📁 用于制作报表的中间件控件,纯java编写,还附带有数据库操作的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info:  http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it  * under the terms of the GNU Lesser General Public License as published by  * the Free Software Foundation; either version 2.1 of the License, or  * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public  * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,  * USA.   * * [Java is a trademark or registered trademark of Sun Microsystems, Inc.  * in the United States and other countries.] * * ---------------------- * CategoryPlotTests.java * ---------------------- * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors. * * Original Author:  David Gilbert (for Object Refinery Limited); * Contributor(s):   -; * * Changes * ------- * 26-Mar-2003 : Version 1 (DG); * 15-Sep-2003 : Added a unit test to reproduce a bug in serialization (now  *               fixed) (DG); * 05-Feb-2007 : Added testAddDomainMarker() and testAddRangeMarker() (DG); * 07-Feb-2007 : Added test1654215() (DG); * */package org.jfree.chart.plot.junit;import java.awt.BasicStroke;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics2D;import java.awt.Stroke;import java.awt.geom.Rectangle2D;import java.awt.image.BufferedImage;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.ObjectInput;import java.io.ObjectInputStream;import java.io.ObjectOutput;import java.io.ObjectOutputStream;import java.util.Arrays;import java.util.List;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import org.jfree.chart.ChartFactory;import org.jfree.chart.JFreeChart;import org.jfree.chart.annotations.CategoryTextAnnotation;import org.jfree.chart.axis.AxisLocation;import org.jfree.chart.axis.AxisSpace;import org.jfree.chart.axis.CategoryAnchor;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.axis.NumberAxis;import org.jfree.chart.event.MarkerChangeListener;import org.jfree.chart.plot.CategoryMarker;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.plot.DatasetRenderingOrder;import org.jfree.chart.plot.IntervalMarker;import org.jfree.chart.plot.Marker;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.plot.ValueMarker;import org.jfree.chart.renderer.category.AreaRenderer;import org.jfree.chart.renderer.category.BarRenderer;import org.jfree.chart.renderer.category.CategoryItemRenderer;import org.jfree.chart.renderer.category.LineAndShapeRenderer;import org.jfree.data.Range;import org.jfree.data.category.DefaultCategoryDataset;import org.jfree.ui.Layer;import org.jfree.ui.RectangleInsets;import org.jfree.util.SortOrder;/** * Tests for the {@link CategoryPlot} class. */public class CategoryPlotTests extends TestCase {    /**     * Returns the tests as a test suite.     *     * @return The test suite.     */    public static Test suite() {        return new TestSuite(CategoryPlotTests.class);    }    /**     * Constructs a new set of tests.     *     * @param name  the name of the tests.     */    public CategoryPlotTests(String name) {        super(name);    }        /**     * Some checks for the constructor.     */    public void testConstructor() {        CategoryPlot plot = new CategoryPlot();        assertEquals(RectangleInsets.ZERO_INSETS, plot.getAxisOffset());    }    /**     * A test for a bug reported in the forum.     */    public void testAxisRange() {        DefaultCategoryDataset datasetA = new DefaultCategoryDataset();        DefaultCategoryDataset datasetB = new DefaultCategoryDataset();        datasetB.addValue(50.0, "R1", "C1");        datasetB.addValue(80.0, "R1", "C1");        CategoryPlot plot = new CategoryPlot(datasetA, new CategoryAxis(null),                 new NumberAxis(null), new LineAndShapeRenderer());        plot.setDataset(1, datasetB);        plot.setRenderer(1, new LineAndShapeRenderer());        Range r = plot.getRangeAxis().getRange();        assertEquals(84.0, r.getUpperBound(), 0.00001);    }        /**     * Test that the equals() method differentiates all the required fields.     */    public void testEquals() {                CategoryPlot plot1 = new CategoryPlot();        CategoryPlot plot2 = new CategoryPlot();        assertTrue(plot1.equals(plot2));            assertTrue(plot2.equals(plot1));                // orientation...        plot1.setOrientation(PlotOrientation.HORIZONTAL);        assertFalse(plot1.equals(plot2));        plot2.setOrientation(PlotOrientation.HORIZONTAL);        assertTrue(plot1.equals(plot2));                // axisOffset...        plot1.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));        assertFalse(plot1.equals(plot2));        plot2.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));        assertTrue(plot1.equals(plot2));        // domainAxis - no longer a separate field but test anyway...        plot1.setDomainAxis(new CategoryAxis("Category Axis"));        assertFalse(plot1.equals(plot2));        plot2.setDomainAxis(new CategoryAxis("Category Axis"));        assertTrue(plot1.equals(plot2));        // domainAxes...        plot1.setDomainAxis(11, new CategoryAxis("Secondary Axis"));        assertFalse(plot1.equals(plot2));        plot2.setDomainAxis(11, new CategoryAxis("Secondary Axis"));        assertTrue(plot1.equals(plot2));        // domainAxisLocation - no longer a separate field but test anyway...        plot1.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);        assertFalse(plot1.equals(plot2));        plot2.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);        assertTrue(plot1.equals(plot2));        // domainAxisLocations...        plot1.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);        assertFalse(plot1.equals(plot2));        plot2.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);        assertTrue(plot1.equals(plot2));        // draw shared domain axis...        plot1.setDrawSharedDomainAxis(!plot1.getDrawSharedDomainAxis());        assertFalse(plot1.equals(plot2));        plot2.setDrawSharedDomainAxis(!plot2.getDrawSharedDomainAxis());        assertTrue(plot1.equals(plot2));                // rangeAxis - no longer a separate field but test anyway...        plot1.setRangeAxis(new NumberAxis("Range Axis"));        assertFalse(plot1.equals(plot2));        plot2.setRangeAxis(new NumberAxis("Range Axis"));        assertTrue(plot1.equals(plot2));        // rangeAxes...        plot1.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));        assertFalse(plot1.equals(plot2));        plot2.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));        assertTrue(plot1.equals(plot2));        // rangeAxisLocation - no longer a separate field but test anyway...        plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);        assertFalse(plot1.equals(plot2));        plot2.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);        assertTrue(plot1.equals(plot2));        // rangeAxisLocations...        plot1.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);        assertFalse(plot1.equals(plot2));        plot2.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);        assertTrue(plot1.equals(plot2));                // datasetToDomainAxisMap...        plot1.mapDatasetToDomainAxis(11, 11);        assertFalse(plot1.equals(plot2));        plot2.mapDatasetToDomainAxis(11, 11);        assertTrue(plot1.equals(plot2));        // datasetToRangeAxisMap...        plot1.mapDatasetToRangeAxis(11, 11);        assertFalse(plot1.equals(plot2));        plot2.mapDatasetToRangeAxis(11, 11);        assertTrue(plot1.equals(plot2));                // renderer - no longer a separate field but test anyway...        plot1.setRenderer(new AreaRenderer());        assertFalse(plot1.equals(plot2));        plot2.setRenderer(new AreaRenderer());        assertTrue(plot1.equals(plot2));                // renderers...        plot1.setRenderer(11, new AreaRenderer());        assertFalse(plot1.equals(plot2));        plot2.setRenderer(11, new AreaRenderer());        assertTrue(plot1.equals(plot2));                // rendering order...        plot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);        assertFalse(plot1.equals(plot2));        plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);        assertTrue(plot1.equals(plot2));        // columnRenderingOrder...        plot1.setColumnRenderingOrder(SortOrder.DESCENDING);        assertFalse(plot1.equals(plot2));        plot2.setColumnRenderingOrder(SortOrder.DESCENDING);        assertTrue(plot1.equals(plot2));                // rowRenderingOrder...        plot1.setRowRenderingOrder(SortOrder.DESCENDING);        assertFalse(plot1.equals(plot2));        plot2.setRowRenderingOrder(SortOrder.DESCENDING);        assertTrue(plot1.equals(plot2));                // domainGridlinesVisible        plot1.setDomainGridlinesVisible(true);        assertFalse(plot1.equals(plot2));        plot2.setDomainGridlinesVisible(true);        assertTrue(plot1.equals(plot2));        // domainGridlinePosition        plot1.setDomainGridlinePosition(CategoryAnchor.END);        assertFalse(plot1.equals(plot2));        plot2.setDomainGridlinePosition(CategoryAnchor.END);        assertTrue(plot1.equals(plot2));        // domainGridlineStroke        Stroke stroke = new BasicStroke(2.0f);        plot1.setDomainGridlineStroke(stroke);        assertFalse(plot1.equals(plot2));        plot2.setDomainGridlineStroke(stroke);        assertTrue(plot1.equals(plot2));                // domainGridlinePaint        plot1.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue,                 3.0f, 4.0f, Color.yellow));        assertFalse(plot1.equals(plot2));        plot2.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue,                 3.0f, 4.0f, Color.yellow));        assertTrue(plot1.equals(plot2));                // rangeGridlinesVisible        plot1.setRangeGridlinesVisible(false);        assertFalse(plot1.equals(plot2));        plot2.setRangeGridlinesVisible(false);        assertTrue(plot1.equals(plot2));        // rangeGridlineStroke        plot1.setRangeGridlineStroke(stroke);        assertFalse(plot1.equals(plot2));        plot2.setRangeGridlineStroke(stroke);        assertTrue(plot1.equals(plot2));                // rangeGridlinePaint        plot1.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green,                 3.0f, 4.0f, Color.yellow));        assertFalse(plot1.equals(plot2));        plot2.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green,                 3.0f, 4.0f, Color.yellow));        assertTrue(plot1.equals(plot2));                // 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));                // 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...

⌨️ 快捷键说明

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