etomica.graphics
Class DeviceBox

java.lang.Object
  extended by etomica.graphics.Device
      extended by etomica.graphics.DeviceBox
All Implemented Interfaces:
DeviceBoxValueChangedListener, GraphicalElement, Dimensioned, EventListener, ChangeListener

public class DeviceBox
extends Device
implements ChangeListener, DeviceBoxValueChangedListener

A simple device the permits editing of a single value via a textbox with an associated label.


Nested Class Summary
static class DeviceBox.LabelType
          Typed constant used to indicate the type of label to be used with the display.
 
Nested classes/interfaces inherited from class etomica.graphics.Device
Device.ActionSet
 
Field Summary
protected  JLabel label
          Descriptive text label to be displayed with the value
protected  String labelString
           
protected  ModifyAction modifyAction
          Modifier connecting the slider to the property
protected  JPanel panel
          Displayed panel that holds the label and value (not yet used; meant to implement to make lightweight display)
protected  int precision
          Integer specifying the number of significant figures to be displayed.
protected  JTextField textField
          Object for displaying the value as a text field
 
Fields inherited from class etomica.graphics.Device
controller, unit
 
Constructor Summary
DeviceBox()
           
 
Method Summary
 void addValueChangedListener(DeviceBoxValueChangedListener dbListener)
          Add an object to be notified when the DeviceBox value to changes
 void deviceBoxValueChanged(DeviceBoxValueChangedEvent ev)
           
 void doUpdate()
          Updates the display of the box with the current value given by the modifier.
static EtomicaInfo getEtomicaInfo()
           
 String getLabel()
           
 Constants.CompassDirection getLabelPosition()
           
 DeviceBox.LabelType getLabelType()
           
 Modifier getModifier()
          Accessor method for the modifier that receives the edit.
 int getPrecision()
          Accessor method of the precision, which specifies the number of significant figures to be displayed.
 Color getTextBackground()
           
 Component graphic(Object obj)
          Interface for a Simulation element that would be used in a simulation graphical user interface (GUI)
 boolean isEditable()
           
 boolean isInteger()
           
 void removeAllValueChangedListeners()
          Removes all objects that are listening for a value changed event.
 void removeValueChangedListener(DeviceBoxValueChangedListener dbListener)
          Remove an object that is listening for the DeviceBox value to change
 void setBorderBackground(Color color)
           
 void setEditable(boolean b)
           
 void setInteger(boolean b)
          Sets a flag indicating if the value should be displayed as an integer.
 void setLabel(String s)
          Sets the value of a descriptive label using the given string.
 void setLabelPosition(Constants.CompassDirection position)
           
 void setLabelType(DeviceBox.LabelType newLabelType)
          Sets the label type to "border" or "string".
 void setModifier(Modifier m)
          Specifies the modifier that receives the edit.
 void setPrecision(int n)
          Accessor method of the precision, which specifies the number of significant figures to be displayed.
 void setTextBackground(Color color)
           
 void setUnit(Unit u)
          Accessor method to set the physical units of the displayed value.
 void stateChanged(ChangeEvent evt)
          calls doUpdate method.
 
Methods inherited from class etomica.graphics.Device
doAction, getController, getDimension, getPostAction, getPreAction, getUnit, graphic, setController, setPostAction, setPreAction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

label

protected JLabel label
Descriptive text label to be displayed with the value


labelString

protected String labelString

textField

protected JTextField textField
Object for displaying the value as a text field


panel

protected JPanel panel
Displayed panel that holds the label and value (not yet used; meant to implement to make lightweight display)


modifyAction

protected ModifyAction modifyAction
Modifier connecting the slider to the property


precision

protected int precision
Integer specifying the number of significant figures to be displayed. Default is 4.

Constructor Detail

DeviceBox

public DeviceBox()
Method Detail

getEtomicaInfo

public static EtomicaInfo getEtomicaInfo()

stateChanged

public void stateChanged(ChangeEvent evt)
calls doUpdate method. Implementation of ChangeListener interface.

Specified by:
stateChanged in interface ChangeListener

doUpdate

public void doUpdate()
Updates the display of the box with the current value given by the modifier.


setEditable

public void setEditable(boolean b)

isEditable

public boolean isEditable()

setUnit

public void setUnit(Unit u)
Accessor method to set the physical units of the displayed value. Text describing unit is used in label.

Specified by:
setUnit in interface Dimensioned
Overrides:
setUnit in class Device

graphic

public Component graphic(Object obj)
Description copied from interface: GraphicalElement
Interface for a Simulation element that would be used in a simulation graphical user interface (GUI)

Specified by:
graphic in interface GraphicalElement
Specified by:
graphic in class Device
Parameters:
obj - An object that might be used to specify the graphic that the GraphicalElement is to return. In most cases the GraphicalElement ignores this parameter, and it can be set to null.
Returns:
A Component that can be used in the GUI of a graphical simulation
See Also:
Device, Display

getPrecision

public int getPrecision()
Accessor method of the precision, which specifies the number of significant figures to be displayed.


setPrecision

public void setPrecision(int n)
Accessor method of the precision, which specifies the number of significant figures to be displayed.


setInteger

public void setInteger(boolean b)
Sets a flag indicating if the value should be displayed as an integer.


isInteger

public boolean isInteger()

setModifier

public void setModifier(Modifier m)
Specifies the modifier that receives the edit.


getModifier

public Modifier getModifier()
Accessor method for the modifier that receives the edit.


setLabel

public void setLabel(String s)
Sets the value of a descriptive label using the given string.


getLabel

public String getLabel()
Returns:
the current value of the descriptive label.

setLabelType

public void setLabelType(DeviceBox.LabelType newLabelType)
Sets the label type to "border" or "string". With border, the label text is part of the border. With "string", the label is inside the border.


getLabelType

public DeviceBox.LabelType getLabelType()

setLabelPosition

public void setLabelPosition(Constants.CompassDirection position)

setTextBackground

public void setTextBackground(Color color)

getTextBackground

public Color getTextBackground()

setBorderBackground

public void setBorderBackground(Color color)

getLabelPosition

public Constants.CompassDirection getLabelPosition()

addValueChangedListener

public void addValueChangedListener(DeviceBoxValueChangedListener dbListener)
Add an object to be notified when the DeviceBox value to changes


removeValueChangedListener

public void removeValueChangedListener(DeviceBoxValueChangedListener dbListener)
Remove an object that is listening for the DeviceBox value to change


removeAllValueChangedListeners

public void removeAllValueChangedListeners()
Removes all objects that are listening for a value changed event.


deviceBoxValueChanged

public void deviceBoxValueChanged(DeviceBoxValueChangedEvent ev)
Specified by:
deviceBoxValueChanged in interface DeviceBoxValueChangedListener