APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.plaf.synth

public Class SynthSliderUI

extends BasicSliderUI
implements PropertyChangeListener, SynthUI
Class Inheritance
All Implemented Interfaces
javax.swing.plaf.synth.SynthUI, javax.swing.plaf.synth.SynthConstants, java.beans.PropertyChangeListener, java.util.EventListener
Imports
java.awt.event.*, java.awt.Graphics, .Dimension, .FontMetrics, .Rectangle, .Point, .Insets, java.beans.*, java.util.Dictionary, .Enumeration, javax.swing.*, javax.swing.plaf.*, javax.swing.plaf.basic.BasicSliderUI, sun.swing.SwingUtilities2

Provides the Synth L&F UI delegate for JSlider.
Author
Joshua Outwater
Since
1.7

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
SynthSliderUI.SynthTrackListener

Track mouse movements.

Field Summary

Modifier and TypeField and Description
private Dimension
lastSize

When a JSlider is used as a renderer in a JTable, its layout is not being recomputed even though the size is changing.

private boolean
private SynthStyle
private SynthStyle
private SynthStyle
private transient boolean
thumbActive

Used to determine the color to paint the thumb.

private int
private transient boolean
private int
private int
private int
private Rectangle
Inherited from javax.swing.plaf.basic.BasicSliderUI:
changeListenercomponentListenercontentRectfocusInsetsfocusListenerfocusRectinsetCachelabelRectleftToRightCacheMAX_SCROLLMIN_SCROLLNEGATIVE_SCROLLPOSITIVE_SCROLLpropertyChangeListenerscrollListenerscrollTimersliderthumbRecttickRecttrackBuffertrackListenertrackRect

Constructor Summary

AccessConstructor and Description
protected
SynthSliderUI(JSlider
a slider
c
)

Constructs a SynthSliderUI.

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
protected BasicSliderUI.TrackListener
public static ComponentUI

Returns:

the UI object
createUI
(JComponent
component to create UI object for
c
)

Hides javax.swing.plaf.basic.BasicSliderUI.createUI.

Creates a new UI object for the given component.

public int
getBaseline(JComponent c, int width, int height)

Overrides javax.swing.plaf.basic.BasicSliderUI.getBaseline.

Returns the baseline.

private int
public SynthContext
getContext(JComponent c)

Implements javax.swing.plaf.synth.SynthUI.getContext.

Returns the Context for the specified component.

private SynthContext
getContext(JComponent c, int state)

private SynthContext
private SynthContext
getContext(JComponent c, Region subregion, int state)

public Dimension
private int

Returns:

padding required to keep label visible.
getPadForLabel
(int
index of the label to calculate pad for.
i
)

Calculates the pad for the label at the specified index.

public Dimension
protected Dimension
protected void
protected void
protected void
layout()

Lays out the slider.

public void
paint(Graphics
the Graphics object used for painting
g
,
JComponent
the component being painted
c
)

Overrides javax.swing.plaf.basic.BasicSliderUI.paint.

Paints the specified component according to the Look and Feel.

protected void
paint(SynthContext
context for the component being painted
context
,
Graphics
the Graphics object used for painting
g
)

Paints the specified component.

public void
paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h)

Implements javax.swing.plaf.synth.SynthUI.paintBorder.

Paints the border.

protected void
paintThumb(SynthContext
context for the component being painted
context
,
Graphics
Graphics object used for painting
g
,
Rectangle
bounding box for the thumb
thumbBounds
)

Paints the slider thumb.

protected void
paintTrack(SynthContext
context for the component being painted
context
,
Graphics
Graphics object used for painting
g
,
Rectangle
bounding box for the track
trackBounds
)

Paints the slider track.

public void
propertyChange(PropertyChangeEvent e)

Implements java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

protected void
private void
setThumbActive(boolean active)

public void
setThumbLocation(int x, int y)

Overrides javax.swing.plaf.basic.BasicSliderUI.setThumbLocation.

Sets the thumb location.

private void
setThumbPressed(boolean pressed)

protected void
protected void
public void
update(Graphics
the Graphics object used for painting
g
,
JComponent
the component being painted
c
)

