source: src/main/java/genius/gui/progress/session/ActionDocumentModel.java@ 209

Last change on this file since 209 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 2.1 KB
Line 
1package genius.gui.progress.session;
2
3import javax.swing.JTextArea;
4import javax.swing.text.BadLocationException;
5import javax.swing.text.Document;
6import javax.swing.text.PlainDocument;
7
8import genius.core.events.MultipartyNegoActionEvent;
9import genius.core.events.NegotiationEvent;
10import genius.core.events.SessionEndedNormallyEvent;
11import genius.core.listener.Listener;
12import genius.core.logging.CsvLogger;
13import genius.core.session.Session;
14
15/**
16 * A document containing all actions that occured on the NegotiationEvent
17 * stream. Since this is a {@link Document} you can directly use this in a
18 * {@link JTextArea}.
19 *
20 */
21@SuppressWarnings("serial")
22public class ActionDocumentModel extends PlainDocument implements Listener<NegotiationEvent> {
23
24 private int currentround = -1;
25
26 public ActionDocumentModel() {
27 writeln("Starting negotiation session.\n");
28 }
29
30 @Override
31 public void notifyChange(NegotiationEvent e) {
32 if (e instanceof MultipartyNegoActionEvent) {
33 MultipartyNegoActionEvent e1 = (MultipartyNegoActionEvent) e;
34 int round = e1.getRound();
35 if (round != currentround) {
36 currentround = round;
37 writeln("Round " + currentround);
38 }
39 writeln(" Turn " + e1.getTurn() + ":" + e1.getAction().getAgent() + " " + e1.getAction());
40 } else if (e instanceof SessionEndedNormallyEvent) {
41 SessionEndedNormallyEvent e1 = (SessionEndedNormallyEvent) e;
42 if (e1.getAgreement() == null)
43 writeln("No agreement found.");
44 else {
45 writeln("Found an agreement: " + e1.getAgreement());
46 }
47 Session session = ((SessionEndedNormallyEvent) e).getSession();
48 double runTime = session.getRuntimeInSeconds();
49 writeln("Finished negotiation session in " + runTime + " s.");
50 try {
51 writeln(CsvLogger.logSingleSession(((SessionEndedNormallyEvent) e).getSession(),
52 session.getInfo().getProtocol(), e1.getParties(), runTime));
53 } catch (Exception e2) {
54 e2.printStackTrace();
55 }
56
57 }
58 }
59
60 private void writeln(String text) {
61 try {
62 insertString(getLength(), text + "\n", null);
63 } catch (BadLocationException e) {
64 e.printStackTrace();
65 }
66 }
67
68}
Note: See TracBrowser for help on using the repository browser.