sim.util.gui
Class PropertyField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by sim.util.gui.PropertyField
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class PropertyField
extends javax.swing.JComponent

A simple class designed to allow the user to modify a property in the form of a string, number, boolean value, or option. PropertyField lets you control the values which the user sets by subclassing the class and overriding the newValue(val) method filters all newly user-set values and "corrects" them. Programmatically set values (by calling setValue(...)) are not filtered through newValue by default. If you need to filter, you should do setValue(newValue(val));

You can optionally specify how the string will be presented to the user: as a text field, as a text field with a slider (requiring certain numerical constraints on the text field), as a list of options (also requiring certain numerical constraints), as a check box (requiring the string to hold boolean values ("true" or "false"), or as a read-only field with a button to press (which in turn calls the viewProperty() method, which you may override).

The specifics about how to present the user with these options is described in the constructor documentation and in the documentation for setValues(...).

PropertyFields can also be set to be either read-only or read/write by the user. When the user edits a read/write PropertyField, the text field changes color. If the user then presses RETURN, the result is submitted to newValue(...). If the user presses ESCAPE, the result is cancelled and reset.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int SHOW_CHECKBOX
           
static int SHOW_LIST
           
static int SHOW_SLIDER
           
static int SHOW_TEXTFIELD
           
static int SHOW_VIEWBUTTON
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PropertyField()
          Constructs a PropertyField as just a writeable, empty text field.
PropertyField(java.lang.String initialValue)
          Constructs a PropertyField as a writeable text field with the provided initial value.
PropertyField(java.lang.String initialValue, boolean isReadWrite)
          Constructs a PropertyField as a text field with the provided initial value, either writeable or not.
PropertyField(java.lang.String label, java.lang.String initialValue)
          Constructs a labelled PropertyField as a writeable text field with the provided initial value.
PropertyField(java.lang.String label, java.lang.String initialValue, boolean isReadWrite)
          Constructs a labelled PropertyField as a text field with the provided initial value, either writeable or not.
PropertyField(java.lang.String label, java.lang.String initialValue, boolean isReadWrite, java.lang.Object domain, int show)
          Constructs a PropertyField with an optional label, an initial value, a "writeable" flag, an optional domain (for the slider and list options), and a display form (checkboxes, view buttons, text fields, sliders, or lists).
 
Method Summary
 java.awt.Color getEditedColor()
           
 javax.swing.JTextField getField()
           
 java.awt.Dimension getMinimumSize()
           
 java.awt.Dimension getPreferredSize()
           
 java.lang.String getValue()
          Returns the most recently set value.
 java.lang.String newValue(java.lang.String newValue)
          Override this to be informed when a new value has been set.
 void setEditedColor(java.awt.Color c)
           
 void setEnabled(boolean b)
           
 void setToolTipText(java.lang.String text)
           
 void setValue(java.lang.String val)
          Sets the value, not filtering it through newValue(val) first.
 void submit()
          Commits to the current setting of the propertyField, filtering it through newValue.
 void update()
          Reverts the property field to its previous string value WITHOUT calling newValue()
 void viewProperty()
          Override this to be informed when a property is to be viewed in its own inspector because the user pressed the "view" button.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SHOW_CHECKBOX

public static final int SHOW_CHECKBOX
See Also:
Constant Field Values

SHOW_TEXTFIELD

public static final int SHOW_TEXTFIELD
See Also:
Constant Field Values

SHOW_VIEWBUTTON

public static final int SHOW_VIEWBUTTON
See Also:
Constant Field Values

SHOW_SLIDER

public static final int SHOW_SLIDER
See Also:
Constant Field Values

SHOW_LIST

public static final int SHOW_LIST
See Also:
Constant Field Values
Constructor Detail

PropertyField

public PropertyField()
Constructs a PropertyField as just a writeable, empty text field.


PropertyField

public PropertyField(java.lang.String initialValue)
Constructs a PropertyField as a writeable text field with the provided initial value.


PropertyField

public PropertyField(java.lang.String initialValue,
                     boolean isReadWrite)
Constructs a PropertyField as a text field with the provided initial value, either writeable or not.


PropertyField

public PropertyField(java.lang.String label,
                     java.lang.String initialValue)
Constructs a labelled PropertyField as a writeable text field with the provided initial value.


PropertyField

public PropertyField(java.lang.String label,
                     java.lang.String initialValue,
                     boolean isReadWrite)
Constructs a labelled PropertyField as a text field with the provided initial value, either writeable or not.


PropertyField

public PropertyField(java.lang.String label,
                     java.lang.String initialValue,
                     boolean isReadWrite,
                     java.lang.Object domain,
                     int show)
Constructs a PropertyField with an optional label, an initial value, a "writeable" flag, an optional domain (for the slider and list options), and a display form (checkboxes, view buttons, text fields, sliders, or lists).
Method Detail

getField

public javax.swing.JTextField getField()

setEditedColor

public void setEditedColor(java.awt.Color c)

getEditedColor

public java.awt.Color getEditedColor()

submit

public void submit()
Commits to the current setting of the propertyField, filtering it through newValue.


update

public void update()
Reverts the property field to its previous string value WITHOUT calling newValue()


setValue

public void setValue(java.lang.String val)
Sets the value, not filtering it through newValue(val) first.


getValue

public java.lang.String getValue()
Returns the most recently set value.


newValue

public java.lang.String newValue(java.lang.String newValue)
Override this to be informed when a new value has been set. The return value should be the value you want the display to show instead.


viewProperty

public void viewProperty()
Override this to be informed when a property is to be viewed in its own inspector because the user pressed the "view" button.


setToolTipText

public void setToolTipText(java.lang.String text)
Overrides:
setToolTipText in class javax.swing.JComponent

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overrides:
getMinimumSize in class javax.swing.JComponent

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent

setEnabled

public void setEnabled(boolean b)
Overrides:
setEnabled in class javax.swing.JComponent