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

public Class SynthSpinnerUI

extends BasicSpinnerUI
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.*, java.awt.event.*, javax.swing.*, javax.swing.plaf.*, javax.swing.plaf.basic.BasicSpinnerUI, java.beans.*

Provides the Synth L&F UI delegate for javax.swing.JSpinner.
Authors
Hans Muller, Joshua Outwater
Since
1.7

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
SynthSpinnerUI.EditorFocusHandler

Listen to editor text field focus changes and repaint whole spinner

private static class
SynthSpinnerUI.SpinnerLayout

A simple layout manager for the editor and the next/previous buttons.

Field Summary

Modifier and TypeField and Description
private SynthSpinnerUI.EditorFocusHandler
editorFocusHandler

A FocusListener implementation which causes the entire spinner to be repainted whenever the editor component (typically a text field) becomes focused, or loses focus.

private SynthStyle
Inherited from javax.swing.plaf.basic.BasicSpinnerUI:
spinner

Constructor Summary

AccessConstructor and Description
public
SynthSpinnerUI()

Constructs a SynthSpinnerUI.

Method Summary

Modifier and TypeMethod and Description
protected JComponent

Returns:

the JSpinners editor JComponent, spinner.getEditor() by default
createEditor
()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.createEditor.

This method is called by installUI to get the editor component of the JSpinner.

protected LayoutManager
createLayout()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.createLayout.

Creates a LayoutManager that manages the editor, nextButton, and previousButton children of the JSpinner.

protected Component
createNextButton()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.createNextButton.

Creates an increment button, i.e. component that replaces the spinner value with the object returned by spinner.getNextValue.

protected Component
createPreviousButton()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.createPreviousButton.

Creates a decrement button, i.e. component that replaces the spinner value with the object returned by spinner.getPreviousValue.

public static ComponentUI

Returns:

a new SynthSpinnerUI object
createUI
(JComponent
the JSpinner (not used)
c
)

Hides javax.swing.plaf.basic.BasicSpinnerUI.createUI.

Returns a new instance of SynthSpinnerUI.

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)

protected void
installDefaults()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.installDefaults.

Initializes the JSpinner border, foreground, and background, properties based on the corresponding "Spinner.*" properties from defaults table.

protected void
installListeners()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.installListeners.

Initializes PropertyChangeListener with a shared object that delegates interesting PropertyChangeEvents to protected methods.

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

Overrides javax.swing.plaf.ComponentUI.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.

public void
propertyChange(PropertyChangeEvent e)

Implements java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

protected void
replaceEditor(JComponent oldEditor, JComponent newEditor)

Overrides javax.swing.plaf.basic.BasicSpinnerUI.replaceEditor.

Called by the PropertyChangeListener when the JSpinner editor property changes.

protected void
uninstallDefaults()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.uninstallDefaults.

Sets the JSpinner's layout manager to null.

protected void
uninstallListeners()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.uninstallListeners.

Removes the PropertyChangeListener added by installListeners.

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
Inherited from javax.swing.plaf.basic.BasicSpinnerUI:
createPropertyChangeListenergetBaselinegetBaselineResizeBehaviorinstallKeyboardActionsinstallNextButtonListenersinstallPreviousButtonListenersinstallUIuninstallUI

Field Detail

editorFocusHandlerback to summary
private SynthSpinnerUI.EditorFocusHandler editorFocusHandler

A FocusListener implementation which causes the entire spinner to be repainted whenever the editor component (typically a text field) becomes focused, or loses focus. This is necessary because since SynthSpinnerUI is composed of an editor and two buttons, it is necessary that all three components indicate that they are "focused" so that they can be drawn appropriately. The repaint is used to ensure that the buttons are drawn in the new focused or unfocused state, mirroring that of the editor.

styleback to summary
private SynthStyle style

Constructor Detail

SynthSpinnerUIback to summary
public SynthSpinnerUI()

Constructs a SynthSpinnerUI.

Method Detail

createEditorback to summary
protected JComponent createEditor()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.createEditor.

