1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.jstats.statistics;
11
12 import javax.swing.table.DefaultTableModel;
13
14 import nl.tudelft.simulation.event.EventInterface;
15 import nl.tudelft.simulation.event.EventListenerInterface;
16 import nl.tudelft.simulation.event.EventType;
17
18 /***
19 * The StatisticsTableModel class defines the tableModel used by the statistics
20 * objects.
21 * <p>
22 * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
23 * University of Technology </a>, the Netherlands. <br>
24 * See for project information <a
25 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
26 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
27 * License (GPL) </a>, no warranty <br>
28 *
29 * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
30 * Jacobs </a>
31 * @version 1.7, 2004-03-24
32 * @since 1.2
33 */
34 public class StatisticsTableModel extends DefaultTableModel implements
35 EventListenerInterface
36 {
37 /*** eventTypes represent the eventTypes corresponding to the colmumns */
38 private EventType[] eventTypes = null;
39
40 /***
41 * constructs a new StatisticsTableModel
42 *
43 * @param columnNames the names of the columns
44 * @param eventTypes the eventTypes representing the column
45 * @param rows the number of rows
46 */
47 public StatisticsTableModel(final Object[] columnNames,
48 final EventType[] eventTypes, final int rows)
49 {
50 super(columnNames, rows);
51 if (rows != eventTypes.length)
52 {
53 throw new IllegalArgumentException("eventTypes.length!=rows");
54 }
55 this.eventTypes = eventTypes;
56 }
57
58 /***
59 * @see nl.tudelft.simulation.event.EventListenerInterface
60 * #notify(nl.tudelft.simulation.event.EventInterface)
61 */
62 public void notify(final EventInterface event)
63 {
64 for (int i = 0; i < this.eventTypes.length; i++)
65 {
66 if (event.getType().equals(this.eventTypes[i]))
67 {
68 this.setValueAt(event.getContent(), i, 1);
69 }
70 }
71 }
72 }