public class VisualExplorer extends javax.swing.JFrame implements ShellObserver
Environment
.
States are
conveyed to the user through a 2D visualization and the user specifies actions
by either pressing keys that are mapped to actions or by typing the actions into the action command field.
Action parameters in the action field are specified by space delineated input. For instance: "stack block0 block1" will cause
the stack action to called with action parameters block0 and block1. The ` key
causes the environment to reset.
Additionally, the VisualExplorer also creates an associated instance of an EnvironmentShell
that you can access using the "Show Shell" button. You can use the shell to modify the state (assuming the input
Environment
implements StateSettableEnvironment
,
record trajectories that you make in the environment, and any number of other tasks. The shell's "programs," specified with
ShellCommand
instances, may also be expanded so that you can create your own runtime tools.
See the BurlapShell
and EnvironmentShell
Java doc for more information on how
to use them. If you need access to the shell instance, you can get it with the getShell()
method. You can
also set shell commands to be executed when a key is pressed in the visualization. Set them with the
addKeyShellCommand(String, String)
method.
A special shell command, "livePoll" is automatically added to the shell, that allows the user to set the visualizer to auto poll the environment at a fixed interval for the state and display it. This is useful when the environment can evolve independent of agent action or explicit shell commands. See it's help in the shell (-h option) for more information on it.
Modifier and Type | Class and Description |
---|---|
class |
VisualExplorer.LivePollCommand
Shell command that allow live polling of the
VisualExplorer to be polled. |
javax.swing.JFrame.AccessibleJFrame
java.awt.Window.AccessibleAWTWindow, java.awt.Window.Type
java.awt.Container.AccessibleAWTContainer
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
ShellObserver.ShellCommandEvent
Modifier and Type | Field and Description |
---|---|
protected javax.swing.JButton |
actionButton |
protected java.awt.TextField |
actionField |
protected int |
cHeight |
protected javax.swing.JFrame |
consoleFrame |
protected int |
cWidth |
protected SADomain |
domain |
protected Environment |
env |
protected java.util.Map<java.lang.String,Action> |
keyActionMap |
protected java.util.Map<java.lang.String,java.lang.String> |
keyShellMap |
protected javax.swing.Timer |
livePollingTimer |
protected Visualizer |
painter |
protected int |
pollInterval |
protected java.awt.TextArea |
propViewer |
protected EnvironmentShell |
shell |
protected javax.swing.JTextArea |
stateConsole |
protected TextAreaStreams |
tstreams |
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor and Description |
---|
VisualExplorer(SADomain domain,
Environment env,
Visualizer painter)
Initializes with a visualization canvas size set to 800x800.
|
VisualExplorer(SADomain domain,
Environment env,
Visualizer painter,
int w,
int h)
Initializes.
|
VisualExplorer(SADomain domain,
Visualizer painter,
State baseState)
Initializes with a domain and initial state, automatically creating a
SimulatedEnvironment
as the environment with which to interact. |
Modifier and Type | Method and Description |
---|---|
void |
addKeyAction(java.lang.String key,
Action action)
Specifies which action to execute for a given key press
|
void |
addKeyAction(java.lang.String key,
java.lang.String actionTypeName,
java.lang.String paramStringRep)
Adds a key action mapping.
|
void |
addKeyShellCommand(java.lang.String key,
java.lang.String shellCommand)
Cause a shell command to be executed when key is pressed with the visualizer highlighted.
|
protected void |
executeAction(Action ga)
Executes the provided
Action in the explorer's environment and records
the result if episodes are being recorded. |
EnvironmentShell |
getShell()
Returns the
EnvironmentShell instance associated with this object. |
Visualizer |
getVisualizer()
Returns the
Visualizer used by this explorer. |
protected void |
handleExecute()
Handles action execute button.
|
protected void |
handleKeyPressed(java.awt.event.KeyEvent e)
Handles key presses
|
protected void |
init(SADomain domain,
Environment env,
Visualizer painter,
int w,
int h) |
void |
initGUI()
Initializes the visual explorer GUI and presents it to the user.
|
void |
observeCommand(BurlapShell shell,
ShellObserver.ShellCommandEvent event)
Received whenever a
ShellCommand completes execution. |
void |
startLiveStatePolling(int msPollDelay)
Starts a thread that polls this explorer's
Environment every
msPollDelay milliseconds for its current state and updates the visualizer to that state. |
void |
stopLivePolling()
Stops this class from live polling this explorer's
Environment . |
protected void |
updatePropTextArea(State s)
Updates the propositional function evaluation text display for the given state.
|
void |
updateState(State s)
Updates the currently visualized state to the input state.
|
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFront
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
protected Environment env
protected SADomain domain
protected java.util.Map<java.lang.String,Action> keyActionMap
protected java.util.Map<java.lang.String,java.lang.String> keyShellMap
protected Visualizer painter
protected java.awt.TextArea propViewer
protected java.awt.TextField actionField
protected javax.swing.JButton actionButton
protected int cWidth
protected int cHeight
protected javax.swing.JFrame consoleFrame
protected javax.swing.JTextArea stateConsole
protected javax.swing.Timer livePollingTimer
protected int pollInterval
protected EnvironmentShell shell
protected TextAreaStreams tstreams
public VisualExplorer(SADomain domain, Visualizer painter, State baseState)
SimulatedEnvironment
as the environment with which to interact. The created SimulatedEnvironment
will
have a NullRewardFunction
and NullTermination
functions set.domain
- the domain to explorepainter
- the 2D state visualizerbaseState
- the initial state from which to explorepublic VisualExplorer(SADomain domain, Environment env, Visualizer painter)
domain
- the domain to exploreenv
- the Environment
with which to interact.painter
- the 2D state visualizerpublic VisualExplorer(SADomain domain, Environment env, Visualizer painter, int w, int h)
domain
- the domain to exploreenv
- the Environment
with which to interact.painter
- the 2D state visualizerw
- the width of the visualizer canvash
- the height of the visualizer canvasprotected void init(SADomain domain, Environment env, Visualizer painter, int w, int h)
public Visualizer getVisualizer()
Visualizer
used by this explorer.Visualizer
used by this explorer.public EnvironmentShell getShell()
EnvironmentShell
instance associated with this object.EnvironmentShell
instance associated with this object.public void addKeyAction(java.lang.String key, Action action)
key
- the key that is pressed by the useraction
- the Action
to take when the key is pressedpublic void addKeyAction(java.lang.String key, java.lang.String actionTypeName, java.lang.String paramStringRep)
key
- the key that is pressed by the useractionTypeName
- the name of the ActionType
paramStringRep
- the string representation of the action parameterspublic void addKeyShellCommand(java.lang.String key, java.lang.String shellCommand)
key
- the key to activate the shell command.shellCommand
- the shell command to execute.public void startLiveStatePolling(int msPollDelay)
Environment
every
msPollDelay milliseconds for its current state and updates the visualizer to that state.
Polling can be stopped with the stopLivePolling()
. If live polling is already running,
this method call will only change the poll rate.msPollDelay
- the number of milliseconds between environment polls and state updates.public void stopLivePolling()
Environment
.public void observeCommand(BurlapShell shell, ShellObserver.ShellCommandEvent event)
ShellObserver
ShellCommand
completes execution.observeCommand
in interface ShellObserver
shell
- the calling BurlapShell
event
- the command event, stored as a ShellObserver.ShellCommandEvent
public void initGUI()
public void updateState(State s)
s
- the state to visualize.protected void handleExecute()
protected void handleKeyPressed(java.awt.event.KeyEvent e)
e
- the key eventprotected void executeAction(Action ga)
Action
in the explorer's environment and records
the result if episodes are being recorded.ga
- the Action
to execute.protected void updatePropTextArea(State s)
s
- the input state on which propositional functions are to be evaluated.