prefuse.util.ui
Class JRangeSlider

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by prefuse.util.ui.JRangeSlider
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener

public class JRangeSlider
extends javax.swing.JComponent
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.KeyListener

Implements a Swing-based Range slider, which allows the user to enter a range (minimum and maximum) value.

Author:
Ben Bederson, Jesse Grosjean, Jon Meyer, Lance Good, jeffrey heer, Colin Combe
See Also:
Serialized Form

Nested Class Summary
protected  class JRangeSlider.RangeSliderChangeListener
          Listener that fires a change event when it receives change event from the slider list model.
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected static int ARROW_HEIGHT
           
protected static int ARROW_SZ
           
protected static int ARROW_WIDTH
           
protected  javax.swing.event.ChangeEvent changeEvent
           
protected  int direction
           
protected  boolean empty
           
static int HORIZONTAL
           
protected  int increment
           
static int LEFTRIGHT_TOPBOTTOM
           
protected  java.util.ArrayList listeners
           
protected  javax.swing.event.ChangeListener lstnr
           
protected  int minExtent
           
protected  javax.swing.BoundedRangeModel model
           
protected  int orientation
           
static int PREFERRED_BREADTH
           
static int PREFERRED_LENGTH
           
static int RIGHTLEFT_BOTTOMTOP
           
protected  java.awt.Color thumbColor
           
static int VERTICAL
           
 
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
JRangeSlider(javax.swing.BoundedRangeModel model, int orientation, int direction)
          Create a new range slider.
JRangeSlider(int minimum, int maximum, int lowValue, int highValue, int orientation)
          Create a new range slider.
JRangeSlider(int minimum, int maximum, int lowValue, int highValue, int orientation, int direction)
          Create a new range slider.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener cl)
          Registers a listener for ChangeEvents.
protected  javax.swing.event.ChangeListener createListener()
          Create a listener to relay change events from the bounded range model.
protected  void customPaint(java.awt.Graphics2D g, int width, int height)
          Override this method to perform custom painting of the slider trough.
protected  void fireChangeEvent()
          Fire a change event to all listeners.
 int getHighValue()
          Returns the current "high" value shown by the range slider's bar.
 int getLowValue()
          Returns the current "low" value shown by the range slider's bar.
 int getMaximum()
          Gets the maximum possible value for either the low value or the high value.
 int getMinimum()
          Gets the minimum possible value for either the low value or the high value.
 javax.swing.BoundedRangeModel getModel()
          Get the BoundedRangeModel backing this slider.
 java.awt.Dimension getPreferredSize()
           
 java.awt.Color getThumbColor()
          Get the slider thumb color.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
protected  void paint3DRectLighting(java.awt.Graphics2D g2, int x, int y, int width, int height)
          Adds Windows2K type 3D lighting effects
protected  void paintArrow(java.awt.Graphics2D g2, double x, double y, int w, int h, boolean topDown)
          This draws an arrow as a series of lines within the specified box.
 void paintComponent(java.awt.Graphics g)
           
 void removeChangeListener(javax.swing.event.ChangeListener cl)
          Removes a listener for ChangeEvents.
 void setEmpty(boolean empty)
          Sets whether this slider is empty.
 void setHighValue(int highValue)
          Sets the high value shown by this range slider.
 void setLowValue(int lowValue)
          Sets the low value shown by this range slider.
 void setMaximum(int maximum)
          Sets the maximum possible value for either the low value or the high value.
 void setMinExtent(int minExtent)
          Sets the minimum extent (difference between low and high values).
 void setMinimum(int minimum)
          Sets the minimum possible value for either the low value or the high value.
 void setModel(javax.swing.BoundedRangeModel brm)
          Set the BoundedRangeModel backing this slider.
 void setRange(int lowValue, int highValue)
          Set the slider range span.
 void setThumbColor(java.awt.Color thumbColor)
          Set the slider thumb color.
protected  int toLocal(int xOrY)
          Converts from screen coordinates to a range value.
