1 42 43 package org.jfree.chart.junit; 44 45 import java.awt.Graphics2D ; 46 import java.awt.geom.Rectangle2D ; 47 import java.awt.image.BufferedImage ; 48 49 import junit.framework.Test; 50 import junit.framework.TestCase; 51 import junit.framework.TestSuite; 52 53 import org.jfree.chart.ChartFactory; 54 import org.jfree.chart.JFreeChart; 55 import org.jfree.chart.axis.ValueAxis; 56 import org.jfree.chart.event.ChartChangeEvent; 57 import org.jfree.chart.event.ChartChangeListener; 58 import org.jfree.chart.labels.CategoryToolTipGenerator; 59 import org.jfree.chart.labels.StandardCategoryToolTipGenerator; 60 import org.jfree.chart.plot.CategoryPlot; 61 import org.jfree.chart.plot.PlotOrientation; 62 import org.jfree.chart.renderer.category.CategoryItemRenderer; 63 import org.jfree.chart.urls.CategoryURLGenerator; 64 import org.jfree.chart.urls.StandardCategoryURLGenerator; 65 import org.jfree.data.Range; 66 import org.jfree.data.category.CategoryDataset; 67 import org.jfree.data.general.DatasetUtilities; 68 69 72 public class LineChart3DTests extends TestCase { 73 74 75 private JFreeChart chart; 76 77 82 public static Test suite() { 83 return new TestSuite(LineChart3DTests.class); 84 } 85 86 91 public LineChart3DTests(String name) { 92 super(name); 93 } 94 95 98 protected void setUp() { 99 this.chart = createLineChart3D(); 100 } 101 102 106 public void testDrawWithNullInfo() { 107 108 boolean success = false; 109 try { 110 BufferedImage image = new BufferedImage ( 111 200 , 100, BufferedImage.TYPE_INT_RGB 112 ); 113 Graphics2D g2 = image.createGraphics(); 114 this.chart.draw( 115 g2, new Rectangle2D.Double (0, 0, 200, 100), null, null 116 ); 117 g2.dispose(); 118 success = true; 119 } 120 catch (Exception e) { 121 success = false; 122 } 123 assertTrue(success); 124 125 } 126 127 130 public void testReplaceDataset() { 131 132 Number [][] data = new Integer [][] 134 {{new Integer (-30), new Integer (-20)}, 135 {new Integer (-10), new Integer (10)}, 136 {new Integer (20), new Integer (30)}}; 137 138 CategoryDataset newData = DatasetUtilities.createCategoryDataset( 139 "S", "C", data 140 ); 141 142 LocalListener l = new LocalListener(); 143 this.chart.addChangeListener(l); 144 this.chart.getCategoryPlot().setDataset(newData); 145 assertEquals(true, l.flag); 146 ValueAxis axis = this.chart.getCategoryPlot().getRangeAxis(); 147 Range range = axis.getRange(); 148 assertTrue("Expecting the lower bound of the range to be around -30: " 149 + range.getLowerBound(), range.getLowerBound() <= -30); 150 assertTrue("Expecting the upper bound of the range to be around 30: " 151 + range.getUpperBound(), range.getUpperBound() >= 30); 152 153 } 154 155 159 public void testSetSeriesToolTipGenerator() { 160 CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); 161 CategoryItemRenderer renderer = plot.getRenderer(); 162 StandardCategoryToolTipGenerator tt 163 = new StandardCategoryToolTipGenerator(); 164 renderer.setSeriesToolTipGenerator(0, tt); 165 CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); 166 assertTrue(tt2 == tt); 167 } 168 169 173 public void testSetSeriesURLGenerator() { 174 CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); 175 CategoryItemRenderer renderer = plot.getRenderer(); 176 StandardCategoryURLGenerator url1 177 = new StandardCategoryURLGenerator(); 178 renderer.setSeriesItemURLGenerator(0, url1); 179 CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); 180 assertTrue(url2 == url1); 181 } 182 183 188 private static JFreeChart createLineChart3D() { 189 190 Number [][] data = new Integer [][] 192 {{new Integer (-3), new Integer (-2)}, 193 {new Integer (-1), new Integer (1)}, 194 {new Integer (2), new Integer (3)}}; 195 196 CategoryDataset dataset 197 = DatasetUtilities.createCategoryDataset("S", "C", data); 198 199 return ChartFactory.createLineChart3D( 201 "Line Chart", 202 "Domain", "Range", 203 dataset, 204 PlotOrientation.HORIZONTAL, 205 true, true, 207 true 208 ); 209 210 } 211 212 216 static class LocalListener implements ChartChangeListener { 217 218 219 private boolean flag = false; 220 221 226 public void chartChanged(ChartChangeEvent event) { 227 this.flag = true; 228 } 229 230 } 231 232 } 233 | Popular Tags |