Package com.sun.interview
Class Question
java.lang.Object
com.sun.interview.Question
- Direct Known Subclasses:
ChoiceArrayQuestion
,ChoiceQuestion
,CompositeQuestion
,FileListQuestion
,FileQuestion
,FloatQuestion
,InetAddressQuestion
,IntQuestion
,ListQuestion
,NullQuestion
,StringListQuestion
,StringQuestion
,TreeQuestion
Questions are the primary constituent elements of
interviews
.
They provide text and an optional graphic to be presented to the user,
and they provide a place to store the user's response.
Various subtypes are provided, according to the type of response they
request and store.
Questions are identified internally by a unique tag, which is used to identify
the question in contexts such as resource bundles, dictionaries, and so on.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a named marker to this question, if it has not already been added.abstract void
clear()
Clear any state for this question, setting the value to a question-specific default value.boolean
Check if this question equals another.protected void
Export any appropriate values to the dictionary, as part ofInterview.export(java.util.Map<java.lang.String, java.lang.String>)
.Get any items which should be added to the interview's checklist.Get the HelpID identifying the "more info" help for this question, or null if none.getImage()
Get the graphic for this question.Return the interview of which this question is a part.getKey()
Get the key for a question.protected abstract Question
getNext()
Get the next question to be asked.protected String
getResourceString
(String key) Get an entry from the interview's resource bundle.protected String
getResourceString
(String key, boolean checkAncestorsFirst) Get an entry from the interview's resource bundle.abstract String
Get the response to this question as a string.Set the summary text for this question.getTag()
Get the tag for a question.getText()
Get the text for this question.protected Object[]
Get any arguments necessary to go with the question text.int
hashCode()
boolean
Check if a marker has been added to this question.boolean
Determine if this question is currently enabled.boolean
isHidden()
Determine if this question is currently "hidden".abstract boolean
Check if the question always has a valid response.abstract boolean
Check if the question currently has a valid response.protected void
Loads any state for this question from the given map, using tag as the key.void
reload()
This methods invokes save(Map), clear() and load(Map).void
removeMarker
(String name) Remove a named marker to this question.protected abstract void
Save any state for this question in a dictionary, using the tag as the key.void
Set HelpID object associated with the Question.void
Set the URL for a specific graphic for this question.protected void
Set the URL for a specific graphic for this question.protected void
setSummary
(String summary) Set the summary text for this question.protected void
Set the text for this question.abstract void
Set the response to this question to the value represented by a string-valued argument.
-
Field Details
-
key
A unique key to identify the resources for this question. -
interview
The interview to which this question belongs. -
tag
A unique tag to identify this question.
-
-
Constructor Details
-
Question
Create a question with a nominated tag.- Parameters:
interview
- The interview containing this question.baseTag
- A name to uniquely identify this question within its interview.
-
Question
Create a question with no identifying tag.- Parameters:
interview
- The interview containing this question.
-
-
Method Details
-
getInterview
Return the interview of which this question is a part.- Returns:
- the interview of which this question is a part
-
getKey
Get the key for a question. The key is the class name of the parent interview followed by a period followed by the tag given to the constructor. It therefore reasonably identifies the question relative to the class of its parent interview. The key is normally used to identify resources such as the question text in a resource file or help information in a help set.- Returns:
- the key for this question
- See Also:
-
getTag
Get the tag for a question. The tag is the tag of the parent interview, followed by a dot, followed by the tag given to the constructor. It therefore reasonably identifies the question relative to the instance of its parent interview. The tag is normally used to identify instance-specific responses in a saved interview file.- Returns:
- the tag for this question
- See Also:
-
getText
Get the text for this question. If not specified, the system will try and locate the text in the containing interviews resource bundle, using the resource name key.text
.- Returns:
- the text for this question
- See Also:
-
setText
Set the text for this question. The text can also be provided in the containing interview's resource bundle, using the resource name key.text
.- Parameters:
text
- the text for this question- See Also:
-
getTextArgs
Get any arguments necessary to go with the question text. The text is formatted using the rules specified forMessageFormat.format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition)
. By default, this method returns null. If the text for the question contains variable entries (using the '{' '}' notation), you should override this method to provide the corresponding values.- Returns:
- An array of objects suitable for formatting in the text of the question.
-
getSummary
Set the summary text for this question.- Returns:
- a short summary of the text for this question
- See Also:
-
setSummary
Set the summary text for this question. The text can also be provided in the containing interview's resource bundle, using the resource name key.smry
.- Parameters:
summary
- a short summary of the text for this question- See Also:
-
getImage
Get the graphic for this question. IfsetImage(java.lang.String)
has been called to supply a specific image for this question, that will be the result here; otherwise, the value defaults first to a question-specific resource (tag.gif
) and then to adefault image
for the interview.- Returns:
- a URL for the question.
- See Also:
-
setImage
Set the URL for a specific graphic for this question.- Parameters:
resource
- The name of a resource containing the desired image.- See Also:
-
setImage
Set the URL for a specific graphic for this question.- Parameters:
u
- The URL of a resource containing the desired image.- See Also:
-
getHelpID
Get the HelpID identifying the "more info" help for this question, or null if none.Normally, this method returns null and real work on JavaHelp HelpID is done by com.sun.interview.wizard.Help class, if wizard presents. Subclasses might override this method to return not null value, in this case returned value will be used. Returned object must be an instance of HelpID.
- Returns:
- the HelpID identifying the "more info" help for this question, or null if none.
-
setHelpID
Set HelpID object associated with the Question.- Parameters:
object
- Should be instance of HelpID
-
getChecklistItems
Get any items which should be added to the interview's checklist.- Returns:
- any items which should be added to the interview's checklist, or null if none.
- See Also:
-
addMarker
Add a named marker to this question, if it has not already been added.- Parameters:
name
- the name of the marker to be added.- Throws:
NullPointerException
- if name is null
-
removeMarker
Remove a named marker to this question.- Parameters:
name
- the name of the marker to be removed.
-
hasMarker
Check if a marker has been added to this question.- Parameters:
name
- the name of the marker to be checked.- Returns:
- true if the marker has been added to this question, and false otherwise.
-
isHidden
public boolean isHidden()Determine if this question is currently "hidden". Hidden questions do not appear on the current path and so are skipped over byInterview.prev()
andInterview.next()
, etc. By default, questions are not hidden, and this method returns false. Override this method if you want to hide a question - note that the value ofisEnabled()
is currently tied to the value of this method. Developers who wish to independently play with hiding and enabling should override both methods.- Returns:
- true if this question has been hidden.
- Since:
- 4.3
- See Also:
-
isEnabled
public boolean isEnabled()Determine if this question is currently enabled. Disabled questions do not appear on the current path and so are skipped over byInterview.prev()
andInterview.next()
, etc. By default, all questions are enabled, and this method returns true. Override this method if you want to hide a question. It can be convenient to determine whether or not a question should be disabled by using the values of earlier questions. Note: for backwards compatibility, the default implementation returns!isHidden()
.- Returns:
- true if this question should appear on the current path, and false otherwise.
-
getNext
Get the next question to be asked.- Returns:
- the next question to be asked
-
clear
public abstract void clear()Clear any state for this question, setting the value to a question-specific default value. Most question types also provide a way to set the default value. -
getStringValue
Get the response to this question as a string.- Returns:
- a string representing the current response to this question, or null.
- See Also:
-
setValue
Set the response to this question to the value represented by a string-valued argument. Subtypes of Question will typically have type-specific methods to set the value as well.- Parameters:
s
- A string containing a value value appropriate for the particular type of question whose value is being set.- Throws:
Interview.Fault
- retained for compatibility; should not be thrown- See Also:
-
isValueValid
public abstract boolean isValueValid()Check if the question currently has a valid response.- Returns:
- true if the question currently has a valid response, and false otherwise.
-
isValueAlwaysValid
public abstract boolean isValueAlwaysValid()Check if the question always has a valid response. This may be true, for example, for a choice question with a default response.- Returns:
- true if the question always has a valid response, and false otherwise.
-
load
Loads any state for this question from the given map, using tag as the key. If the loaded value is not null then calls methodsetValue(String)
passing the value.- Parameters:
data
- The map from which to load the value for this question.
-
save
Save any state for this question in a dictionary, using the tag as the key.- Parameters:
data
- The map in which to save the value for this question.
-
export
Export any appropriate values to the dictionary, as part ofInterview.export(java.util.Map<java.lang.String, java.lang.String>)
. The default is to do nothing. Note that only questions which are on the current path have their export method called. Questions do not appear on the current path if they are not accessible from any question on the path, or if they have been disabled.- Parameters:
data
- The map in which to export any data for this question.- See Also:
-
reload
public void reload()This methods invokes save(Map), clear() and load(Map). These actions will lead to the default value (if set) will become the question value. -
equals
Check if this question equals another. By default, two questions are equal if they have equal tags, and the string values are either both null or are equal. -
hashCode
public int hashCode() -
getResourceString
Get an entry from the interview's resource bundle. The parent and other ancestors bundles will be checked first before this interview's bundle, allowing the root interview a chance to override the default value provided by this interview.- Parameters:
key
- the name of the entry to be returned- Returns:
- the value of the resource, or null if not found
- See Also:
-
getResourceString
Get an entry from the interview's resource bundle. If checkAncestorsFirst is true, then the parent and other ancestor interviews' bundles will be checked first before this interview's bundle, allowing the root interview a chance to override the default value provided by this interview. Otherwise, the parent bundles will only be checked if this bundle does not provide a value.- Parameters:
key
- the name of the entry to be returnedcheckAncestorsFirst
- whether to recursively call this method on the parent (if any) before checking this bundle, or only afterwards, if this bundle does not provide a value- Returns:
- the value of the resource, or null if not found
- See Also:
-