com.google.gwt.widgetideas.client
Class SliderBar

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Panel
              extended by com.google.gwt.user.client.ui.SimplePanel
                  extended by com.google.gwt.user.client.ui.FocusPanel
                      extended by com.google.gwt.widgetideas.client.SliderBar
All Implemented Interfaces:
com.google.gwt.user.client.EventListener, com.google.gwt.user.client.ui.HasFocus, com.google.gwt.user.client.ui.HasWidgets, com.google.gwt.user.client.ui.SourcesChangeEvents, com.google.gwt.user.client.ui.SourcesClickEvents, com.google.gwt.user.client.ui.SourcesFocusEvents, com.google.gwt.user.client.ui.SourcesKeyboardEvents, com.google.gwt.user.client.ui.SourcesMouseEvents, com.google.gwt.user.client.ui.SourcesMouseWheelEvents, ResizableWidget

public class SliderBar
extends com.google.gwt.user.client.ui.FocusPanel
implements ResizableWidget, com.google.gwt.user.client.ui.SourcesChangeEvents

A widget that allows the user to select a value within a range of possible values using a sliding bar that responds to mouse events.

Keyboard Events

SliderBar listens for the following key events. Holding down a key will repeat the action until the key is released.

CSS Style Rules


Nested Class Summary
static interface SliderBar.LabelFormatter
          A formatter used to format the labels displayed in the widget.
static interface SliderBar.SliderBarImages
          An ImageBundle that provides images for SliderBar.
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
SliderBar(double minValue, double maxValue)
          Create a slider bar.
SliderBar(double minValue, double maxValue, SliderBar.LabelFormatter labelFormatter)
          Create a slider bar.
SliderBar(double minValue, double maxValue, SliderBar.LabelFormatter labelFormatter, SliderBar.SliderBarImages images)
          Create a slider bar.
 
Method Summary
 void addChangeListener(com.google.gwt.user.client.ui.ChangeListener listener)
          Add a change listener to this SliderBar.
protected  java.lang.String formatLabel(double value)
          Format the label to display above the ticks Override this method in a subclass to customize the format.
 double getCurrentValue()
          Return the current value.
protected  double getKnobPercent()
          Get the percentage of the knob's position relative to the size of the line.
 SliderBar.LabelFormatter getLabelFormatter()
          Return the label formatter.
 double getMaxValue()
          Return the max value.
 double getMinValue()
          Return the minimum value.
 int getNumLabels()
          Return the number of labels.
 int getNumTicks()
          Return the number of ticks.
 double getStepSize()
          Return the step size.
 double getTotalRange()
          Return the total range between the minimum and maximum values.
 void onBrowserEvent(com.google.gwt.user.client.Event event)
          Listen for events that will move the knob.
protected  void onLoad()
          This method is called immediately after a widget becomes attached to the browser's document.
 void onResize(int width, int height)
          This method is called when the dimensions of the parent element change.
 void redraw()
          Redraw the progress bar when something changes the layout.
 void removeChangeListener(com.google.gwt.user.client.ui.ChangeListener listener)
          Remove a change listener from this SliderBar.
 void setCurrentValue(double curValue)
          Set the current value and fire the onValueChange event.
 void setCurrentValue(double curValue, boolean fireEvent)
          Set the current value and optionally fire the onValueChange event.
 void setLabelFormatter(SliderBar.LabelFormatter labelFormatter)
          Set the label formatter.
 void setMaxValue(double maxValue)
          Set the max value.
 void setMinValue(double minValue)
          Set the minimum value.
 void setNumLabels(int numLabels)
          Set the number of labels to show on the line.
 void setNumTicks(int numTicks)
          Set the number of ticks to show on the line.
 void setStepSize(double stepSize)
          Set the step size.
 void shiftLeft(int numSteps)
          Shift to the left (smaller value).
 void shiftRight(int numSteps)
          Shift to the right (greater value).
 
Methods inherited from class com.google.gwt.user.client.ui.FocusPanel
addClickListener, addFocusListener, addKeyboardListener, addMouseListener, addMouseWheelListener, getTabIndex, removeClickListener, removeFocusListener, removeKeyboardListener, removeMouseListener, removeMouseWheelListener, setAccessKey, setFocus, setTabIndex
 
Methods inherited from class com.google.gwt.user.client.ui.SimplePanel
add, getContainerElement, getWidget, iterator, remove, setWidget
 
Methods inherited from class com.google.gwt.user.client.ui.Panel
adopt, adopt, clear, disown, doAttachChildren, doDetachChildren, onUnload, orphan
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
getParent, isAttached, onAttach, onDetach, removeFromParent, setElement
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.widgetideas.client.ResizableWidget
getElement, isAttached
 

Constructor Detail

SliderBar

public SliderBar(double minValue,
                 double maxValue)
Create a slider bar.

Parameters:
minValue - the minimum value in the range
maxValue - the maximum value in the range

SliderBar

public SliderBar(double minValue,
                 double maxValue,
                 SliderBar.LabelFormatter labelFormatter)
Create a slider bar.

Parameters:
minValue - the minimum value in the range
maxValue - the maximum value in the range
labelFormatter - the label formatter

