|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
edu.neu.ccs.gui.DisplayPanel
edu.neu.ccs.gui.BasePane
edu.neu.ccs.gui.SliderView
Class SliderView permits the construction of
a slider with pixel-level control of the size of the slider
track. The caller can therefore control the relationship
between the minimum and maximum values represented by the
slider and the physical implementation in pixels. This can
permit users to make slider selections with more accuracy.
The SliderView code was completely rewritten
for version 2.6.0. A few older methods that are now obsolete
have been retained for backward compatibility as is noted in
the comments. This class no longer depends on the Java class
JSlider.
In addition to pixel-level control of the size of the slider,
SliderView offers several advantages over the Java
class JSlider.
JSlider, it
is not the default.SliderView provides what we
believe is a better algorithm for automatically computing
the location of tick marks and labels. Moreover, the
underlying methods for showing tick marks and labels are
public so the caller can manually fine tune these objects
to any degree desired.SliderView includes a text
field that shows the current slider value and may be used
to set that value if desired by the user. The text field
may, however, be omitted from the GUI by setting a certain
constructor parameter appropriately.SliderView provides many constructors
which allow the caller to exercise whatever degree of control
is needed in the slider construction.The constructors for class SliderView allow
the following options:
HORIZONTAL or VERTICAL.Remarks on the minimum and maximum settings and the track pixels setting:
After construction, the caller may add one or more actions that will be performed in any of the following 3 situations:
These actions should normally behave as listeners, that is,
they may query information about the slider from methods such
as getValue and getTrackLocation but
they should normally not call methods that change the slider
state. These actions are intended to be used to control other
objects in the program, especially, in the GUI.
The actions are explicity forbidden to call four methods:
setValue, setTrackLocation,
setViewState, and reset. The
reason for this explict ban is that the four methods invoke
the actions internally and therefore calling them from the
actions will set up a recursive infinite loop.
In unusual situations, the actions may change slider state
via calls to two helper methods setValueHelper
and setTrackLocationHelper which do not invoke
the actions. This facility should be used with great caution
as what happens may be confusing to the interactive user.
Final comment: When the mouse is released after a click or a slide, both the sliding action and the release action will be performed. This policy guarantees that the sliding action is performed at least once between the mouse press on the thumb or track and the subsequent mouse release.
| Nested Class Summary |
| Nested classes inherited from class javax.swing.JPanel |
JPanel.AccessibleJPanel |
| Nested classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
| Nested classes inherited from class java.awt.Container |
Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
protected MouseActionAdapter |
adapter
The mouse adapter of the main component. |
protected Color |
commonColor
The common color for lines, borders, and text labels. |
protected int |
cornerX
The x-coordinate of the top-left corner of the main bounds (as an integer). |
protected int |
cornerY
The y-coordinate of the top-left corner of the main bounds (as an integer). |
protected int |
defaultValue
The default value for this slider. |
protected int |
delta
The difference (maximum - minimum). |
protected boolean |
dragging
The dragging parameter will be set to true if and only if the user is currently dragging the thumb. |
protected double |
f_loc_to_val
The scale factor for locationToValue. |
protected double |
f_val_to_loc
The scale factor for valueToLocation. |
protected PaintableSequence |
labelSequence
The paintable sequence for slider labels. |
protected int |
limit
The track limit, that is, the last valid location on the track along its major direction. |
protected int |
location
The thumb location along the track. |
protected XRect |
mainBounds
Once initialized by freezeBounds(),
this rectangle contains the bounds of the sequence
mainSequence. |
protected PaintableComponent |
mainComponent
The paintable component to hold the main sequence. |
protected PaintableSequence |
mainSequence
The paintable sequence for all of the paintables in the slider GUI including the thumb, the track, the major and minor tick marks, and the labels. |
static int |
MAJOR_TICK_SIZE
The default major tick size: 8. |
protected int |
majorTicks
The major ticks setting. |
protected int |
maximum
The track maximum value. |
protected int |
minimum
The track minimum value. |
static int |
MINIMUM_PIXELS
The minimum permitted pixels value: 20. |
static int |
MINOR_TICK_SIZE
The default minor tick size: 4. |
protected int |
minorTicks
The minor ticks setting. |
protected MouseAction |
mousePressAction
The mouse press action. |
protected MouseAction |
mouseReleaseAction
The mouse release action. |
protected MouseAction |
mouseSlidingAction
The mouse sliding action. |
protected int |
mouseX
The x-coordinate of the current mouse position as adjusted by cornerX to be in the coordinate system of the main sequence. |
protected int |
mouseY
The y-coordinate of the current mouse position as adjusted by cornerY to be in the coordinate system of the main sequence. |
protected PaintableSequence |
objectSequence
The paintable sequence for more general Paintable objects. |
protected Paint |
ordinaryThumbPaint
The ordinary fill paint for the thumb. |
protected int |
orientation
The slider orientation which should be either HORIZONTAL or VERTICAL. |
protected int |
pixels
The track pixels, that is, the size of the track along its major direction. |
static int |
PRESS_ACTION
The ID for a press action event. |
protected ActionSequence |
pressActions
The caller-defined actions performed when the slider thumb is pressed. |
ActionEvent |
pressEvent
The standard event that will be passed to the sequence pressActions when the mouse is pressed in
the active area of the slider (thumb or track). |
protected InputProperties |
properties
The property list for this view object. |
static int |
RELEASE_ACTION
The ID for a release action event. |
protected ActionSequence |
releaseActions
The caller-defined actions performed when the slider thumb is released. |
ActionEvent |
releaseEvent
The standard event that will be passed to the sequence releaseActions when the mouse is released
after being pressed in the active area of the slider
(thumb or track). |
protected Paint |
selectedThumbPaint
The selected fill paint for the thumb. |
protected SimpleAction |
setValueFromValueTFV
The action to set the slider value from the value text field view. |
static int |
SLIDING_ACTION
The ID for a sliding action event. |
protected ActionSequence |
slidingActions
The caller-defined actions performed when the slider thumb is sliding. |
ActionEvent |
slidingEvent
The standard event that will be passed to the sequence slidingActions when the mouse is sliding
after being pressed in the active area of the slider
(thumb or track). |
static Stroke |
STROKE2
Stroke of size 2: BasicStroke(2). |
protected double |
t_loc_to_val
The translation for locationToValue. |
protected double |
t_val_to_loc
The translation for valueToLocation. |
protected ShapePaintable |
thumb
The slider thumb. |
static int |
THUMB_PLUS
The thumb size plus 1. |
static int |
THUMB_SIZE
The thumb size: 9. |
protected Shape |
thumbShape
The slider thumb shape. |
protected PaintableSequence |
tickSequence
The paintable sequence for slider tick marks. |
protected ShapePaintable |
track
The slider track. |
static int |
TRACK_BORDER_THICK
The track border thickness: 2. |
static int |
TRACK_THICK
The track thickness: 6. |
protected ShapePaintable |
trackBorder
The slider track border. |
protected XRect |
trackBorderRect
The slider track border rect. |
protected Paint |
trackPaint
The fill paint for the track. |
protected XRect |
trackRect
The slider track rect. |
protected int |
value
The value of the slider, that is, what will be returned by the call getValue(). |
protected TextFieldView |
valueTFV
The text field view that will echo the current conceptual value of the slider. |
| Fields inherited from class edu.neu.ccs.gui.BasePane |
baseFontSize, buttonFont, DEFAULT_BASE_FONT_SIZE, fieldFont, fontSize, gap, labelFont, largeFieldWidth, mediumFieldWidth, MINIMUM_FONT_SIZE, monospacedFontName, sansserifFontName, serifFontName, smallFieldWidth |
| Fields inherited from class edu.neu.ccs.gui.DisplayPanel |
background, codec, CODEC |
| Fields inherited from class javax.swing.JPanel |
|
| Fields inherited from class javax.swing.JComponent |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Container |
|
| Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface edu.neu.ccs.gui.TypedView |
DATA_TYPE |
| Fields inherited from interface edu.neu.ccs.gui.Displayable |
DEFAULT_VIEW_STATE, VIEW_STATE |
| Fields inherited from interface edu.neu.ccs.util.JPTConstants |
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE |
| Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
| Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
SliderView()
Constructs a default SliderView. |
|
SliderView(int orientation)
Constructs a SliderView with the given
orientation which must be HORIZONTAL or
VERTICAL. |
|
SliderView(int orientation,
int minimum,
int maximum,
int value)
Constructs a SliderView with the given
parameters. |
|
SliderView(int orientation,
int minimum,
int maximum,
int value,
int pixels)
Constructs a SliderView with the given
parameters. |
|
SliderView(int orientation,
int minimum,
int maximum,
int value,
int pixels,
int majorTicks,
int minorTicks)
Constructs a SliderView with the given
parameters. |
|
SliderView(int orientation,
int minimum,
int maximum,
int value,
int pixels,
int majorTicks,
int minorTicks,
Paint ordinaryThumbPaint,
Paint selectedThumbPaint,
Paint trackPaint,
Color commonColor,
boolean showValueTFV)
Constructs a SliderView with the given
parameters. |
|
| Method Summary | |
void |
addPressAction(ActionListener a)
Adds the given action listener to the sequence of actions that is performed when slider is pressed in its active area (thumb or track). |
void |
addReleaseAction(ActionListener a)
Adds the given action listener to the sequence of actions that is performed when slider is released after being pressed in its active area (thumb or track). |
void |
addSlidingAction(ActionListener a)
Adds the given action listener to the sequence of actions that is performed when slider is sliding after being pressed in its active area (thumb or track). |
Stringable |
demandObject()
Returns an XInt object
whose state is set to the value of this slider. |
protected void |
freezeBounds()
This method computes the bounds of the sequence mainSequence, stores those bounds in
mainBounds, and sets the corner data
cornerX and cornerY for
use in computation of mouse coordinates. |
Class |
getDataType()
Returns the XInt class object. |
String |
getDefaultViewState()
Returns a String representation
of the default integer value of this slider. |
InputProperties |
getInputProperties()
Returns the input properties for this view. |
ActionSequence |
getPressActions()
Returns the sequence of press actions. |
ActionSequence |
getReleaseActions()
Returns the sequence of release actions. |
ActionSequence |
getSlidingActions()
Returns the sequence of sliding actions. |
int[] |
getTickValues(int spacing)
Returns the array of slider values that will be used to generate the tick value positions based on the given tick spacing and the internal minimum and maximum. |
int |
getTrackLocation()
Returns the current track location of the slider. |
int |
getValidLocation(int loc)
If the given location is between 0 and limit, then return that location; otherwise return the closest valid location to the given location. |
int |
getValidValue(int val)
If the given value is between minimum and maximum, then return that value; otherwise return the closest valid value to the given value. |
int |
getValue()
Returns the current conceptual value of the slider. |
String |
getViewState()
Returns a String representation
of the current integer value of this slider. |
protected void |
initializeMainSequence()
Appends all items to the main paintable sequence. |
protected void |
initializeMouse()
Initializes the mouse behavior. |
protected void |
initializeNumerics(int orientation,
int minimum,
int maximum,
int value,
int pixels,
int majorTicks,
int minorTicks)
Initializes important numerical parameters. |
protected void |
initializePaints(Paint ordinaryThumbPaint,
Paint selectedThumbPaint,
Paint trackPaint,
Color commonColor)
Performs the paint and color initializations. |
protected void |
initializeThumb()
Performs the initializations for the thumb. |
protected void |
initializeTrack()
Performs the initializations for the track and track border. |
protected void |
initializeValueTFV()
Performs the initializations for the value text field. |
void |
installDefaultLabels()
Installs the default labels provided that the majorTicks value is positive. |
void |
installDefaultMajorTicks()
Installs the default major ticks provided that the majorTicks value is positive. |
void |
installDefaultMinorTicks()
Installs the default minor ticks provided that the minorTicks value is positive. |
void |
installLabels(int[] values,
String[] labels,
int size)
Makes an array of TextPaintable labels
using the given value positions and String labels and
installs the created labels in the internal paintable
sequence that is associated with labels. |
protected void |
installMainPanel(boolean showValueTFV)
Installs the main panel with the slider and optionally the value text field. |
void |
installObjects(Paintable[] objects)
Installs the given Paintable objects as
decorations in the internal paintable sequence that is
associated with objects. |
void |
installStandardLabels()
Installs standard labels following the very simple algorithm available in this class prior to version 2.6.0. |
void |
installStandardTicks()
Installs standard major tick marks following the very simple algorithm available in this class prior to version 2.6.0. |
void |
installTicks(int[] values,
int size)
Installs ticks of the given size at the given value positions. |
int |
locationToValue(int loc)
The affine transform that converts the given location on the track to its best approximation as a value. |
TextPaintable |
makeLabel(int val,
String label,
int size)
Creates the paintable for one label. |
TextPaintable[] |
makeLabels(int[] values,
String[] labels,
int size)
Returns the array of TextPaintable labels
positioned at the given value positions and using the
given String labels. |
String[] |
makeLabelStrings(int[] values)
Returns the array of numeric Strings corresponding to the array of integer values. |
ShapePaintable |
makeTick(int val,
int size)
Creates the paintable for one tick. |
protected void |
mousePress(MouseEvent evt)
The mouse press behavior. |
protected void |
mouseRelease(MouseEvent evt)
The mouse release behavior. |
protected void |
mouseSliding(MouseEvent evt)
The mouse sliding behavior. |
void |
removePressAction(ActionListener a)
Removes the given action listener from the press actions. |
void |
removeReleaseAction(ActionListener a)
Removes the given action listener from the release actions. |
void |
removeSlidingAction(ActionListener a)
Removes the given action listener from the sliding actions. |
Stringable |
requestObject()
Returns an XInt object
whose state is set to the value of this slider. |
void |
reset()
Resets the slider to its default value. |
void |
resetThumb()
The method to reset the location of the slider thumb on the track. |
void |
setCommonColor(Color color)
Set the common color of ticks, borders, and text labels. |
void |
setDefaultViewState(String data)
Sets the default value for this slider to the int value represented
by the given String data. |
void |
setInputProperties(InputProperties p)
Sets the input properties for this view to the provided input properties. |
protected void |
setMouseCoordinates(MouseEvent evt)
Sets mouseX and mouseY
by adjusting the mouse position in the given mouse
event by the corner coordinates. |
void |
setOrdinaryThumbPaint(Paint paint)
Set the ordinary paint for the thumb. |
void |
setPressActions(ActionSequence sequence)
Sets the sequence of press actions. |
void |
setReleaseActions(ActionSequence sequence)
Sets the sequence of release actions. |
void |
setSelectedThumbPaint(Paint paint)
Set the selected paint for the thumb. |
void |
setSlidingActions(ActionSequence sequence)
Sets the sequence of sliding actions. |
void |
setTrackLocation(int loc)
Sets the current track location of the slider in a manner that simulates what happens when the slider is set interactively via the mouse. |
void |
setTrackLocationHelper(int loc)
Sets the current track location of the slider but does not invoke the press, sliding, or release actions. |
void |
setTrackPaint(Paint paint)
Set the paint for the track. |
void |
setValue(int val)
Sets the current conceptual value of the slider in a manner that simulates what happens when the slider is set interactively via the mouse. |
protected void |
setValueFromValueTFV()
The method to update the value using the contents of the value text field view. |
void |
setValueHelper(int val)
Sets the current conceptual value of the slider but does not invoke the press, sliding, or release actions. |
void |
setViewState(String data)
Sets the value for this slider to the int value represented
by the given String data. |
String |
toString()
Returns a String representation
of the current integer value of this slider. |
protected void |
updateValueTFV()
The method to update the value text field view using the current value settings. |
int |
valueToLocation(int val)
The affine transform that converts the given value to its best approximation as a location on the track. |
| Methods inherited from class edu.neu.ccs.gui.BasePane |
getButtonFont, getFieldFont, getFontSize, getGap, getLabelFont, getLargeFieldWidth, getMediumFieldWidth, getSmallFieldWidth, initializeBasePane |
| Methods inherited from class javax.swing.JPanel |
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface edu.neu.ccs.gui.Displayable |
setEnabled |
| Field Detail |
public static final int MINIMUM_PIXELS
20.
public static final int THUMB_SIZE
9.
public static final int THUMB_PLUS
public static final int TRACK_THICK
6.
public static final int TRACK_BORDER_THICK
2.
public static final int MAJOR_TICK_SIZE
8.
public static final int MINOR_TICK_SIZE
4.
public static final Stroke STROKE2
BasicStroke(2).
public static final int PRESS_ACTION
public static final int SLIDING_ACTION
public static final int RELEASE_ACTION
protected Shape thumbShape
The slider thumb shape.
protected ShapePaintable thumb
The slider thumb.
protected Paint ordinaryThumbPaint
The ordinary fill paint for the thumb.
Default: Color.white.
protected Paint selectedThumbPaint
The selected fill paint for the thumb.
Default: Color.red.
protected XRect trackRect
The slider track rect.
protected ShapePaintable track
The slider track.
protected Paint trackPaint
The fill paint for the track.
Default: Color.yellow.
protected XRect trackBorderRect
The slider track border rect.
protected ShapePaintable trackBorder
The slider track border.
protected Color commonColor
The common color for lines, borders, and text labels.
Default: Color.black.
protected final PaintableSequence tickSequence
The paintable sequence for slider tick marks.
An empty sequence is constructed in this class.
If majorTicks and/or minorTicks is positive then the corresponding default methods below will populate this paintable sequence with ticks.
If both majorTicks and minorTicks are zero, then the caller has complete control of what ticks, if any, will be installed.
protected final PaintableSequence labelSequence
The paintable sequence for slider labels.
An empty sequence is constructed in this class.
If majorTicks is positive, then the default labels will be installed at the corresponding ticks.
If majorTicks is zero, then the caller has complete control of what labels, if any, will be installed.
protected final PaintableSequence objectSequence
The paintable sequence for more general
Paintable objects.
The caller has complete control of what objects, if any, will be installed.
protected final PaintableSequence mainSequence
The paintable sequence for all of the paintables in the slider GUI including the thumb, the track, the major and minor tick marks, and the labels.
Populated by initializeSequence().
This sequence contains other sequences as items.
These other sequences are populated by their own
methods.
protected XRect mainBounds
Once initialized by freezeBounds(),
this rectangle contains the bounds of the sequence
mainSequence.
protected int cornerX
protected int cornerY
protected PaintableComponent mainComponent
protected MouseActionAdapter adapter
protected int mouseX
protected int mouseY
protected MouseAction mousePressAction
protected MouseAction mouseSlidingAction
protected MouseAction mouseReleaseAction
protected ActionSequence pressActions
protected ActionSequence slidingActions
protected ActionSequence releaseActions
public final ActionEvent pressEvent
The standard event that will be passed to the sequence
pressActions when the mouse is pressed in
the active area of the slider (thumb or track).
The source is this.
The ID is PRESS_ACTION.
The command string is empty.
public final ActionEvent slidingEvent
The standard event that will be passed to the sequence
slidingActions when the mouse is sliding
after being pressed in the active area of the slider
(thumb or track).
The source is this.
The ID is SLIDING_ACTION.
The command string is empty.
public final ActionEvent releaseEvent
The standard event that will be passed to the sequence
releaseActions when the mouse is released
after being pressed in the active area of the slider
(thumb or track).
The source is this.
The ID is RELEASE_ACTION.
The command string is empty.
protected TextFieldView valueTFV
protected SimpleAction setValueFromValueTFV
protected int orientation
HORIZONTAL or VERTICAL.
protected int minimum
The track minimum value.
If the caller enters a minimum larger than the maximum then that will reverse the order on the slider.
It is required that minimum and maximum be unequal.
protected int maximum
The track maximum value.
If the caller enters a minimum larger than the maximum then that will reverse the order on the slider.
It is required that minimum and maximum be unequal.
protected int delta
protected int value
The value of the slider, that is, what will be returned
by the call getValue().
The value should be between minimum and maximum.
protected int defaultValue
protected int pixels
The track pixels, that is, the size of the track along its major direction.
It is required that pixels be at least
MINIMUM_PIXELS.
protected int limit
The track limit, that is, the last valid location on the track along its major direction.
Equivalent to (pixels - 1).
protected int location
The thumb location along the track.
The location should be between 0 and limit.
protected double f_loc_to_val
locationToValue.
protected double t_loc_to_val
locationToValue.
protected double f_val_to_loc
valueToLocation.
protected double t_val_to_loc
valueToLocation.
protected int majorTicks
The major ticks setting.
If zero, then major ticks and labels will not be shown automatically but may be added by the caller.
protected int minorTicks
The minor ticks setting.
If zero, then minor ticks will not be shown automatically but may be added by the caller.
protected boolean dragging
The dragging parameter will be set to true if and only if the user is currently dragging the thumb. This is only used internally.
protected InputProperties properties
| Constructor Detail |
public SliderView()
Constructs a default SliderView.
The orientation will be horizontal.
The minimum will be 0.
The maximum will be 100.
The initial value will be 50.
The size of the track will be 101 pixels. To control
the track size you must use one of the constructors that
include the pixels parameter.
If this constructor is used, there will be no automatic major ticks, minor ticks, or labels. These may be added by the caller if desired by using the methods of this class.
This constructor will show the text field in which the value of the slider is automatically displayed.
This constructor is included for backward compatibility and to permit experiments since no parameters are required.
public SliderView(int orientation)
Constructs a SliderView with the given
orientation which must be HORIZONTAL or
VERTICAL.
The minimum will be 0.
The maximum will be 100.
The initial value will be 50.
The size of the track will be 101 pixels. To control
the track size you must use one of the constructors that
include the pixels parameter.
If this constructor is used, there will be no automatic major ticks, minor ticks, or labels. These may be added by the caller if desired by using the methods of this class.
This constructor will show the text field in which the value of the slider is automatically displayed.
This constructor is included for backward compatibility.
public SliderView(int orientation,
int minimum,
int maximum,
int value)
Constructs a SliderView with the given
parameters.
The orientation controls the orientation
of the slider in the GUI and should be either
HORIZONTAL or VERTICAL.
The minimum and maximum
parameters determine the minimum and maximum values that
the slider can return via the getValue()
method. It is permissible for these values to be in the
opposite order and in that case the slider will work in
the opposite order.
The value paramter is the initial slider
value, except that, if it is out of range, then it will
be forced into range.
The size of the track will be 101 pixels. To control
the track size you must use one of the constructors that
include the pixels parameter.
If this constructor is used, there will be no automatic major ticks, minor ticks, or labels. These may be added by the caller if desired by using the methods of this class.
This constructor will show the text field in which the value of the slider is automatically displayed.
Throws IllegalArgumentException
if minimum equals maximum
or if pixels is less than MINIMUM_PIXELS.
This constructor is included for backward compatibility.
public SliderView(int orientation,
int minimum,
int maximum,
int value,
int pixels)
Constructs a SliderView with the given
parameters.
The orientation controls the orientation
of the slider in the GUI and should be either
HORIZONTAL or VERTICAL.
The minimum and maximum
parameters determine the minimum and maximum values that
the slider can return via the getValue()
method. It is permissible for these values to be in the
opposite order and in that case the slider will work in
the opposite order.
The value paramter is the initial slider
value, except that, if it is out of range, then it will
be forced into range.
The pixelsparameter is the physical size
of the slider track in the direction of slider motion.
If this constructor is used, there will be no automatic major ticks, minor ticks, or labels. These may be added by the caller if desired by using the methods of this class.
This constructor will show the text field in which the value of the slider is automatically displayed.
Throws IllegalArgumentException
if minimum equals maximum
or if pixels is less than MINIMUM_PIXELS.
public SliderView(int orientation,
int minimum,
int maximum,
int value,
int pixels,
int majorTicks,
int minorTicks)
Constructs a SliderView with the given
parameters.
The orientation controls the orientation
of the slider in the GUI and should be either
HORIZONTAL or VERTICAL.
The minimum and maximum
parameters determine the minimum and maximum values that
the slider can return via the getValue()
method. It is permissible for these values to be in the
opposite order and in that case the slider will work in
the opposite order.
The value paramter is the initial slider
value, except that, if it is out of range, then it will
be forced into range.
The pixelsparameter is the physical size
of the slider track in the direction of slider motion.
The majorTicksparameter controls the
position of the major ticks along the slider and the
associated automatic labels. If this parameter is 0,
then major ticks and labels will not be automatically
drawn. These decorations may be supplied manually by
the caller using methods in the class.
The minorTicksparameter controls the
position of the minor ticks along the slider. If
this parameter is 0, then minor ticks will not be
automatically drawn.
This constructor will show the text field in which the value of the slider is automatically displayed.
Throws IllegalArgumentException
if minimum equals maximum
or if pixels is less than MINIMUM_PIXELS.
public SliderView(int orientation,
int minimum,
int maximum,
int value,
int pixels,
int majorTicks,
int minorTicks,
Paint ordinaryThumbPaint,
Paint selectedThumbPaint,
Paint trackPaint,
Color commonColor,
boolean showValueTFV)
Constructs a SliderView with the given
parameters.
The orientation controls the orientation
of the slider in the GUI and should be either
HORIZONTAL or VERTICAL.
The minimum and maximum
parameters determine the minimum and maximum values that
the slider can return via the getValue()
method. It is permissible for these values to be in the
opposite order and in that case the slider will work in
the opposite order.
The value paramter is the initial slider
value, except that, if it is out of range, then it will
be forced into range.
The pixelsparameter is the physical size
of the slider track in the direction of slider motion.
The majorTicksparameter controls the
position of the major ticks along the slider and the
associated automatic labels. If this parameter is 0,
then major ticks and labels will not be automatically
drawn. These decorations may be supplied manually by
the caller using methods in the class.
The minorTicksparameter controls the
position of the minor ticks along the slider. If
this parameter is 0, then minor ticks will not be
automatically drawn.
This constructor allows the caller to set the various
paints and colors used in the GUI. If a parameter is
null then the default will be used.
The paint and color defaults are:
ordinaryThumbPaint: Color.whiteselectedThumbPaint: Color.redtrackPaint: Color.yellowcommonColor: Color.blackThe common color is used for tick marks, borders, and text.
This constructor will show the text field in which the
value of the slider is automatically displayed if the
showValueTFV parameter is set to true.
Throws IllegalArgumentException
if minimum equals maximum
or if pixels is less than MINIMUM_PIXELS.
| Method Detail |
protected final void initializeNumerics(int orientation,
int minimum,
int maximum,
int value,
int pixels,
int majorTicks,
int minorTicks)
Initializes important numerical parameters.
Initializes the orientation so that it must be
either HORIZONTAL
or VERTICAL.
Initializes the numeric relationships between the conceptual slider data (minimum, maximum, value) and the pixel data (pixels, limit, location).
Initializes the tick settings. Furthermore, if both tick settings are positive, then minorTicks is forced to be a divisor of majorTicks.
Throws IllegalArgumentException
if minimum equals maximum
or if pixels is less than MINIMUM_PIXELS.
protected final void initializePaints(Paint ordinaryThumbPaint,
Paint selectedThumbPaint,
Paint trackPaint,
Color commonColor)
Performs the paint and color initializations.
This method which is called by the most elaborate constructor
allows the caller to set the various paints and colors used in
the GUI. If a parameter is null then the default
will be used.
The paint and color defaults are:
ordinaryThumbPaint: Color.whiteselectedThumbPaint: Color.redtrackPaint: Color.yellowcommonColor: Color.blackThe common color is used by tick marks, borders, and text.
There are individual public methods to reset each particular paint or color after a constructor has been called.
protected final void initializeValueTFV()
protected final void initializeThumb()
protected final void initializeTrack()
Performs the initializations for the track and track border.
Sets the original default bounds to allow for the thumb.
protected final void initializeMainSequence()
Appends all items to the main paintable sequence.
These are in order:
thumbtracktrackBordertickSequence for tickslabelSequence for labelsobjectSequence for general decorationsThis order is the top-to-bottom order of painting. In particular, any general decorations will be below all other objects in the GUI.
protected final void initializeMouse()
protected final void installMainPanel(boolean showValueTFV)
Installs the main panel with the slider and optionally the value text field.
If showValueTFV is true then the text field
in which the value of the slider is automatically displayed
will be installed in the GUI.
public final ShapePaintable makeTick(int val,
int size)
Creates the paintable for one tick.
val - the tick position in value coordinatessize - the tick sizepublic int[] getTickValues(int spacing)
Returns the array of slider values that will be used to generate the tick value positions based on the given tick spacing and the internal minimum and maximum.
For example, if minimum = 1, maximum = 99, and spacing = 10, the following array of values will be returned:
1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 99
Thus, the tick value positions strictly between minimum and maximum are multiples of the spacing.
This algorithm in NOT the one used in the Java
JSlider class.
This method may be overridden in a derived class if a different algorithm is desired. Alternatively, several methods below accept an explicit array of values and a caller may supply whatever values are desired.
Returns an empty array if spacing <= 0;
spacing - the tick spacing in value coordinates
public final void installTicks(int[] values,
int size)
Installs ticks of the given size at the given value positions.
values - the tick positions in value coordinatessize - the tick sizepublic final void installDefaultMajorTicks()
Installs the default major ticks provided that the majorTicks value is positive. Does nothing if majorTicks is zero.
Calls getTickValues to get the
tick positions.
Uses MAJOR_TICK_SIZE for the tick size.
public final void installDefaultMinorTicks()
Installs the default minor ticks provided that the minorTicks value is positive. Does nothing if minorTicks is zero.
Calls getTickValues to get the
tick positions.
Uses MINOR_TICK_SIZE for the tick size.
public final void installStandardTicks()
Installs standard major tick marks following the very simple algorithm available in this class prior to version 2.6.0.
Since the installation of tick marks is now made
automatic in several constructors, this method will
do nothing if either majorTicks or
minorTicks is positive. If both of
these settings are zero, then this method will make
major ticks using a spacing of (1/10) of the
difference between maximum and
minimum. It will not make minor ticks.
This method is retained for backward compatibility but is not recommended for new code.
public final TextPaintable makeLabel(int val,
String label,
int size)
Creates the paintable for one label.
This method allows space for a tick whose size is given by the size parameter. If this parameter is zero, then no allowance is made for a tick.
val - the label position in value coordinateslabel - the label as a Stringsize - the tick sizepublic final String[] makeLabelStrings(int[] values)
Returns the array of numeric Strings corresponding to the array of integer values.
Returns an empty array if the parameter array is
null.
values - the integer values to convert to String
public final TextPaintable[] makeLabels(int[] values,
String[] labels,
int size)
Returns the array of TextPaintable labels
positioned at the given value positions and using the
given String labels.
Returns an empty array if either parameter array is
null.
If the parameter arrays have unequal length, then the minimum of the lengths is used in the construction.
This method allows space for a tick whose size is given by the size parameter. If this parameter is zero, then no allowance is made for a tick.
values - the value positions for the labelslabels - the label data as Stringsize - the tick size
public final void installLabels(int[] values,
String[] labels,
int size)
Makes an array of TextPaintable labels
using the given value positions and String labels and
installs the created labels in the internal paintable
sequence that is associated with labels.
This method allows space for a tick whose size is given by the size parameter. If this parameter is zero, then no allowance is made for a tick.
values - the value positions for the labelslabels - the label data as Stringsize - the tick sizepublic final void installDefaultLabels()
Installs the default labels provided that the majorTicks value is positive. Does nothing if majorTicks is zero.
Calls getTickValues to get the
tick positions.
Then calls makeLabelStrings to
get the String labels.
Assumes MAJOR_TICK_SIZE as the
tick size.
Then calls installLabels.
public void installStandardLabels()
Installs standard labels following the very simple algorithm available in this class prior to version 2.6.0.
Since the installation of labels is now made
automatic in several constructors, this method will
do nothing if either majorTicks or
minorTicks is positive. If both of
these settings are zero, then this method will make
labels using a spacing of (1/10) of the
difference between maximum and
minimum.
This method is retained for backward compatibility but is not recommended for new code.
public final void installObjects(Paintable[] objects)
Installs the given Paintable objects as
decorations in the internal paintable sequence that is
associated with objects.
This method gives the caller complete control of what
Paintable objects are placed as decorations
in the slider GUI and where.
These decorations will be below all other objects in the GUI. It is recommended that the caller experiment carefully with the placement of decorations to avoid visual conflicts.
This method supports rather esoteric needs and will likely not be used by most callers of this class.
objects - the paintable objects to place in the GUIpublic final int getValidValue(int val)
If the given value is between minimum and maximum, then return that value; otherwise return the closest valid value to the given value.
This method is a helper method that does not change the slider state.
val - the value to testpublic final int getValidLocation(int loc)
If the given location is between 0 and limit, then return that location; otherwise return the closest valid location to the given location.
This method is a helper method that does not change the slider state.
loc - the location to testpublic final int valueToLocation(int val)
The affine transform that converts the given value to its best approximation as a location on the track.
This method is a helper method that does not change the slider state.
val - the value to convertpublic final int locationToValue(int loc)
The affine transform that converts the given location on the track to its best approximation as a value.
This method is a helper method that does not change the slider state.
loc - the location to convertpublic final int getValue()
public final void setValue(int val)
Sets the current conceptual value of the slider in a manner that simulates what happens when the slider is set interactively via the mouse.
Uses the following steps:
pressActions.setValueHelper.slidingActions.releaseActions.
val - the value to setpublic final void setValueHelper(int val)
Sets the current conceptual value of the slider but does not invoke the press, sliding, or release actions.
Ensures that the value used is valid.
Updates the corresponding track location to the best approximation for this value.
Calls resetThumb() and
updateValueTFV() to update the GUI.
This method is normally not called directly since it does not invoke the user defined actions. However, to support unusual circumstances, it is available as a public method.
val - the value to setpublic final int getTrackLocation()
public final void setTrackLocation(int loc)
Sets the current track location of the slider in a manner that simulates what happens when the slider is set interactively via the mouse.
Uses the following steps:
pressActions.setLocationHelper.slidingActions.releaseActions.
loc - the location to setpublic final void setTrackLocationHelper(int loc)
Sets the current track location of the slider but does not invoke the press, sliding, or release actions.
Ensures that the location used is valid.
Updates the corresponding conceptual value to the best approximation for this location.
Calls resetThumb() and
updateValueTFV() to update the GUI.
This method is normally not called directly since it does not invoke the user defined actions. However, to support unusual circumstances, it is available as a public method.
loc - the location to setpublic final void resetThumb()
The method to reset the location of the slider thumb on the track.
public final void setOrdinaryThumbPaint(Paint paint)
paint - the paint to setpublic final void setSelectedThumbPaint(Paint paint)
paint - the paint to setpublic final void setTrackPaint(Paint paint)
paint - the paint to setpublic final void setCommonColor(Color color)
public void addPressAction(ActionListener a)
Adds the given action listener to the sequence of actions that is performed when slider is pressed in its active area (thumb or track).
This action will be invoked with the standard event
pressEvent.
This action may query this slider using the methods
getValue() or getTrackLocation()
to decide what to do.
a - the press action listener to addpublic void addSlidingAction(ActionListener a)
Adds the given action listener to the sequence of actions that is performed when slider is sliding after being pressed in its active area (thumb or track).
This action will be invoked with the standard event
slidingEvent.
This action may query this slider using the methods
getValue() or getTrackLocation()
to decide what to do.
a - the sliding action listener to addpublic void addReleaseAction(ActionListener a)
Adds the given action listener to the sequence of actions that is performed when slider is released after being pressed in its active area (thumb or track).
This action will be invoked with the standard event
releaseEvent.
This action may query this slider using the methods
getValue() or getTrackLocation()
to decide what to do.
a - the release action listener to addpublic void removePressAction(ActionListener a)
a - the press action listener to removepublic void removeSlidingAction(ActionListener a)
a - the sliding action listener to removepublic void removeReleaseAction(ActionListener a)
a - the release action listener to removepublic void setPressActions(ActionSequence sequence)
Sets the sequence of press actions.
Clears the press actions if the parameter is
null.
sequence - the new press actionspublic void setSlidingActions(ActionSequence sequence)
Sets the sequence of sliding actions.
Clears the sliding actions if the parameter is
null.
sequence - the new sliding actionspublic void setReleaseActions(ActionSequence sequence)
Sets the sequence of release actions.
Clears the release actions if the parameter is
null.
sequence - the new release actionspublic ActionSequence getPressActions()
public ActionSequence getSlidingActions()
public ActionSequence getReleaseActions()
protected final void freezeBounds()
This method computes the bounds of the sequence
mainSequence, stores those bounds in
mainBounds, and sets the corner data
cornerX and cornerY for
use in computation of mouse coordinates.
This method also sets the default bounds of
mainSequence to the newly computed
mainBounds so that any further change
to the main sequence cannot affect its bounds.
The purpose of this method is make computations with the mouse efficient.
This method will be called when the first mouse interaction with the main component occurs. If it is called again, it will do nothing.
protected final void setMouseCoordinates(MouseEvent evt)
Sets mouseX and mouseY
by adjusting the mouse position in the given mouse
event by the corner coordinates.
evt - the mouse eventprotected final void updateValueTFV()
The method to update the value text field view using the current value settings.
protected final void setValueFromValueTFV()
The method to update the value using the contents of the value text field view.
If the contents of the value text field view
causes a parse exception, the user will be given
a chance to correct the error or cancel. If the
contents is parsable as an integer, then it will
be used in a call to setValue. If
that call determines that the value is invalid
then the value set will be forced into range.
This method implements the action of the same name and the corresponding action is set as a listener for the value text field view.
If successful, this method will reset the thumb and perform a press, sliding, release sequence for the user-defined actions.
protected final void mousePress(MouseEvent evt)
The mouse press behavior.
If the mouse was pressed in the active area of the slider (thumb or track), performs the standard startup behavior for the mouse press:
pressActions
passing the standard event pressEvent.
Before processing, calls freezeBounds
to ensure that the relation between
the event coordinates for the main component and
the mouse coordinates relative to the main sequence
is fixed once and for all.
protected final void mouseSliding(MouseEvent evt)
The mouse sliding behavior.
If the mouse was pressed in the active area of the slider (thumb or track), performs the standard sliding behavior for the subsequent mouse movement:
slidingActions
passing the standard event slidingEvent.
protected final void mouseRelease(MouseEvent evt)
The mouse release behavior.
If the mouse was pressed in the active area of the slider (thumb or track), performs the standard release behavior for the subsequent mouse release:
slidingActions
passing the standard event slidingEvent.releaseActions
passing the standard event releaseEvent.
public Stringable demandObject()
XInt object
whose state is set to the value of this slider.
demandObject in interface TypedViewStringable model objectTypedView.requestObject()public Stringable requestObject()
XInt object
whose state is set to the value of this slider.
requestObject in interface TypedViewStringable model objectTypedView.demandObject()public void setInputProperties(InputProperties p)
TypedViewSets the input properties for this view to the provided input properties.
If the given input properties list is null, the
property list for this view is set to the base property list
containing default property values.
setInputProperties in interface TypedViewp - the new input properties for the viewTypedView.getInputProperties()public InputProperties getInputProperties()
TypedView
getInputProperties in interface TypedViewTypedView.setInputProperties(InputProperties)public Class getDataType()
XInt class object.
getDataType in interface TypedViewpublic void setViewState(String data)
Sets the value for this slider
to the int value represented
by the given String data.
If the String is not parsable to
an int, then this method does
nothing.
If the String is parsable to an
int but that int is not
in range then the value will be forced into range.
setViewState in interface DisplayablesetViewState in class DisplayPaneldata - the new view statepublic String getViewState()
String representation
of the current integer value of this slider.
getViewState in interface DisplayablegetViewState in class DisplayPanelpublic void setDefaultViewState(String data)
Sets the default value for this slider
to the int value represented
by the given String data.
If the String is not parsable to
an int, then this method does
nothing.
If the String is parsable to an
int but that int is not
in range then the value will be forced into range.
setDefaultViewState in interface DisplayablesetDefaultViewState in class DisplayPaneldata - the new default view statepublic String getDefaultViewState()
String representation
of the default integer value of this slider.
getDefaultViewState in interface DisplayablegetDefaultViewState in class DisplayPanelpublic void reset()
reset in interface Displayablereset in class DisplayPanelpublic String toString()
String representation
of the current integer value of this slider.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||