1
2
3
4 package org.telscenter.pas.steps;
5
6 import java.awt.BorderLayout;
7 import java.awt.Component;
8 import java.awt.FlowLayout;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11 import java.beans.beancontext.BeanContextServices;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.Iterator;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.TooManyListenersException;
18 import java.util.logging.Logger;
19
20 import javax.swing.JButton;
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import javax.swing.JTextArea;
24 import javax.swing.JTextField;
25
26 import net.sf.sail.core.beans.service.AgentService;
27 import net.sf.sail.core.beans.service.AnnotationService;
28 import net.sf.sail.core.beans.service.SessionService;
29 import net.sf.sail.core.entity.IAgent;
30 import net.sf.sail.core.entity.ISock;
31 import net.sf.sail.core.entity.MismatchedAgentSetSizeException;
32 import net.sf.sail.core.entity.Rim;
33 import net.sf.sail.core.entity.Role;
34 import net.sf.sail.core.entity.UnsupportedRimShapeException;
35
36 import org.telscenter.pas.beans.IWorkReporter;
37 import org.telscenter.pas.beans.PasStep;
38 import org.telscenter.pas.service.NavigateAction;
39 import org.telscenter.pas.steps.domain.AssessmentItem;
40 import org.telscenter.pas.steps.domain.ResponseDeclaration;
41 import org.telscenter.pas.steps.domain.SimpleChoice;
42
43 import com.lowagie.text.pdf.PdfPCell;
44
45 /***
46 * A generic Pas step type, used for testing and demonstration purposes.
47 *
48 * @author turadg
49 */
50
51 public class HelloWorld extends PasStep implements IWorkReporter {
52
53 private static final Logger logger = Logger.getLogger(HelloWorld.class
54 .getName());
55
56 private String message;
57
58 private Integer possibleScore;
59
60 protected transient AgentService agentService;
61
62 protected transient SessionService sessionService;
63
64 private Rim<String> workRim;
65
66 private ISock<String> workSock;
67
68 private JTextArea messagesLabel;
69
70 protected void consumeService(BeanContextServices bcs,
71 Class<? extends Object> serviceClass) {
72 if (serviceClass == AgentService.class) {
73 try {
74 final AgentService p = (AgentService) bcs.getService(this,
75 this, AgentService.class, this, this);
76 IAgent agent = p.getAgentsInRole(Role.RUN_WORKGROUP)
77 .getSingle();
78 workSock = p.getSock(workRim, agent);
79 } catch (TooManyListenersException e) {
80 logger.severe("exception: " + e);
81 } catch (MismatchedAgentSetSizeException e) {
82 logger.severe("exception: " + e);
83 } catch (UnsupportedRimShapeException e) {
84 logger.severe("exception: " + e);
85 }
86 }
87 }
88
89 public static void saveMessage(String message) {
90
91 }
92
93 /***
94 * gets the current message
95 *
96 * @return
97 */
98 public String getMessage() {
99 return message;
100 }
101
102 /***
103 * sets the current message
104 *
105 * @param message
106 */
107 public void setMessage(String message) {
108 Object old = this.message;
109 this.message = message;
110 firePropertyChange("message", old, message);
111 }
112
113 public Component getComponent() {
114
115 JPanel mainPanel = new JPanel(new BorderLayout(0, 0));
116
117 JPanel messageBoxPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
118
119 final JTextField messageBox = new JTextField(getMessage());
120 messageBox.setColumns(15);
121
122 JButton saveMessageButton = new JButton("Save Message");
123 saveMessageButton.addActionListener(new ActionListener() {
124
125 public void actionPerformed(ActionEvent e) {
126 getWorkSock().add(messageBox.getText());
127 updateLabelMessage();
128 logger.info("ASSESSMENT ENTRY DATA SAVED");
129 }
130 });
131
132 messageBoxPanel.add(new JLabel("Say Something to HelloWorld: "));
133 messageBoxPanel.add(messageBox);
134 messageBoxPanel.add(saveMessageButton);
135
136 mainPanel.add(messageBoxPanel, BorderLayout.NORTH);
137
138 messagesLabel = new JTextArea(10,20);
139 messagesLabel.setWrapStyleWord(true);
140 messagesLabel.setLineWrap(true);
141 messagesLabel.setEditable(false);
142 messagesLabel.setAutoscrolls(true);
143 messagesLabel.setText(makeMessageFromSock());
144 mainPanel.add(messagesLabel, BorderLayout.CENTER);
145 return mainPanel;
146 }
147
148 protected String makeMessageFromSock() {
149 StringBuilder messagesString = new StringBuilder();
150
151 messagesString.append("people says: ").append("\n\n");
152
153 ISock<String> sock = getWorkSock();
154
155 for (String entry : sock) {
156 messagesString.append(entry +"\n");
157 }
158
159 return messagesString.toString();
160 }
161
162 /***
163 *
164 */
165 protected void updateLabelMessage() {
166 messagesLabel.setText(makeMessageFromSock());
167 }
168
169 public JPanel getReportForLearner() {
170 JPanel panel = new JPanel();
171 panel.add(new JLabel("HelloWord says: " + getMessage()));
172 return panel;
173 }
174
175 public PdfPCell getReportForLearnerPDF() {
176
177 return null;
178 }
179
180 public JPanel getReportForLearnerWithAnnotations() {
181
182 return null;
183 }
184
185
186
187
188
189
190 public List<JLabel> getCurrentAnswers() {
191 List<JLabel> answers = new ArrayList<JLabel>();
192 answers.add(new JLabel("here is an answer"));
193 return answers;
194 }
195
196 public List<String> getCurrentPrompts() {
197 List<String> promptList = new ArrayList<String>();
198 promptList.add("Here is a prompt");
199 return promptList;
200 }
201
202 public List<JPanel> getCurrentStepParts() {
203 JPanel panel = new JPanel();
204 panel.add(new JLabel("nothing"));
205 List<JPanel> panelList = new ArrayList<JPanel>();
206 panelList.add(panel);
207 return panelList;
208 }
209
210 public void initStepParts() {
211
212
213 }
214
215 public Map<String, String> getEntityToPromptMap() {
216 return new HashMap<String, String>();
217 }
218
219 public Integer getPossibleScore() {
220 return possibleScore;
221 }
222
223 public void setPossibleScore(Integer possibleScore) {
224 this.possibleScore = possibleScore;
225 }
226
227 /***
228 * @return the workRim
229 */
230 public Rim<String> getWorkRim() {
231 return workRim;
232 }
233
234 /***
235 * @param workRim
236 * the workRim to set
237 */
238 public void setWorkRim(Rim<String> workRim) {
239 this.workRim = workRim;
240 }
241
242 /***
243 * @return the workSock
244 */
245 public ISock<String> getWorkSock() {
246 return workSock;
247 }
248
249 /***
250 * @param workSock
251 * the workSock to set
252 */
253 public void setWorkSock(ISock<String> workSock) {
254 this.workSock = workSock;
255 }
256
257 public JPanel getReportForLearner(NavigateAction navigateAction) {
258
259 return null;
260 }
261
262 public JPanel getReportForLearnerWithAnnotations(
263 NavigateAction navigateAction) {
264
265 return null;
266 }
267
268 public PdfPCell getReportForLearnerPDF(AnnotationService annotationService) {
269 return null;
270 }
271
272 }