Package pygar.state
Class SequenceDisplayMachine
java.lang.Object
pygar.state.SequenceDisplayMachine
- All Implemented Interfaces:
java.util.Observer
public class SequenceDisplayMachine
extends java.lang.Object
implements java.util.Observer
The SequenceDisplayMachine is a helper class used with StateMachine. It is used to visualize and
manage a sequence of steps each of which corresponds to a state. The correspondence
is based purely on the name, so the connection of sequence steps and state can be either
close or loose.
The main purpose of this class is the way it stores configuration information and then
turns that information into two optional display panels - one for pushbuttons and one
for a progress display.
There are three assumed state names: "NotStarted", "Canceled" and "Completed". The first names the
initial state of the display machine before any other state is set. The second state is
outside the normal state sequence. When the machine receives a "cancel" call, the "Canceled"
state is set on, all future changes are blocked, and the old state persists until a "restart"
call is received. Lastly, the "Completed" state indicates that the final step has been completed.
-
Field Summary
Fields Modifier and Type Field Description java.util.Vector<java.lang.String>
states
-
Constructor Summary
Constructors Constructor Description SequenceDisplayMachine(java.lang.String path, java.lang.String progressText)
Display a sequence of steps and their status in the progression. -
Method Summary
Modifier and Type Method Description void
addButton(java.lang.String displayText, java.awt.event.ActionListener listener)
Add a Button to the operator's control button panel.void
addButtonEnabledStates(java.lang.String buttonDisplayText, java.util.List<java.lang.String> stateNames)
Declare that several buttons are activated in a certain state.void
addCanceledState(java.lang.String displayText)
Add a line to the sequence step display that visibly shows when the sequence has been canceled.void
addFirstState(java.lang.String name)
Name the state in which the machine starts.void
addNextState(java.lang.String name, java.awt.event.ActionListener listener, java.lang.String displayText)
Add the next step in the sequence.void
buildPanels()
Complete the object by building the display components from the previously added steps and buttons.void
buttonEnabledState(java.lang.String displayText, java.lang.String stateName)
Declare that a certain button is activated in a certain state.void
cancel()
Declare the step sequence canceled.javax.swing.JPanel
getButtonPanel()
Return the panel containing buttons.javax.swing.JPanel
getSequencePanel()
create and return the panel that shows the status of the sequence.static void
main(java.lang.String[] args)
main program *has not* tracked program changes - needs revision.void
printEnabledButtons()
Print the button names and the states in which each button is enabled.void
setState(java.lang.String name, PmessageStateMachine stateMachine)
Set the current sequence state to the given value, call the listener for the new state if it is not null, and adjust the display widget.void
update(java.util.Observable sm, java.lang.Object obj)
-
Field Details
-
states
public java.util.Vector<java.lang.String> states
-
-
Constructor Details
-
SequenceDisplayMachine
public SequenceDisplayMachine(java.lang.String path, java.lang.String progressText)Display a sequence of steps and their status in the progression. Each step is shown as text plus an icon that show not-started, in-progress, or completed. The sequence may include invisible states that are not displayed. When a system is in one of these states, the prior step is completed and the next step is not-started and none are in-progress. Lifecycle: 1) construct the object 2) add the steps 3) add the buttons and the button enabled options 4) call buildPanels to complete the construction of the Swing components.- Parameters:
path
- file location where the images director must resideprogressText
- text appearing above the list of steps
-
-
Method Details
-
buildPanels
public void buildPanels()Complete the object by building the display components from the previously added steps and buttons. -
addFirstState
public void addFirstState(java.lang.String name)Name the state in which the machine starts. If the first state is not explicitly named, then it is assumed to be named "NotStarted".- Parameters:
name
-
-
addNextState
public void addNextState(java.lang.String name, java.awt.event.ActionListener listener, java.lang.String displayText) throws java.lang.ExceptionAdd the next step in the sequence. When the sequence advances to the step, invoke the listener. If displayText is set, show this step as a visible milestone in the sequence. Otherwise, do not display it. Throw exception on an attempt to add a duplicate state name.- Parameters:
name
-listener
-displayText
-- Throws:
java.lang.Exception
-
setState
Set the current sequence state to the given value, call the listener for the new state if it is not null, and adjust the display widget. If the name does not name a known state, write an error message but otherwise do nothing. Optionally, the second parameter refers to the current state machine. This reference is saved. When the reference is non-null the procedure sendButtonEvent will forward the button name as an event to the state machine as a context-free event where the button name is the event name. If the reference is null, the procedure is a no-op.- Parameters:
name
- the state namestateMachine
- current state machine - may be null and used without state machine connection.
-
cancel
public void cancel()Declare the step sequence canceled. -
addButton
public void addButton(java.lang.String displayText, java.awt.event.ActionListener listener)Add a Button to the operator's control button panel.- Parameters:
displayText
-listener
-
-
buttonEnabledState
public void buttonEnabledState(java.lang.String displayText, java.lang.String stateName)Declare that a certain button is activated in a certain state. Buttons may be active in several states.- Parameters:
displayText
-stateName
-
-
addButtonEnabledStates
public void addButtonEnabledStates(java.lang.String buttonDisplayText, java.util.List<java.lang.String> stateNames)Declare that several buttons are activated in a certain state. Buttons may be active in several states.- Parameters:
buttonDisplayText
-stateNames
-
-
printEnabledButtons
public void printEnabledButtons()Print the button names and the states in which each button is enabled. -
addCanceledState
public void addCanceledState(java.lang.String displayText)Add a line to the sequence step display that visibly shows when the sequence has been canceled.- Parameters:
displayText
-
-
getButtonPanel
public javax.swing.JPanel getButtonPanel()Return the panel containing buttons.- Returns:
- buttonPanel
-
getSequencePanel
public javax.swing.JPanel getSequencePanel()create and return the panel that shows the status of the sequence. The sequence should be established prior to calling this routine.- Returns:
- JPanel
-
main
public static void main(java.lang.String[] args) throws java.lang.Exceptionmain program *has not* tracked program changes - needs revision.- Parameters:
args
-- Throws:
java.lang.Exception
-
update
public void update(java.util.Observable sm, java.lang.Object obj)- Specified by:
update
in interfacejava.util.Observer
-