talx x1.0.5

constraint
Class ConstraintAdapter

java.lang.Object
  extended byconstraint.ConstraintAdapter
All Implemented Interfaces:
Constraint, ConstraintConstants, SettingsConstants, StateConstants
Direct Known Subclasses:
AddInboxBuddy, AddReaderPicture, AutoBackspace, AutoClick, AutoClickOnHighlight, AutoClickOnModelHighlight, AutoFingerFirstTargetTextError, AutoMove, AutoMove, AutoMove, AutoMoveAndClick, AutoMoveAndClickRepeat, AutoMoveAndScroll, AutoMoveToHighlight, AutoMoveToModelHighlight, AutoSelectLastUserTextError, AutoType, AutoTypeTargetText, BottomOutPictureReader, BullseyeTimer, BullseyeTimer, BullseyeTimer, ChangeStateOnInboxButton, ChangeStateOnQuitButton, ChangeStateOnReaderTextVisible, ChangeStateOnReplyButton, ChangeStateOnScrollReplyButton, ChangeStateOnScrollSendButton, ChangeStateOnSendButton, ChangeStateOnWriteButton, CompleteTaskOnButton, ComposerScrollToBottom, ComposerScrollToTop, EasyChangeStateOnScrollReplyButton, FailOnAllTyping, FailOnAnyKeyPress, FailOnButton, FailOnKeyPress, FailOnKeyPressAndState, FailOnTimer, FixToModelHighlight, HideButton, HideKeymap, HideLogoutButton, HideTargetText, HideUserText, HighlightInboxOnClick, InboxScrollToBottom, InboxScrollToTop, InitialQuestionConstraint, MediaFinishOnTrainerButton, PassElseFailOnButton, PassOnButton, PassOnButton, PassOnCaretPositionAndButton, PassOnErase, PassOnKeyPress, PassOnKeyPressAndTimer, PassOnLogicalCaretPositionAndButton, PassOnLooseTextAndButton, PassOnMediaFinished, PassOnMouseButtonPressAndRelease, PassOnMouseClicked, PassOnMouseClickedModelSelection, PassOnMouseClickedSelection, PassOnMouseOverAnything, PassOnMouseOverModelSelection, PassOnMouseOverSelection, PassOnPositionAndTimer, PassOnQuitAndState, PassOnSameTextAndButton, PassOnSameTextAndTimer, PassOnSendAndThisText, PassOnSendAndWords, PassOnSomeTextAndTimer, ReaderScrollToBottom, ReaderScrollToTop, SetColors, SetComposerCaption, SetComposerGray, SetComposerSubject, SetComposerText, SetDeleteButton, SetDontButton, SetGridSize, SetImage, SetInboxGray, SetInboxHighlight, SetInstructionFont, SetMouseGlobalPosition, SetMouseImage, SetMouseModelDirection, SetMousePadPosition, SetMousePosition, SetMouseToButton, SetMouseToHighlight, SetMouseToModelHighlight, SetMovie, SetReaderCaption, SetReaderDate, SetReaderGray, SetReaderSubject, SetReaderText, SetReplyButton, SetSaveButton, SetSelectedSquare, SetSelectedSquarePosition, SetSendButton, SetState, SetTargetCircleColor, SetTargetHighlightColor, SetTargetHighlightTextColor, SetTargetText, SetTargetText, SetTargetTextHighlight, SetUserCaretBlinkRate, SetUserCaretColor, SetUserCaretWidth, SetUserCircleColor, SetUserHighlightColor, SetUserHighlightTextColor, SetUserSelectionColor, SetUserText, SetUserTextCaret, SetUserTextHighlight, SetUserTextHighlightBackspace, SetUserTextLogicalCaret, SetUserTextLogicalHighlight, ShowAllMovement, ShowAllTyping, ShowArrow, ShowButton, ShowCorrectTyping, ShowCorrectTypingAndBeepForSomeReason, ShowDialog, ShowGridMouseFinger, ShowKeymap, ShowKeymapFinger, ShowMouseFinger, ShowTargetTextFinger, ShowUserTextFinger, SucceedOnBuddyVisible, SucceedOnComposerTextVisible, SucceedOnPictureVisible, SucceedOnReaderTextVisible, SucceedOnReaderTextVisibleInComposerState, SucceedOnTimer, TOCConstraint, UsePictureReader

public class ConstraintAdapter
extends java.lang.Object
implements Constraint, ConstraintConstants, StateConstants, SettingsConstants

Skeleton class for Constraint implementations. Implementation classes for constraints can extend this class and override only those methods that deal with events of interest. This class also provides support of value interpretation, and auto-firing of events.
Constraints that use callback functions to monitor task property values should implement LayeredConstraint instead of ConstraintAdapter. If an implementation class of this class fires a callback action in response to an action event, this will cause an infinite recursion in the controller queue. Therefore, aside from the autofiring mechanism provided here, all callback functionality should be provided by the mechanism in LayeredConstraint.


Field Summary
 
