Class SliderSpecifier
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.config.SpecifierPanel<java.lang.Double>
-
- uk.ac.starlink.ttools.plot2.config.SliderSpecifier
-
- All Implemented Interfaces:
Specifier<java.lang.Double>
public class SliderSpecifier extends SpecifierPanel<java.lang.Double>
Double value specifier that uses a slider to choose a value in the range betwen two given values. Linear and logarithmic scaling are available. The slider can optionally be accompanied by a text entry field.- Since:
- 13 Jan 2014
- Author:
- Mark Taylor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SliderSpecifier.TextOption
Specifies whether and how a text display field should appear alongside the slider for user entry.
-
Constructor Summary
Constructors Constructor Description SliderSpecifier(double lo, double hi, boolean log, double reset)
Constructs a specifier with minimal options.SliderSpecifier(double lo, double hi, boolean log, double reset, boolean flip, SliderSpecifier.TextOption txtOpt)
Constructs a specifier with all options.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.swing.JComponent
createComponent()
Abstract method called lazily duringgetComponent
to obtain the graphical component used by this specifier.javax.swing.JSlider
getSlider()
Returns the slider component used by this specifier.double
getSliderValue()
Returns the value currently represented by the slider, regardless of whether the slider or text field is currently active.java.lang.Double
getSpecifiedValue()
Returns the typed value currently specified by the graphical component.javax.swing.JTextField
getTextField()
Returns the text entry component used by this specifier.double
getTextValue()
Returns the value currently entered in the text field, regardless of whether the text field or slider is currently active.boolean
isSliderActive()
Indicates whether the slider or the text field is the currently selected input component.void
setSliderActive(boolean isActive)
Configures programmatically whether the slider or the text field is the currently selected input component.void
setSpecifiedValue(java.lang.Double dValue)
Sets the typed value represented by the graphical component.void
submitReport(ReportMap report)
Accepts information about a completed plot that was drawn with input from this specifier.java.lang.String
valueToString(double value)
Formats a value provided by this specifier for display.-
Methods inherited from class uk.ac.starlink.ttools.plot2.config.SpecifierPanel
addActionListener, fireAction, getActionForwarder, getChangeForwarder, getComponent, isXFill, removeActionListener
-
-
-
-
Constructor Detail
-
SliderSpecifier
public SliderSpecifier(double lo, double hi, boolean log, double reset)
Constructs a specifier with minimal options.- Parameters:
lo
- slider lower boundhi
- slider upper boundlog
- true for logarithmic slider scale, false for linearreset
- value reset button resets to, or NaN for no reset
-
SliderSpecifier
public SliderSpecifier(double lo, double hi, boolean log, double reset, boolean flip, SliderSpecifier.TextOption txtOpt)
Constructs a specifier with all options.- Parameters:
lo
- slider lower boundhi
- slider upper boundlog
- true for logarithmic slider scale, false for linearreset
- value reset button resets to, or NaN for no resetflip
- true to make slider values increase right to lefttxtOpt
- configures whether a text field should appear; null means NONE
-
-
Method Detail
-
createComponent
protected javax.swing.JComponent createComponent()
Description copied from class:SpecifierPanel
Abstract method called lazily duringgetComponent
to obtain the graphical component used by this specifier. It will be called a maximum of once. It is not necessary that the component actually be created in this method, for instance it may be created at construction time if that's more convenient.- Specified by:
createComponent
in classSpecifierPanel<java.lang.Double>
- Returns:
- graphical component
-
getSpecifiedValue
public java.lang.Double getSpecifiedValue()
Description copied from interface:Specifier
Returns the typed value currently specified by the graphical component.- Returns:
- specified value
-
setSpecifiedValue
public void setSpecifiedValue(java.lang.Double dValue)
Description copied from interface:Specifier
Sets the typed value represented by the graphical component. Calling this method ought to make it clear to the user what value it is set at; in any case a subsequent call ofgetSpecifiedValue
should yield the same result.However if a value is set which is of the correct type but cannot be represented by this specifier, results are unpredictable.
- Parameters:
dValue
- new value
-
submitReport
public void submitReport(ReportMap report)
Description copied from interface:Specifier
Accepts information about a completed plot that was drawn with input from this specifier. In many cases, the implementation of this method will be a no-op, but it gives this object a chance to update its state or its component's appearance based on the way the plot was actually drawn, which may provide information not otherwise available to this object.- Parameters:
report
- report of a plot partially specified by this object
-
isSliderActive
public boolean isSliderActive()
Indicates whether the slider or the text field is the currently selected input component.- Returns:
- true for slider, false for text field
-
setSliderActive
public void setSliderActive(boolean isActive)
Configures programmatically whether the slider or the text field is the currently selected input component.- Parameters:
isActive
- true for slider, false for text field
-
getTextValue
public double getTextValue()
Returns the value currently entered in the text field, regardless of whether the text field or slider is currently active.- Returns:
- text field value as a double, may be NaN
-
getSliderValue
public double getSliderValue()
Returns the value currently represented by the slider, regardless of whether the slider or text field is currently active.- Returns:
- slider value
-
getSlider
public javax.swing.JSlider getSlider()
Returns the slider component used by this specifier.- Returns:
- slider
-
getTextField
public javax.swing.JTextField getTextField()
Returns the text entry component used by this specifier.- Returns:
- text field
-
valueToString
public java.lang.String valueToString(double value)
Formats a value provided by this specifier for display. The default implementation does something obvious, but may be overridden by subclasses.- Parameters:
value
- double value as provided by this specifier- Returns:
- string representation for preseentation to the user
-
-