1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.gscg.common.gui.statistics.components;
15
16 import java.rmi.RemoteException;
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import nl.tudelft.simulation.event.EventInterface;
21 import nl.tudelft.simulation.event.EventType;
22 import nl.tudelft.simulation.event.TimedEvent;
23 import nl.tudelft.simulation.jstats.charts.xy.XYDataset;
24 import nl.tudelft.simulation.jstats.charts.xy.XYSeries;
25 import nl.tudelft.simulation.supplychain.stock.StockUpdateData;
26
27 import org.gscg.common.gui.ActorApplicationInterface;
28 import org.gscg.common.gui.ClientInterface;
29 import org.gscg.common.gui.exceptions.ReceivedUnknownEventException;
30
31 /***
32 * The StatisticsStockXYChart is used to display a set of values (x,y) using a
33 * xy-chart. <br>
34 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
35 * Delft, the Netherlands. All rights reserved.
36 *
37 * See for project information <a href="http://www.simulation.tudelft.nl/">
38 * www.simulation.tudelft.nl </a>.
39 *
40 * The source code and binary code of this software is proprietary information
41 * of Delft University of Technology.
42 *
43 * @author <a
44 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
45 * van Houten </a>
46 * @version $Revision: 1.1 $ $Date: 2005/06/16 12:33:54 $
47 * @since 1.0.0
48 */
49 public class StatisticsStockXYChart extends StatisticsXYChart
50 {
51 /*** the set */
52 private XYDataset set = null;
53
54 /*** the series */
55 private List series = new ArrayList();
56
57 /*** the sub string to search for */
58 private String titleSubString = null;
59
60 /***
61 * the StatisticsStockXYChart show the statistics per area which are used in
62 * the are infromation frame
63 *
64 * @param actorPanel the actor panel
65 * @param eventType the event type is used to update the xy chart
66 * @param chartName the name of the chart
67 * @param domainLabel the label of the domain
68 * @param rangeLabel the label of the range
69 * @param runLength the run length
70 * @param titleSubString the title substring to search for
71 */
72 public StatisticsStockXYChart(final ActorApplicationInterface actorPanel,
73 final EventType eventType, final String chartName,
74 final String domainLabel, final String rangeLabel,
75 final double runLength, final String titleSubString)
76 {
77 super(actorPanel, eventType, chartName, domainLabel, rangeLabel,
78 runLength);
79 this.titleSubString = titleSubString;
80 }
81
82 /***
83 * @see nl.tudelft.simulation.event.EventListenerInterface#notify(nl.tudelft.simulation.event.EventInterface)
84 */
85 public void notify(final EventInterface event) throws RemoteException
86 {
87 if (event.getType().equals(super.eventType))
88 {
89 if (event.getClass().equals(TimedEvent.class))
90 {
91 StockUpdateData data = (StockUpdateData) event.getContent();
92 String productName = data.getProductName();
93 if (this.titleSubString.indexOf(productName) >= 0)
94 {
95 if (this.series != null)
96 {
97 for (int i = 0; i < this.series.size(); i++)
98 {
99 if (((XYSeries) this.series.get(i)).getSeriesName()
100 .indexOf(productName) >= 0)
101 {
102 if (((XYSeries) this.series.get(i))
103 .getSeriesName().indexOf("actual") >= 0)
104 {
105 ((XYSeries) this.series.get(i))
106 .notify(new TimedEvent(event
107 .getType(), event
108 .getSource(), new Double(
109 data.getActualAmount()),
110 ((TimedEvent) event)
111 .getTimeStamp()));
112 }
113 if (((XYSeries) this.series.get(i))
114 .getSeriesName().indexOf("committed") >= 0)
115 {
116 ((XYSeries) this.series.get(i))
117 .notify(new TimedEvent(event
118 .getType(), event
119 .getSource(), new Double(
120 data.getClaimedAmount()),
121 ((TimedEvent) event)
122 .getTimeStamp()));
123 }
124 if (((XYSeries) this.series.get(i))
125 .getSeriesName().indexOf("ordered") >= 0)
126 {
127 ((XYSeries) this.series.get(i))
128 .notify(new TimedEvent(event
129 .getType(), event
130 .getSource(), new Double(
131 data.getOrderedAmount()),
132 ((TimedEvent) event)
133 .getTimeStamp()));
134 }
135 }
136 }
137 } else
138 {
139 this.cache.add(event);
140 }
141
142 } else
143 {
144 for (int i = 0; i < this.series.size(); i++)
145 {
146 if (((XYSeries) this.series.get(i)).getSeriesName()
147 .indexOf(productName) >= 0)
148 {
149 if (((XYSeries) this.series.get(i)).getSeriesName()
150 .indexOf("actual") >= 0)
151 {
152 ((XYSeries) this.series.get(i))
153 .notify(new TimedEvent(event.getType(),
154 event.getSource(),
155 new Double(data
156 .getActualAmount()),
157 ((TimedEvent) event)
158 .getTimeStamp()));
159 }
160 if (((XYSeries) this.series.get(i)).getSeriesName()
161 .indexOf("committed") >= 0)
162 {
163 ((XYSeries) this.series.get(i))
164 .notify(new TimedEvent(event.getType(),
165 event.getSource(),
166 new Double(data
167 .getClaimedAmount()),
168 ((TimedEvent) event)
169 .getTimeStamp()));
170 }
171 if (((XYSeries) this.series.get(i)).getSeriesName()
172 .indexOf("ordered") >= 0)
173 {
174 ((XYSeries) this.series.get(i))
175 .notify(new TimedEvent(event.getType(),
176 event.getSource(),
177 new Double(data
178 .getOrderedAmount()),
179 ((TimedEvent) event)
180 .getTimeStamp()));
181 }
182 }
183 }
184
185
186 for (int i = 0; i < this.cache.size(); i++)
187 {
188 this.notify((EventInterface) this.cache.get(i));
189 }
190 this.cache.clear();
191
192 }
193 } else
194
195 {
196 if (this.set == null)
197 {
198 this.set = new XYDataset();
199 XYSeries[][] series = (XYSeries[][]) event.getContent();
200
201 for (int i = 0; i < series.length; i++)
202 {
203 for (int j = 0; j < series[i].length; j++)
204 {
205 if (series[i][j].getSeriesName().indexOf(
206 this.titleSubString) >= 0)
207 {
208 this.set.addSeries(series[i][j]);
209 this.series.add(series[i][j]);
210 }
211 }
212 }
213 super.xyChart.getChart().getXYPlot().setDataset(this.set);
214 }
215 }
216 return;
217 }
218 if (event.getType().equals(
219 ClientInterface.UNSUBSCRIBE_FROM_SERVER_EVENT))
220 {
221 super.setStatus(false);
222 return;
223 }
224 new ReceivedUnknownEventException(this, "notify", event.getType());
225 }
226 }