com.sun.interview
Class Question

java.lang.Object
  extended by com.sun.interview.Question
Direct Known Subclasses:
ChoiceArrayQuestion, ChoiceQuestion, CompositeQuestion, FileListQuestion, FileQuestion, FloatQuestion, InetAddressQuestion, IntQuestion, ListQuestion, NullQuestion, StringListQuestion, StringQuestion, TreeQuestion

public abstract class Question
extends java.lang.Object

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
protected  Interview interview
          The interview to which this question belongs.
protected  java.lang.String key
          A unique key to identify the resources for this question.
protected  java.lang.String tag
          A unique tag to identify this question.
 
Constructor Summary
protected Question(Interview interview)
          Create a question with no identifying tag.
protected Question(Interview interview, java.lang.String baseTag)
          Create a question with a nominated tag.
 
Method Summary
 void addMarker(java.lang.String name)
          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 equals(java.lang.Object other)
          Check if this question equals another.
protected  void export(java.util.Map data)
          Export any appropriate values to the dictionary, as part of Interview.export(java.util.Map).
 Checklist.Item[] getChecklistItems()
          Get any items which should be added to the interview's checklist.
 javax.help.Map.ID getHelpID()
          Get the JavaHelp ID identifying the "more info" help for this question, or null if none.
 java.net.URL getImage()
          Get the graphic for this question.
 Interview getInterview()
          Return the interview of which this question is a part.
 java.lang.String getKey()
          Get the key for a question.
protected abstract  Question getNext()
          Get the next question to be asked.
protected  java.lang.String getResourceString(java.lang.String key)
          Get an entry from the interview's resource bundle.
protected  java.lang.String getResourceString(java.lang.String key, boolean checkAncestorsFirst)
          Get an entry from the interview's resource bundle.
abstract  java.lang.String getStringValue()
          Get the response to this question as a string.
 java.lang.String getSummary()
          Set the summary text for this question.
 java.lang.String getTag()
          Get the tag for a question.
 java.lang.String getText()
          Get the text for this question.
protected  java.lang.Object[] getTextArgs()
          Get any arguments necessary to go with the question text.
 int hashCode()
           
 boolean hasMarker(java.lang.String name)
          Check if a marker has been added to this question.
 boolean isEnabled()
          Determine if this question is currently enabled.
 boolean isHidden()
          Determine if this question is currently "hidden".
abstract  boolean isValueAlwaysValid()
          Check if the question always has a valid response.
abstract  boolean isValueValid()
          Check if the question currently has a valid response.
protected abstract  void load(java.util.Map data)
          Load any state for this question from a dictionary, using the tag as the key.
 void reload()
          This methods invokes save(Map), clear() and load(Map).
 void removeMarker(java.lang.String name)
          Remove a named marker to this question.
protected abstract  void save(java.util.Map data)
          Save any state for this question in a dictionary, using the tag as the key.
 void setImage(java.lang.String resource)
          Set the URL for a specific graphic for this question.
protected  void setImage(java.net.URL u)
          Set the URL for a specific graphic for this question.
protected  void setSummary(java.lang.String summary)
          Set the summary text for this question.
protected  void setText(java.lang.String text)
          Set the text for this question.
abstract  void setValue(java.lang.String s)
          Set the response to this question to the value represented by a string-valued argument.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

interview

protected Interview interview
The interview to which this question belongs.


tag

protected java.lang.String tag
A unique tag to identify this question.


key

protected final java.lang.String key
A unique key to identify the resources for this question.

Constructor Detail

Question

protected Question(Interview interview,
                   java.lang.String baseTag)
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

protected Question(Interview interview)
Create a question with no identifying tag.

Parameters:
interview - The interview containing this question.
Method Detail

getInterview

public Interview getInterview()
Return the interview of which this question is a part.

Returns:
the interview of which this question is a part

getKey

public java.lang.String 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()

getTag

public java.lang.String 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:
getKey()

setText

protected void setText(java.lang.String text)
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:
getText()

getText

public java.lang.String 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(java.lang.String)

getTextArgs

protected java.lang.Object[] getTextArgs()
Get any arguments necessary to go with the question text. The text is formatted using the rules specified for MessageFormat.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.

setSummary

protected void setSummary(java.lang.String summary)
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:
getSummary()

getSummary

public java.lang.String getSummary()
Set the summary text for this question.

Returns:
a short summary of the text for this question
See Also:
setSummary(java.lang.String)

setImage

public void setImage(java.lang.String resource)
Set the URL for a specific graphic for this question.

Parameters:
resource - The name of a resource containing the desired image.
See Also:
getImage()

setImage

protected void setImage(java.net.URL u)
Set the URL for a specific graphic for this question.

Parameters:
u - The URL of a resource containing the desired image.
See Also:
getImage()

getImage

public java.net.URL getImage()
Get the graphic for this question. If setImage(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 a default image for the interview.

Returns:
a URL for the question.
See Also:
setImage(java.lang.String)

getHelpID

public javax.help.Map.ID getHelpID()
Get the JavaHelp ID identifying the "more info" help for this question, or null if none.

Returns:
the JavaHelp ID identifying the "more info" help for this question, or null if none.

getChecklistItems

public Checklist.Item[] 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:
Interview.createChecklist()

addMarker

public void addMarker(java.lang.String name)
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:
java.lang.NullPointerException - if name is null

removeMarker

public void removeMarker(java.lang.String name)
Remove a named marker to this question.

Parameters:
name - the name of the marker to be removed.

hasMarker

public boolean hasMarker(java.lang.String name)
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 by Interview.prev() and Interview.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 of isEnabled() 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()

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 by Interview.prev() and Interview.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

protected abstract Question 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

public abstract java.lang.String 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(String)

setValue

public abstract void setValue(java.lang.String s)
                       throws Interview.Fault
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:
getStringValue()

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

protected abstract void load(java.util.Map data)
Load any state for this question from a dictionary, using the tag as the key.

Parameters:
data - The map from which to load the value for this question.

save

protected abstract void save(java.util.Map data)
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

protected void export(java.util.Map data)
Export any appropriate values to the dictionary, as part of Interview.export(java.util.Map). 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:
Interview.getPath(), isEnabled()

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

public boolean equals(java.lang.Object other)
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.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getResourceString

protected java.lang.String getResourceString(java.lang.String key)
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:
Interview.getResourceString(String)

getResourceString

protected java.lang.String getResourceString(java.lang.String key,
                                             boolean checkAncestorsFirst)
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 returned
checkAncestorsFirst - 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:
Interview.getResourceString(String, boolean)


Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.