Mp3dings 
20100427

de.mospace.swing
Class VariableRangeSlider

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by de.mospace.swing.VariableRangeSlider
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class VariableRangeSlider
extends JPanel

A JSlider whose range and central value can be modified by the user.

Version:
$Revision: 12 $ ($Date: 2007-07-27 11:48:53 +0200 (Fr, 27 Jul 2007) $)
Author:
Moritz Ringler
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
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
static int MAX_LOG_RANGE
          A constant holding the maximum value allowed for logrange in setLogRange(int).
static double MAX_VALUE
          A constant holding the largest positive finite value the slider can assume.
static int MIN_LOG_RANGE
          A constant holding the minimum value allowed for logrange in setLogRange(int).
static double MIN_VALUE
          A constant holding the smallest positive nonzero value the slider can assume.
static DecimalFormat NUMBER_FORMAT
          The NumberFormat used to output the slider value.
protected  JSpinner range
          The JSpinner used to set the power of ten that corresponds to half the slider length.
protected  JSlider slider
          The internal JSlider of the VariableRangeSlider.
protected  JFormattedTextField value
          The JTextField used to set and print the value of the slider.
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
VariableRangeSlider()
          Constructs a new slider with central value 0, range -10 to 10 and gridsize 201.
VariableRangeSlider(double value, int logrange)
          Constructs a new slider with the given central value, and range ±10logrange and gridsize 101.
 
Method Summary
 void addChangeListener(ChangeListener l)
          Adds a ChangeListener to the slider.
protected  void fireStateChanged()
          Notifies all registered ChangeListeners.
 String getFormattedValue()
          Gets the current value of the slider as a formatted String.
 int getGridsize()
          Gets the number of steps used for the slider.
 int getLogRange()
          Gets the power of ten that corresponds to half the slider length.
 Dimension getMinimumSize()
          Overrides method in superclass java.awt.Component.
 Dimension getPreferredSize()
          Overrides method in superclass java.awt.Component.
 double getValue()
          Gets the current value of the slider.
 Dimension minimumSize()
          Deprecated.  
 Dimension preferredSize()
          Deprecated.  
 void removeChangeListener(ChangeListener l)
          Removes a ChangeListener from the slider.
 void setGridsize(int i)
          Sets the number of steps used for the slider.
 void setLogRange(int lr)
          Sets the power of ten that corresponds to half the slider length.
 void setValue(double d)
          Sets the value of the slider to d and makes it resume a central position.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, 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, getNextFocusableComponent, getPopupLocation, 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, setFont, 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, paintComponents, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_LOG_RANGE

public static final int MAX_LOG_RANGE
A constant holding the maximum value allowed for logrange in setLogRange(int).


MIN_LOG_RANGE

public static final int MIN_LOG_RANGE
A constant holding the minimum value allowed for logrange in setLogRange(int).


MAX_VALUE

public static final double MAX_VALUE
A constant holding the largest positive finite value the slider can assume.

See Also:
Constant Field Values

MIN_VALUE

public static final double MIN_VALUE
A constant holding the smallest positive nonzero value the slider can assume.

See Also:
Constant Field Values

NUMBER_FORMAT

public static final DecimalFormat NUMBER_FORMAT
The NumberFormat used to output the slider value.


slider

protected JSlider slider
The internal JSlider of the VariableRangeSlider.


value

protected JFormattedTextField value
The JTextField used to set and print the value of the slider.


range

protected JSpinner range
The JSpinner used to set the power of ten that corresponds to half the slider length.

Constructor Detail

VariableRangeSlider

public VariableRangeSlider()
Constructs a new slider with central value 0, range -10 to 10 and gridsize 201.


VariableRangeSlider

public VariableRangeSlider(double value,
                           int logrange)
Constructs a new slider with the given central value, and range ±10logrange and gridsize 101.

Method Detail

setValue

public void setValue(double d)
Sets the value of the slider to d and makes it resume a central position.

Parameters:
d - a legal double value
Throws:
IllegalArgumentException - when d is out of range
See Also:
MAX_VALUE, MIN_VALUE

getValue

public double getValue()
Gets the current value of the slider.

Returns:
the value of the slider

getFormattedValue

public String getFormattedValue()
Gets the current value of the slider as a formatted String.

Returns:
the value of the slider
See Also:
NUMBER_FORMAT

setGridsize

public void setGridsize(int i)
Sets the number of steps used for the slider.

Parameters:
i - will automatically be converted to an odd integer >= 3.

getGridsize

public int getGridsize()
Gets the number of steps used for the slider.

Returns:
the number of steps

setLogRange

public void setLogRange(int lr)
Sets the power of ten that corresponds to half the slider length.

Parameters:
lr - log10 of the desired range

getLogRange

public int getLogRange()
Gets the power of ten that corresponds to half the slider length.

Returns:
log10 of the current range

addChangeListener

public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the slider.

Parameters:
l - the listener to be added

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the slider.

Parameters:
l - the listener to be removed

fireStateChanged

protected void fireStateChanged()
Notifies all registered ChangeListeners.


getPreferredSize

public Dimension getPreferredSize()
Overrides method in superclass java.awt.Component.

Overrides:
getPreferredSize in class JComponent

getMinimumSize

public Dimension getMinimumSize()
Overrides method in superclass java.awt.Component.

Overrides:
getMinimumSize in class JComponent

preferredSize

public Dimension preferredSize()
Deprecated. 

Overrides method in superclass java.awt.Component.

Overrides:
preferredSize in class Container
See Also:
getPreferredSize()

minimumSize

public Dimension minimumSize()
Deprecated. 

Overrides method in superclass java.awt.Component.

Overrides:
minimumSize in class Container
See Also:
getMinimumSize()

Mp3dings 
20100427