org.opensha.commons.param.editor
Class AbstractParameterEditor<E>

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.opensha.commons.gui.LabeledBorderPanel
                      extended by org.opensha.commons.param.editor.AbstractParameterEditor<E>
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, ParameterEditor<E>
Direct Known Subclasses:
ArbitrarilyDiscretizedFuncParameterEditor, BooleanParameterEditor, ButtonParameterEditor, ConstrainedCPTParameterEditor, ConstrainedDoubleDiscreteParameterEditor, ConstrainedIntegerDiscreteParameterEditor, ConstrainedStringParameterEditor, DoubleParameterEditor, EnumParameterEditor, FileParameterEditor, IntegerParameterEditor, ParameterListParameterEditor, StringParameterEditor, WeightedListParameterEditor

public abstract class AbstractParameterEditor<E>
extends LabeledBorderPanel
implements ParameterEditor<E>

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected static Border CONST_BORDER
           
static Font DEFAULT_FONT
           
protected static Border ETCHED
           
protected static Border FOCUS_BORDER
           
protected static Dimension LABEL_DIM
           
protected static Dimension LABEL_PANEL_DIM
           
protected static Dimension WIGET_PANEL_DIM
           
 
Fields inherited from class org.opensha.commons.gui.LabeledBorderPanel
addDefault, borderColor, C, D, editorPanel, GBL, jScrollPane1, mainPanel, PARAMETER_LABEL_FONT, PARAMTER_FORE_COLOR, title
 
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
AbstractParameterEditor()
          Default Constructor.
AbstractParameterEditor(Parameter<E> param)
          Create the parameter editor and set the parameter to the given parameter.
 
Method Summary
protected abstract  JComponent buildWidget()
          This will be called by refreshParamEditor to initially build the widget component.
 JComponent getComponent()
           
protected  String getLabelToolTipText()
           
 Parameter<E> getParameter()
          Returns the parameter that is stored internally that this GUI widget is editing
 E getValue()
          Returns the value of the parameter object.
protected  JComponent getWidget()
           
protected  String getWidgetToolTipText()
           
 boolean isFocusEnabled()
          Returns the focusEnabled boolean indicating this is the GUI componet with the current focus
abstract  boolean isParameterSupported(Parameter<E> param)
          Abstract method that allows subclasses to define if a specific parameter is valid.
static JLabel makeSingleConstraintValueLabel(String label)
           
 void refreshParamEditor()
          Called when the parameter has changed independently from the editor.
protected  void removeWidget()
           
 void setEditorBorder(Border border)
           
abstract  void setEnabled(boolean enabled)
           
 void setFocusEnabled(boolean newFocusEnabled)
          Sets the focusEnabled boolean indicating this is the GUI componet with the current focus
 void setParameter(Parameter<E> model)
          Sets the parameter that is stored internally for this GUI widget to edit
 void setValue(E value)
          Set the value in the parameter.
 void unableToSetValue(Object value)
          Needs to be called by subclasses when editable widget field change fails due to constraint problems.
protected  void updateTitle()
           
protected abstract  JComponent updateWidget()
          This is called by refreshParamEditor when the parameters value is changed externally and the widget needs to be updated to reflect the new value.
 
Methods inherited from class org.opensha.commons.gui.LabeledBorderPanel
add, add, add, add, add, getBorderColor, getTitle, initParameterLookAndFeel, jbInit, remove, remove, removeAll, setBorderColor, setLayout, setTitle, setTitleFont, setTitleJustification, setTitlePosition
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
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, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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
 
Methods inherited from interface org.opensha.commons.param.editor.ParameterEditor
isVisible, setVisible
 

Field Detail

LABEL_DIM

protected static final Dimension LABEL_DIM

LABEL_PANEL_DIM

protected static final Dimension LABEL_PANEL_DIM

WIGET_PANEL_DIM

protected static final Dimension WIGET_PANEL_DIM

DEFAULT_FONT

public static Font DEFAULT_FONT

CONST_BORDER

protected static final Border CONST_BORDER

FOCUS_BORDER

protected static final Border FOCUS_BORDER

ETCHED

protected static final Border ETCHED
Constructor Detail