Overrides javax.swing.plaf.ComponentUI.update.

Notifies this UI delegate to repaint the specified component.

private void
private void
updateThumbState(int x, int y)

private void
updateThumbState(int x, int y, boolean pressed)

public int
valueForXPosition(int xPos)

Overrides javax.swing.plaf.basic.BasicSliderUI.valueForXPosition.

Returns the value at the x position.

public int
valueForYPosition(int yPos)

Overrides javax.swing.plaf.basic.BasicSliderUI.valueForYPosition.

Returns the value at the y position.

protected int
xPositionForValue(int value)

Overrides javax.swing.plaf.basic.BasicSliderUI.xPositionForValue.

Returns the x position for a value.

protected int
yPositionForValue(int value, int trackY, int trackHeight)

Overrides javax.swing.plaf.basic.BasicSliderUI.yPositionForValue.

Returns the y location for the specified value.

Inherited from javax.swing.plaf.basic.BasicSliderUI:
calculateContentRectcalculateFocusRectcalculateLabelRectcalculateThumbSizecalculateTickRectcalculateTrackBuffercalculateTrackRectcreateChangeListenercreateComponentListenercreateFocusListenercreatePropertyChangeListenercreateScrollListenerdrawInvertedgetBaselineResizeBehaviorgetFocusColorgetHeightOfHighValueLabelgetHeightOfLowValueLabelgetHeightOfTallestLabelgetHighestValuegetHighestValueLabelgetHighlightColorgetLowestValuegetLowestValueLabelgetMaximumSizegetMinimumHorizontalSizegetMinimumVerticalSizegetPreferredHorizontalSizegetPreferredVerticalSizegetShadowColorgetTickLengthgetWidthOfHighValueLabelgetWidthOfLowValueLabelgetWidthOfWidestLabelinstallKeyboardActionsinstallUIisDragginglabelsHaveSameBaselinespaintFocuspaintHorizontalLabelpaintLabelspaintMajorTickForHorizSliderpaintMajorTickForVertSliderpaintMinorTickForHorizSliderpaintMinorTickForVertSliderpaintThumbpaintTickspaintTrackpaintVerticalLabelrecalculateIfOrientationChangedscrollByBlockscrollByUnitscrollDueToClickInTrackuninstallKeyboardActionsuninstallUIyPositionForValue

Field Detail

lastSizeback to summary
private Dimension lastSize

When a JSlider is used as a renderer in a JTable, its layout is not being recomputed even though the size is changing. Even though there is a ComponentListener installed, it is not being notified. As such, at times when being asked to paint the layout should first be redone. At the end of the layout method we set this lastSize variable, which represents the size of the slider the last time it was laid out. In the paint method we then check to see that this is accurate, that the slider has not changed sizes since being last laid out. If necessary we recompute the layout.

paintValueback to summary
private boolean paintValue
sliderThumbStyleback to summary
private SynthStyle sliderThumbStyle
sliderTrackStyleback to summary
private SynthStyle sliderTrackStyle
styleback to summary
private SynthStyle style
thumbActiveback to summary
private transient boolean thumbActive

Used to determine the color to paint the thumb.

thumbHeightback to summary
private int thumbHeight
thumbPressedback to summary
private transient boolean thumbPressed
thumbWidthback to summary
private int thumbWidth
trackBorderback to summary
private int trackBorder
trackHeightback to summary
private int trackHeight
valueRectback to summary
private Rectangle valueRect

Constructor Detail

SynthSliderUIback to summary
protected SynthSliderUI(JSlider c)

Constructs a SynthSliderUI.

Parameters
c:JSlider

a slider

Method Detail

calculateGeometryback to summary
protected void calculateGeometry()

Overrides javax.swing.plaf.basic.BasicSliderUI.calculateGeometry.

Doc from javax.swing.plaf.basic.BasicSliderUI.calculateGeometry.

Calculates the geometry.

Annotations
@Override
calculateThumbLocationback to summary
protected void calculateThumbLocation()

Overrides javax.swing.plaf.basic.BasicSliderUI.calculateThumbLocation.

Doc from javax.swing.plaf.basic.BasicSliderUI.calculateThumbLocation.

Calculates the thumb location.

Annotations
@Override
createTrackListenerback to summary
protected BasicSliderUI.TrackListener createTrackListener(JSlider s)

Overrides javax.swing.plaf.basic.BasicSliderUI.createTrackListener.

Doc from javax.swing.plaf.basic.BasicSliderUI.createTrackListener.

Creates a track listener.

Annotations
@Override
createUIback to summary
public static ComponentUI createUI(JComponent c)

Hides javax.swing.plaf.basic.BasicSliderUI.createUI.

Creates a new UI object for the given component.

Parameters
c:JComponent

component to create UI object for

Returns:ComponentUI

the UI object

getBaselineback to summary
public int getBaseline(JComponent c, int width, int height)

Overrides javax.swing.plaf.basic.BasicSliderUI.getBaseline.

Doc from javax.swing.plaf.basic.BasicSliderUI.getBaseline.

Returns the baseline.

Annotations
@Override
getComponentStateback to summary
private int getComponentState(JComponent c, Region region)
getContextback to summary
public SynthContext getContext(JComponent c)

Implements javax.swing.plaf.synth.SynthUI.getContext.

Doc from javax.swing.plaf.synth.SynthUI.getContext.

Returns the Context for the specified component.

Annotations
@Override
getContextback to summary
private SynthContext getContext(JComponent c, int state)
getContextback to summary
private SynthContext getContext(JComponent c, Region subregion)
getContextback to summary
private SynthContext getContext(JComponent c, Region subregion, int state)
getMinimumSizeback to summary
public Dimension getMinimumSize(JComponent c)

Overrides javax.swing.plaf.basic.BasicSliderUI.getMinimumSize.

Doc from javax.swing.plaf.basic.BasicSliderUI.getMinimumSize.

Returns the minimum size.

Annotations
@Override
getPadForLabelback to summary
private int getPadForLabel(int i)

Calculates the pad for the label at the specified index.

Parameters
i:int

index of the label to calculate pad for.

Returns:int

padding required to keep label visible.

getPreferredSizeback to summary
public Dimension getPreferredSize(JComponent c)

Overrides javax.swing.plaf.basic.BasicSliderUI.getPreferredSize.

Doc from javax.swing.plaf.basic.BasicSliderUI.getPreferredSize.

Returns the preferred size.

Annotations
@Override
getThumbSizeback to summary
protected Dimension getThumbSize()

Overrides javax.swing.plaf.basic.BasicSliderUI.getThumbSize.

Doc from javax.swing.plaf.basic.BasicSliderUI.getThumbSize.

Returns the thumb size.

Annotations
@Override
installDefaultsback to summary
protected void installDefaults(JSlider slider)

Overrides javax.swing.plaf.basic.BasicSliderUI.installDefaults.

Doc from javax.swing.plaf.basic.BasicSliderUI.installDefaults.

Installs the defaults.

Annotations
@Override
installListenersback to summary
protected void installListeners(JSlider slider)

Overrides javax.swing.plaf.basic.BasicSliderUI.installListeners.

Doc from javax.swing.plaf.basic.BasicSliderUI.installListeners.

Installs listeners.

Annotations
@Override
layoutback to summary
protected void layout()

Lays out the slider.

paintback to summary
public void paint(Graphics g, JComponent c)

Overrides javax.swing.plaf.basic.BasicSliderUI.paint.

Paints the specified component according to the Look and Feel.

This method is not used by Synth Look and Feel. Painting is handled by the paint(SynthContext, Graphics) method.

Parameters
g:Graphics

the Graphics object used for painting

c:JComponent

the component being painted

Annotations
@Override
See Also
paint(SynthContext, Graphics)
paintback to summary
protected void paint(SynthContext context, Graphics g)

Paints the specified component.

Parameters
context:SynthContext

context for the component being painted

g:Graphics

the Graphics object used for painting

See Also
update(Graphics, JComponent)
paintBorderback to summary
public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h)

Implements javax.swing.plaf.synth.SynthUI.paintBorder.

Doc from javax.swing.plaf.synth.SynthUI.paintBorder.

Paints the border.

Annotations
@Override
paintThumbback to summary
protected void paintThumb(SynthContext context, Graphics g, Rectangle thumbBounds)

Paints the slider thumb.

Parameters
context:SynthContext

context for the component being painted

g:Graphics

Graphics object used for painting

thumbBounds:Rectangle

bounding box for the thumb

paintTrackback to summary
protected void paintTrack(SynthContext context, Graphics g, Rectangle trackBounds)

Paints the slider track.

Parameters
context:SynthContext

context for the component being painted

g:Graphics

Graphics object used for painting

trackBounds:Rectangle

bounding box for the track

propertyChangeback to summary
public void propertyChange(PropertyChangeEvent e)

Implements java.beans.PropertyChangeListener.propertyChange.

Doc from java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

Annotations
@Override
recalculateIfInsetsChangedback to summary
protected void recalculateIfInsetsChanged()

Overrides javax.swing.plaf.basic.BasicSliderUI.recalculateIfInsetsChanged.

Doc from javax.swing.plaf.basic.BasicSliderUI.recalculateIfInsetsChanged.

Recalculates if the insets have changed.

Annotations
@Override
setThumbActiveback to summary
private void setThumbActive(boolean active)
setThumbLocationback to summary
public void setThumbLocation(int x, int y)

Overrides javax.swing.plaf.basic.BasicSliderUI.setThumbLocation.

Doc from javax.swing.plaf.basic.BasicSliderUI.setThumbLocation.

Sets the thumb location.

Annotations
@Override
setThumbPressedback to summary
private void setThumbPressed(boolean pressed)
uninstallDefaultsback to summary
protected void uninstallDefaults(JSlider slider)

Overrides javax.swing.plaf.basic.BasicSliderUI.uninstallDefaults.

Uninstalls default setting. This method is called when a LookAndFeel is uninstalled.

uninstallListenersback to summary
protected void uninstallListeners(JSlider slider)

Overrides javax.swing.plaf.basic.BasicSliderUI.uninstallListeners.

Doc from javax.swing.plaf.basic.BasicSliderUI.uninstallListeners.

Uninstalls listeners.

Annotations
@Override
updateback to summary
public void update(Graphics g, JComponent c)

Overrides javax.swing.plaf.ComponentUI.update.

Notifies this UI delegate to repaint the specified component. This method paints the component background, then calls the paint(SynthContext, Graphics) method.

In general, this method does not need to be overridden by subclasses. All Look and Feel rendering code should reside in the paint method.

Parameters
g:Graphics

the Graphics object used for painting

c:JComponent

the component being painted

Annotations
@Override
See Also
paint(SynthContext, Graphics)
updateStyleback to summary
private void updateStyle(JSlider c)
updateThumbStateback to summary
private void updateThumbState(int x, int y)
updateThumbStateback to summary
private void updateThumbState(int x, int y, boolean pressed)
valueForXPositionback to summary
public int valueForXPosition(int xPos)

Overrides javax.swing.plaf.basic.BasicSliderUI.valueForXPosition.

Doc from javax.swing.plaf.basic.BasicSliderUI.valueForXPosition.

Returns the value at the x position. If xPos is beyond the track at the left or the right, this method sets the value to either the minimum or maximum value of the slider, depending on if the slider is inverted or not.

Annotations
@Override
valueForYPositionback to summary
public int valueForYPosition(int yPos)

Overrides javax.swing.plaf.basic.BasicSliderUI.valueForYPosition.

Doc from javax.swing.plaf.basic.BasicSliderUI.valueForYPosition.

Returns the value at the y position. If yPos is beyond the track at the bottom or the top, this method sets the value to either the minimum or maximum value of the slider, depending on if the slider is inverted or not.

Annotations
@Override
xPositionForValueback to summary
protected int xPositionForValue(int value)

Overrides javax.swing.plaf.basic.BasicSliderUI.xPositionForValue.

Doc from javax.swing.plaf.basic.BasicSliderUI.xPositionForValue.

Returns the x position for a value.

Annotations
@Override
yPositionForValueback to summary
protected int yPositionForValue(int value, int trackY, int trackHeight)