Fields inherited from interface constraint.ConstraintConstants
ACTION_COMMAND_KEY, ACTION_TYPE_SOUND_FINISHED, COMPONENT_FINGER_POSITION, COMPONENT_FINGER_PRESS_POSITION, COMPONENT_HORIZONTAL_ARROW_POSITION, COMPONENT_INSTRUCTION_BACKGROUND_COLOR, COMPONENT_INSTRUCTION_TEXT, COMPONENT_INSTRUCTION_TEXT_ATTRIBUTES, COMPONENT_INSTRUCTION_TEXT_COLOR, COMPONENT_INSTRUCTION_TEXT_FONT_FACE, COMPONENT_INSTRUCTION_TEXT_SIZE, COMPONENT_MOUSE_FINGER_POSITION, COMPONENT_SOUND, COMPONENT_SOUND_IS_PLAYING, COMPONENT_SOUND_QUIT, COMPONENT_TIMER, COMPONENT_VERTICAL_ARROW_POSITION, DIALOG, HIDE_BULLSEYE, LESSON_STOP_ACTION, MOUSE_BULLSEYE, MOUSE_FINGER_IMAGE, NO_TOKEN, PREVIOUS_TASK_COMPLETION_REASON, PROGRESS_PANEL_VISIBLITY, SHOW_BULLSEYE, SKIP_TASK_ACTION, TAL_DIALOG, TASK_FAIL_COUNT, TASK_STATUS, TASK_SUCCEED_COUNT, YES_TOKEN
 
Fields inherited from interface controller.StateConstants
ACTION, ACTION_TYPE_CONTINUE, ACTION_TYPE_GOTO, ACTION_TYPE_IGNORE, ACTION_TYPE_PANIC, ACTION_TYPE_QUIT, ACTION_TYPE_RESTART, ACTION_TYPE_REVIEW, ACTION_TYPE_SKIP_DRILL, ACTION_TYPE_SKIP_SKILL, ACTION_TYPE_SKIP_TASK, ACTION_TYPE_TASK_STARTED, ACTION_TYPE_TRAIN, CALLBACK_COMMAND, FIRST_CALLBACK, FOURTH_CALLBACK, SECOND_CALLBACK, THIRD_CALLBACK
 
Fields inherited from interface util.SettingsConstants
ALTERNATIVE_BACKGROUND_COLOR, ALTERNATIVE_BACKGROUND_COLOR_ALIAS, ALTERNATIVE_FONT_ATTRIBUTES, ALTERNATIVE_FONT_ATTRIBUTES_ALIAS, ALTERNATIVE_FONT_COLOR, ALTERNATIVE_FONT_COLOR_ALIAS, CARET_BLINK_RATE, CARET_COLOR, CARET_WIDTH, DECORATED, DEFAULT_UI_STATE_CLASS, FONT_FACE, FONT_FACE_ALIAS, FONT_SIZE, FONT_SIZE_ALIAS, INNER_BACKGROUND_COLOR, INSTRUCTION_BACKGROUND_COLOR, INSTRUCTION_BACKGROUND_COLOR_ALIAS, INSTRUCTION_FONT_ATTRIBUTES, INSTRUCTION_FONT_ATTRIBUTES_ALIAS, INSTRUCTION_FONT_COLOR, INSTRUCTION_FONT_COLOR_ALIAS, LARGE_FONT_SIZE, LARGE_FONT_SIZE_ALIAS, LESSON_UI_STATE_CLASS, LOGGER_CLASS, LOGGER_DIRECTORY, LOGGER_PARAMS, SAVE_FILENAME, SCREEN_PERCENT, SKILL_LATTICE_FILENAME, SMALL_FONT_SIZE, SMALL_FONT_SIZE_ALIAS, STATS_FILENAME, TAL_SETTINGS_FILENAME, TITLE, TITLE_ALIAS, TITLE_ICON, TITLE_ICON_ALIAS, TRAINER_UI_STATE_CLASS, USER_ID
 
Constructor Summary
ConstraintAdapter()
           
 
Method Summary
 boolean fireAutoAction(TaskProperties tp)
          Determines whether the autoaction should continue to fire.
 int getIntValue()
          Returns the value converted to an int, or zero if the conversion fails.
 java.lang.String getType()
           
 java.lang.String getValue()
           
 void process(EventWrapper ev, TaskProperties tp)
          Unwraps the event and sends it to the appropriate process method.
 void processActionEvent(java.awt.event.ActionEvent ev, TaskProperties tp)
           
 void processInit(TaskProperties tp)
           
 void processKeyEvent(java.awt.event.KeyEvent ev, TaskProperties tp)
          When key events get to the constraint, they have already been consumed.
 void processMouseEvent(java.awt.event.MouseEvent ev, TaskProperties tp)
          When mouse events are delivered to the constraint, they have not been seen or processed by the source component.
 void setValue(java.lang.String value, java.lang.String type, TaskProperties tp)
          Performs task initialization code.
