comparison ExperimentGui.java @ 26:c5db34797ff3

Visual feedback for responses: consistent for mouse and keyboard input; disable buttons when not inactive. Improved debugging messages.
author Jeremy Gow <jeremy.gow@gmail.com>
date Mon, 12 Nov 2012 22:48:39 +0000
parents 9fc8683b8fed
children 796b3e3e053f
comparison
equal deleted inserted replaced
25:cd11981476ec 26:c5db34797ff3
30 private Boolean acceptingResponses; 30 private Boolean acceptingResponses;
31 31
32 /* accessors */ 32 /* accessors */
33 public Boolean getAcceptingResponses() { return acceptingResponses; } 33 public Boolean getAcceptingResponses() { return acceptingResponses; }
34 public void setAcceptingResponses(Boolean b) { 34 public void setAcceptingResponses(Boolean b) {
35 if (exp.getDebug()) 35 if (b)
36 System.out.println("\n\nChanging acceptingResponses from " + acceptingResponses + " to " + b); 36 debug("STARTED accepting responses");
37 else
38 debug("STOPPED accepting responses");
37 acceptingResponses = b; 39 acceptingResponses = b;
40 stimulusPanel.setResponseEnabled(b);
38 } 41 }
39 public Experiment getExperiment() { return exp; } 42 public Experiment getExperiment() { return exp; }
40 public InstructionsPanel getInstructionsPanel() { return instructionsPanel; } 43 public InstructionsPanel getInstructionsPanel() { return instructionsPanel; }
41 public StimulusPanel getStimulusPanel() { return stimulusPanel; } 44 public StimulusPanel getStimulusPanel() { return stimulusPanel; }
42 public SubjectDataPanel getSubjectDataPanel() { return subjectDataPanel; } 45 public SubjectDataPanel getSubjectDataPanel() { return subjectDataPanel; }
48 // initialise experiment 51 // initialise experiment
49 exp = experiment; 52 exp = experiment;
50 acceptingResponses = false; 53 acceptingResponses = false;
51 54
52 // set up the clock 55 // set up the clock
53 clock = new Clock(); 56 clock = new Clock(exp.getDebug());
54 57
55 // construct the frame 58 // construct the frame
56 JFrame.setDefaultLookAndFeelDecorated(true); 59 JFrame.setDefaultLookAndFeelDecorated(true);
57 this.getContentPane().setBackground (Color.black); 60 this.getContentPane().setBackground (Color.black);
58 this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); 61 this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
61 // The different cards 64 // The different cards
62 instructionsPanel = new InstructionsPanel(this); 65 instructionsPanel = new InstructionsPanel(this);
63 stimulusPanel = new StimulusPanel(this, clock); 66 stimulusPanel = new StimulusPanel(this, clock);
64 interBlockPanel = new InterBlockPanel(exp); 67 interBlockPanel = new InterBlockPanel(exp);
65 subjectDataPanel = new SubjectDataPanel(this, exp.getSubjectResults()); 68 subjectDataPanel = new SubjectDataPanel(this, exp.getSubjectResults());
69
70 stimulusPanel.setResponseEnabled(false);
66 71
67 // The Controller 72 // The Controller
68 ExperimentController ec = new ExperimentController(this); 73 ExperimentController ec = new ExperimentController(this);
69 74
70 // Show it all 75 // Show it all
107 } 112 }
108 } 113 }
109 114
110 /* Show the Fixation Point */ 115 /* Show the Fixation Point */
111 public void showFixationPoint() { 116 public void showFixationPoint() {
112 System.out.println("showFixationPoint"); 117 debug("showFixationPoint");
113 clock.showClock = false; 118 clock.showClock = false;
114 clock.showFullClock = false; 119 clock.showFullClock = false;
115 clock.repaint(); 120 clock.repaint();
116 } 121 }
117 122
129 try { Thread.sleep (1000); } catch (InterruptedException e) {} 134 try { Thread.sleep (1000); } catch (InterruptedException e) {}
130 showFixationPoint(); 135 showFixationPoint();
131 } 136 }
132 137
133 138
139 public void debug(String message) {
140 if (exp.getDebug()) {
141 System.out.println(message);
142 }
143 }
144
145 public void debugList(String name, ArrayList list) {
146 if (exp.getDebug()) {
147 Iterator itr = list.iterator();
148 System.out.print("\n" + name + " (" + list.size() + "): ");
149 while (itr.hasNext()) {
150 System.out.print(" " + itr.next());
151 }
152 System.out.print("\n");
153 }
154 }
155
134 /* Run method for this thread */ 156 /* Run method for this thread */
135 public void run() { 157 public void run() {
136 System.out.println("Run!"); 158
159 boolean debug = exp.getDebug();
160
161 debug("\nBegin trial");
137 //showFixationPoint(); 162 //showFixationPoint();
138 clock.reset(); 163 clock.reset();
139 showClock(); 164 showClock();
140 165
141 int clockUnits = exp.getClockUnits();
142 int numUnits = exp.getNumUnits();
143 long tatum = exp.getCurrentBlock().getTatum(); 166 long tatum = exp.getCurrentBlock().getTatum();
144 long tatumInMilliseconds = tatum / 1000; 167 long tatumInMilliseconds = tatum / 1000;
145 int nMinutes = 60 / numUnits; 168 int nMinutes = 60 / exp.getNumUnits();
146 169
170 debug("Tatum: " + tatum);
171
147 ArrayList onsets = exp.getCurrentBlock().getOnsets(); 172 ArrayList onsets = exp.getCurrentBlock().getOnsets();
148 ArrayList probes = exp.getCurrentBlock().getProbePositions(); 173 ArrayList probes = exp.getCurrentBlock().getProbePositions();
149 ArrayList clockStartTimes = exp.getCurrentBlock().getClockStartTimes(); 174 ArrayList clockStartTimes = exp.getCurrentBlock().getClockStartTimes();
150 175
176 debugList("Onset times", onsets);
177 debugList("Probe times", probes);
178 debugList("Clock start times", clockStartTimes);
179
151 Iterator oi = onsets.iterator(); 180 Iterator oi = onsets.iterator();
152 Iterator pi = probes.iterator(); 181 Iterator pi = probes.iterator();
153 Iterator ci = clockStartTimes.iterator(); 182 Iterator ci = clockStartTimes.iterator();
154 183
155 ProbeID probe = ProbeID.NOT_PROBE; 184 ProbeID probe = ProbeID.NOT_PROBE;
156 185
157 long currentOnset = 0; 186 long currentTime = 0;
158 long nextEventOnset = ((Long)(oi.next())).longValue(); 187 long nextEventOnset = ((Long)(oi.next())).longValue();
159 long nextClockStartTime = ((Long)(ci.next())).longValue(); 188 long nextClockStartTime = ((Long)(ci.next())).longValue();
160 189
161 int clockUnit = 0; 190 int clockUnit = 0;
162 boolean clockTicking = false; 191 boolean clockTicking = false;
163 192
164 do { //using a do-while construct allows the user to enter a value at the end 193 do {// Using a do-while construct allows the user to enter a value at the end
165 //this should not really be in the 'view' anyway... 194 // this should not really be in the 'view' anyway...
166 System.out.println("TATUM: " +tatum); 195
167 tatumInMilliseconds = tatum/1000; 196 debug("\n\nTicking = " + clockTicking +
168 if (exp.getDebug()) 197 "; clockUnit = " + clockUnit +
169 System.out.println("Ticking = " + clockTicking + 198 "; currentTime = " + currentTime +
170 "; clockUnit = " + clockUnit + 199 "; nextEventOnset = " + nextEventOnset +
171 "; currentOnset = " + currentOnset + 200 "; nextClockStartTime = " + nextClockStartTime);
172 "; nextEventOnset = " + nextEventOnset + 201
173 "; nextClockStartTime = " + nextClockStartTime + 202 // Tick the clock every <clockUnit> cycles
174 "; probe = " + probe); 203 if (clockTicking && clockUnit == 0) {
175 if (clockTicking == true && clockUnit == 0) 204 debug("Tick");
176 tick(nMinutes); 205 tick(nMinutes);
206 }
177 207
178 if (currentOnset >= nextClockStartTime) { 208 // Start the clock
209 if (currentTime >= nextClockStartTime) {
210 debug("Start clock (" + (currentTime - nextClockStartTime) + " ago)");
179 //new Thread(clock).start(); 211 //new Thread(clock).start();
180 clock.reset(); 212 clock.reset();
181 showClock(); 213 showClock();
182 clockTicking = true; 214 clockTicking = true;
215
183 if (ci.hasNext()) 216 if (ci.hasNext())
184 nextClockStartTime = ((Long)(ci.next())).longValue(); 217 nextClockStartTime = ((Long)(ci.next())).longValue();
185 else 218 else
186 nextClockStartTime = Long.MAX_VALUE; 219 nextClockStartTime = Long.MAX_VALUE;
187 } 220 }
188 if (currentOnset >= nextEventOnset) { 221
189 probe = (ProbeID)pi.next(); 222 // Event onset
223 if (currentTime >= nextEventOnset) {
224
225 // Update probe identifier and onset
226
227 probe = (ProbeID) pi.next();
228 debug("Event " + probe + " " + nextEventOnset + " (" + (currentTime - nextEventOnset) + " ago)");
229 nextEventOnset = ((Long)(oi.next())).longValue();
230
190 // Manipulate display depending on probe identifier 231 // Manipulate display depending on probe identifier
191 switch (probe) { 232 switch (probe) {
192 case NOT_PROBE: 233 case NOT_PROBE:
193 // if (clock.showClock == true) 234 // if (clock.showClock == true)
194 // tick(nMinutes); 235 // tick(nMinutes);
195 break; 236 break;
196 case START_CLOCK: 237 /*
238 case START_CLOCK: // No longer used...
197 //clock.reset(); 239 //clock.reset();
198 //showClock(); 240 //showClock();
199 //tick(nMinutes); 241 //tick(nMinutes);
200 break; 242 break;
243 */
201 case BEFORE_PROBE: 244 case BEFORE_PROBE:
202 if (exp.getDebug()) 245 debug("BEFORE_PROBE: acceptingResponses = " + acceptingResponses);
203 System.out.println("BEFORE_PROBE: acceptingResponses = " + 246 if (acceptingResponses) {
204 acceptingResponses);
205 if (acceptingResponses == true)
206 exp.getCurrentBlock().addResponse(0, System.nanoTime()); 247 exp.getCurrentBlock().addResponse(0, System.nanoTime());
248 debug("Recording zero response");
249 }
207 else 250 else
208 setAcceptingResponses(true); 251 setAcceptingResponses(true);
209 //tick(nMinutes); 252 //tick(nMinutes);
210 clockTicking = false; 253 clockTicking = false;
211 break; 254 break;
212 case PROBE: 255 case PROBE:
213 case PROBE_EX: 256 case PROBE_EX:
214 case PROBE_UNEX: 257 case PROBE_UNEX:
215 if (exp.getDebug()) 258 debug("PROBE_{UN,}EX: acceptingResponses = " + acceptingResponses);
216 System.out.println("PROBE_{UN,}EX: acceptingResponses = "
217 + acceptingResponses);
218 clock.showFullClock = false; 259 clock.showFullClock = false;
219 clock.repaint(); 260 clock.repaint();
220 break; 261 break;
221 case AFTER_PROBE: 262 case AFTER_PROBE:
222 //clock.showFullClock = false; 263 showFixationPoint();
223 //clock.repaint();
224 //showFixationPoint();
225 break; 264 break;
226 default: 265 default:
227 System.out.println("Unexpected probe id: " + probe); 266 System.out.println("Unexpected probe id: " + probe);
228 break; 267 break;
229 } 268 }
230 // Update probe identifier and onset
231
232 if (exp.getDebug())
233 System.out.println("Next probe = " + probe);
234 nextEventOnset =((Long)(oi.next())).longValue();
235 } 269 }
236 // sleep for a tatum 270
271 // Sleep for tatum
237 try { Thread.sleep(tatumInMilliseconds); } 272 try { Thread.sleep(tatumInMilliseconds); }
238 catch (InterruptedException e) {} 273 catch (InterruptedException e) {}
239 currentOnset += tatum; 274 currentTime += tatum;
240 clockUnit = (clockUnit + 1) % clockUnits; 275 clockUnit = (clockUnit + 1) % exp.getClockUnits();
276
241 } while(oi.hasNext()); 277 } while(oi.hasNext());
278
242 showFixationPoint(); 279 showFixationPoint();
243 } 280 }
281
282
283
244 } 284 }