symplik.flower
Class Question

java.lang.Object
  extended by symplik.flower.Question
All Implemented Interfaces:
Constants
Direct Known Subclasses:
DefaultQuestion

public abstract class Question
extends java.lang.Object
implements Constants

This is the abstract class for any screen which requires user interaction or displays textual information. The sequence of method to be executed when a Question is instantiated:

To create a Question, you must extend this class and override any method if needed. You can create alias for your subclass in the flower.properties file by:
classAliasXXX = com.blah.questionXXX
You can use this alias to get the answer:
Answer.getInstance().getA("classAlias")
public String nextAction() { return "classAliasXXX"; }

Version:
$Revision: 8 $
Author:
$Author: Christopher Ho $

Field Summary
static java.lang.String RCS_ID
           
 
Fields inherited from interface symplik.flower.Constants
CLASS_DEFAULT_START, CLASS_DIR_BROWSER, CLASS_FILE_BROWSER, DISPLAY_MODE, DISPLAY_MODE_CONSOLE, DISPLAY_MODE_GUI, DISPLAY_MODE_SLIENT, FILE_BROWSER_CURR_DIR, FILE_BROWSER_DIR, FILE_BROWSER_FILE, FLOWER_CONFIG, FLOWER_CONFIG_FILE, FLOWER_LAST_QUESTION, FLOWER_LOG_FILE, FLOWER_LOG_LEVEL, FLOWER_LOG_OUTPUT, FLOWER_RESPONSES, FLOWER_RESPONSES_FILE, LOG_DEBUG, LOG_ERROR, LOG_INFO, LOG_OUTPUT_FILE, LOG_OUTPUT_SYSTEM_OUT, LOG_WARN, SORT_AS_IS, SORT_BY_DESC, SORT_BY_DESC_CI, SORT_BY_KEY, SORT_BY_KEY_CI
 
Constructor Summary
Question()
           
 
Method Summary
 java.util.ArrayList<Choice> choices()
          override this method to construct an sorted Arraylist of Choice object Arraylist can be sorted by the sortChoicesBy method.
 boolean enterQuestion()
          override this method to tell whether this question will be shown
 Message enterQuestionMsg(boolean flag)
          override this method to return a message after enterQuestion is processed.
 java.lang.String fileExtension()
          override this method to restrict the file with extension specified.
 java.lang.String getExplanation()
          override this method if you want to show explanation of this question.
 java.lang.String getQuestion()
          override this method to return the question content.
 java.lang.String getTitle()
          override this method to set the GUI title.
 boolean isDirectoryInput()
          override this method if you want end-user to select a directory.
 boolean isFileInput()
          override this method if you want end-user to select a file.
 boolean isMultipleChoices()
          override this method to tell whether the response is a free-text or a multiple choice.
 boolean isNewScreen()
          return true if you want to display the question as a new screen (i.e.
 boolean isPasswordInput()
          override this method if the input field is a password.
 java.lang.String lastAction()
          Override to tell which Question/Action to go back if it is allowed for a Question.
 boolean leaveQuestion()
          implement this method if you need some kind of validation on the answer or run some code after the answer is present.
 Message leaveQuestionMsg(boolean flag)
          implement this method if you need to return a message after leaveMessage method is done.
 boolean lineWrap()
          Override this method to set linewarp on or off for this question.
 boolean needAnswer()
          sometimes the question is optional; no answer is needed.
 java.lang.String nextAction()
          override this method to tell which Question or Action class to be the next one.
 boolean showExit()
          This method is for multiple choice question only.
 java.lang.String sortChoicesBy()
          override this method to specify how the multiple choices are sorted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RCS_ID

public static final java.lang.String RCS_ID
See Also:
Constant Field Values
Constructor Detail

Question

public Question()
Method Detail

enterQuestion

public boolean enterQuestion()
override this method to tell whether this question will be shown

Returns:
True if you want to carry on; False to give up this question

enterQuestionMsg

public Message enterQuestionMsg(boolean flag)
override this method to return a message after enterQuestion is processed.

Parameters:
flag - return value of enterQuestion.
Returns:
message object to be displayed

choices

public java.util.ArrayList<Choice> choices()
override this method to construct an sorted Arraylist of Choice object Arraylist can be sorted by the sortChoicesBy method. e.g.
       ArrayList al = new ArrayList();
       al.add(new Choice("A", "Option A");
       al.add(new Choice("B", "Option B");
       al.add(new Choice("C", "Option C");
 

Returns:
the ArrayList of Choice object

getQuestion

public java.lang.String getQuestion()
override this method to return the question content.

Returns:
The content of this question

showExit

public boolean showExit()
This method is for multiple choice question only.

Returns:
False if you don't want to see the "[x] Exit" option. Default is True.

getExplanation

public java.lang.String getExplanation()
override this method if you want to show explanation of this question. This content is shown below the Question content.

Returns:
explanation content

isPasswordInput

public boolean isPasswordInput()
override this method if the input field is a password. The response will be masked when entered. Work for free-text input (isMultipleChoices is False).

Returns:
True if masking is needed. Default is False.

isDirectoryInput

public boolean isDirectoryInput()
override this method if you want end-user to select a directory. A directory browser will be shown in GUI mode. Work for free-text input (isMultipleChoices is False).

Returns:
True if input is a directory. Default is False.

isFileInput

public boolean isFileInput()
override this method if you want end-user to select a file. A file browser will be shown in GUI mode. You can further restrict the file extension to be selected by setting the fileExtension method. Work for free-text input (isMultipleChoices is False).

Returns:
True if input is a file. Default is False.

fileExtension

public java.lang.String fileExtension()
override this method to restrict the file with extension specified. This method is used if isFileInput is True.

Returns:
The file extension to be selected by the file browser

isMultipleChoices

public boolean isMultipleChoices()
override this method to tell whether the response is a free-text or a multiple choice.

Returns:
False if the question requires a free-text answer. Default is True.

sortChoicesBy

public java.lang.String sortChoicesBy()
override this method to specify how the multiple choices are sorted.

Returns:
SORT_AS_IS, SORT_BY_KEY, SORT_BY_DESC

needAnswer

public boolean needAnswer()
sometimes the question is optional; no answer is needed. By default the question requires an answer.

Returns:
False if this question does not require an answer. Default is True.

leaveQuestion

public boolean leaveQuestion()
implement this method if you need some kind of validation on the answer or run some code after the answer is present.

Returns:
True if process can carry on, False if you want it from proceeding

leaveQuestionMsg

public Message leaveQuestionMsg(boolean flag)
implement this method if you need to return a message after leaveMessage method is done.

Parameters:
value - from leaveQuestion
Returns:
Message shown after leaveQuestion

lastAction

public java.lang.String lastAction()
Override to tell which Question/Action to go back if it is allowed for a Question. This method is for multiple choice question only.

Returns:
If defined you will want to see the "[b] Back" option. Default is null.

nextAction

public java.lang.String nextAction()
override this method to tell which Question or Action class to be the next one. If none specified, the program will exit.

Returns:
Class alias or full qualified class name

isNewScreen

public boolean isNewScreen()
return true if you want to display the question as a new screen (i.e. content of previous question/action will be flushed)

Returns:
True to refresh the screen; False to append from the last screen

getTitle

public java.lang.String getTitle()
override this method to set the GUI title. It does nothing in Console mode.

Returns:
GUI window title

lineWrap

public boolean lineWrap()
Override this method to set linewarp on or off for this question. Work for GUI mode only.

Returns:
False if you don't want lines are wrapped. Default is True.


Copyright © 2010 Symplik Tech. Co. Ltd. All Rights Reserved.