Class Options.RadioOption<ValueType extends Options.OptionValue>
- java.lang.Object
-
- com.biomatters.geneious.publicapi.plugin.Options.Option<ValueType,ComponentType>
-
- com.biomatters.geneious.publicapi.plugin.Options.RadioOption<ValueType>
-
- All Implemented Interfaces:
XMLSerializable
- Enclosing class:
- Options
public static class Options.RadioOption<ValueType extends Options.OptionValue> extends Options.Option<ValueType,ComponentType>
An option that provides the user with a list of radio buttons to select one of
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Options.RadioOption.DependentPosition
-
Nested classes/interfaces inherited from interface com.biomatters.geneious.publicapi.documents.XMLSerializable
XMLSerializable.OldVersionCompatible, XMLSerializable.VersionSupportType
-
-
Field Summary
-
Fields inherited from interface com.biomatters.geneious.publicapi.documents.XMLSerializable
ROOT_ELEMENT_NAME
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RadioOption(java.lang.String name, java.lang.String label, ValueType[] possibleValues, ValueType defaultValue, Options.Alignment alignment)
Construct a new Radio option.protected
RadioOption(org.jdom.Element e)
Constructor for XML Serialization.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDependent(ValueType optionValue, Options.Option dependent, boolean layoutDependentNearRadioButton)
Adds a dependent option that will be enabled when the radio button associated with the OptionValue is selected, and disabled when it is not.void
addDependent(ValueType optionValue, Options dependentOptions, boolean layoutDependentNearRadioButton)
Adds a dependent option that will be enabled when the radio button associated with the OptionValue is selected, and disabled when it is not.void
addLayoutDependent(ValueType optionValue, Options.Option layoutDependent)
Causes the component for the dependent to appear immediately under the radio button associated with the given OptionValue in any panel returned by this RadioOption.protected javax.swing.JPanel
createComponent()
Create a graphical component representing this option.protected ValueType
generateValidValue(ValueType value)
Converts a potentially invalid value into a valid one.Options.Alignment
getAlignment()
java.util.List<ValueType>
getPossibleOptionValues()
Get all possible option values (passed to the constructor or added later usingaddPossibleValue(com.biomatters.geneious.publicapi.plugin.Options.OptionValue)
), including all disabled option values.java.lang.String
getPossibleValues()
Provide a descriptive string representation of possible values of this option.java.util.List<javax.swing.AbstractButton>
getRadioButtons()
Get the list of buttons for this radio option.ValueType
getValueFromString(java.lang.String value)
Convert a String into an instance of the object type used by this option.protected void
handleSetEnabled(javax.swing.JPanel panel, boolean enabled)
Set the enabled state of a component.boolean
moveToOptions(Options newParentOptions, java.lang.String optionalNewLabel, java.lang.String optionalNewName)
Moves this Option from its current parent Options to another parent Options.void
setDependentPosition(Options.RadioOption.DependentPosition radioDependentPosition)
Set the position of all options that are dependent (set withaddDependent
) on this RadioOpion.protected void
setValueOnComponent(javax.swing.JPanel panel, Options.OptionValue value)
Set the value on this component.org.jdom.Element
toXML()
Convert object to a JDOM element.-
Methods inherited from class com.biomatters.geneious.publicapi.plugin.Options.Option
addChangeListener, addChildOptionsDependent, addDependent, addDependentIfNot, addLayoutDependent, fromXML, getComponent, getComponentWithUnitsAndHelpButton, getDefaultValue, getDependents, getDependentsIfNot, getDescription, getDescriptionAndState, getDisplayedLabel, getExtraPersistentInformation, getHelp, getLabel, getName, getNormalizedStringValue, getParentOptions, getValue, getValueAsString, getValueAsString, getVerticalWeight, hasComponentBeenCreated, hideWarningMessage, isAdvanced, isAlwaysUsesDefaultPreferenceLocation, isEnabled, isFillHorizontalSpace, isProOnly, isRestoreDefaultApplies, isRestorePreferenceApplies, isSpanningComponent, isVisible, removeChangeListener, restoreDefault, setAdvanced, setAlwaysUsesDefaultPreferenceLocation, setDefaultValue, setDescription, setDisabledValue, setEnabled, setExtraPersistentInformation, setFillHorizontalSpace, setHelp, setHidden, setHidden, setLabelComponent, setPreferredHeight, setPreferredWidth, setProOnly, setRestoreDefaultApplies, setRestorePreferenceApplies, setShouldSaveValue, setSpanningComponent, setValue, setValue, setValueFromString, setVerticalWeight, setVisible, setWarningMessage, shouldSaveValue, toString
-
-
-
-
Constructor Detail
-
RadioOption
protected RadioOption(org.jdom.Element e) throws XMLSerializationException
Constructor for XML Serialization. SeeXMLSerializable
- Parameters:
e
- The JDOM Element from which the constructed object should be initialised.- Throws:
XMLSerializationException
- if such an exception occurs while initialising the element from XML
-
RadioOption
protected RadioOption(java.lang.String name, java.lang.String label, ValueType[] possibleValues, ValueType defaultValue, Options.Alignment alignment)
Construct a new Radio option. This is a list of options that are provided to the user graphically as a set of radio buttons- Parameters:
name
- the name to be used for referencing this option. For example from scripts or source code which wish to programmatically get or set the value of this option. Names should be in standard Java variable name style eg. "myAwesomeOption".label
- a label describing this option to be displayed to the user. eg. "My Awesome Option"possibleValues
- An array containing all possible values (i.e. all the radio button names)defaultValue
- the default value for this option, not nullalignment
- the alignment of the radio buttons (horizontally or vertically)
-
-
Method Detail
-
toXML
public org.jdom.Element toXML()
Description copied from interface:XMLSerializable
Convert object to a JDOM element. The representation should be complete so thatXMLSerializable.fromXML(org.jdom.Element)
can completely restore the object's representation. It is recommended that the returned element useXMLSerializable.ROOT_ELEMENT_NAME
as its name, in which case it must not define an attribute called "type". In this case, fromXML, will be called with an element whose name may differ from the element return from this function. This recommendation allows a more compact representation of the XML can be stored. This method generally should not be called directly. Instead, you should usually callXMLSerializer.classToXML(String, XMLSerializable)
which calls this method internally. PluginDocument implementations of this method may choose to throw anXMLSerializationException
, enclosed in aRuntimeException
.- Specified by:
toXML
in interfaceXMLSerializable
- Overrides:
toXML
in classOptions.Option<ValueType extends Options.OptionValue,javax.swing.JPanel>
- Returns:
- object encoded as a JDOM element
-
getAlignment
public Options.Alignment getAlignment()
- Returns:
- the alignment parameter passed to the constructor which specifies whether the radio options should be horizontally or vertically aligned
- Since:
- API 4.202000 (Geneious 2020.0.0)
-
getPossibleValues
public java.lang.String getPossibleValues()
Description copied from class:Options.Option
Provide a descriptive string representation of possible values of this option. For example, combo box and radio options should provide a list of all available values. The default implementation returns null. Radio and ComboBox options provideOptions.ComboBoxOrRadioOption.getPossibleOptionValues()
to get possible values as a List of OptionValues.- Overrides:
getPossibleValues
in classOptions.Option<ValueType extends Options.OptionValue,javax.swing.JPanel>
- Returns:
- a descriptive string representation of possible values of this option or null if this option may have any String value.
- See Also:
Options.ComboBoxOrRadioOption.getPossibleOptionValues()
-
getValueFromString
public ValueType getValueFromString(java.lang.String value)
Description copied from class:Options.Option
Convert a String into an instance of the object type used by this option. This method should generally create a new object every time it is invoked. Only disregard this advice if you know what you are doing - e.g. it is safe to maintain an object pool and return the same object more than once if your Option's ValueType is immutable. This method is the inverse ofOptions.Option.getValueAsString(Object)
.- Specified by:
getValueFromString
in classOptions.Option<ValueType extends Options.OptionValue,javax.swing.JPanel>
- Parameters:
value
- the string representation of the object value- Returns:
- the object value or the default value if the string representation is not valid.
-
moveToOptions
public boolean moveToOptions(Options newParentOptions, java.lang.String optionalNewLabel, java.lang.String optionalNewName)
Description copied from class:Options.Option
Moves this Option from its current parent Options to another parent Options. Any option dependencies will be removed. The original parent Options should no longer be used after the move and may be left in an inconsistent state. Options that have already had its component constructed cannot be moved - they will return false- Overrides:
moveToOptions
in classOptions.Option<ValueType extends Options.OptionValue,javax.swing.JPanel>
- Parameters:
newParentOptions
- the Options to move this Option tooptionalNewLabel
- a new label (seeOptions.Option.getLabel()
) to assign to this Option or null to leave it unchanged.optionalNewName
- a new name (seeOptions.Option.getName()
()})to assign to this Option or null to leave it unchanged.- Returns:
- true if this option was successfully moved.
-
createComponent
protected javax.swing.JPanel createComponent()
Description copied from class:Options.Option
Create a graphical component representing this option. The implementation is responsible for making sure that the returned component is initialised to the current value ofOptions.Option.getValue()
. The implementation is also responsible for making sure that the returned component listens to any changes made to itself and reflects those changes in the value of this option using theOptions.Option.setValue(Object)
method. This method will only be called once for each instance of an Option. After it has been called, getComponent() will return a cached copy of it.- Specified by:
createComponent
in classOptions.Option<ValueType extends Options.OptionValue,javax.swing.JPanel>
- Returns:
- a graphical component representing this option. May not be null.
-
generateValidValue
protected ValueType generateValidValue(ValueType value)
Description copied from class:Options.Option
Converts a potentially invalid value into a valid one. The default implementation always returnscandidateValue
, implying that all values are valid. Subclasses can override this method e.g. to clamp integer values to a certain interval, or to ensure that a disabled radio item cannot be selected. If a new value is determined to be invalid, a subclass may choose to return the current value (Options.Option.getValue()
or any arbitrary other value. IMPORTANT: subclasses which implement this method should callOptions.Option.setDefaultValue(Object)
at the end of their constructor(s)- Overrides:
generateValidValue
in classOptions.Option<ValueType extends Options.OptionValue,javax.swing.JPanel>
- Parameters:
value
- the value to determine the validity of- Returns:
- an allowed value.
-
setValueOnComponent
protected void setValueOnComponent(javax.swing.JPanel panel, Options.OptionValue value)
Description copied from class:Options.Option
Set the value on this component.- Specified by:
setValueOnComponent
in classOptions.Option<ValueType extends Options.OptionValue,javax.swing.JPanel>
- Parameters:
panel
- a component return fromOptions.Option.createComponent()
value
- the value to set.
-
handleSetEnabled
protected void handleSetEnabled(javax.swing.JPanel panel, boolean enabled)
Description copied from class:Options.Option
Set the enabled state of a component. A sub-class need only override this if it needs to do something more complicated than calling setEnabled on this component- Overrides:
handleSetEnabled
in classOptions.Option<ValueType extends Options.OptionValue,javax.swing.JPanel>
- Parameters:
panel
- the component to set the enabled state ofenabled
- true if it should be enabled
-
getRadioButtons
public final java.util.List<javax.swing.AbstractButton> getRadioButtons()
Get the list of buttons for this radio option. These can be layed out in a new panel.- Returns:
- list of radio buttons
-
addDependent
public void addDependent(ValueType optionValue, Options.Option dependent, boolean layoutDependentNearRadioButton)
Adds a dependent option that will be enabled when the radio button associated with the OptionValue is selected, and disabled when it is not. Optionally (by settinglayoutDependentNearRadioButton
to true), the component for the dependent can appear immediately under the radio button associated with the given OptionValue in any panel returned by this RadioOption. UsesetDependentPosition(com.biomatters.geneious.publicapi.plugin.Options.RadioOption.DependentPosition)
to specify the exact dependent positioning in this case. To just layout the component next to this option value without changing its enabled state, useaddLayoutDependent(OptionValue, Option)
- Parameters:
optionValue
- The OptionValue that will be the parent of the dependent Optiondependent
- the option whose enabled state (and optionally its position) will changelayoutDependentNearRadioButton
- make the component for the dependent can appear immediately under or to the right (seesetDependentPosition
) of the radio button associated with the given OptionValue in any panel returned by this RadioOption. Using false for this parameter means that only the enabled state of the dependent is affected.
-
addLayoutDependent
public void addLayoutDependent(ValueType optionValue, Options.Option layoutDependent)
Causes the component for the dependent to appear immediately under the radio button associated with the given OptionValue in any panel returned by this RadioOption. UsesetDependentPosition(com.biomatters.geneious.publicapi.plugin.Options.RadioOption.DependentPosition)
to specify the exact dependent positioning in this case.- Parameters:
optionValue
- the option value to position this other option next tolayoutDependent
- the option to layout next to this option value- Since:
- API 4.902 (Geneious 9.0.2)
- See Also:
addDependent(OptionValue, Option, boolean)
-
addDependent
public void addDependent(ValueType optionValue, Options dependentOptions, boolean layoutDependentNearRadioButton)
Adds a dependent option that will be enabled when the radio button associated with the OptionValue is selected, and disabled when it is not. Optionally (by settinglayoutDependentNearRadioButton
to true), the component for the dependent can appear immediately under the radio button associated with the given OptionValue in any panel returned by this RadioOption. UsesetDependentPosition(com.biomatters.geneious.publicapi.plugin.Options.RadioOption.DependentPosition)
to specify the exact dependent positioning in this case.- Parameters:
optionValue
- The OptionValue that will be the parent of the dependent OptiondependentOptions
- the option whose enabled state (and optionally its position) will changelayoutDependentNearRadioButton
- make the component for the dependent can appear immediately under or to the right (seesetDependentPosition
) of the radio button associated with the given OptionValue in any panel returned by this RadioOption. Using false for this parameter means that only the enabled state of the dependent is affected.
-
setDependentPosition
public void setDependentPosition(Options.RadioOption.DependentPosition radioDependentPosition)
Set the position of all options that are dependent (set withaddDependent
) on this RadioOpion.- Parameters:
radioDependentPosition
- the position to set. SeeOptions.RadioOption.DependentPosition.BELOW
andOptions.RadioOption.DependentPosition.RIGHT
.
-
getPossibleOptionValues
public java.util.List<ValueType> getPossibleOptionValues()
Get all possible option values (passed to the constructor or added later usingaddPossibleValue(com.biomatters.geneious.publicapi.plugin.Options.OptionValue)
), including all disabled option values.- Returns:
- all possible option values
-
-