SliderBar

public SliderBar(double minValue,
                 double maxValue,
                 SliderBar.LabelFormatter labelFormatter,
                 SliderBar.SliderBarImages images)
Create a slider bar.

Parameters:
minValue - the minimum value in the range
maxValue - the maximum value in the range
labelFormatter - the label formatter
images - the images to use for the slider
Method Detail

addChangeListener

public void addChangeListener(com.google.gwt.user.client.ui.ChangeListener listener)
Add a change listener to this SliderBar.

Specified by:
addChangeListener in interface com.google.gwt.user.client.ui.SourcesChangeEvents
Parameters:
listener - the listener to add

getCurrentValue

public double getCurrentValue()
Return the current value.

Returns:
the current value

getLabelFormatter

public SliderBar.LabelFormatter getLabelFormatter()
Return the label formatter.

Returns:
the label formatter

getMaxValue

public double getMaxValue()
Return the max value.

Returns:
the max value

getMinValue

public double getMinValue()
Return the minimum value.

Returns:
the minimum value

getNumLabels

public int getNumLabels()
Return the number of labels.

Returns:
the number of labels

getNumTicks

public int getNumTicks()
Return the number of ticks.

Returns:
the number of ticks

getStepSize

public double getStepSize()
Return the step size.

Returns:
the step size

getTotalRange

public double getTotalRange()
Return the total range between the minimum and maximum values.

Returns:
the total range

onBrowserEvent

public void onBrowserEvent(com.google.gwt.user.client.Event event)
Listen for events that will move the knob.

Specified by:
onBrowserEvent in interface com.google.gwt.user.client.EventListener
Overrides:
onBrowserEvent in class com.google.gwt.user.client.ui.FocusPanel
Parameters:
event - the event that occurred

onResize

public void onResize(int width,
                     int height)
This method is called when the dimensions of the parent element change. Subclasses should override this method as needed.

Specified by:
onResize in interface ResizableWidget
Parameters:
width - the new client width of the element
height - the new client height of the element

redraw

public void redraw()
Redraw the progress bar when something changes the layout.


removeChangeListener

public void removeChangeListener(com.google.gwt.user.client.ui.ChangeListener listener)
Remove a change listener from this SliderBar.

Specified by:
removeChangeListener in interface com.google.gwt.user.client.ui.SourcesChangeEvents
Parameters:
listener - the listener to remove

setCurrentValue

public void setCurrentValue(double curValue)
Set the current value and fire the onValueChange event.

Parameters:
curValue - the current value

setCurrentValue

public void setCurrentValue(double curValue,
                            boolean fireEvent)
Set the current value and optionally fire the onValueChange event.

Parameters:
curValue - the current value
fireEvent - fire the onValue change event if true

setLabelFormatter

public void setLabelFormatter(SliderBar.LabelFormatter labelFormatter)
Set the label formatter.

Parameters:
labelFormatter - the label formatter

setMaxValue

public void setMaxValue(double maxValue)
Set the max value.

Parameters:
maxValue - the current value

setMinValue

public void setMinValue(double minValue)
Set the minimum value.

Parameters:
minValue - the current value

setNumLabels

public void setNumLabels(int numLabels)
Set the number of labels to show on the line. Labels indicate the value of the slider at that point. Use this method to enable labels. If you set the number of labels equal to the total range divided by the step size, you will get a properly aligned "jumping" effect where the knob jumps between labels. Note that the number of labels displayed will be one more than the number you specify, so specify 1 labels to show labels on either end of the line. In other words, numLabels is really the number of slots between the labels. setNumLabels(0) will disable labels.

Parameters:
numLabels - the number of labels to show

setNumTicks

public void setNumTicks(int numTicks)
Set the number of ticks to show on the line. A tick is a vertical line that represents a division of the overall line. Use this method to enable ticks. If you set the number of ticks equal to the total range divided by the step size, you will get a properly aligned "jumping" effect where the knob jumps between ticks. Note that the number of ticks displayed will be one more than the number you specify, so specify 1 tick to show ticks on either end of the line. In other words, numTicks is really the number of slots between the ticks. setNumTicks(0) will disable ticks.

Parameters:
numTicks - the number of ticks to show

setStepSize

public void setStepSize(double stepSize)
Set the step size.

Parameters:
stepSize - the current value

shiftLeft

public void shiftLeft(int numSteps)
Shift to the left (smaller value).

Parameters:
numSteps - the number of steps to shift

shiftRight

public void shiftRight(int numSteps)
Shift to the right (greater value).

Parameters:
numSteps - the number of steps to shift

formatLabel

protected java.lang.String formatLabel(double value)
Format the label to display above the ticks Override this method in a subclass to customize the format. By default, this method returns the integer portion of the value.

Parameters:
value - the value at the label
Returns:
the text to put in the label

getKnobPercent

protected double getKnobPercent()
Get the percentage of the knob's position relative to the size of the line. The return value will be between 0.0 and 1.0.

Returns:
the current percent complete

onLoad

protected void onLoad()
This method is called immediately after a widget becomes attached to the browser's document.

Overrides:
onLoad in class com.google.gwt.user.client.ui.Panel