This method is called by installUI to get the editor component of the JSpinner. By default it just returns JSpinner.getEditor(). Subclasses can override createEditor to return a component that contains the spinner's editor or null, if they're going to handle adding the editor to the JSpinner in an installUI override.

Typically this method would be overridden to wrap the editor with a container with a custom border, since one can't assume that the editors border can be set directly.

The replaceEditor method is called when the spinners editor is changed with JSpinner.setEditor. If you've overridden this method, then you'll probably want to override replaceEditor as well.

Returns:JComponent

the JSpinners editor JComponent, spinner.getEditor() by default

Annotations
@Override
See Also
installUI, replaceEditor, JSpinner#getEditor
createLayoutback to summary
protected LayoutManager createLayout()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.createLayout.

Doc from javax.swing.plaf.basic.BasicSpinnerUI.createLayout.

Creates a LayoutManager that manages the editor, nextButton, and previousButton children of the JSpinner. These three children must be added with a constraint that identifies their role: "Editor", "Next", and "Previous". The default layout manager can handle the absence of any of these children.

Annotations
@Override
createNextButtonback to summary
protected Component createNextButton()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.createNextButton.

Doc from javax.swing.plaf.basic.BasicSpinnerUI.createNextButton.

Creates an increment button, i.e. component that replaces the spinner value with the object returned by spinner.getNextValue. By default the nextButton is a JButton. If the increment button is not needed this method should return null.

Annotations
@Override
createPreviousButtonback to summary
protected Component createPreviousButton()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.createPreviousButton.

Doc from javax.swing.plaf.basic.BasicSpinnerUI.createPreviousButton.

Creates a decrement button, i.e. component that replaces the spinner value with the object returned by spinner.getPreviousValue. By default the previousButton is a JButton. If the decrement button is not needed this method should return null.

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

Hides javax.swing.plaf.basic.BasicSpinnerUI.createUI.

Returns a new instance of SynthSpinnerUI.

Parameters
c:JComponent

the JSpinner (not used)

Returns:ComponentUI

a new SynthSpinnerUI object

See Also
ComponentUI#createUI
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)
installDefaultsback to summary
protected void installDefaults()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.installDefaults.

Initializes the JSpinner border, foreground, and background, properties based on the corresponding "Spinner.*" properties from defaults table. The JSpinners layout is set to the value returned by createLayout. This method is called by installUI.

Annotations
@Override
See Also
uninstallDefaults, installUI, createLayout, LookAndFeel#installBorder, LookAndFeel#installColors
installListenersback to summary
protected void installListeners()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.installListeners.

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

Initializes PropertyChangeListener with a shared object that delegates interesting PropertyChangeEvents to protected methods.

This method is called by installUI.

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

Overrides javax.swing.plaf.ComponentUI.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. This implementation does nothing.

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
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
replaceEditorback to summary
protected void replaceEditor(JComponent oldEditor, JComponent newEditor)

Overrides javax.swing.plaf.basic.BasicSpinnerUI.replaceEditor.

Called by the PropertyChangeListener when the JSpinner editor property changes. It's the responsibility of this method to remove the old editor and add the new one. By default this operation is just:

spinner.remove(oldEditor);
spinner.add(newEditor, "Editor");
The implementation of replaceEditor should be coordinated with the createEditor method.
Annotations
@Override
See Also
createEditor, createPropertyChangeListener
uninstallDefaultsback to summary
protected void uninstallDefaults()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.uninstallDefaults.

Sets the JSpinner's layout manager to null. This method is called by uninstallUI.

Annotations
@Override
See Also
installDefaults, uninstallUI
uninstallListenersback to summary
protected void uninstallListeners()

Overrides javax.swing.plaf.basic.BasicSpinnerUI.uninstallListeners.

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

Removes the PropertyChangeListener added by installListeners.

This method is called by uninstallUI.

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)
updateEditorAlignmentback to summary
private void updateEditorAlignment(JComponent editor)

Hides javax.swing.plaf.basic.BasicSpinnerUI.updateEditorAlignment.

