|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jsurveylib.Survey
public final class Survey
The Survey object stores the data and the state of the survey.
try {
ClientSurvey survey = new Survey("surveyGettingStarted.xml");
SurveyPanel surveyPanel = new SurveyPanel(survey);
survey.addSurveyListener(this);
frame.setLayout(new BorderLayout());
frame.add(surveyPanel, BorderLayout.CENTER);
frame.setJMenuBar(new SurveyMenu(survey, this));
} catch (Exception e) {
e.printStackTrace();
}
The Survey, ClientSurvey, SurveyPanel and the SurveyAdapter are the ONLY objects that the client should interact with directly. Even then, there
may be public methods in this class that are marked "for internal use only". Methods marked "for
internal use only" may be renamed, removed or replaced in future versions. Because of this uncertain future,
it is highly recommended you don't use these methods: Your application may not compile when you upgrade.
Most other classes are marked "for internal use only" but even if they aren't, these are the only
classes that you should be interacting with.
Constructor Summary | |
---|---|
Survey(java.io.Reader xmlConfigReader)
|
|
Survey(java.lang.String xmlConfigFile)
|
|
Survey(SurveyReader reader)
|
Method Summary | |
---|---|
void |
accept(Visitor visitor)
FOR INTERNAL USE ONLY. |
void |
addInsertQuestionListener(InsertQuestionListener listener)
FOR INTERNAL USE ONLY. Add a listener that gets informed when a new question is inserted into the survey. |
void |
addPageListener(PageListener listener)
FOR INTERNAL USE ONLY. Add a listener that gets informed when a page changes. |
void |
addSurveyListener(SurveyListener listener)
Add a listener which will be informed when the survey is finished |
void |
addSurveyResetListener(SurveyResetListener listener)
FOR INTERNAL USE ONLY. Add a listener that gets informed when the survey gets reset. |
void |
answerChanged(Question question,
boolean evaluateScript)
FOR INTERNAL USE ONLY. |
void |
finish()
FOR INTERNAL USE ONLY. This informs every SurveyListener that the survey has been finished and makes isFinished() return true and informs all survey listeners. |
java.lang.String |
getAnswer(java.lang.String id)
Get the current answer of a question by its question id. |
java.util.Map<java.lang.String,java.lang.String> |
getAnswerMap()
Returns an answer map of the survey. |
Page |
getCurrentPage()
FOR INTERNAL USE ONLY. This will return the current Page that the survey is on. |
int |
getCurrentPageNumber()
FOR INTERNAL USE ONLY. This will return the current page number the survey is on. |
int |
getCurrentPageNumberExcludingSkipped()
FOR INTERNAL USE ONLY. This will return the current page number the survey is on but it will not count skipped pages. |
java.util.Map<java.lang.String,Question> |
getIdMap()
FOR INTERNAL USE ONLY. This returns an unmodifiable map that has question id's as keys and questions as values. |
ScriptInterpreter |
getInterpreter()
FOR INTERNAL USE ONLY. This returns the survey's script interpreter. |
Menu |
getMenu()
FOR INTERNAL USE ONLY. |
java.util.List<Page> |
getPages()
FOR INTERNAL USE ONLY. Returns an unmodifiable List of the pages in this Survey. |
Question |
getQuestionByID(java.lang.String id)
FOR INTERNAL USE ONLY. Get a Question object using it's id. |
Strings |
getStrings()
FOR INTERNAL USE ONLY. |
java.util.Map<java.lang.String,Template> |
getTemplateMap()
FOR INTERNAL USE ONLY. This returns a map where the keys are template names and the values are template questions. |
java.lang.String |
getTitle()
Gets the title of this survey. |
int |
getTotalPagesExcludingSkipped()
FOR INTERNAL USE ONLY. This will return the total page number the survey has but it will not count skipped pages. |
java.lang.String |
getWorkingFilePath()
This will return the "working file" path of the survey. |
void |
goToFirstPage()
FOR INTERNAL USE ONLY. This will go to the first page, considering that some pages may be skipped. |
void |
goToLastPage()
FOR INTERNAL USE ONLY. This will go to the last page or the page that has blank required/invalid questions, considering that some pages may be skipped. |
void |
goToNextPage()
FOR INTERNAL USE ONLY. This will increment the current page then fire a page changed event. |
void |
goToPage(int pageNum)
FOR INTERNAL USE ONLY. This method changes the page to the pageNum passed in. |
void |
goToPreviousPage()
FOR INTERNAL USE ONLY. This will decrement the current page and fire a page changed event. |
void |
insertQuestion(Question question,
int pageNum,
int row)
FOR INTERNAL USE ONLY. This is called to insert a question on a survey that is already running. |
void |
insertQuestion(Question question,
Page page,
int row)
FOR INTERNAL USE ONLY. This is called to insert a question on a survey that is already running. |
boolean |
isDirty()
FOR INTERNAL USE ONLY. |
boolean |
isLastPageAndComplete()
FOR INTERNAL USE ONLY. This will return true if the current page is the last page and all other non-skipped pages have their requirements met. |
boolean |
isNextPageAvailable()
FOR INTERNAL USE ONLY. Returns true if the next page is available. |
boolean |
isPreviousPageAvailable()
FOR INTERNAL USE ONLY. Returns true if the previous page is available. |
void |
loadXMLAnswers(java.io.Reader answerXMLReader)
This will set the survey's questions to all the answers in answerReader. |
void |
loadXMLAnswers(java.lang.String answerXMLFile)
This is the same as loadXMLAnswers(Reader answerXMLReader) except it takes a String instead of a reader for convenience. |
void |
onClick(java.lang.String url)
FOR INTERNAL USE ONLY. |
Page |
pageOf(java.lang.String questionId)
FOR INTERNAL USE ONLY. This will return the page that a question resides in or null if the question does not exist on any page. |
void |
removeInsertQuestionListener(InsertQuestionListener listener)
FOR INTERNAL USE ONLY. Remove a insert question listener. |
void |
removePageListener(PageListener listener)
FOR INTERNAL USE ONLY. Remove a page listener. |
void |
removeSurveyListener(SurveyListener listener)
Remove a survey listener |
void |
removeSurveyResetListener(SurveyResetListener listener)
FOR INTERNAL USE ONLY. Remove a insert question listener. |
void |
reset()
FOR INTERNAL USE ONLY. Reset the survey so it looks like it did when it was first started. |
boolean |
saveToFileOnFinish()
FOR INTERNAL USE ONLY. |
void |
saveXMLAnswers(java.lang.String outputXMLFile)
Save the answers of the survey to an XML file. |
void |
saveXMLAnswers(java.io.Writer writer)
This method does the same thing as saveXMLAnswers(String) but it takes a Writer instead of a path to a file. |
void |
setAnswer(java.lang.String id,
java.lang.String answer)
FOR INTERNAL USE ONLY. Sets the answer of a question. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Survey(java.lang.String xmlConfigFile) throws java.lang.Exception
java.lang.Exception
public Survey(java.io.Reader xmlConfigReader) throws java.lang.Exception
java.lang.Exception
public Survey(SurveyReader reader)
Method Detail |
---|
public void reset()
public void goToFirstPage()
public void goToLastPage()
public void addSurveyListener(SurveyListener listener)
addSurveyListener
in interface ClientSurvey
listener
- The object that will be informed of the survey finishing.public void removeSurveyListener(SurveyListener listener)
removeSurveyListener
in interface ClientSurvey
listener
- The survey listener to be removed.public void addPageListener(PageListener listener)
listener
- A listener that will be notified when the current page changes to another pagepublic void removePageListener(PageListener listener)
listener
- A listener that will be notified when the current page changes to another pagepublic void addInsertQuestionListener(InsertQuestionListener listener)
listener
- A listener that will be notified when the current page changes to another pagepublic void removeInsertQuestionListener(InsertQuestionListener listener)
listener
- A listener that will be notified when a question is added to a pagepublic void addSurveyResetListener(SurveyResetListener listener)
listener
- A listener that will be notified when the survey resetspublic void removeSurveyResetListener(SurveyResetListener listener)
listener
- A listener that will be notified when the survey resetspublic void loadXMLAnswers(java.io.Reader answerXMLReader) throws java.io.IOException, org.xml.sax.SAXException
loadXMLAnswers
in interface ClientSurvey
answerXMLReader
- A Reader that reads from an XML file that is valid against this XSD: http://jsurveylib.sourceforge.net/result-7.10.4.4.xsd
java.io.IOException
- If there is a problem reading from the file.
org.xml.sax.SAXException
- If there is an error parsing the file.saveXMLAnswers(String)
,
saveXMLAnswers(java.io.Writer)
public void loadXMLAnswers(java.lang.String answerXMLFile) throws java.io.IOException, org.xml.sax.SAXException
answerXMLFile
. isDirty() will
return false after this method is called.
loadXMLAnswers
in interface ClientSurvey
answerXMLFile
- A path to an XML file that is valid against this XSD: http://jsurveylib.sourceforge.net/result-7.10.4.4.xsd
java.io.IOException
- If there is a problem reading from the file.
org.xml.sax.SAXException
- If there is an error parsing the file.loadXMLAnswers(java.io.Reader)
public void setAnswer(java.lang.String id, java.lang.String answer)
id
- The id of the question you are answeringanswer
- The text/id/path/etc. that answers the question.
java.lang.RuntimeException
- A RuntimeException may be thrown if an invalid answer is set for the question.public boolean isNextPageAvailable()
public boolean isPreviousPageAvailable()
public boolean isLastPageAndComplete()
public void goToNextPage()
public void goToPreviousPage()
public void goToPage(int pageNum)
pageNum
- The to make the new current page.
java.lang.IllegalStateException
- If the pageNum is an index to a skipped pagepublic void saveXMLAnswers(java.lang.String outputXMLFile) throws java.io.IOException
outputXMLFile
after you call this method. isDirty() will return false after this method is called.
saveXMLAnswers
in interface ClientSurvey
outputXMLFile
- The path to the file that will have the answers written to it.
java.io.IOException
- If an error occurs writing the file.public void saveXMLAnswers(java.io.Writer writer) throws java.io.IOException
saveXMLAnswers
in interface ClientSurvey
writer
- A writer that the xml will be written to.
java.io.IOException
- If an error occurs writing to the writer.saveXMLAnswers(String)
public java.util.Map<java.lang.String,java.lang.String> getAnswerMap()
getAnswerMap
in interface ClientSurvey
public java.lang.String getAnswer(java.lang.String id)
getAnswer
in interface ClientSurvey
id
- The id of the question you want to get the answer of.
public java.lang.String getTitle()
getTitle
in interface ClientSurvey
public java.lang.String getWorkingFilePath()
getWorkingFilePath
in interface ClientSurvey
public int getCurrentPageNumber()
getCurrentPageNumberExcludingSkipped()
public int getCurrentPageNumberExcludingSkipped()
getCurrentPageNumber()
public int getTotalPagesExcludingSkipped()
public Page getCurrentPage()
public void finish()
public java.util.List<Page> getPages()
public Question getQuestionByID(java.lang.String id)
id
- The ID of the question to get.
getAnswer(String)
,
setAnswer(String,String)
public java.util.Map<java.lang.String,Question> getIdMap()
public void insertQuestion(Question question, int pageNum, int row)
question
- The question to insertpageNum
- The page number to insert the question on. The first page is page 0row
- The row to insert the question on. All SurveyElements on or after this
row will be incremented by one row.
java.lang.IllegalArgumentException
- If a question with this id exists or the page number is
out of bounds.public void insertQuestion(Question question, Page page, int row)
question
- The question to insertpage
- The page to insert the question onrow
- The row to insert the question on. All SurveyElements on or after this
row will be incremented by one row.
java.lang.IllegalArgumentException
- If a question with this id or the page number is
out of bounds.public ScriptInterpreter getInterpreter()
public java.util.Map<java.lang.String,Template> getTemplateMap()
Question.populateTemplate(String,String,boolean,String)
public Page pageOf(java.lang.String questionId)
questionId
- The question ID of a question that exists on a page
public void accept(Visitor visitor)
accept
in interface Visitable
public void onClick(java.lang.String url)
onClick
in interface LinkListener
public Strings getStrings()
public Menu getMenu()
public void answerChanged(Question question, boolean evaluateScript)
answerChanged
in interface AnswerListener
question
- The question whose answer changedevaluateScript
- If true, the survey's script will be evaluated. If false, the script will not be evaluated.public boolean isDirty()
public boolean saveToFileOnFinish()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |