jview
Class JTunableSlider

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JSlider
                  extended by jview.JTunableSlider
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants, PropertyAware, PropertyComposed

public class JTunableSlider
extends JSlider
implements PropertyComposed

A slider that can change the extend of its accessible values by keeping the central value fixed and either increasing or decreasing the range. This is useful, if one wants to penetrate deeper and deeper into a parameter.

You consturct such a slider with a central value and a initial half-span (mandatory). Each refinement changes the span (and possibly the central value) by an specifiable amount, defaulting to DEFREFINEMENT. Different to the standard slider, you specify the number of ticks and the number of labels you want to see on the slider. Internally, this numbers are used to define the (integer) range of the underlying slider. Calling the set...TickSpacing methods still work, but might produce interesting results.
Two buttons for increaseing/decreasing the accessible slider range are available, but displaying them must be done externally. If the user clicks on either button, or calls shrink or expand, the range of the slider changes.

See Also:
Serialized Form

Nested Class Summary
static class JTunableSlider.Show
          Test class, shows an adjustable slider and prints out the values.
 
Nested classes/interfaces inherited from class javax.swing.JSlider
JSlider.AccessibleJSlider
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  double central
          The current central value.
private static int DEFLABELCOUNT
          Default number of labels.
private static double DEFREFINEMENT
          Default change in range on shrink/expand.
private static int DEFTICKCOUNT
          Default number of ticks.
private  JButton expand
          The expand button.
private  PropertySupplying info
          My properties.
static String KEY_LABELCOUNT
          The number of labels to display per half-intervall.
static String KEY_REFINEMENT
          The change in the sliders range by a call to shrink.
static String KEY_TICKCOUNT
          The number of ticks to display per half-intervall.
private  double range
          The current slider half-range.
private  JButton shrink
          The shrink button.
 
Fields inherited from class javax.swing.JSlider
changeEvent, changeListener, majorTickSpacing, minorTickSpacing, orientation, sliderModel, snapToTicks
 
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.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
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
JTunableSlider(double mid, double span)
          Constructs a new tunable slider, all values defaulting.
JTunableSlider(double mid, double span, Map<String,String> p)
          Constructs a new tunable slider, all non-default values specified in the provided lookup table.
JTunableSlider(double mid, double span, PropertySupplying info)
          Constructs a new tunable slider, all non-default values specified in the provided lookup table.
 
Method Summary
private  void adjustLabels()
          Adjust the labels displayed to the true values covered in the slider.
private  double convertSliderPosition(int slider)
          Converts an integer position on the slider to the correct double value.
private  void createButtons(int orientation)
          We create the shrink and expand button, depending on the slider orientation.
