1 | package genius.gui.negosession;
|
---|
2 |
|
---|
3 | import java.util.LinkedHashMap;
|
---|
4 |
|
---|
5 | import genius.core.events.NegotiationEvent;
|
---|
6 | import genius.core.events.SessionEndedNormallyEvent;
|
---|
7 | import genius.core.events.SessionFailedEvent;
|
---|
8 | import genius.core.listener.Listener;
|
---|
9 | import genius.gui.progress.DataKey;
|
---|
10 | import genius.gui.progress.DataKeyTableModel;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Tracks the Multiparty tournament and keeps a {@link DataKeyTableModel} up to
|
---|
14 | * date. This determines the layout of log file and tables. This can be listened
|
---|
15 | * to and shown in a table.
|
---|
16 | *
|
---|
17 | * @author W.Pasman
|
---|
18 | *
|
---|
19 | */
|
---|
20 | @SuppressWarnings("serial")
|
---|
21 | public class MultiPartyDataModel extends DataKeyTableModel implements Listener<NegotiationEvent> {
|
---|
22 |
|
---|
23 | public MultiPartyDataModel(int numAgents) {
|
---|
24 | super(makeDataModel(numAgents));
|
---|
25 | }
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * create the dataModel. This determines what is logged, the exact order of
|
---|
29 | * the columns, etc. Currently it makes a table with ALL known
|
---|
30 | * {@link DataKey}s.
|
---|
31 | *
|
---|
32 | * @return datamodel that layouts data.
|
---|
33 | */
|
---|
34 | private static LinkedHashMap<DataKey, Integer> makeDataModel(int numAgents) {
|
---|
35 |
|
---|
36 | LinkedHashMap<DataKey, Integer> colspec = new LinkedHashMap<DataKey, Integer>();
|
---|
37 | for (DataKey key : DataKey.values()) {
|
---|
38 | if (key == DataKey.AGENTS || key == DataKey.FILES || key == DataKey.UTILS
|
---|
39 | || key == DataKey.DISCOUNTED_UTILS || key == DataKey.PERCEIVED_UTILS) {
|
---|
40 | colspec.put(key, numAgents);
|
---|
41 | } else {
|
---|
42 | colspec.put(key, 1);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | return colspec;
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public void notifyChange(NegotiationEvent e) {
|
---|
51 | if (e instanceof SessionEndedNormallyEvent) {
|
---|
52 | SessionEndedNormallyEvent e1 = (SessionEndedNormallyEvent) e;
|
---|
53 | addRow(e1.getValues());
|
---|
54 | } else if (e instanceof SessionFailedEvent) {
|
---|
55 | SessionFailedEvent e1 = (SessionFailedEvent) e;
|
---|
56 | addRow(e1.getValues());
|
---|
57 |
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|