AbstractParameterEditor

public AbstractParameterEditor()
Default Constructor. Sets parameter to null.


AbstractParameterEditor

public AbstractParameterEditor(Parameter<E> param)
Create the parameter editor and set the parameter to the given parameter.

Parameters:
param -
Method Detail

setValue

public final void setValue(E value)
                    throws NullPointerException
Set the value in the parameter. This also calls refreshParamEditor, and should be used to externally both set the parameter value and refresh the parameter.

Specified by:
setValue in interface ParameterEditor<E>
Parameters:
value - the value to set in the current parameter
Throws:
NullPointerException - if the current parameter is null

getValue

public final E getValue()
                 throws NullPointerException
Description copied from interface: ParameterEditor
Returns the value of the parameter object.

Specified by:
getValue in interface ParameterEditor<E>
Throws:
NullPointerException

unableToSetValue

public void unableToSetValue(Object value)
Description copied from interface: ParameterEditor
Needs to be called by subclasses when editable widget field change fails due to constraint problems. Allows rollback to the previous good value.

Specified by:
unableToSetValue in interface ParameterEditor<E>

getParameter

public final Parameter<E> getParameter()
Description copied from interface: ParameterEditor
Returns the parameter that is stored internally that this GUI widget is editing

Specified by:
getParameter in interface ParameterEditor<E>

setParameter

public final void setParameter(Parameter<E> model)
Description copied from interface: ParameterEditor
Sets the parameter that is stored internally for this GUI widget to edit

Specified by:
setParameter in interface ParameterEditor<E>

isParameterSupported

public abstract boolean isParameterSupported(Parameter<E> param)
Abstract method that allows subclasses to define if a specific parameter is valid. An editor could, for example, disallow null parameters or only allow parameters with a specific type of constraint. This is called when setParameter is called.

Parameters:
param -
Returns:

updateTitle

protected void updateTitle()

setFocusEnabled

public final void setFocusEnabled(boolean newFocusEnabled)
Description copied from interface: ParameterEditor
Sets the focusEnabled boolean indicating this is the GUI componet with the current focus

Specified by:
setFocusEnabled in interface ParameterEditor<E>

isFocusEnabled

public final boolean isFocusEnabled()
Description copied from interface: ParameterEditor
Returns the focusEnabled boolean indicating this is the GUI componet with the current focus

Specified by:
isFocusEnabled in interface ParameterEditor<E>

getComponent

public final JComponent getComponent()
Specified by:
getComponent in interface ParameterEditor<E>

refreshParamEditor

public final void refreshParamEditor()
Description copied from interface: ParameterEditor
Called when the parameter has changed independently from the editor. This function needs to be called to to update the GUI component ( text field, picklsit, etc. ) with the new parameter value.

Specified by:
refreshParamEditor in interface ParameterEditor<E>

setEnabled

public abstract void setEnabled(boolean enabled)
Specified by:
setEnabled in interface ParameterEditor<E>
Overrides:
setEnabled in class JComponent

buildWidget

protected abstract JComponent buildWidget()
This will be called by refreshParamEditor to initially build the widget component.

Returns:
widget editing component to be displayed in the editor

updateWidget

protected abstract JComponent updateWidget()
This is called by refreshParamEditor when the parameters value is changed externally and the widget needs to be updated to reflect the new value. If the widget can be simply updated to display/edit the new value, it should do so.

If it needs to be rebuilt, then this can either return null (which will result in a subsequent call to buildWidget), or return the new component.

Returns:
updated component, or new component/null if it needs to be rebuilt

getLabelToolTipText

protected String getLabelToolTipText()
Returns:
tool tip text for the parameter label. can be overridden if constraint specific text needs to be added.

getWidgetToolTipText

protected String getWidgetToolTipText()
Returns:
tool tip text for the parameter. can be overridden if constraint specific text needs to be added.

removeWidget

protected void removeWidget()

getWidget

protected final JComponent getWidget()

setEditorBorder

public void setEditorBorder(Border border)
Specified by:
setEditorBorder in interface ParameterEditor<E>

makeSingleConstraintValueLabel

public static JLabel makeSingleConstraintValueLabel(String label)