protected  int toScreen(int xOrY)
          Converts from a range value to screen coordinates.
protected  double toScreenDouble(int xOrY)
          Converts from a range value to screen coordinates.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, 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, updateUI
 
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

VERTICAL

public static final int VERTICAL
See Also:
Constant Field Values

HORIZONTAL

public static final int HORIZONTAL
See Also:
Constant Field Values

LEFTRIGHT_TOPBOTTOM

public static final int LEFTRIGHT_TOPBOTTOM
See Also:
Constant Field Values

RIGHTLEFT_BOTTOMTOP

public static final int RIGHTLEFT_BOTTOMTOP
See Also:
Constant Field Values

PREFERRED_BREADTH

public static final int PREFERRED_BREADTH
See Also:
Constant Field Values

PREFERRED_LENGTH

public static final int PREFERRED_LENGTH
See Also:
Constant Field Values

ARROW_SZ

protected static final int ARROW_SZ
See Also:
Constant Field Values

ARROW_WIDTH

protected static final int ARROW_WIDTH
See Also:
Constant Field Values

ARROW_HEIGHT

protected static final int ARROW_HEIGHT
See Also:
Constant Field Values

model

protected javax.swing.BoundedRangeModel model

orientation

protected int orientation

direction

protected int direction

empty

protected boolean empty

increment

protected int increment

minExtent

protected int minExtent

listeners

protected java.util.ArrayList listeners

changeEvent

protected javax.swing.event.ChangeEvent changeEvent

lstnr

protected javax.swing.event.ChangeListener lstnr

thumbColor

protected java.awt.Color thumbColor
Constructor Detail

JRangeSlider

public JRangeSlider(int minimum,
                    int maximum,
                    int lowValue,
                    int highValue,
                    int orientation)
Create a new range slider.

Parameters:
minimum - - the minimum value of the range.
maximum - - the maximum value of the range.
lowValue - - the current low value shown by the range slider's bar.
highValue - - the current high value shown by the range slider's bar.
orientation - - construct a horizontal or vertical slider?

JRangeSlider

public JRangeSlider(int minimum,
                    int maximum,
                    int lowValue,
                    int highValue,
                    int orientation,
                    int direction)
Create a new range slider.

Parameters:
minimum - - the minimum value of the range.
maximum - - the maximum value of the range.
lowValue - - the current low value shown by the range slider's bar.
highValue - - the current high value shown by the range slider's bar.
orientation - - construct a horizontal or vertical slider?
direction - - Is the slider left-to-right/top-to-bottom or right-to-left/bottom-to-top

JRangeSlider

public JRangeSlider(javax.swing.BoundedRangeModel model,
                    int orientation,
                    int direction)
Create a new range slider.

Parameters:
model - - a BoundedRangeModel specifying the slider's range
orientation - - construct a horizontal or vertical slider?
direction - - Is the slider left-to-right/top-to-bottom or right-to-left/bottom-to-top
Method Detail

createListener

protected javax.swing.event.ChangeListener createListener()
Create a listener to relay change events from the bounded range model.

Returns:
a ChangeListener to relay events from the range model

getLowValue

public int getLowValue()
Returns the current "low" value shown by the range slider's bar. The low value meets the constraint minimum <= lowValue <= highValue <= maximum.


setLowValue

public void setLowValue(int lowValue)
Sets the low value shown by this range slider. This causes the range slider to be repainted and a ChangeEvent to be fired.

Parameters:
lowValue - the low value to use

getHighValue

public int getHighValue()
Returns the current "high" value shown by the range slider's bar. The high value meets the constraint minimum <= lowValue <= highValue <= maximum.


setHighValue

public void setHighValue(int highValue)
Sets the high value shown by this range slider. This causes the range slider to be repainted and a ChangeEvent to be fired.

Parameters:
highValue - the high value to use

setRange

public void setRange(int lowValue,
                     int highValue)
Set the slider range span.

Parameters:
lowValue - the low value of the slider range
highValue - the high value of the slider range

getMinimum

