[1] | 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>();
|
---|
[232] | 37 | for (DataKey key : DataKey.values())
|
---|
| 38 | {
|
---|
| 39 | if (key.getMultiple())
|
---|
[1] | 40 | colspec.put(key, numAgents);
|
---|
[232] | 41 | else
|
---|
[1] | 42 | colspec.put(key, 1);
|
---|
| 43 | }
|
---|
| 44 | return colspec;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | @Override
|
---|
| 48 | public void notifyChange(NegotiationEvent e) {
|
---|
| 49 | if (e instanceof SessionEndedNormallyEvent) {
|
---|
| 50 | SessionEndedNormallyEvent e1 = (SessionEndedNormallyEvent) e;
|
---|
| 51 | addRow(e1.getValues());
|
---|
| 52 | } else if (e instanceof SessionFailedEvent) {
|
---|
| 53 | SessionFailedEvent e1 = (SessionFailedEvent) e;
|
---|
| 54 | addRow(e1.getValues());
|
---|
| 55 |
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|