View Javadoc

1   /*
2    * @(#) FinanceStatisticsXYChart.java Feb 13, 2005
3    * 
4    * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands. All rights reserved.
6    * 
7    * See for project information <a href="http://www.simulation.tudelft.nl/">
8    * www.simulation.tudelft.nl </a>.
9    * 
10   * The source code and binary code of this software is proprietary information
11   * of Delft University of Technology.
12   */
13  package org.gscg.common.gui.statistics.components;
14  
15  import java.rmi.RemoteException;
16  
17  import nl.tudelft.simulation.event.EventInterface;
18  import nl.tudelft.simulation.event.EventType;
19  import nl.tudelft.simulation.event.TimedEvent;
20  import nl.tudelft.simulation.jstats.charts.xy.XYDataset;
21  import nl.tudelft.simulation.jstats.charts.xy.XYSeries;
22  import nl.tudelft.simulation.logger.Logger;
23  
24  import org.gscg.common.gui.ActorApplicationInterface;
25  import org.gscg.common.gui.ClientInterface;
26  import org.gscg.common.gui.exceptions.ReceivedUnknownEventException;
27  
28  /***
29   * <p>
30   * (c) copyright 2005 <a href="http://www.simulation.tudelft.nl">Delft
31   * University of Technology </a>, the Netherlands. <br>
32   * See for project information <a
33   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
34   * 
35   * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
36   * Delft, the Netherlands. All rights reserved.
37   * 
38   * See for project information <a href="http://www.simulation.tudelft.nl/">
39   * www.simulation.tudelft.nl </a>.
40   * 
41   * The source code and binary code of this software is proprietary information
42   * of Delft University of Technology.
43   * 
44   * @author <a
45   *         href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
46   *         van Houten </a>
47   * @version $Revision: 1.1 $ $Date: 2005/06/16 12:33:54 $
48   * @since 1.1.3
49   */
50  public class FinanceStatisticsXYChart extends StatisticsXYChart
51  {
52  	/*** the series */
53  	private XYSeries[] series = null;
54  
55  	/***
56  	 * constructs a new FinanceStatisticsXYChart
57  	 * 
58  	 * @param actorPanel the actor panel
59  	 * @param eventType the event type
60  	 * @param chartName the name of the chart
61  	 * @param domainLabel the label of the domain
62  	 * @param rangeLabel the label of the range
63  	 * @param runLength the runlength, most likely expressed in days
64  	 */
65  	public FinanceStatisticsXYChart(final ActorApplicationInterface actorPanel,
66  			final EventType eventType, final String chartName,
67  			final String domainLabel, final String rangeLabel,
68  			final double runLength)
69  	{
70  		super(actorPanel, eventType, chartName, domainLabel, rangeLabel,
71  				runLength);
72  	}
73  
74  	/***
75  	 * @see nl.tudelft.simulation.event.EventListenerInterface#notify(nl.tudelft.simulation.event.EventInterface)
76  	 */
77  	public void notify(final EventInterface event) throws RemoteException
78  	{
79  		if (event.getType().equals(this.eventType))
80  		{
81  			if (event instanceof TimedEvent)
82  			{
83  				if (this.series != null)
84  				{
85  					if (this.series.length == 1)
86  					{
87  						this.series[0].notify(event);
88  					} else
89  					{
90  						Logger.warning(this, "notify",
91  								"Series is bigger than 1, namely: "
92  										+ this.series.length);
93  					}
94  				} else
95  				{
96  					this.cache.add(event);
97  				}
98  			} else
99  			// set the chart
100 			{
101 				XYDataset set = new XYDataset();
102 				this.series = (XYSeries[]) event.getContent();
103 				for (int i = 0; i < this.series.length; i++)
104 				{
105 					set.addSeries(this.series[i]);
106 				}
107 				this.xyChart.getChart().getXYPlot().setDataset(set);
108 
109 				// empty the cache
110 				for (int i = 0; i < this.cache.size(); i++)
111 				{
112 					this.series[0].notify((EventInterface) this.cache.get(i));
113 				}
114 				this.cache.clear();
115 			}
116 			return;
117 		}
118 		if (event.getType().equals(
119 				ClientInterface.UNSUBSCRIBE_FROM_SERVER_EVENT))
120 		{
121 			this.setStatus(false);
122 			return;
123 		}
124 		new ReceivedUnknownEventException(this, "notify", event.getType());
125 
126 	}
127 
128 }