public int getMinimum()
Gets the minimum possible value for either the low value or the high value.

Returns:
the minimum possible range value

setMinimum

public void setMinimum(int minimum)
Sets the minimum possible value for either the low value or the high value.

Parameters:
minimum - the minimum possible range value

getMaximum

public int getMaximum()
Gets the maximum possible value for either the low value or the high value.

Returns:
the maximum possible range value

setMaximum

public void setMaximum(int maximum)
Sets the maximum possible value for either the low value or the high value.

Parameters:
maximum - the maximum possible range value

setMinExtent

public void setMinExtent(int minExtent)
Sets the minimum extent (difference between low and high values). This method does not change the current state of the model, but can affect all subsequent interaction.

Parameters:
minExtent - the minimum extent allowed in subsequent interaction

setEmpty

public void setEmpty(boolean empty)
Sets whether this slider is empty.

Parameters:
empty - true if set to empty, false otherwise

getThumbColor

public java.awt.Color getThumbColor()
Get the slider thumb color. This is the part of the slider between the range resize buttons.

Returns:
the slider thumb color

setThumbColor

public void setThumbColor(java.awt.Color thumbColor)
Set the slider thumb color. This is the part of the slider between the range resize buttons.

Parameters:
thumbColor - the slider thumb color

getModel

public javax.swing.BoundedRangeModel getModel()
Get the BoundedRangeModel backing this slider.

Returns:
the slider's range model

setModel

public void setModel(javax.swing.BoundedRangeModel brm)
Set the BoundedRangeModel backing this slider.

Parameters:
brm - the slider range model to use

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener cl)
Registers a listener for ChangeEvents.

Parameters:
cl - the ChangeListener to add

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener cl)
Removes a listener for ChangeEvents.

Parameters:
cl - the ChangeListener to remove

fireChangeEvent

protected void fireChangeEvent()
Fire a change event to all listeners.


getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent
See Also:
Component.getPreferredSize()

customPaint

protected void customPaint(java.awt.Graphics2D g,
                           int width,
                           int height)
Override this method to perform custom painting of the slider trough.

Parameters:
g - a Graphics2D context for rendering
width - the width of the slider trough
height - the height of the slider trough

paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent
See Also:
JComponent.paintComponent(java.awt.Graphics)

paintArrow

protected void paintArrow(java.awt.Graphics2D g2,
                          double x,
                          double y,
                          int w,
                          int h,
                          boolean topDown)
This draws an arrow as a series of lines within the specified box. The last boolean specifies whether the point should be at the right/bottom or left/top.


paint3DRectLighting

protected void paint3DRectLighting(java.awt.Graphics2D g2,
                                   int x,
                                   int y,
                                   int width,
                                   int height)
Adds Windows2K type 3D lighting effects


toLocal

protected int toLocal(int xOrY)
Converts from screen coordinates to a range value.


toScreen

protected int toScreen(int xOrY)
Converts from a range value to screen coordinates.


toScreenDouble

protected double toScreenDouble(int xOrY)
Converts from a range value to screen coordinates.


mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener
See Also:
MouseListener.mousePressed(java.awt.event.MouseEvent)

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
See Also:
MouseMotionListener.mouseDragged(java.awt.event.MouseEvent)

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener
See Also:
MouseListener.mouseReleased(java.awt.event.MouseEvent)

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
See Also:
MouseMotionListener.mouseMoved(java.awt.event.MouseEvent)

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener
See Also:
MouseListener.mouseClicked(java.awt.event.MouseEvent)

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener
See Also:
MouseListener.mouseEntered(java.awt.event.MouseEvent)

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener
See Also:
MouseListener.mouseExited(java.awt.event.MouseEvent)

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener
See Also:
KeyListener.keyPressed(java.awt.event.KeyEvent)

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener
See Also:
KeyListener.keyReleased(java.awt.event.KeyEvent)

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener
See Also:
KeyListener.keyTyped(java.awt.event.KeyEvent)


Copyright © 2007 Regents of the University of California