Overrides javax.swing.plaf.basic.BasicSliderUI.yPositionForValue.

Doc from javax.swing.plaf.basic.BasicSliderUI.yPositionForValue.

Returns the y location for the specified value. No checking is done on the arguments. In particular if trackHeight is negative undefined results may occur.

Annotations
@Override
javax.swing.plaf.synth back to summary

private Class SynthSliderUI.SynthTrackListener

extends TrackListener
Class Inheritance

Track mouse movements.

Field Summary

Inherited from javax.swing.plaf.basic.BasicSliderUI.TrackListener:
currentMouseXcurrentMouseYoffset

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
mouseDragged(MouseEvent e)

Overrides javax.swing.plaf.basic.BasicSliderUI.TrackListener.mouseDragged.

Implements java.awt.event.MouseMotionListener.mouseDragged.

Set the models value to the position of the top/left of the thumb relative to the origin of the track.

public void
mouseExited(MouseEvent e)

Overrides java.awt.event.MouseAdapter.mouseExited.

Implements java.awt.event.MouseListener.mouseExited.

Invoked when the mouse exits a component.

public void
mouseMoved(MouseEvent e)

Overrides javax.swing.plaf.basic.BasicSliderUI.TrackListener.mouseMoved.

Implements java.awt.event.MouseMotionListener.mouseMoved.

Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.

public void
mousePressed(MouseEvent e)

Overrides javax.swing.plaf.basic.BasicSliderUI.TrackListener.mousePressed.

Implements java.awt.event.MouseListener.mousePressed.

If the mouse is pressed above the "thumb" component then reduce the scrollbars value by one page ("page up"), otherwise increase it by one page.

public void
mouseReleased(MouseEvent e)

Overrides javax.swing.plaf.basic.BasicSliderUI.TrackListener.mouseReleased.

Implements java.awt.event.MouseListener.mouseReleased.

Invoked when a mouse button has been released on a component.

Inherited from javax.swing.plaf.basic.BasicSliderUI.TrackListener:
shouldScroll

Constructor Detail

SynthTrackListenerback to summary
private SynthTrackListener()

Method Detail

mouseDraggedback to summary
public void mouseDragged(MouseEvent e)

Overrides javax.swing.plaf.basic.BasicSliderUI.TrackListener.mouseDragged.

Implements java.awt.event.MouseMotionListener.mouseDragged.

Doc from javax.swing.plaf.basic.BasicSliderUI.TrackListener.mouseDragged.

Set the models value to the position of the top/left of the thumb relative to the origin of the track.

Annotations
@Override
mouseExitedback to summary
public void mouseExited(MouseEvent e)

Overrides java.awt.event.MouseAdapter.mouseExited.

Implements java.awt.event.MouseListener.mouseExited.

Doc from java.awt.event.MouseListener.mouseExited.

Invoked when the mouse exits a component.

Annotations
@Override
mouseMovedback to summary
public void mouseMoved(MouseEvent e)

Overrides javax.swing.plaf.basic.BasicSliderUI.TrackListener.mouseMoved.

Implements java.awt.event.MouseMotionListener.mouseMoved.

Doc from javax.swing.plaf.basic.BasicSliderUI.TrackListener.mouseMoved.

Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed.

Annotations
@Override
mousePressedback to summary
public void mousePressed(MouseEvent e)

Overrides javax.swing.plaf.basic.BasicSliderUI.TrackListener.mousePressed.

Implements java.awt.event.MouseListener.mousePressed.

Doc from javax.swing.plaf.basic.BasicSliderUI.TrackListener.mousePressed.

If the mouse is pressed above the "thumb" component then reduce the scrollbars value by one page ("page up"), otherwise increase it by one page. If there is no thumb then page up if the mouse is in the upper half of the track.

Annotations
@Override
mouseReleasedback to summary
public void mouseReleased(MouseEvent e)

Overrides javax.swing.plaf.basic.BasicSliderUI.TrackListener.mouseReleased.

Implements java.awt.event.MouseListener.mouseReleased.

Doc from javax.swing.plaf.basic.BasicSliderUI.TrackListener.mouseReleased.

Invoked when a mouse button has been released on a component.

Annotations
@Override