1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.gscg.singleuser.interactionlayer.business.statistics;
15
16 import java.rmi.RemoteException;
17
18 import nl.tudelft.simulation.event.Event;
19 import nl.tudelft.simulation.event.EventInterface;
20 import nl.tudelft.simulation.event.EventListenerInterface;
21 import nl.tudelft.simulation.event.EventProducer;
22 import nl.tudelft.simulation.event.EventType;
23 import nl.tudelft.simulation.jstats.charts.xy.XYChart;
24 import nl.tudelft.simulation.jstats.charts.xy.XYSeries;
25 import nl.tudelft.simulation.logger.Logger;
26 import nl.tudelft.simulation.supplychain.actor.Trader;
27 import nl.tudelft.simulation.supplychain.banking.BankAccount;
28
29 import org.gscg.common.interactionlayer.AnnounceInterface;
30 import org.gscg.singleuser.interactionlayer.SingleUserInteractionLayerInterface;
31
32 /***
33 * The BankStatistics subscribes to bank account changed events fired by the
34 * bank account of an actor. During execution of the simulation, all the bank
35 * account changed events are stored. When a player becomes online, its client
36 * side chart is updated. And as long as the player is online, future bank
37 * account changed events are stored and immediately sent to the client-side
38 * gui.
39 * <p>
40 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
41 * Delft, the Netherlands. All rights reserved.
42 *
43 * See for project information <a href="http://www.simulation.tudelft.nl/">
44 * www.simulation.tudelft.nl </a>.
45 *
46 * The source code and binary code of this software is proprietary information
47 * of Delft University of Technology.
48 *
49 * @author <a
50 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
51 * van Houten </a>
52 * @version $Revision: 1.2 $ $Date: 2005/08/09 15:43:42 $
53 * @since 1.0.0
54 */
55 public class BankStatistics extends EventProducer implements
56 EventListenerInterface, AnnounceInterface
57 {
58 /*** the serial version uid */
59 private static final long serialVersionUID = 11L;
60
61 /*** fired in case of bank changed events */
62 public static final EventType BANK_ACCOUNT_CHANGED_EVENT = new EventType(
63 "BANK_ACCOUNT_CHANGED_EVENT");
64
65 /*** the XYSeries for the bank account */
66 private XYSeries series = null;
67
68 /*** the single user interaction layer */
69 private SingleUserInteractionLayerInterface owner = null;
70
71 /***
72 * constructs a new BankStatistics
73 *
74 * @param owner the owner
75 * @param trader the trader
76 * @param numberOfDays the number of days in the simulation
77 */
78 public BankStatistics(final SingleUserInteractionLayerInterface owner,
79 final Trader trader, final int numberOfDays)
80 {
81 super();
82 this.owner = owner;
83 trader.getBankAccount().addListener(this,
84 BankAccount.BANK_ACCOUNT_CHANGED_EVENT);
85 this.series = new XYSeries("balance", XYChart.XLINEAR_YLINEAR,
86 numberOfDays);
87 this.addListener(owner, BankStatistics.BANK_ACCOUNT_CHANGED_EVENT);
88 try
89 {
90 this.owner.addEventType(BankStatistics.BANK_ACCOUNT_CHANGED_EVENT);
91 this.owner.addEventTypeToAnnounceList(
92 BankStatistics.BANK_ACCOUNT_CHANGED_EVENT, this);
93 } catch (RemoteException remoteException)
94 {
95 Logger.severe(this, "init", remoteException);
96 }
97 }
98
99 /***
100 * @see org.gscg.common.interactionlayer.AnnounceInterface#announce(nl.tudelft.simulation.event.EventType,
101 * boolean)
102 */
103 public void announce(final EventType eventType, final boolean announce)
104 {
105 try
106 {
107 this.owner.notifyAnnounced(new Event(
108 BankStatistics.BANK_ACCOUNT_CHANGED_EVENT, this,
109 new XYSeries[]{this.series}));
110 } catch (RemoteException remoteException)
111 {
112 Logger.severe(this, "announce", remoteException);
113 }
114 }
115
116 /***
117 * @see nl.tudelft.simulation.event.EventListenerInterface#notify(nl.tudelft.simulation.event.EventInterface)
118 */
119 public void notify(final EventInterface event) throws RemoteException
120 {
121 if (event.getType().equals(BankAccount.BANK_ACCOUNT_CHANGED_EVENT))
122 {
123 this.series.notify(event);
124 this.fireEvent(event);
125 }
126 }
127 }