updateStyleback to summary
private void updateStyle(JSpinner c)
javax.swing.plaf.synth back to summary

private Class SynthSpinnerUI.EditorFocusHandler

extends Object
implements FocusListener
Class Inheritance
All Implemented Interfaces
java.awt.event.FocusListener, java.util.EventListener

Listen to editor text field focus changes and repaint whole spinner

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
focusGained(FocusEvent e)

Implements java.awt.event.FocusListener.focusGained.

Invoked when a editor text field gains the keyboard focus.

public void
focusLost(FocusEvent e)

Implements java.awt.event.FocusListener.focusLost.

Invoked when a editor text field loses the keyboard focus.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EditorFocusHandlerback to summary
private EditorFocusHandler()

Method Detail

focusGainedback to summary
public void focusGained(FocusEvent e)

Implements java.awt.event.FocusListener.focusGained.

Invoked when a editor text field gains the keyboard focus.

Annotations
@Override
focusLostback to summary
public void focusLost(FocusEvent e)

Implements java.awt.event.FocusListener.focusLost.

Invoked when a editor text field loses the keyboard focus.

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

private Class SynthSpinnerUI.SpinnerLayout

extends Object
implements LayoutManager, UIResource
Class Inheritance
All Implemented Interfaces
javax.swing.plaf.UIResource, java.awt.LayoutManager

A simple layout manager for the editor and the next/previous buttons. See the SynthSpinnerUI javadoc for more information about exactly how the components are arranged.

Field Summary

Modifier and TypeField and Description
private Component
private Component
private Component

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
addLayoutComponent(String name, Component c)

Implements java.awt.LayoutManager.addLayoutComponent.

If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.

public void
layoutContainer(Container parent)

Implements java.awt.LayoutManager.layoutContainer.

Lays out the specified container.

public Dimension
minimumLayoutSize(Container parent)

Implements java.awt.LayoutManager.minimumLayoutSize.

Calculates the minimum size dimensions for the specified container, given the components it contains.

public Dimension
preferredLayoutSize(Container parent)

Implements java.awt.LayoutManager.preferredLayoutSize.

Calculates the preferred size dimensions for the specified container, given the components it contains.

private Dimension
public void
removeLayoutComponent(Component c)

Implements java.awt.LayoutManager.removeLayoutComponent.

Removes the specified component from the layout.

private void
setBounds(Component c, int x, int y, int width, int height)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

editorback to summary
private Component editor
nextButtonback to summary
private Component nextButton
previousButtonback to summary
private Component previousButton

Constructor Detail

SpinnerLayoutback to summary
private SpinnerLayout()

Method Detail

addLayoutComponentback to summary
public void addLayoutComponent(String name, Component c)

Implements java.awt.LayoutManager.addLayoutComponent.

Doc from java.awt.LayoutManager.addLayoutComponent.

If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.

layoutContainerback to summary
public void layoutContainer(Container parent)

Implements java.awt.LayoutManager.layoutContainer.

Doc from java.awt.LayoutManager.layoutContainer.

Lays out the specified container.

minimumLayoutSizeback to summary
public Dimension minimumLayoutSize(Container parent)

Implements java.awt.LayoutManager.minimumLayoutSize.

Doc from java.awt.LayoutManager.minimumLayoutSize.

Calculates the minimum size dimensions for the specified container, given the components it contains.

preferredLayoutSizeback to summary
public Dimension preferredLayoutSize(Container parent)

Implements java.awt.LayoutManager.preferredLayoutSize.

Doc from java.awt.LayoutManager.preferredLayoutSize.

Calculates the preferred size dimensions for the specified container, given the components it contains.

preferredSizeback to summary
private Dimension preferredSize(Component c)
removeLayoutComponentback to summary
public void removeLayoutComponent(Component c)

Implements java.awt.LayoutManager.removeLayoutComponent.

Doc from java.awt.LayoutManager.removeLayoutComponent.

Removes the specified component from the layout.

setBoundsback to summary
private void setBounds(Component c, int x, int y, int width, int height)