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: * AbstractRendererTests.java
029: * --------------------------
030: * (C) Copyright 2003, 2004, 2007, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: AbstractRendererTests.java,v 1.1.2.4 2007/06/13 10:57:40 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 23-Oct-2003 : Version 1 (DG);
040: * 01-Mar-2004 : Added serialization test (DG);
041: * 19-Feb-2007 : Added testCloning (DG);
042: * 28-Feb-2007 : Added checks for cloning (DG);
043: *
044: */
045:
046: package org.jfree.chart.renderer.junit;
047:
048: import java.awt.BasicStroke;
049: import java.awt.Color;
050: import java.awt.Font;
051: import java.awt.GradientPaint;
052: import java.awt.Rectangle;
053: import java.awt.Shape;
054: import java.awt.Stroke;
055: import java.awt.geom.Rectangle2D;
056: import java.io.ByteArrayInputStream;
057: import java.io.ByteArrayOutputStream;
058: import java.io.ObjectInput;
059: import java.io.ObjectInputStream;
060: import java.io.ObjectOutput;
061: import java.io.ObjectOutputStream;
062:
063: import junit.framework.Test;
064: import junit.framework.TestCase;
065: import junit.framework.TestSuite;
066:
067: import org.jfree.chart.axis.CategoryAxis;
068: import org.jfree.chart.axis.NumberAxis;
069: import org.jfree.chart.event.RendererChangeEvent;
070: import org.jfree.chart.event.RendererChangeListener;
071: import org.jfree.chart.labels.ItemLabelAnchor;
072: import org.jfree.chart.labels.ItemLabelPosition;
073: import org.jfree.chart.plot.CategoryPlot;
074: import org.jfree.chart.plot.DefaultDrawingSupplier;
075: import org.jfree.chart.renderer.AbstractRenderer;
076: import org.jfree.chart.renderer.category.BarRenderer;
077: import org.jfree.chart.renderer.category.LineAndShapeRenderer;
078: import org.jfree.ui.TextAnchor;
079:
080: /**
081: * Tests for the {@link AbstractRenderer} class.
082: */
083: public class AbstractRendererTests extends TestCase {
084:
085: /**
086: * Returns the tests as a test suite.
087: *
088: * @return The test suite.
089: */
090: public static Test suite() {
091: return new TestSuite(AbstractRendererTests.class);
092: }
093:
094: /**
095: * Constructs a new set of tests.
096: *
097: * @param name the name of the tests.
098: */
099: public AbstractRendererTests(String name) {
100: super (name);
101: }
102:
103: /**
104: * Test that the equals() method distinguishes all fields.
105: */
106: public void testEquals() {
107: // have to use a concrete subclass...
108: BarRenderer r1 = new BarRenderer();
109: BarRenderer r2 = new BarRenderer();
110: assertTrue(r1.equals(r2));
111: assertTrue(r2.equals(r1));
112:
113: // seriesVisible
114: r1.setSeriesVisible(Boolean.TRUE);
115: assertFalse(r1.equals(r2));
116: r2.setSeriesVisible(Boolean.TRUE);
117: assertTrue(r1.equals(r2));
118:
119: // seriesVisibleList
120: r1.setSeriesVisible(2, Boolean.TRUE);
121: assertFalse(r1.equals(r2));
122: r2.setSeriesVisible(2, Boolean.TRUE);
123: assertTrue(r1.equals(r2));
124:
125: // baseSeriesVisible
126: r1.setBaseSeriesVisible(false);
127: assertFalse(r1.equals(r2));
128: r2.setBaseSeriesVisible(false);
129: assertTrue(r1.equals(r2));
130:
131: // seriesVisibleInLegend
132: r1.setSeriesVisibleInLegend(Boolean.TRUE);
133: assertFalse(r1.equals(r2));
134: r2.setSeriesVisibleInLegend(Boolean.TRUE);
135: assertTrue(r1.equals(r2));
136:
137: // seriesVisibleInLegendList
138: r1.setSeriesVisibleInLegend(1, Boolean.TRUE);
139: assertFalse(r1.equals(r2));
140: r2.setSeriesVisibleInLegend(1, Boolean.TRUE);
141: assertTrue(r1.equals(r2));
142:
143: // baseSeriesVisibleInLegend
144: r1.setBaseSeriesVisibleInLegend(false);
145: assertFalse(r1.equals(r2));
146: r2.setBaseSeriesVisibleInLegend(false);
147: assertTrue(r1.equals(r2));
148:
149: // paint
150: r1.setPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f,
151: 4.0f, Color.red));
152: assertFalse(r1.equals(r2));
153: r2.setPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f,
154: 4.0f, Color.red));
155: assertTrue(r1.equals(r2));
156:
157: // paintList
158: r1.setSeriesPaint(0, new GradientPaint(1.0f, 2.0f, Color.red,
159: 3.0f, 4.0f, Color.white));
160: assertFalse(r1.equals(r2));
161: r2.setSeriesPaint(0, new GradientPaint(1.0f, 2.0f, Color.red,
162: 3.0f, 4.0f, Color.white));
163: assertTrue(r1.equals(r2));
164:
165: // basePaint
166: r1.setBasePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f,
167: 4.0f, Color.red));
168: assertFalse(r1.equals(r2));
169: r2.setBasePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f,
170: 4.0f, Color.red));
171: assertTrue(r1.equals(r2));
172:
173: // fillPaint
174: r1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f,
175: 4.0f, Color.red));
176: assertFalse(r1.equals(r2));
177: r2.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f,
178: 4.0f, Color.red));
179: assertTrue(r1.equals(r2));
180:
181: // fillPaintList
182: r1.setSeriesFillPaint(0, new GradientPaint(1.0f, 2.0f,
183: Color.blue, 3.0f, 4.0f, Color.red));
184: assertFalse(r1.equals(r2));
185: r2.setSeriesFillPaint(0, new GradientPaint(1.0f, 2.0f,
186: Color.blue, 3.0f, 4.0f, Color.red));
187: assertTrue(r1.equals(r2));
188:
189: // baseFillPaint
190: r1.setBaseFillPaint(new GradientPaint(1.0f, 2.0f, Color.blue,
191: 3.0f, 4.0f, Color.red));
192: assertFalse(r1.equals(r2));
193: r2.setBaseFillPaint(new GradientPaint(1.0f, 2.0f, Color.blue,
194: 3.0f, 4.0f, Color.red));
195: assertTrue(r1.equals(r2));
196:
197: // outlinePaint
198: r1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue,
199: 3.0f, 4.0f, Color.red));
200: assertFalse(r1.equals(r2));
201: r2.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue,
202: 3.0f, 4.0f, Color.red));
203: assertTrue(r1.equals(r2));
204:
205: // outlinePaintList
206: r1.setSeriesOutlinePaint(0, new GradientPaint(1.0f, 2.0f,
207: Color.blue, 3.0f, 4.0f, Color.red));
208: assertFalse(r1.equals(r2));
209: r2.setSeriesOutlinePaint(0, new GradientPaint(1.0f, 2.0f,
210: Color.blue, 3.0f, 4.0f, Color.red));
211: assertTrue(r1.equals(r2));
212:
213: // baseOutlinePaint
214: r1.setBaseOutlinePaint(new GradientPaint(1.0f, 2.0f,
215: Color.blue, 3.0f, 4.0f, Color.red));
216: assertFalse(r1.equals(r2));
217: r2.setBaseOutlinePaint(new GradientPaint(1.0f, 2.0f,
218: Color.blue, 3.0f, 4.0f, Color.red));
219: assertTrue(r1.equals(r2));
220:
221: // stroke
222: Stroke s = new BasicStroke(3.21f);
223: r1.setStroke(s);
224: assertFalse(r1.equals(r2));
225: r2.setStroke(s);
226: assertTrue(r1.equals(r2));
227:
228: // strokeList
229: r1.setSeriesStroke(1, s);
230: assertFalse(r1.equals(r2));
231: r2.setSeriesStroke(1, s);
232: assertTrue(r1.equals(r2));
233:
234: // baseStroke
235: r1.setBaseStroke(s);
236: assertFalse(r1.equals(r2));
237: r2.setBaseStroke(s);
238: assertTrue(r1.equals(r2));
239:
240: // outlineStroke
241: r1.setOutlineStroke(s);
242: assertFalse(r1.equals(r2));
243: r2.setOutlineStroke(s);
244: assertTrue(r1.equals(r2));
245:
246: // outlineStrokeList
247: r1.setSeriesOutlineStroke(0, s);
248: assertFalse(r1.equals(r2));
249: r2.setSeriesOutlineStroke(0, s);
250: assertTrue(r1.equals(r2));
251:
252: // baseOutlineStroke
253: r1.setBaseOutlineStroke(s);
254: assertFalse(r1.equals(r2));
255: r2.setBaseOutlineStroke(s);
256: assertTrue(r1.equals(r2));
257:
258: // shape
259: r1.setShape(new Rectangle(1, 2, 3, 4));
260: assertFalse(r1.equals(r2));
261: r2.setShape(new Rectangle(1, 2, 3, 4));
262: assertTrue(r1.equals(r2));
263:
264: // shapeList
265: r1.setSeriesShape(1, new Rectangle(1, 2, 3, 4));
266: assertFalse(r1.equals(r2));
267: r2.setSeriesShape(1, new Rectangle(1, 2, 3, 4));
268: assertTrue(r1.equals(r2));
269:
270: // baseShape
271: r1.setBaseShape(new Rectangle(1, 2, 3, 4));
272: assertFalse(r1.equals(r2));
273: r2.setBaseShape(new Rectangle(1, 2, 3, 4));
274: assertTrue(r1.equals(r2));
275:
276: // itemLabelsVisible
277: r1.setItemLabelsVisible(true);
278: assertFalse(r1.equals(r2));
279: r2.setItemLabelsVisible(true);
280: assertTrue(r1.equals(r2));
281:
282: // itemLabelsVisibleList
283: r1.setSeriesItemLabelsVisible(1, Boolean.TRUE);
284: assertFalse(r1.equals(r2));
285: r2.setSeriesItemLabelsVisible(1, Boolean.TRUE);
286: assertTrue(r1.equals(r2));
287:
288: // baseItemLabelsVisible
289: r1.setBaseItemLabelsVisible(true);
290: assertFalse(r1.equals(r2));
291: r2.setBaseItemLabelsVisible(true);
292: assertTrue(r1.equals(r2));
293:
294: // itemLabelFont
295: r1.setItemLabelFont(new Font("Serif", Font.PLAIN, 10));
296: assertFalse(r1.equals(r2));
297: r2.setItemLabelFont(new Font("Serif", Font.PLAIN, 10));
298: assertTrue(r1.equals(r2));
299:
300: // itemLabelFontList
301: r1.setSeriesItemLabelFont(1, new Font("Serif", Font.BOLD, 9));
302: assertFalse(r1.equals(r2));
303: r2.setSeriesItemLabelFont(1, new Font("Serif", Font.BOLD, 9));
304: assertTrue(r1.equals(r2));
305:
306: // baseItemLabelFont
307: r1.setBaseItemLabelFont(new Font("Serif", Font.PLAIN, 10));
308: assertFalse(r1.equals(r2));
309: r2.setBaseItemLabelFont(new Font("Serif", Font.PLAIN, 10));
310: assertTrue(r1.equals(r2));
311:
312: // itemLabelPaint
313: r1.setItemLabelPaint(new GradientPaint(1.0f, 2.0f, Color.red,
314: 3.0f, 4.0f, Color.gray));
315: assertFalse(r1.equals(r2));
316: r2.setItemLabelPaint(new GradientPaint(1.0f, 2.0f, Color.red,
317: 3.0f, 4.0f, Color.gray));
318: assertTrue(r1.equals(r2));
319:
320: // itemLabelPaintList
321: r1.setSeriesItemLabelPaint(0, new GradientPaint(1.0f, 2.0f,
322: Color.red, 3.0f, 4.0f, Color.gray));
323: assertFalse(r1.equals(r2));
324: r2.setSeriesItemLabelPaint(0, new GradientPaint(1.0f, 2.0f,
325: Color.red, 3.0f, 4.0f, Color.gray));
326: assertTrue(r1.equals(r2));
327:
328: // baseItemLabelPaint
329: r1.setBaseItemLabelPaint(new GradientPaint(1.0f, 2.0f,
330: Color.red, 3.0f, 4.0f, Color.gray));
331: assertFalse(r1.equals(r2));
332: r2.setBaseItemLabelPaint(new GradientPaint(1.0f, 2.0f,
333: Color.red, 3.0f, 4.0f, Color.gray));
334: assertTrue(r1.equals(r2));
335:
336: // positiveItemLabelPosition;
337: r1.setPositiveItemLabelPosition(new ItemLabelPosition());
338: assertFalse(r1.equals(r2));
339: r2.setPositiveItemLabelPosition(new ItemLabelPosition());
340: assertTrue(r1.equals(r2));
341:
342: // positiveItemLabelPositionList;
343: r1.setSeriesPositiveItemLabelPosition(0,
344: new ItemLabelPosition());
345: assertFalse(r1.equals(r2));
346: r2.setSeriesPositiveItemLabelPosition(0,
347: new ItemLabelPosition());
348: assertTrue(r1.equals(r2));
349:
350: // basePositiveItemLabelPosition;
351: r1.setBasePositiveItemLabelPosition(new ItemLabelPosition(
352: ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_RIGHT));
353: assertFalse(r1.equals(r2));
354: r2.setBasePositiveItemLabelPosition(new ItemLabelPosition(
355: ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_RIGHT));
356: assertTrue(r1.equals(r2));
357:
358: // negativeItemLabelPosition;
359: r1.setNegativeItemLabelPosition(new ItemLabelPosition(
360: ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_RIGHT));
361: assertFalse(r1.equals(r2));
362: r2.setNegativeItemLabelPosition(new ItemLabelPosition(
363: ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_RIGHT));
364: assertTrue(r1.equals(r2));
365:
366: // negativeItemLabelPositionList;
367: r1.setSeriesNegativeItemLabelPosition(1, new ItemLabelPosition(
368: ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_RIGHT));
369: assertFalse(r1.equals(r2));
370: r2.setSeriesNegativeItemLabelPosition(1, new ItemLabelPosition(
371: ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_RIGHT));
372: assertTrue(r1.equals(r2));
373:
374: // baseNegativeItemLabelPosition;
375: r1.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
376: ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_RIGHT));
377: assertFalse(r1.equals(r2));
378: r2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
379: ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_RIGHT));
380: assertTrue(r1.equals(r2));
381:
382: // itemLabelAnchorOffset
383: r1.setItemLabelAnchorOffset(3.0);
384: assertFalse(r1.equals(r2));
385: r2.setItemLabelAnchorOffset(3.0);
386: assertTrue(r1.equals(r2));
387:
388: // createEntities;
389: r1.setCreateEntities(Boolean.TRUE);
390: assertFalse(r1.equals(r2));
391: r2.setCreateEntities(Boolean.TRUE);
392: assertTrue(r1.equals(r2));
393:
394: // createEntitiesList;
395: r1.setSeriesCreateEntities(0, Boolean.TRUE);
396: assertFalse(r1.equals(r2));
397: r2.setSeriesCreateEntities(0, Boolean.TRUE);
398: assertTrue(r1.equals(r2));
399:
400: // baseCreateEntities;
401: r1.setBaseCreateEntities(false);
402: assertFalse(r1.equals(r2));
403: r2.setBaseCreateEntities(false);
404: assertTrue(r1.equals(r2));
405:
406: }
407:
408: /**
409: * Confirm that cloning works.
410: */
411: public void testCloning() {
412: LineAndShapeRenderer r1 = new LineAndShapeRenderer();
413: Rectangle2D shape = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
414: Rectangle2D baseShape = new Rectangle2D.Double(11.0, 12.0,
415: 13.0, 14.0);
416: r1.setShape(shape);
417: r1.setBaseShape(baseShape);
418:
419: LineAndShapeRenderer r2 = null;
420: try {
421: r2 = (LineAndShapeRenderer) r1.clone();
422: } catch (CloneNotSupportedException e) {
423: e.printStackTrace();
424: }
425: assertTrue(r1 != r2);
426: assertTrue(r1.getClass() == r2.getClass());
427: assertTrue(r1.equals(r2));
428:
429: r1.setSeriesVisible(0, Boolean.FALSE);
430: assertFalse(r1.equals(r2));
431: r2.setSeriesVisible(0, Boolean.FALSE);
432: assertTrue(r1.equals(r2));
433:
434: r1.setSeriesVisibleInLegend(0, Boolean.FALSE);
435: assertFalse(r1.equals(r2));
436: r2.setSeriesVisibleInLegend(0, Boolean.FALSE);
437: assertTrue(r1.equals(r2));
438:
439: r1.setSeriesPaint(0, Color.black);
440: assertFalse(r1.equals(r2));
441: r2.setSeriesPaint(0, Color.black);
442: assertTrue(r1.equals(r2));
443:
444: r1.setSeriesFillPaint(0, Color.yellow);
445: assertFalse(r1.equals(r2));
446: r2.setSeriesFillPaint(0, Color.yellow);
447: assertTrue(r1.equals(r2));
448:
449: r1.setSeriesOutlinePaint(0, Color.yellow);
450: assertFalse(r1.equals(r2));
451: r2.setSeriesOutlinePaint(0, Color.yellow);
452: assertTrue(r1.equals(r2));
453:
454: r1.setSeriesStroke(0, new BasicStroke(2.2f));
455: assertFalse(r1.equals(r2));
456: r2.setSeriesStroke(0, new BasicStroke(2.2f));
457: assertTrue(r1.equals(r2));
458:
459: r1.setSeriesOutlineStroke(0, new BasicStroke(2.2f));
460: assertFalse(r1.equals(r2));
461: r2.setSeriesOutlineStroke(0, new BasicStroke(2.2f));
462: assertTrue(r1.equals(r2));
463:
464: shape.setRect(4.0, 3.0, 2.0, 1.0);
465: assertFalse(r1.equals(r2));
466: r2.setShape(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
467: assertTrue(r1.equals(r2));
468:
469: baseShape.setRect(4.0, 3.0, 2.0, 1.0);
470: assertFalse(r1.equals(r2));
471: r2.setBaseShape(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
472: assertTrue(r1.equals(r2));
473:
474: r1
475: .setSeriesShape(0, new Rectangle2D.Double(1.0, 2.0,
476: 3.0, 4.0));
477: assertFalse(r1.equals(r2));
478: r2
479: .setSeriesShape(0, new Rectangle2D.Double(1.0, 2.0,
480: 3.0, 4.0));
481: assertTrue(r1.equals(r2));
482:
483: r1.setSeriesItemLabelsVisible(0, Boolean.TRUE);
484: assertFalse(r1.equals(r2));
485: r2.setSeriesItemLabelsVisible(0, Boolean.TRUE);
486: assertTrue(r1.equals(r2));
487:
488: r1.setSeriesItemLabelPaint(0, Color.red);
489: assertFalse(r1.equals(r2));
490: r2.setSeriesItemLabelPaint(0, Color.red);
491: assertTrue(r1.equals(r2));
492:
493: r1.setSeriesPositiveItemLabelPosition(0,
494: new ItemLabelPosition());
495: assertFalse(r1.equals(r2));
496: r2.setSeriesPositiveItemLabelPosition(0,
497: new ItemLabelPosition());
498: assertTrue(r1.equals(r2));
499:
500: r1.setSeriesNegativeItemLabelPosition(0,
501: new ItemLabelPosition());
502: assertFalse(r1.equals(r2));
503: r2.setSeriesNegativeItemLabelPosition(0,
504: new ItemLabelPosition());
505: assertTrue(r1.equals(r2));
506:
507: r1.setSeriesCreateEntities(0, Boolean.FALSE);
508: assertFalse(r1.equals(r2));
509: r2.setSeriesCreateEntities(0, Boolean.FALSE);
510: assertTrue(r1.equals(r2));
511: }
512:
513: /**
514: * A utility class for listening to changes to a renderer.
515: */
516: static class MyRendererChangeListener implements
517: RendererChangeListener {
518:
519: /** The last event received. */
520: public RendererChangeEvent lastEvent;
521:
522: /**
523: * Creates a new instance.
524: */
525: public MyRendererChangeListener() {
526: this .lastEvent = null;
527: }
528:
529: public void rendererChanged(RendererChangeEvent event) {
530: this .lastEvent = event;
531: }
532: }
533:
534: /**
535: * A check for cloning.
536: */
537: public void testCloning2() {
538: LineAndShapeRenderer r1 = new LineAndShapeRenderer();
539: r1.setBasePaint(Color.blue);
540: LineAndShapeRenderer r2 = null;
541: try {
542: r2 = (LineAndShapeRenderer) r1.clone();
543: } catch (CloneNotSupportedException e) {
544: e.printStackTrace();
545: }
546: assertTrue(r1 != r2);
547: assertTrue(r1.getClass() == r2.getClass());
548: assertTrue(r1.equals(r2));
549:
550: MyRendererChangeListener listener = new MyRendererChangeListener();
551: r2.addChangeListener(listener);
552: r2.setBasePaint(Color.red);
553: assertTrue(listener.lastEvent.getRenderer() == r2);
554: assertFalse(r1.hasListener(listener));
555: }
556:
557: /**
558: * Test that setting the series visibility for ALL series does in fact work.
559: */
560: public void testSetSeriesVisible() {
561: BarRenderer r = new BarRenderer();
562: r.setSeriesVisible(Boolean.TRUE);
563: assertTrue(r.getItemVisible(0, 0));
564: }
565:
566: /**
567: * Test that setting the paint for ALL series does in fact work.
568: */
569: public void testSetPaint() {
570: BarRenderer r = new BarRenderer();
571: r.setPaint(Color.orange);
572: assertEquals(Color.orange, r.getItemPaint(0, 0));
573: }
574:
575: /**
576: * Test that setting the outline paint for ALL series does in fact work.
577: */
578: public void testSetOutlinePaint() {
579: BarRenderer r = new BarRenderer();
580: r.setOutlinePaint(Color.orange);
581: assertEquals(Color.orange, r.getItemOutlinePaint(0, 0));
582: }
583:
584: /**
585: * Test that setting the stroke for ALL series does in fact work.
586: */
587: public void testSetStroke() {
588: BarRenderer r = new BarRenderer();
589: Stroke s = new BasicStroke(10.0f);
590: r.setStroke(s);
591: assertEquals(s, r.getItemStroke(0, 0));
592: }
593:
594: /**
595: * Test that setting the outline stroke for ALL series does in fact work.
596: */
597: public void testSetOutlineStroke() {
598: BarRenderer r = new BarRenderer();
599: Stroke s = new BasicStroke(10.0f);
600: r.setOutlineStroke(s);
601: assertEquals(s, r.getItemOutlineStroke(0, 0));
602: }
603:
604: /**
605: * Test that setting the shape for ALL series does in fact work.
606: */
607: public void testSetShape() {
608: BarRenderer r = new BarRenderer();
609: Shape s = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
610: r.setShape(s);
611: assertEquals(s, r.getItemShape(0, 0));
612: }
613:
614: /**
615: * Test that setting the item label visibility for ALL series does in fact
616: * work.
617: */
618: public void testSetItemLabelsVisible() {
619: BarRenderer r = new BarRenderer();
620: r.setItemLabelsVisible(true);
621: assertTrue(r.isItemLabelVisible(0, 0));
622: }
623:
624: /**
625: * Test that setting the font for ALL series does in fact work (it was
626: * broken at one point).
627: */
628: public void testSetItemLabelFont() {
629: BarRenderer r = new BarRenderer();
630: r.setItemLabelFont(new Font("SansSerif", Font.PLAIN, 33));
631: assertEquals(new Font("SansSerif", Font.PLAIN, 33), r
632: .getItemLabelFont(0, 0));
633: }
634:
635: /**
636: * Test that setting the paint for ALL series does in fact work (it was
637: * broken at one point).
638: */
639: public void testSetItemLabelPaint() {
640: BarRenderer r = new BarRenderer();
641: r.setItemLabelPaint(Color.green);
642: assertEquals(Color.green, r.getItemLabelPaint(0, 0));
643: }
644:
645: /**
646: * Test that setting the positive item label position for ALL series does
647: * in fact work.
648: */
649: public void testSetPositiveItemLabelPosition() {
650: BarRenderer r = new BarRenderer();
651: r.setPositiveItemLabelPosition(new ItemLabelPosition(
652: ItemLabelAnchor.INSIDE1, TextAnchor.BASELINE_LEFT));
653: assertEquals(new ItemLabelPosition(ItemLabelAnchor.INSIDE1,
654: TextAnchor.BASELINE_LEFT), r
655: .getPositiveItemLabelPosition(0, 0));
656: }
657:
658: /**
659: * Test that setting the negative item label position for ALL series does
660: * in fact work.
661: */
662: public void testSetNegativeItemLabelPosition() {
663: BarRenderer r = new BarRenderer();
664: r.setNegativeItemLabelPosition(new ItemLabelPosition(
665: ItemLabelAnchor.INSIDE1, TextAnchor.BASELINE_LEFT));
666: assertEquals(new ItemLabelPosition(ItemLabelAnchor.INSIDE1,
667: TextAnchor.BASELINE_LEFT), r
668: .getNegativeItemLabelPosition(0, 0));
669: }
670:
671: /**
672: * Tests each setter method to ensure that it sends an event notification.
673: */
674: public void testEventNotification() {
675:
676: RendererChangeDetector detector = new RendererChangeDetector();
677: BarRenderer r1 = new BarRenderer(); // have to use a subclass of
678: // AbstractRenderer
679: r1.addChangeListener(detector);
680:
681: // PAINT
682: detector.setNotified(false);
683: r1.setPaint(Color.red);
684: assertTrue(detector.getNotified());
685:
686: detector.setNotified(false);
687: r1.setSeriesPaint(0, Color.red);
688: assertTrue(detector.getNotified());
689:
690: detector.setNotified(false);
691: r1.setBasePaint(Color.red);
692: assertTrue(detector.getNotified());
693:
694: // OUTLINE PAINT
695: detector.setNotified(false);
696: r1.setOutlinePaint(Color.red);
697: assertTrue(detector.getNotified());
698:
699: detector.setNotified(false);
700: r1.setSeriesOutlinePaint(0, Color.red);
701: assertTrue(detector.getNotified());
702:
703: detector.setNotified(false);
704: r1.setBaseOutlinePaint(Color.red);
705: assertTrue(detector.getNotified());
706:
707: // STROKE
708: detector.setNotified(false);
709: r1.setStroke(new BasicStroke(1.0f));
710: assertTrue(detector.getNotified());
711:
712: detector.setNotified(false);
713: r1.setSeriesStroke(0, new BasicStroke(1.0f));
714: assertTrue(detector.getNotified());
715:
716: detector.setNotified(false);
717: r1.setBaseStroke(new BasicStroke(1.0f));
718: assertTrue(detector.getNotified());
719:
720: // OUTLINE STROKE
721: detector.setNotified(false);
722: r1.setOutlineStroke(new BasicStroke(1.0f));
723: assertTrue(detector.getNotified());
724:
725: detector.setNotified(false);
726: r1.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
727: assertTrue(detector.getNotified());
728:
729: detector.setNotified(false);
730: r1.setBaseOutlineStroke(new BasicStroke(1.0f));
731: assertTrue(detector.getNotified());
732:
733: // SHAPE
734: detector.setNotified(false);
735: r1.setShape(new Rectangle2D.Float());
736: assertTrue(detector.getNotified());
737:
738: detector.setNotified(false);
739: r1.setSeriesShape(0, new Rectangle2D.Float());
740: assertTrue(detector.getNotified());
741:
742: detector.setNotified(false);
743: r1.setBaseShape(new Rectangle2D.Float());
744: assertTrue(detector.getNotified());
745:
746: // ITEM_LABELS_VISIBLE
747: detector.setNotified(false);
748: r1.setItemLabelsVisible(Boolean.TRUE);
749: assertTrue(detector.getNotified());
750:
751: detector.setNotified(false);
752: r1.setSeriesItemLabelsVisible(0, Boolean.TRUE);
753: assertTrue(detector.getNotified());
754:
755: detector.setNotified(false);
756: r1.setBaseItemLabelsVisible(Boolean.TRUE);
757: assertTrue(detector.getNotified());
758:
759: // ITEM_LABEL_FONT
760: detector.setNotified(false);
761: r1.setItemLabelFont(new Font("Serif", Font.PLAIN, 12));
762: assertTrue(detector.getNotified());
763:
764: detector.setNotified(false);
765: r1.setSeriesItemLabelFont(0, new Font("Serif", Font.PLAIN, 12));
766: assertTrue(detector.getNotified());
767:
768: detector.setNotified(false);
769: r1.setBaseItemLabelFont(new Font("Serif", Font.PLAIN, 12));
770: assertTrue(detector.getNotified());
771:
772: // ITEM_LABEL_PAINT
773: detector.setNotified(false);
774: r1.setItemLabelPaint(Color.blue);
775: assertTrue(detector.getNotified());
776:
777: detector.setNotified(false);
778: r1.setSeriesItemLabelPaint(0, Color.blue);
779: assertTrue(detector.getNotified());
780:
781: detector.setNotified(false);
782: r1.setBaseItemLabelPaint(Color.blue);
783: assertTrue(detector.getNotified());
784:
785: // POSITIVE ITEM LABEL POSITION
786: detector.setNotified(false);
787: r1.setPositiveItemLabelPosition(new ItemLabelPosition(
788: ItemLabelAnchor.CENTER, TextAnchor.CENTER));
789: assertTrue(detector.getNotified());
790:
791: detector.setNotified(false);
792: r1.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(
793: ItemLabelAnchor.CENTER, TextAnchor.CENTER));
794: assertTrue(detector.getNotified());
795:
796: detector.setNotified(false);
797: r1.setBasePositiveItemLabelPosition(new ItemLabelPosition(
798: ItemLabelAnchor.CENTER, TextAnchor.CENTER));
799: assertTrue(detector.getNotified());
800:
801: // NEGATIVE ITEM LABEL ANCHOR
802: detector.setNotified(false);
803: r1.setNegativeItemLabelPosition(new ItemLabelPosition(
804: ItemLabelAnchor.CENTER, TextAnchor.CENTER));
805: assertTrue(detector.getNotified());
806:
807: detector.setNotified(false);
808: r1.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(
809: ItemLabelAnchor.CENTER, TextAnchor.CENTER));
810: assertTrue(detector.getNotified());
811:
812: detector.setNotified(false);
813: r1.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
814: ItemLabelAnchor.CENTER, TextAnchor.CENTER));
815: assertTrue(detector.getNotified());
816:
817: }
818:
819: /**
820: * Serialize an instance, restore it, and check for equality. In addition,
821: * test for a bug that was reported where the listener list is 'null' after
822: * deserialization.
823: */
824: public void testSerialization() {
825:
826: BarRenderer r1 = new BarRenderer();
827: BarRenderer r2 = null;
828:
829: try {
830: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
831: ObjectOutput out = new ObjectOutputStream(buffer);
832: out.writeObject(r1);
833: out.close();
834:
835: ObjectInput in = new ObjectInputStream(
836: new ByteArrayInputStream(buffer.toByteArray()));
837: r2 = (BarRenderer) in.readObject();
838: in.close();
839: } catch (Exception e) {
840: e.printStackTrace();
841: }
842: assertEquals(r1, r2);
843: try {
844: r2.notifyListeners(new RendererChangeEvent(r2));
845: } catch (NullPointerException e) {
846: assertTrue(false); // failed
847: }
848:
849: }
850:
851: /**
852: * Some checks for the autoPopulate flag default values.
853: */
854: public void testAutoPopulateFlagDefaults() {
855: BarRenderer r = new BarRenderer();
856: assertEquals(true, r.getAutoPopulateSeriesPaint());
857: assertEquals(false, r.getAutoPopulateSeriesFillPaint());
858: assertEquals(false, r.getAutoPopulateSeriesOutlinePaint());
859: assertEquals(false, r.getAutoPopulateSeriesStroke());
860: assertEquals(false, r.getAutoPopulateSeriesOutlineStroke());
861: assertEquals(true, r.getAutoPopulateSeriesShape());
862: }
863:
864: /**
865: * Some checks for the paint lookup mechanism.
866: */
867: public void testPaintLookup() {
868: BarRenderer r = new BarRenderer();
869: assertEquals(Color.blue, r.getBasePaint());
870:
871: // first check that autoPopulate==false works as expected
872: r.setAutoPopulateSeriesPaint(false);
873: assertEquals(Color.blue, r.lookupSeriesPaint(0));
874: assertNull(r.getSeriesPaint(0));
875:
876: // now check autoPopulate==true
877: r.setAutoPopulateSeriesPaint(true);
878: /*CategoryPlot plot =*/new CategoryPlot(null,
879: new CategoryAxis("Category"), new NumberAxis("Value"),
880: r);
881: assertEquals(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[0],
882: r.lookupSeriesPaint(0));
883: assertNotNull(r.getSeriesPaint(0));
884: }
885:
886: /**
887: * Some checks for the fill paint lookup mechanism.
888: */
889: public void testFillPaintLookup() {
890: BarRenderer r = new BarRenderer();
891: assertEquals(Color.white, r.getBaseFillPaint());
892:
893: // first check that autoPopulate==false works as expected
894: r.setAutoPopulateSeriesFillPaint(false);
895: assertEquals(Color.white, r.lookupSeriesFillPaint(0));
896: assertNull(r.getSeriesFillPaint(0));
897:
898: // now check autoPopulate==true
899: r.setAutoPopulateSeriesFillPaint(true);
900: /*CategoryPlot plot =*/new CategoryPlot(null,
901: new CategoryAxis("Category"), new NumberAxis("Value"),
902: r);
903: assertEquals(
904: DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE[0],
905: r.lookupSeriesFillPaint(0));
906: assertNotNull(r.getSeriesFillPaint(0));
907: }
908:
909: /**
910: * Some checks for the outline paint lookup mechanism.
911: */
912: public void testOutlinePaintLookup() {
913: BarRenderer r = new BarRenderer();
914: assertEquals(Color.gray, r.getBaseOutlinePaint());
915:
916: // first check that autoPopulate==false works as expected
917: r.setAutoPopulateSeriesOutlinePaint(false);
918: assertEquals(Color.gray, r.lookupSeriesOutlinePaint(0));
919: assertNull(r.getSeriesOutlinePaint(0));
920:
921: // now check autoPopulate==true
922: r.setAutoPopulateSeriesOutlinePaint(true);
923: /*CategoryPlot plot =*/new CategoryPlot(null,
924: new CategoryAxis("Category"), new NumberAxis("Value"),
925: r);
926: assertEquals(
927: DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE[0],
928: r.lookupSeriesOutlinePaint(0));
929: assertNotNull(r.getSeriesOutlinePaint(0));
930: }
931:
932: }
|