1 | package genius.gui.progress.session;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import javax.swing.DefaultListModel;
|
---|
6 |
|
---|
7 | import genius.core.AgentID;
|
---|
8 | import genius.core.Bid;
|
---|
9 | import genius.core.actions.ActionWithBid;
|
---|
10 | import genius.core.events.MultipartyNegoActionEvent;
|
---|
11 | import genius.core.events.NegotiationEvent;
|
---|
12 | import genius.core.events.SessionEndedNormallyEvent;
|
---|
13 | import genius.core.listener.Listener;
|
---|
14 | import genius.core.parties.PartyWithUtility;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Outcomes model. Listens to {@link NegotiationEvent}s and keeps a
|
---|
18 | * {@link DefaultListModel} with the {@link Outcome}s that were reported.
|
---|
19 | *
|
---|
20 | * Notice: some panels assume that only 1 item is added to OutcomesModel at a
|
---|
21 | * time.
|
---|
22 | *
|
---|
23 | */
|
---|
24 | @SuppressWarnings("serial")
|
---|
25 | public class OutcomesListModel extends DefaultListModel<Outcome> implements Listener<NegotiationEvent> {
|
---|
26 |
|
---|
27 | private List<? extends PartyWithUtility> parties;
|
---|
28 |
|
---|
29 | public OutcomesListModel(List<? extends PartyWithUtility> parties) {
|
---|
30 | this.parties = parties;
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public void notifyChange(NegotiationEvent e) {
|
---|
35 | Bid bid = null;
|
---|
36 | int round = 0, turn = 0;
|
---|
37 | boolean isAgreement = false;
|
---|
38 | double time = 0;
|
---|
39 | AgentID agent = null;
|
---|
40 | if (e instanceof MultipartyNegoActionEvent) {
|
---|
41 | MultipartyNegoActionEvent event = (MultipartyNegoActionEvent) e;
|
---|
42 | if (event.getAction() instanceof ActionWithBid) {
|
---|
43 | round = event.getRound();
|
---|
44 | turn = event.getTurn();
|
---|
45 | bid = ((ActionWithBid) event.getAction()).getBid();
|
---|
46 | agent = ((ActionWithBid) event.getAction()).getAgent();
|
---|
47 | time = event.getTime();
|
---|
48 | }
|
---|
49 | } else if (e instanceof SessionEndedNormallyEvent) {
|
---|
50 | SessionEndedNormallyEvent event = (SessionEndedNormallyEvent) e;
|
---|
51 | bid = event.getAgreement();
|
---|
52 | round = ((SessionEndedNormallyEvent) e).getSession().getRoundNumber();
|
---|
53 | turn = ((SessionEndedNormallyEvent) e).getSession().getTurnNumber();
|
---|
54 | isAgreement = true;
|
---|
55 | if (event.getSession().getMostRecentAction() != null) {
|
---|
56 | agent = event.getSession().getMostRecentAction().getAgent();
|
---|
57 | } else {
|
---|
58 | // crash in first round of first agent.
|
---|
59 | agent = ((SessionEndedNormallyEvent) e).getParties().get(0).getID();
|
---|
60 | }
|
---|
61 | time = event.getSession().getTimeline().getTime();
|
---|
62 | }
|
---|
63 | // FIXME handle other cases?
|
---|
64 | if (bid != null) {
|
---|
65 | addElement(new Outcome(bid, round, turn, parties, isAgreement, agent, time));
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * @return the list of parties in this negotiation.
|
---|
71 | */
|
---|
72 | public List<? extends PartyWithUtility> getParties() {
|
---|
73 | return parties;
|
---|
74 | }
|
---|
75 |
|
---|
76 | }
|
---|