01: package com.xoetrope.awt.survey;
02:
03: import com.xoetrope.survey.Question;
04: import com.xoetrope.survey.XSurveyManager;
05: import net.xoetrope.xui.XPage;
06: import net.xoetrope.xui.XProject;
07: import net.xoetrope.xui.XProjectManager;
08:
09: /**
10: * XQuestionPage is a page class that provides support for questionaires by way
11: * of a QuestionManager.
12: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
13: * the GNU Public License (GPL), please see license.txt for more details. If
14: * you make commercial use of this software you must purchase a commercial
15: * license from Xoetrope.</p>
16: * <p>$Revision: 1.3 $</p>
17: */
18: public class XQuestionPage extends XPage {
19: private int maxQuestions, numQuestions;
20: private int maxOptions, numOptions;
21: private Question currentQuestion;
22: private XSurveyManager surveyManager;
23:
24: public XQuestionPage() {
25: super ();
26: maxQuestions = 5;
27: surveyManager = (XSurveyManager) project
28: .getObject("SurveyManager");
29: if (surveyManager == null) {
30: surveyManager = new XSurveyManager(project);
31: project.setObject("SurveyManager", surveyManager);
32: }
33: }
34:
35: /**
36: * Checks if there are more questions available
37: * @return true if more questions are available
38: */
39: public Boolean hasMoreQuestions() {
40: return new Boolean(numQuestions < maxQuestions);
41: }
42:
43: /**
44: * Gets the text of teh next question
45: * @return the question text
46: */
47: public String getNextQuestion() {
48: numQuestions++;
49: currentQuestion = surveyManager.getNextQuestion();
50: maxOptions = currentQuestion.getNumOptions();
51: numOptions = 0;
52: return currentQuestion.getText();
53: }
54:
55: /**
56: * Checks if there are more options/choices available for the current question
57: * @return true if here re more options
58: */
59: public Boolean hasMoreOptions() {
60: return new Boolean(numOptions < maxOptions);
61: }
62:
63: /**
64: * Gets the text of the next available option
65: * @return the text/caption
66: */
67: public String getNextOption() {
68: numOptions++;
69: return currentQuestion.getOptionText(numOptions - 1);
70: }
71:
72: /**
73: * Gets the ID of the next option
74: * @return theID
75: */
76: public String getOptionId() {
77: return new Integer(currentQuestion.getOptionId(numOptions - 1))
78: .toString();
79: }
80: }
|