private  void createSlider()
          Creates the (super) slider out of the properties specified earlier.
 void expand(double nucen)
          Expands the tunable range, but enlarges the accuracy of the slider positioning.
 JComponent getBox()
          Convenience method: get the slider and the shrink and expand buttons in a properly laid-out box.
 double getCentralValue()
          Returns the central value.
 PropertySupplying getComposedProperties()
          Returns my properties.
 double getDoubleValue()
          We cannot overload getValue, because this returns an int.
 void setCentralValue(double nucen)
          Sets the central value keeps the range.
 void setCentralValue(double nucen, double nuran)
          Sets the central value plus the range.
 void setComposedProperties(PropertySupplying prop)
          Sets the composed properties.
 void setDoubleValue(double knob)
          The setter method, adjust the knob.
 void setDoubleValue(double knob, boolean suppress)
          The setter method, adjust the knob.
 void setOrientation(int orientation)
          We set the orientation and change the layout of our buttons.
 void setRange(double nuran)
           
 void shrink(double nucen)
          On setting the orientation, we also /** Shrinks the tunable range, but enlarges the accuracy of the slider positioning.
 
Methods inherited from class javax.swing.JSlider
addChangeListener, createChangeListener, createStandardLabels, createStandardLabels, fireStateChanged, getAccessibleContext, getChangeListeners, getExtent, getInverted, getLabelTable, getMajorTickSpacing, getMaximum, getMinimum, getMinorTickSpacing, getModel, getOrientation, getPaintLabels, getPaintTicks, getPaintTrack, getSnapToTicks, getUI, getUIClassID, getValue, getValueIsAdjusting, paramString, removeChangeListener, setExtent, setFont, setInverted, setLabelTable, setMajorTickSpacing, setMaximum, setMinimum, setMinorTickSpacing, setModel, setPaintLabels, setPaintTicks, setPaintTrack, setSnapToTicks, setUI, setValue, setValueIsAdjusting, updateLabelUIs, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_REFINEMENT

public static final String KEY_REFINEMENT
The change in the sliders range by a call to shrink.

See Also:
Constant Field Values

KEY_TICKCOUNT

public static final String KEY_TICKCOUNT
The number of ticks to display per half-intervall.

See Also:
Constant Field Values

KEY_LABELCOUNT

public static final String KEY_LABELCOUNT
The number of labels to display per half-intervall.

See Also:
Constant Field Values

DEFREFINEMENT

private static final double DEFREFINEMENT
Default change in range on shrink/expand.

See Also:
Constant Field Values

DEFTICKCOUNT

private static final int DEFTICKCOUNT
Default number of ticks.

See Also:
Constant Field Values

DEFLABELCOUNT

private static final int DEFLABELCOUNT
Default number of labels.

See Also:
Constant Field Values

info

private PropertySupplying info
My properties.


central

private double central
The current central value.


range

private double range
The current slider half-range.


shrink

private JButton shrink
The shrink button.


expand

private JButton expand
The expand button.

Constructor Detail

JTunableSlider

public JTunableSlider(double mid,
                      double span)
Constructs a new tunable slider, all values defaulting.


JTunableSlider

public JTunableSlider(double mid,
                      double span,
                      Map<String,String> p)
Constructs a new tunable slider, all non-default values specified in the provided lookup table.


JTunableSlider

public JTunableSlider(double mid,
                      double span,
                      PropertySupplying info)
Constructs a new tunable slider, all non-default values specified in the provided lookup table.

Method Detail

setOrientation

public void setOrientation(int orientation)
We set the orientation and change the layout of our buttons.

Overrides:
setOrientation in class JSlider

setComposedProperties

public void setComposedProperties(PropertySupplying prop)
Sets the composed properties. Defaults non-set values for the refinement and the number of ticks/labels. From this, the actual size of the underlying slider is calculated.

Specified by:
setComposedProperties in interface PropertyAware

getComposedProperties

public PropertySupplying getComposedProperties()
Returns my properties.

Specified by:
getComposedProperties in interface PropertyComposed

shrink

public void shrink(double nucen)
On setting the orientation, we also /** Shrinks the tunable range, but enlarges the accuracy of the slider positioning. Updates labels and sets the new center to the specified value.


expand

public void expand(double nucen)
Expands the tunable range, but enlarges the accuracy of the slider positioning. Updates labels and sets the new center to the specified value.


getCentralValue

public double getCentralValue()
Returns the central value.


setRange

public void setRange(double nuran)

setCentralValue

public void setCentralValue(double nucen)
Sets the central value keeps the range.


setCentralValue

public void setCentralValue(double nucen,
                            double nuran)
Sets the central value plus the range.


getDoubleValue

public double getDoubleValue()
We cannot overload getValue, because this returns an int.


setDoubleValue

public void setDoubleValue(double knob)
The setter method, adjust the knob.


setDoubleValue

public void setDoubleValue(double knob,
                           boolean suppress)
The setter method, adjust the knob. If the second argument is true, we remove all change listeners prior to calling setValue and add all after setting the value. This is the only circumvention I found for supressing change events to be generated.


getBox

public JComponent getBox()
Convenience method: get the slider and the shrink and expand buttons in a properly laid-out box.


convertSliderPosition

private double convertSliderPosition(int slider)
Converts an integer position on the slider to the correct double value.


createSlider

private void createSlider()
Creates the (super) slider out of the properties specified earlier.


createButtons

private void createButtons(int orientation)
We create the shrink and expand button, depending on the slider orientation. Both buttons have an action listener registered to them that shrinks respectively expands the slider's range.


adjustLabels

private void adjustLabels()
Adjust the labels displayed to the true values covered in the slider.