-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoggingDemo.java
186 lines (146 loc) · 4.83 KB
/
LoggingDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import evaluation.evalBench.EvaluationDelegate;
import evaluation.evalBench.EvaluationManager;
import evaluation.evalBench.session.EvaluationSession;
import evaluation.evalBench.session.EvaluationSessionGroup;
import evaluation.evalBench.task.Task;
/**
* Almost minimal demo for using EvalBench for interaction logging.
* @author rind
*/
public class LoggingDemo {
/**
* show a frame with some buttons
*/
private static void buildAndShowFrame() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.err.println("could not set look and feel "
+ e.getLocalizedMessage());
}
JFrame frame = new JFrame("EvalBench Demo :: Logging");
JPanel visPane = new JPanel();
visPane.setBorder(BorderFactory.createTitledBorder("Prototype"));
visPane.add(new JButton(new DemoAction()));
frame.getContentPane().add(visPane, BorderLayout.CENTER);
JPanel evalPane = new JPanel();
evalPane.add(new JButton(new StartSessionAction(1)));
evalPane.add(new JButton(new StartSessionAction(2)));
evalPane.add(new JButton(new RestartLoggingAction()));
evalPane.add(new JButton(new StopLoggingAction()));
frame.getContentPane().add(evalPane, BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
/**
* shows a frame with a button and start logging
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
buildAndShowFrame();
// this starts logging with minimal overhead
EvaluationManager.getInstance().initLoggingForExploration();
// following code is needed ONLY IF using sessions
EvaluationManager.getInstance().setDelegate(
new DummyDelegate());
EvaluationSessionGroup aSessionGroup = new EvaluationSessionGroup(
"user");
EvaluationManager.getInstance().setSessionGroup(aSessionGroup);
}
});
}
/**
* this simulates one of the interactions to be observed
*/
static class DemoAction extends AbstractAction {
private static final long serialVersionUID = 1764598133118923984L;
public DemoAction() {
putValue(AbstractAction.NAME, "Perfom interaction");
}
@Override
public void actionPerformed(ActionEvent e) {
EvaluationManager.getInstance().log(getValue(AbstractAction.NAME).toString());
}
}
/**
* starts a new interaction log file with a new timestamp
*/
static class RestartLoggingAction extends AbstractAction {
private static final long serialVersionUID = -726618589690256076L;
public RestartLoggingAction() {
putValue(AbstractAction.NAME, "Restart logging");
}
@Override
public void actionPerformed(ActionEvent e) {
EvaluationManager.getInstance().initLoggingForExploration();
}
}
/**
* stops logging
*/
static class StopLoggingAction extends AbstractAction {
private static final long serialVersionUID = 8764981638202257302L;
public StopLoggingAction() {
putValue(AbstractAction.NAME, "Stop logging");
}
@Override
public void actionPerformed(ActionEvent e) {
EvaluationManager.getInstance().stopLogging();
}
}
/**
* configures EvalBench so that a dedicated session is started, which results in a separate file
*/
static class StartSessionAction extends AbstractAction {
private static final long serialVersionUID = -726618589690256076L;
private int number;
public StartSessionAction(int aNumber) {
this.number = aNumber;
putValue(AbstractAction.NAME, "Start session " + aNumber);
}
@Override
public void actionPerformed(ActionEvent e) {
EvaluationSession aSession = new EvaluationSession("session" + number);
String taskFileName = "xml/demotasks.xml";
EvaluationManager.getInstance().getSessionGroup().addSession(aSession);
EvaluationManager.getInstance().startEvaluationSession(aSession, taskFileName );
}
}
/**
* does nothing but is needed for EvalBench sessions to work without error.
* This is not needed for <tt>initLoggingForExploration()</tt>
*/
static class DummyDelegate implements EvaluationDelegate {
@Override
public void prepareForEvaluationSessionGroup(
EvaluationSessionGroup aSessionGroup) {
}
@Override
public void prepareForEvaluationSession(EvaluationSession aSession) {
}
@Override
public void evaluationSessionDidFinish(EvaluationSession aSession) {
}
@Override
public void resetGUIForEvaluationSession(
EvaluationSession evaluationSession) {
}
@Override
public void prepareForEvaluationTask(Task aTask) {
}
@Override
public void evaluationTaskWasAnswered(Task aTask) {
}
}
}