Source Code Cross Referenced for XYBarChartTests.java in  » Chart » jfreechart » org » jfree » chart » junit » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chart » jfreechart » org.jfree.chart.junit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ===========================================================
002:         * JFreeChart : a free chart library for the Java(tm) platform
003:         * ===========================================================
004:         *
005:         * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006:         *
007:         * Project Info:  http://www.jfree.org/jfreechart/index.html
008:         *
009:         * This library is free software; you can redistribute it and/or modify it 
010:         * under the terms of the GNU Lesser General Public License as published by 
011:         * the Free Software Foundation; either version 2.1 of the License, or 
012:         * (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but 
015:         * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017:         * License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library; if not, write to the Free Software
021:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022:         * USA.  
023:         *
024:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025:         * in the United States and other countries.]
026:         *
027:         * --------------------
028:         * XYBarChartTests.java
029:         * --------------------
030:         * (C) Copyright 2005, 2007, by Object Refinery Limited.
031:         *
032:         * Original Author:  David Gilbert (for Object Refinery Limited);
033:         * Contributor(s):   -;
034:         *
035:         * $Id: XYBarChartTests.java,v 1.1.2.2 2007/03/02 11:16:20 mungady Exp $
036:         *
037:         * Changes:
038:         * --------
039:         * 12-Apr-2005 : Version 1 (DG);
040:         *
041:         */
042:
043:        package org.jfree.chart.junit;
044:
045:        import java.awt.Graphics2D;
046:        import java.awt.geom.Rectangle2D;
047:        import java.awt.image.BufferedImage;
048:
049:        import junit.framework.Test;
050:        import junit.framework.TestCase;
051:        import junit.framework.TestSuite;
052:
053:        import org.jfree.chart.ChartFactory;
054:        import org.jfree.chart.JFreeChart;
055:        import org.jfree.chart.axis.ValueAxis;
056:        import org.jfree.chart.event.ChartChangeEvent;
057:        import org.jfree.chart.event.ChartChangeListener;
058:        import org.jfree.chart.labels.StandardXYToolTipGenerator;
059:        import org.jfree.chart.labels.XYToolTipGenerator;
060:        import org.jfree.chart.plot.PlotOrientation;
061:        import org.jfree.chart.plot.XYPlot;
062:        import org.jfree.chart.renderer.xy.XYItemRenderer;
063:        import org.jfree.data.Range;
064:        import org.jfree.data.xy.IntervalXYDataset;
065:        import org.jfree.data.xy.XYBarDataset;
066:        import org.jfree.data.xy.XYDataset;
067:        import org.jfree.data.xy.XYSeries;
068:        import org.jfree.data.xy.XYSeriesCollection;
069:
070:        /**
071:         * Some tests for an XY bar chart.
072:         */
073:        public class XYBarChartTests extends TestCase {
074:
075:            /** A chart. */
076:            private JFreeChart chart;
077:
078:            /**
079:             * Returns the tests as a test suite.
080:             *
081:             * @return The test suite.
082:             */
083:            public static Test suite() {
084:                return new TestSuite(XYBarChartTests.class);
085:            }
086:
087:            /**
088:             * Constructs a new set of tests.
089:             *
090:             * @param name  the name of the tests.
091:             */
092:            public XYBarChartTests(String name) {
093:                super (name);
094:            }
095:
096:            /**
097:             * Common test setup.
098:             */
099:            protected void setUp() {
100:                this .chart = createChart();
101:            }
102:
103:            /**
104:             * Draws the chart with a null info object to make sure that no exceptions 
105:             * are thrown (a problem that was occurring at one point).
106:             */
107:            public void testDrawWithNullInfo() {
108:
109:                boolean success = false;
110:                try {
111:                    BufferedImage image = new BufferedImage(200, 100,
112:                            BufferedImage.TYPE_INT_RGB);
113:                    Graphics2D g2 = image.createGraphics();
114:                    this .chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100),
115:                            null, null);
116:                    g2.dispose();
117:                    success = true;
118:                } catch (Exception e) {
119:                    success = false;
120:                    e.printStackTrace();
121:                }
122:                assertTrue(success);
123:
124:            }
125:
126:            /**
127:             * Replaces the dataset and checks that it has changed as expected.
128:             */
129:            public void testReplaceDataset() {
130:
131:                // create a dataset...
132:                XYSeries series1 = new XYSeries("Series 1");
133:                series1.add(10.0, 10.0);
134:                series1.add(20.0, 20.0);
135:                series1.add(30.0, 30.0);
136:                XYDataset dataset = new XYSeriesCollection(series1);
137:
138:                LocalListener l = new LocalListener();
139:                this .chart.addChangeListener(l);
140:
141:                XYPlot plot = (XYPlot) this .chart.getPlot();
142:                plot.setDataset(dataset);
143:                assertEquals(true, l.flag);
144:                ValueAxis axis = plot.getRangeAxis();
145:                Range range = axis.getRange();
146:                assertTrue(
147:                        "Expecting the lower bound of the range to be around 10: "
148:                                + range.getLowerBound(),
149:                        range.getLowerBound() <= 10);
150:                assertTrue(
151:                        "Expecting the upper bound of the range to be around 30: "
152:                                + range.getUpperBound(),
153:                        range.getUpperBound() >= 30);
154:
155:            }
156:
157:            /**
158:             * Check that setting a tool tip generator for a series does override the
159:             * default generator.
160:             */
161:            public void testSetSeriesToolTipGenerator() {
162:                XYPlot plot = (XYPlot) this .chart.getPlot();
163:                XYItemRenderer renderer = plot.getRenderer();
164:                StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator();
165:                renderer.setSeriesToolTipGenerator(0, tt);
166:                XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);
167:                assertTrue(tt2 == tt);
168:            }
169:
170:            /**
171:             * Create a horizontal bar chart with sample data in the range -3 to +3.
172:             *
173:             * @return The chart.
174:             */
175:            private static JFreeChart createChart() {
176:
177:                // create a dataset...
178:                XYSeries series1 = new XYSeries("Series 1");
179:                series1.add(1.0, 1.0);
180:                series1.add(2.0, 2.0);
181:                series1.add(3.0, 3.0);
182:                IntervalXYDataset dataset = new XYBarDataset(
183:                        new XYSeriesCollection(series1), 1.0);
184:
185:                // create the chart...
186:                return ChartFactory.createXYBarChart("XY Bar Chart", // chart title
187:                        "Domain", false, "Range", dataset, // data
188:                        PlotOrientation.VERTICAL, true, // include legend
189:                        true, // tooltips
190:                        true // urls
191:                        );
192:
193:            }
194:
195:            /**
196:             * A chart change listener.
197:             *
198:             */
199:            static class LocalListener implements  ChartChangeListener {
200:
201:                /** A flag. */
202:                private boolean flag = false;
203:
204:                /**
205:                 * Event handler.
206:                 *
207:                 * @param event  the event.
208:                 */
209:                public void chartChanged(ChartChangeEvent event) {
210:                    this .flag = true;
211:                }
212:
213:            }
214:
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.