static java.util.Map splitPairs(java.lang.String s)
          Splits the given string into name=value pairs.
 void startAutoAction(java.lang.String actionCommand, long interval, long delay, TaskProperties tp)
          Starts an auto action firing sequence for the current task.
 void stopAutoAction(TaskProperties tp)
          Stops an auto action firing sequence.
static java.lang.String stringToRGB(java.lang.String name)
          Returns the RGB string for the color constant with the given name.
 java.lang.String toString()
          Returns the fully qualified pathname of the constraint.
protected  boolean valueContains(java.lang.String token)
          Performs case-insensitive search for token in the value of this constraint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConstraintAdapter

public ConstraintAdapter()
Method Detail

splitPairs

public static java.util.Map splitPairs(java.lang.String s)
Splits the given string into name=value pairs. The returned map associates key strings with string, Integer or int[] values. The input string is expected to be a white-space-delimited list of name=value pairs with no space within the name. If the value contains space, then it is expected to be enclosed in double quotes. if the value can be interpreted as an int, it will be stored in the map as an Integer object. If the value is enclosed in square brackets, and consists entirely of comma and white-space-delimited integer values, it is stored as an int array. Otherwise, it is returned as a string. Any tokens that are found that do not contain an equals sign are returned as a concatenated, space-delimited string using the empty string as the key. All names are converted to lower case.


stringToRGB

public static java.lang.String stringToRGB(java.lang.String name)
Returns the RGB string for the color constant with the given name. The match is not case sensitive, so "LightGray", "LIGHTGRAY", and "light_gray" all return the color constant referred to as Color.LightGray or Color.LIGHT_GRAY. If no matching color constant could be found, this method returns the original string.

Throws:
java.lang.NullPointerException - if name is null.

valueContains

protected boolean valueContains(java.lang.String token)
Performs case-insensitive search for token in the value of this constraint.


startAutoAction

public void startAutoAction(java.lang.String actionCommand,
                            long interval,
                            long delay,
                            TaskProperties tp)
Starts an auto action firing sequence for the current task. To use this mechanism:
  1. Override the fireAutoAction method to determine when to continue firing actions (see fireAutoAction)
  2. override the processActionEvent method to look for actions with the command you supplied here. Each time you get an action with the given command, perform your automatic update.
  3. In the processActionEvent method, also look for the StateConstants.ACTION_TYPE_TASK_STARTED command. When you see this command, the task is just beginning. At that time, call this method (startAutoAction) with the appropriate parameters.
Only one auto action can be active at a time. Subsequent calls to this method will cause a previously started firing sequence to stop.

Parameters:
actionCommand - the command to fire in this sequence.
interval - the time in milliseconds to wait between firing the action command.
delay - the time in milliseconds to wait before beginning the sequence.

stopAutoAction

public void stopAutoAction(TaskProperties tp)
Stops an auto action firing sequence. Normally, implementations would just implement fireAutoAction to stop firing at the appropriate goal, but constraints that want to explicitely stop the firing sequence, can call this method.


fireAutoAction

public boolean fireAutoAction(TaskProperties tp)
Determines whether the autoaction should continue to fire. This method is called each time the auto action is scheduled to fire. (See startAutoAction.) If this method returns true, the auto action will fire. If this method returns false, the auto action will not fire and its thread will shut down until another call to startAutoAction. The default behavior is to return true, so the action will continue to fire throughout the lifetime of the task. All firing sequences terminate when the task terminates.


process

public void process(EventWrapper ev,
                    TaskProperties tp)
Unwraps the event and sends it to the appropriate process method.

Specified by:
process in interface Constraint

processActionEvent

public void processActionEvent(java.awt.event.ActionEvent ev,
                               TaskProperties tp)

processMouseEvent

public void processMouseEvent(java.awt.event.MouseEvent ev,
                              TaskProperties tp)
When mouse events are delivered to the constraint, they have not been seen or processed by the source component. Thus, the constraint can consume the event and thus cause the component to not react.


processKeyEvent

public void processKeyEvent(java.awt.event.KeyEvent ev,
                            TaskProperties tp)
When key events get to the constraint, they have already been consumed. Thus, a constraint may do anything it wants with the characters, but nothing will happen automatically.


processInit

public void processInit(TaskProperties tp)

setValue

public void setValue(java.lang.String value,
                     java.lang.String type,
                     TaskProperties tp)
Performs task initialization code. This sets up the internal state to support subsequent calls to getValue. Subclasses should override the processInit method rather than this one.

Specified by:
setValue in interface Constraint

getValue

public java.lang.String getValue()
Specified by:
getValue in interface Constraint

getIntValue

public int getIntValue()
Returns the value converted to an int, or zero if the conversion fails.


getType

public java.lang.String getType()
Specified by:
getType in interface Constraint

toString

public java.lang.String toString()
Returns the fully qualified pathname of the constraint.


talx x1.0.5

© 2001-2005 University of Oregon.
Eugene OR 97403, U.S.A. All Rights Reserved.