public class NumberWidget extends SimpleWidget implements javax.swing.event.ChangeListener
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
label
The label for the widget
|
static javax.swing.Icon |
WIDGET_ICON
The icon for the widget
|
name
Constructor and Description |
---|
NumberWidget(java.lang.String name)
Creates a new instance of a number chooser widget
(this specific constructor is used by the PCD editor ONLY!).
|
NumberWidget(java.lang.String name,
java.lang.String label,
int min,
int max,
int value)
Creates a new instance of a number chooser widget
(or simply, number widget)
|
Modifier and Type | Method and Description |
---|---|
void |
display(java.awt.Container dest,
CloseableWindow window)
Displays the current widget within the container 'dest'.
|
java.awt.Component |
displayEdit(javax.swing.JFrame mainFrame)
Displays the current widget in an editor panel.
|
java.awt.event.ActionListener |
editWindow(java.awt.Container dest)
Populates a container with the component objects
necessary for editing the current widget's properties.
|
WidgetInstance |
getInstance()
Creates a new widget instance of the widget
A widget instance is an object that stores the value of a widget past
after the widget has been closed.
|
void |
pcdOut(int scope,
java.lang.Appendable out)
Writes the BioPCD representation of the menu widget to a writer object
(see BioLegato's BioPCD editor for more details)
|
void |
setValue(java.lang.String newValue)
Changes the current value for the widget.
|
void |
stateChanged(javax.swing.event.ChangeEvent e)
Handles synchronization between the slider and the spinner.
|
editImage, recursiveDraw
protected java.lang.String label
public static final javax.swing.Icon WIDGET_ICON
public NumberWidget(java.lang.String name)
name
- the PCD variable name (this name can be referenced
in the command using the % symbol; for example,
if the name value was set to "A", the value of this
widget could be accessed by using %A% (lower or
upper-case) within the PCD menu command string.public NumberWidget(java.lang.String name, java.lang.String label, int min, int max, int value)
name
- the PCD variable name (this name can be referenced
in the command using the % symbol; for example,
if the name value was set to "A", the value of this
widget could be accessed by using %A% (lower or
upper-case) within the PCD menu command string.label
- the label to display representing the parameter to be
manipulated by the number widget. This is the text the
user will see to the left of the widget in any BioLegato
menu windows.min
- the minimum numerical value selectable by the number widgetmax
- the maximum numerical value selectable by the number widgetvalue
- the default number to be selected by the number widget
(this is the value that the widget is initialized with).
Please note that this widget remembers whatever value the
user last selected; therefore, the default value only
applies when the window is first opened, afterwards, the
widget will default to whatever value the user previously
selected.public void stateChanged(javax.swing.event.ChangeEvent e)
stateChanged
in interface javax.swing.event.ChangeListener
e
- used to determine which widget was changed.public void display(java.awt.Container dest, CloseableWindow window)
display
in interface Widget
dest
- the destination Container to display the widget. Note that
this will almost definitely be different from the window
parameter, and in most cases, should be a JPanel object.window
- the parent window to communicate with. The communication
involved is supposed to be limited to just using 'window'
to create modal dialog boxes when necessary (for example,
the AbstractFileChooser's "Browse" file choice dialog box).
Please note that this field may be null!! (e.g. displaying
the current state of the widget in the editor canvas)public WidgetInstance getInstance()
getInstance
in interface Widget
public java.awt.Component displayEdit(javax.swing.JFrame mainFrame)
displayEdit
in interface Widget
displayEdit
in class SimpleWidget
mainFrame
- a JFrame object for adding modality to any dialog
boxes, which are created by this function.public java.awt.event.ActionListener editWindow(java.awt.Container dest)
Populates a container with the component objects necessary for editing the current widget's properties.
This method takes the Container 'dest' and populates it with components which can change the properties of the current widget. In other words, this is the window which pops up when you double click on a widget in the PCD editor. For instance, if you place a text box in a PCD menu, then double click on it, you can set its internal PCD 'name' and default value, among other things.
This method returns an action listener, which is called when the widget should update. The reason for this is class extension. To allow sub-classes to use the same method ('editWindow') with only one button, and without re-writing code, an ActionListener object can be passed downwards to the child class. The child class may add code to call its parent class's ActionListener.
Please note that the ActionListener will likely be used by a calling method to create an "Update" button.
editWindow
in class SimpleWidget
dest
- the destination Container object; this is where the
'editWindow' function will add add all of the Components
necessary for editing the Widget parameters (NOTE: this
class implements the Widget interface).public void pcdOut(int scope, java.lang.Appendable out) throws java.io.IOException
pcdOut
in interface Widget
pcdOut
in class SimpleWidget
scope
- the level of scope to write the menu widget. In the case
of PCD, the scope of each line is indicated by the number
of spaced preceding the line. Every 4 spaces count as
one level of scope (any number not divisible by 4 is
considered an error), thus if a line is preceded by 4
spaces, its scope level is considered to be 1out
- the Appendable object to output the BioPCD code.java.io.IOException
public void setValue(java.lang.String newValue)
Changes the current value for the widget. This is used to ensure that any Components that the widget creates for a PCD menu will update the widget object itself. This is important because the widget is expected to store the last value it was set to after a window was closed.
For example, if you opened a PCD menu and set a NumberWidget to 10, and then closed the window, if you reopen the window the NumberWidget should still be 10 (regardless of any default values).
Copyright © 2008-2022 University of Manitoba.