uchicago.src.sim.engine
Class ModelManipulator

java.lang.Object
  extended by uchicago.src.sim.engine.ModelManipulator

public class ModelManipulator
extends java.lang.Object

Creates sliders and buttons for the manipulation of models. ModelManipulator can be used by a modeler to create buttons, sliders and checkboxes that can alter the state of the model while its running. These buttons, sliders, and checkboxes are displayed in gui run of a model on the Custom Actions tab in the settings window.

SimModelImpl contains a protected ivar (modelManipulator) of this type that can be used by all models extending SimModelImpl. See Heat Bugs and Hypercycles demonstration simulations for examples of its use.

Version:
$Revision: 1.6 $ $Date: 2004/11/03 19:50:57 $
Author:
Nick Collier

Constructor Summary
ModelManipulator()
           
 
Method Summary
 void addButton(java.lang.String label, java.awt.event.ActionListener listener)
          Adds a button with the specified label and listener to this ModelManipulator.
 void addCheckBox(java.lang.String label, CheckBoxListener listener, boolean isSelected)
          Adds a checkbox to this ModelManipulator with the specified label, CheckBoxListener, and whether the box should be selected initially.
 void addComponent(java.awt.Component comp)
          Adds the specified Component to this ModelManipulation.
 void addSlider(java.lang.String label, int min, int max, int tickInterval, SliderListener listener)
          Adds a slider with the specified label, min and max values, tick interval and SliderListener to this manipulator.
 javax.swing.JPanel getPanel()
          Gets a JPanel with the sliders, buttons, and checkboxes defined in the add* methods laid out and ready for display.
 void init()
          Initializes the manipulator by clearing any previously added sliders, buttons, or checkboxes.
 boolean isEnabled()
          Is this ModelManipulator's sliders, buttons, and checkboxes enabled
 void setEnabled(boolean enabled)
          Enables or disables all the sliders, buttons, and checkboxes associated with this ModelManipulator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelManipulator

public ModelManipulator()
Method Detail

init

public void init()
Initializes the manipulator by clearing any previously added sliders, buttons, or checkboxes. This should be done at the start of each simulation run. Either in the the setup() method of a model, or in a method that the setup() method calls (e.g. setupCustomActions().


addSlider

public void addSlider(java.lang.String label,
                      int min,
                      int max,
                      int tickInterval,
                      SliderListener listener)
Adds a slider with the specified label, min and max values, tick interval and SliderListener to this manipulator. This slider will then show up on the Custom Actions tab in the settings window.

Parameters:
label - the label for this slider
min - the minimum value for this slider
max - the maximum value for this slider
tickInterval - the interval at which to draw label ticks for this slider.
listener - a listener that listens for and responds to events fired by this slider. The action that should occur when a user moves the slider is defined in this listener.
See Also:
SliderListener

addButton

public void addButton(java.lang.String label,
                      java.awt.event.ActionListener listener)
Adds a button with the specified label and listener to this ModelManipulator. This button will appear on the Custom Actions tab in the settings window. The behavoir that should occur when the button is pressed is defined in the listener.

Parameters:
label - the label displayed by the button
listener - the listener that listens for and responds to clicks of the button.
See Also:
ActionListener

addComponent

public void addComponent(java.awt.Component comp)
Adds the specified Component to this ModelManipulation. The Component itself will appear on the Custom Actions tabs in the settings window.

This Component could be, for example, a JPanel containing a JTextField and JButton such that whenever the button is clicked some data from the model is saved to a file named in the JTextField.

Parameters:
comp - the component to addd

addCheckBox

public void addCheckBox(java.lang.String label,
                        CheckBoxListener listener,
                        boolean isSelected)
Adds a checkbox to this ModelManipulator with the specified label, CheckBoxListener, and whether the box should be selected initially. This button will appear on the Custom Actions tab in the settings window. The behavoir that should occur when the box is checked is defined in the listener.

Parameters:
label - the label for this check box
listener - the listener for this checkbox
isSelected - if true the box will initially display as checked other as not checked.

setEnabled

public void setEnabled(boolean enabled)
Enables or disables all the sliders, buttons, and checkboxes associated with this ModelManipulator.

Parameters:
enabled - if true all the sliders, buttons, and checkboxes associated with this ModelManipulator with be enabled. If false, they will be disabled.

isEnabled

public boolean isEnabled()
Is this ModelManipulator's sliders, buttons, and checkboxes enabled


getPanel

public javax.swing.JPanel getPanel()
Gets a JPanel with the sliders, buttons, and checkboxes defined in the add* methods laid out and ready for display.

Returns:
a JPanel containing sliders, buttons, and checkboxes.