Class Options.ComboBoxOption<ValueType extends Options.OptionValue>
- java.lang.Object
-
- com.biomatters.geneious.publicapi.plugin.Options.Option<ValueType,ComponentType>
-
- com.biomatters.geneious.publicapi.plugin.Options.ComboBoxOption<ValueType>
-
- All Implemented Interfaces:
XMLSerializable
- Enclosing class:
- Options
public static class Options.ComboBoxOption<ValueType extends Options.OptionValue> extends Options.Option<ValueType,ComponentType>
An option that provides the user with a list of options in a combo box
-
-
Nested Class Summary
-
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
ComboBoxOption(java.lang.String name, java.lang.String label, java.util.List<? extends ValueType> possibleValues, ValueType defaultValue)
Construct a new ComboBoxOption.protected
ComboBoxOption(java.lang.String name, java.lang.String label, ValueType[] options, ValueType defaultValue)
Construct a new ComboBoxOption.protected
ComboBoxOption(org.jdom.Element e)
Constructor for XML Serialization.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPossibleValue(ValueType newValue)
Add a new value for this option.protected javax.swing.JComboBox
createComponent()
Create a graphical component representing this option.protected ValueType
generateValidValue(ValueType value)
Converts a potentially invalid value into a valid one.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.ValueType
getValueFromString(java.lang.String valueString)
Convert a String into an instance of the object type used by this option.void
setAcceptsUnknownPossibleValues(boolean acceptsUnknownPossibleValues)
Sets whether or not this combo box allowsOptions.Option.setValue(Object)
orOptions.setStringValue(String, String)
to accept values not in the list ofOptions.ComboBoxOrRadioOption.getPossibleOptionValues()
.void
setPossibleValues(java.util.List<? extends ValueType> possibleValues)
Set the values the user can select from in the combo box.void
setPrototypeDisplayValue(ValueType prototypeDisplayValue)
Sets a prototype display value for both the combo box and its drop down list.void
setPrototypeDisplayValueWithVariableHeight(ValueType prototypeDisplayValue)
Sets a prototype display value for the combo box but not its drop down list.protected void
setValueOnComponent(javax.swing.JComboBox component, 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, handleSetEnabled, hasComponentBeenCreated, hideWarningMessage, isAdvanced, isAlwaysUsesDefaultPreferenceLocation, isEnabled, isFillHorizontalSpace, isProOnly, isRestoreDefaultApplies, isRestorePreferenceApplies, isSpanningComponent, isVisible, moveToOptions, 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
-
ComboBoxOption
protected ComboBoxOption(org.jdom.Element e) throws XMLSerializationException
Constructor for XML Serialization. SeeXMLSerializable
- Throws:
XMLSerializationException
-
ComboBoxOption
protected ComboBoxOption(java.lang.String name, java.lang.String label, ValueType[] options, ValueType defaultValue)
Construct a new ComboBoxOption. This is a list of options that are provided to the user graphically as a combo box.- 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"defaultValue
- the default value for this optionoptions
- An array containing all possible values (i.e. all the entries to appear in the combo box)
-
ComboBoxOption
protected ComboBoxOption(java.lang.String name, java.lang.String label, java.util.List<? extends ValueType> possibleValues, ValueType defaultValue)
Construct a new ComboBoxOption. This is a list of options that are provided to the user graphically as a combo box.- 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"defaultValue
- the default value for this optionpossibleValues
- A list containing all possible values (i.e. all the entries to appear in the combo box)
-
-
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.JComboBox<com.biomatters.geneious.publicapi.plugin.Options.OptionValueWrapper>>
- Returns:
- object encoded as a JDOM element
-
setPossibleValues
public void setPossibleValues(java.util.List<? extends ValueType> possibleValues)
Set the values the user can select from in the combo box. If the existing value is not in the list of new possible values, the existing value becomes the first new possible value.- Parameters:
possibleValues
- A list containing all possible values (i.e. all the entries to appear in the combo box)
-
addPossibleValue
public void addPossibleValue(ValueType newValue)
Add a new value for this option. The value will be appended to the end of the ComboBox returned by getComponent() without changing the selection, i.e. the new value will initially not be selected.- Parameters:
newValue
- New option value to add.
-
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.JComboBox<com.biomatters.geneious.publicapi.plugin.Options.OptionValueWrapper>>
- 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 valueString)
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.JComboBox<com.biomatters.geneious.publicapi.plugin.Options.OptionValueWrapper>>
- Parameters:
valueString
- the string representation of the object value- Returns:
- the object value or the default value if the string representation is not valid.
-
createComponent
protected javax.swing.JComboBox 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.JComboBox<com.biomatters.geneious.publicapi.plugin.Options.OptionValueWrapper>>
- Returns:
- a graphical component representing this option. May not be null.
-
setPrototypeDisplayValue
public void setPrototypeDisplayValue(ValueType prototypeDisplayValue)
Sets a prototype display value for both the combo box and its drop down list. This should be used on combo boxes which may contain thousands of items in order to improve performance. On combo boxes with fewer items, it is often desirable for them to be as wide as their widest option, in which case it is preferable to not call this method. For combo boxes where item heights may differ, usesetPrototypeDisplayValueWithVariableHeight(OptionValue)
instead.- Parameters:
prototypeDisplayValue
- the prototype value used for calculating a fixed width and height for the combo box.- Since:
- API 4.202110 (Geneious 2021.1.0)
- See Also:
setPrototypeDisplayValueWithVariableHeight(OptionValue)
-
setPrototypeDisplayValueWithVariableHeight
public void setPrototypeDisplayValueWithVariableHeight(ValueType prototypeDisplayValue)
Sets a prototype display value for the combo box but not its drop down list. It is better to usesetPrototypeDisplayValue(OptionValue)
instead if all items in the combo box will have the same height as each other.- Parameters:
prototypeDisplayValue
- the prototype value used for calculating a fixed width for the combo box.- Since:
- API 4.202120 (Geneious 2021.2.0)
- See Also:
setPrototypeDisplayValueWithVariableHeight(OptionValue)
-
setValueOnComponent
protected void setValueOnComponent(javax.swing.JComboBox component, 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.JComboBox<com.biomatters.geneious.publicapi.plugin.Options.OptionValueWrapper>>
- Parameters:
component
- a component return fromOptions.Option.createComponent()
value
- the value to set.
-
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.JComboBox<com.biomatters.geneious.publicapi.plugin.Options.OptionValueWrapper>>
- Parameters:
value
- the value to determine the validity of- Returns:
- an allowed value.
-
setAcceptsUnknownPossibleValues
public void setAcceptsUnknownPossibleValues(boolean acceptsUnknownPossibleValues)
Sets whether or not this combo box allowsOptions.Option.setValue(Object)
orOptions.setStringValue(String, String)
to accept values not in the list ofOptions.ComboBoxOrRadioOption.getPossibleOptionValues()
. WARNING: Since setStringValue instantiates a new OptionValue, setAcceptsUnknownPossibleValues must not be used on ComboBox Options that use custom OptionValue sub-classes.- Parameters:
acceptsUnknownPossibleValues
- true to accept unknown values and automatically add the to the list ofgetPossibleOptionValues()
.- Since:
- API 4.700 (Geneious 7.0.0)
-
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
-
-