net.pacbell.jfai.toh.ui
Class TowerOfHanoiView

java.lang.Object
  extended by java.awt.event.MouseAdapter
      extended by net.pacbell.jfai.toh.ui.TowerOfHanoiView
All Implemented Interfaces:
MouseListener, EventListener, Solver.IStateListener

public class TowerOfHanoiView
extends MouseAdapter
implements Solver.IStateListener

Provides the user interface for the Solver of Tower Of Hanoi. It also functions as the "glue" between the model (Solver) and the various user interface components. Provides apply/cancel editor functions for the bound properties of the Solver model.


Field Summary
(package private) static Log LOG
          The trace log.
 
Constructor Summary
TowerOfHanoiView(Solver aModel)
          Creates an instance for the given Solver.
 
Method Summary
protected  void beginPinSelection(BufferedValue pinModel)
          Prepares for the selection of a pin in the scene.
protected  void changeButtonLabel(JToggleButton button, String caption)
          Changes the text of the given button.
protected  void changeEditing(boolean isChanging)
          When changes are present, enables the controls to apply changes and disables the start button.
protected  void changeSizeSlider(int value)
          Changes the value of the slider for number of disks.
 void cleanUp()
          Ends the visualization.
static float depth()
          Answers the depth of the puzzle.
protected  void enableConfigurationControls(boolean isEnable)
          Enables or disables the user interface components that change the puzzle.
protected  void endPinSelection()
          Ends the selection of a pin.
protected  CanvasPanel getCanvasPanel()
          Gets the canvas panel.
protected  JPanel getContainer()
          Gets the container.
protected  ControlPanel getControlPanel()
          Gets the control panel.
protected  TowerOfHanoiEditor getEditor()
          Gets the editor.
 Solver getModel()
          Gets the model.
(package private)  ActionListener getStartButtonListener()
          Gets the listener for the start button.
(package private)  StatusPanel getStatusPanel()
          Gets the status panel.
static float height()
          Answers the height of the puzzle.
 void idling()
          Notifies the listener that the state was changed to Idle.
 void mouseExited(MouseEvent e)
          When a pin selection button is pressed, this view is registered as a listener for mouse events for the 3D canvas.
protected  void pause()
          Tells the model to pause while solving the puzzle.
 void paused()
          Notifies the listener that the state was changed to Paused.
 void prepare(JPanel contentPane)
          Prepares the initial view of the model.
protected  void resume()
          Tells the model to resume solving the puzzle.
(package private)  void setStartButtonListener(ActionListener startButtonListener)
          Sets the listener for the start button action.
protected  void solve()
          Tells the model to start solving the puzzle.
 void solving()
          Notifies the listener that the state was changed to Solving.
static float width()
          Answers the width of the puzzle.
 
Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseEntered, mousePressed, mouseReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

static final Log LOG
The trace log.

Constructor Detail

TowerOfHanoiView

public TowerOfHanoiView(Solver aModel)
Creates an instance for the given Solver.

Parameters:
aModel - a Solver
Method Detail

depth

public static final float depth()
Answers the depth of the puzzle.

Returns:
the depth of the puzzle

height

public static final float height()
Answers the height of the puzzle.

Returns:
the height of the puzzle

width

public static final float width()
Answers the width of the puzzle.

Returns:
the width of the puzzle

cleanUp

public void cleanUp()
Ends the visualization.


getModel

public Solver getModel()
Gets the model.

Returns:
a Solver

idling

public void idling()
Notifies the listener that the state was changed to Idle.

Specified by:
idling in interface Solver.IStateListener
See Also:
Solver.IStateListener.idling()

mouseExited

public void mouseExited(MouseEvent e)
When a pin selection button is pressed, this view is registered as a listener for mouse events for the 3D canvas. If the mouse exits the canvas, the pin selection is over.

Specified by:
mouseExited in interface MouseListener
Overrides:
mouseExited in class MouseAdapter
See Also:
MouseAdapter.mouseExited(java.awt.event.MouseEvent)

paused

public void paused()
Notifies the listener that the state was changed to Paused.

Specified by:
paused in interface Solver.IStateListener
See Also:
Solver.IStateListener.paused()

prepare

public void prepare(JPanel contentPane)
Prepares the initial view of the model. All components are added into the given content pane of a root container.

TODO: prevent window from getting too small

Parameters:
contentPane - the content pane of a root container

solving

public void solving()
Notifies the listener that the state was changed to Solving.

Specified by:
solving in interface Solver.IStateListener
See Also:
Solver.IStateListener.solving()

beginPinSelection

protected void beginPinSelection(BufferedValue pinModel)
Prepares for the selection of a pin in the scene. The parameter is the editor model for the pin that is to be selected.

Parameters:
pinModel - a BufferedValue for the selected pin

changeButtonLabel

protected void changeButtonLabel(JToggleButton button,
                                 String caption)
Changes the text of the given button. This is triggered in a thread different from the event dispatch thread.

Parameters:
button - the button
caption - the new caption

changeEditing

protected void changeEditing(boolean isChanging)
When changes are present, enables the controls to apply changes and disables the start button. Otherwise does the opposite and removes any selection from the pin toggle buttons.

This may be called from a thread different than the event dispatch thread.

Parameters:
isChanging - Are any changes pending?

changeSizeSlider

protected void changeSizeSlider(int value)
Changes the value of the slider for number of disks. This is necessary during a cancel operation, and can be triggered in a thread different from the event dispatch thread.

Parameters:
value - the number of disks

enableConfigurationControls

protected void enableConfigurationControls(boolean isEnable)
Enables or disables the user interface components that change the puzzle.

Parameters:
isEnable - enable the controls?

endPinSelection

protected void endPinSelection()
Ends the selection of a pin. Removes all selections from the source and target pin controls. Removes the picking callback.


getCanvasPanel

protected CanvasPanel getCanvasPanel()
Gets the canvas panel.

Returns:
the canvas Panel.

getContainer

protected JPanel getContainer()
Gets the container.

Returns:
the Container

getControlPanel

protected ControlPanel getControlPanel()
Gets the control panel.

Returns:
the control Panel.

getEditor

protected TowerOfHanoiEditor getEditor()
Gets the editor.

Returns:
the editor

pause

protected void pause()
Tells the model to pause while solving the puzzle.

Assumes that this method is called in the event dispatch thread, for example, when a pause button was pressed.


resume

protected void resume()
Tells the model to resume solving the puzzle.

Assumes that this method is called in the event dispatch thread, for example, when a resume button was pressed.


solve

protected void solve()
Tells the model to start solving the puzzle.

Assumes that this method is called in the event dispatch thread, for example, when a start button was pressed.


getStartButtonListener

ActionListener getStartButtonListener()
Gets the listener for the start button.

Returns:
the listener for the start button action

getStatusPanel

StatusPanel getStatusPanel()
Gets the status panel.

Returns:
the statusPanel

setStartButtonListener

void setStartButtonListener(ActionListener startButtonListener)
Sets the listener for the start button action.

Parameters:
startButtonListener - the listener for the start button action