Package org.scijava.widget
Class DefaultWidgetModel
- java.lang.Object
-
- org.scijava.AbstractContextual
-
- org.scijava.widget.DefaultWidgetModel
-
- All Implemented Interfaces:
Contextual,WidgetModel
public class DefaultWidgetModel extends AbstractContextual implements WidgetModel
The backing data model for a particularInputWidget.- Author:
- Curtis Rueden
-
-
Constructor Summary
Constructors Constructor Description DefaultWidgetModel(Context context, InputPanel<?,?> inputPanel, Module module, ModuleItem<?> item, List<?> objectPool)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcallback()Executes the callback associated with this widget's associated input.String[]getChoices()Gets the multiple choice list for the module input.ModuleItem<?>getItem()Gets the module input's associated item descriptor.NumbergetMax()Gets the maximum value for the module input.NumbergetMin()Gets the minimum value for the module input.ModulegetModule()Gets the module's associated module instance.List<?>getObjectPool()Gets the available objects for use with the widget.InputPanel<?,?>getPanel()Gets the input panel intended to house the widget.NumbergetSoftMax()Gets the "soft" maximum value for the module input.NumbergetSoftMin()Gets the "soft" minimum value for the module input.NumbergetStepSize()Gets the step size between values for the module input.StringgetText()Gets the input's value rendered as a string.StringgetValidationMessage()Gets the current validation error message for this widget.ObjectgetValue()Gets the current value of the module input.StringgetWidgetLabel()Gets the text to use when labeling this widget.booleanisBoolean()Gets whether the input is a boolean type (i.e.,Booleanorboolean).booleanisCharacter()Gets whether the input is a character type (i.e.,Characterorchar).booleanisInitialized()Gets the widget's initialization state.booleanisMessage()Gets whether the input is a message.booleanisMultipleChoice()Gets whether the input provides a restricted set of choices.booleanisNumber()booleanisStyle(String style)Gets whether the widget is the given style.booleanisText()booleanisType(Class<?> type)Gets whether the input is compatible with the given type.voidsetInitialized(boolean initialized)Toggles the widget's initialization state.voidsetValue(Object value)Sets the current value of the module input.voidupdateValidation()Re-runs this item's validation and updates the stored validation message.-
Methods inherited from class org.scijava.AbstractContextual
context, getContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
-
-
-
-
Constructor Detail
-
DefaultWidgetModel
public DefaultWidgetModel(Context context, InputPanel<?,?> inputPanel, Module module, ModuleItem<?> item, List<?> objectPool)
-
-
Method Detail
-
getPanel
public InputPanel<?,?> getPanel()
Description copied from interface:WidgetModelGets the input panel intended to house the widget.- Specified by:
getPanelin interfaceWidgetModel
-
getModule
public Module getModule()
Description copied from interface:WidgetModelGets the module's associated module instance.- Specified by:
getModulein interfaceWidgetModel
-
getItem
public ModuleItem<?> getItem()
Description copied from interface:WidgetModelGets the module input's associated item descriptor.- Specified by:
getItemin interfaceWidgetModel
-
getObjectPool
public List<?> getObjectPool()
Description copied from interface:WidgetModelGets the available objects for use with the widget. For example,ObjectWidgets typically display a dropdown combo box providing multiple choice selection between these objects.Note that this list does not represent a constraint in allowed widget values, but rather provides a list of possibilities in cases where the realm of values is not defined by the type in some other way.
- Specified by:
getObjectPoolin interfaceWidgetModel- See Also:
ObjectWidget
-
getWidgetLabel
public String getWidgetLabel()
Description copied from interface:WidgetModelGets the text to use when labeling this widget. The linked item's label will be given if available (i.e.,BasicDetails.getLabel()). Otherwise, a capitalized version of the item's name is given (i.e.,Named.getName()).- Specified by:
getWidgetLabelin interfaceWidgetModel
-
isStyle
public boolean isStyle(String style)
Description copied from interface:WidgetModelGets whether the widget is the given style. A widget may have multiple styles separated by commas, so this method is more correct than usingstyle.equals(getItem().getWidgetStyle()).- Specified by:
isStylein interfaceWidgetModel
-
getValue
public Object getValue()
Description copied from interface:WidgetModelGets the current value of the module input.In the case of inputs with a limited set of choices (i.e.,
ChoiceWidgets andObjectWidgets), this method ensures the value is in the set; if not, it returns the first item of the set.- Specified by:
getValuein interfaceWidgetModel
-
setValue
public void setValue(Object value)
Description copied from interface:WidgetModelSets the current value of the module input.- Specified by:
setValuein interfaceWidgetModel
-
callback
public void callback()
Description copied from interface:WidgetModelExecutes the callback associated with this widget's associated input.- Specified by:
callbackin interfaceWidgetModel
-
getMin
public Number getMin()
Description copied from interface:WidgetModelGets the minimum value for the module input.- Specified by:
getMinin interfaceWidgetModel- Returns:
- The minimum value, or null if the type is unbounded.
-
getMax
public Number getMax()
Description copied from interface:WidgetModelGets the maximum value for the module input.- Specified by:
getMaxin interfaceWidgetModel- Returns:
- The maximum value, or null if the type is unbounded.
-
getSoftMin
public Number getSoftMin()
Description copied from interface:WidgetModelGets the "soft" minimum value for the module input.- Specified by:
getSoftMinin interfaceWidgetModel- Returns:
- The "soft" minimum value, or
WidgetModel.getMin()if none. - See Also:
ModuleItem.getSoftMinimum()
-
getSoftMax
public Number getSoftMax()
Description copied from interface:WidgetModelGets the "soft" maximum value for the module input.- Specified by:
getSoftMaxin interfaceWidgetModel- Returns:
- The "soft" maximum value, or
WidgetModel.getMax()if none. - See Also:
ModuleItem.getSoftMaximum()
-
getStepSize
public Number getStepSize()
Description copied from interface:WidgetModelGets the step size between values for the module input.- Specified by:
getStepSizein interfaceWidgetModel- Returns:
- The step size, or 1 by default.
-
getChoices
public String[] getChoices()
Description copied from interface:WidgetModelGets the multiple choice list for the module input.- Specified by:
getChoicesin interfaceWidgetModel- Returns:
- The available choices, or an empty list if not multiple choice.
- See Also:
ChoiceWidget
-
getText
public String getText()
Description copied from interface:WidgetModelGets the input's value rendered as a string.- Specified by:
getTextin interfaceWidgetModel- Returns:
- String representation of the input value, or the empty string if the value is null or the null character ('\0').
-
isMessage
public boolean isMessage()
Description copied from interface:WidgetModelGets whether the input is a message.- Specified by:
isMessagein interfaceWidgetModel- See Also:
ItemVisibility.MESSAGE
-
isText
public boolean isText()
Description copied from interface:WidgetModel- Specified by:
isTextin interfaceWidgetModel
-
isCharacter
public boolean isCharacter()
Description copied from interface:WidgetModelGets whether the input is a character type (i.e.,Characterorchar).- Specified by:
isCharacterin interfaceWidgetModel
-
isNumber
public boolean isNumber()
Description copied from interface:WidgetModel- Specified by:
isNumberin interfaceWidgetModel
-
isBoolean
public boolean isBoolean()
Description copied from interface:WidgetModelGets whether the input is a boolean type (i.e.,Booleanorboolean).- Specified by:
isBooleanin interfaceWidgetModel
-
isMultipleChoice
public boolean isMultipleChoice()
Description copied from interface:WidgetModelGets whether the input provides a restricted set of choices.- Specified by:
isMultipleChoicein interfaceWidgetModel
-
isType
public boolean isType(Class<?> type)
Description copied from interface:WidgetModelGets whether the input is compatible with the given type.- Specified by:
isTypein interfaceWidgetModel
-
setInitialized
public void setInitialized(boolean initialized)
Description copied from interface:WidgetModelToggles the widget's initialization state. An initialized widget can be assumed to be an active part of a containerInputPanel.- Specified by:
setInitializedin interfaceWidgetModel
-
isInitialized
public boolean isInitialized()
Description copied from interface:WidgetModelGets the widget's initialization state. An initialized widget can be assumed to be an active part of a containerInputPanel.- Specified by:
isInitializedin interfaceWidgetModel
-
getValidationMessage
public String getValidationMessage()
Description copied from interface:WidgetModelGets the current validation error message for this widget.- Specified by:
getValidationMessagein interfaceWidgetModel- Returns:
- the error message from the most recent validation run, or
nullif the last validation passed or no validation has been run yet. - See Also:
ModuleItem.validateMessage(org.scijava.module.Module)
-
updateValidation
public void updateValidation()
Description copied from interface:WidgetModelRe-runs this item's validation and updates the stored validation message.This should be called on all widgets whenever any parameter value changes, since a change to one parameter may affect the validity of others.
- Specified by:
updateValidationin interfaceWidgetModel- See Also:
WidgetModel.getValidationMessage()
-
-