Quaqua 5.4.1 2009-07-14

ch.randelshofer.quaqua
Class Quaqua14SpinnerUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.SpinnerUI
          extended by javax.swing.plaf.basic.BasicSpinnerUI
              extended by ch.randelshofer.quaqua.Quaqua14SpinnerUI
All Implemented Interfaces:
VisuallyLayoutable

public class Quaqua14SpinnerUI
extends javax.swing.plaf.basic.BasicSpinnerUI
implements VisuallyLayoutable

Quaqua14SpinnerUI.

Version:
1.1 2005-09-03 Fixed visual margin.
1.1 2005-07-17 Adapted to changes in interface VisuallyLayoutable.
1.0 June 27, 2005 Created.
Author:
Werner Randelshofer

Field Summary
 
Fields inherited from class javax.swing.plaf.basic.BasicSpinnerUI
spinner
 
Fields inherited from interface ch.randelshofer.quaqua.VisuallyLayoutable
CLIP_BOUNDS, COMPONENT_BOUNDS, TEXT_BOUNDS
 
Constructor Summary
Quaqua14SpinnerUI()
           
 
Method Summary
protected  javax.swing.JComponent createEditor()
          This method is called by installUI to get the editor component of the JSpinner.
protected  java.awt.LayoutManager createLayout()
          Create a LayoutManager that manages the editor, nextButton, and previousButton children of the JSpinner.
protected  java.awt.Component createNextButton()
          Create a component that will replace the spinner models value with the object returned by spinner.getNextValue.
protected  java.awt.Component createPreviousButton()
          Create a component that will replace the spinner models value with the object returned by spinner.getPreviousValue.
protected  java.beans.PropertyChangeListener createPropertyChangeListener()
          Create a PropertyChangeListener that can be added to the JSpinner itself.
static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
           
 int getBaseline(javax.swing.JComponent c, int width, int height)
          Returns the baseline for the specified component, or -1 if the baseline can not be determined.
protected  java.awt.Insets getMargin()
           
 java.awt.Rectangle getVisualBounds(javax.swing.JComponent c, int layoutType, int width, int height)
          Returns the visual bounds for the specified component, or null if the visual bounds can not be determined.
protected  void installListeners()
          Initializes propertyChangeListener with a shared object that delegates interesting PropertyChangeEvents to protected methods.
 void installUI(javax.swing.JComponent c)
          Calls installDefaults, installListeners, and then adds the components returned by createNextButton, createPreviousButton, and createEditor.
 void paint(java.awt.Graphics g, javax.swing.JComponent c)
           
protected  void replaceEditor(javax.swing.JComponent oldEditor, javax.swing.JComponent newEditor)
          Called by the PropertyChangeListener when the JSpinner editor property changes.
protected  void uninstallListeners()
          Removes the propertyChangeListener added by installListeners.
 
Methods inherited from class javax.swing.plaf.basic.BasicSpinnerUI
installDefaults, installKeyboardActions, installNextButtonListeners, installPreviousButtonListeners, uninstallDefaults, uninstallUI
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Quaqua14SpinnerUI

public Quaqua14SpinnerUI()
Method Detail

createUI

public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)

createPreviousButton

protected java.awt.Component createPreviousButton()
Create a component that will replace the spinner models value with the object returned by spinner.getPreviousValue. By default the previousButton is a JButton who's ActionListener updates it's JSpinner ancestors model. If a previousButton isn't needed (in a subclass) then override this method to return null.

Overrides:
createPreviousButton in class javax.swing.plaf.basic.BasicSpinnerUI
Returns:
a component that will replace the spinners model with the next value in the sequence, or null
See Also:
installUI(javax.swing.JComponent), createNextButton()

createNextButton

protected java.awt.Component createNextButton()
Create a component that will replace the spinner models value with the object returned by spinner.getNextValue. By default the nextButton is a JButton who's ActionListener updates it's JSpinner ancestors model. If a nextButton isn't needed (in a subclass) then override this method to return null.

Overrides:
createNextButton in class javax.swing.plaf.basic.BasicSpinnerUI
Returns:
a component that will replace the spinners model with the next value in the sequence, or null
See Also:
installUI(javax.swing.JComponent), createPreviousButton()

createLayout

protected java.awt.LayoutManager createLayout()
Create 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.

Overrides:
createLayout in class javax.swing.plaf.basic.BasicSpinnerUI
Returns:
a LayoutManager for the editor, next button, and previous button.
See Also:
createNextButton(), createPreviousButton(), createEditor()

createPropertyChangeListener

protected java.beans.PropertyChangeListener createPropertyChangeListener()
Create a PropertyChangeListener that can be added to the JSpinner itself. Typically, this listener will call replaceEditor when the "editor" property changes, since it's the SpinnerUI's responsibility to add the editor to the JSpinner (and remove the old one). This method is called by installListeners.

Overrides:
createPropertyChangeListener in class javax.swing.plaf.basic.BasicSpinnerUI
Returns:
A PropertyChangeListener for the JSpinner itself
See Also:
installListeners()

createEditor

protected javax.swing.JComponent 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 overriden this method, then you'll probably want to override replaceEditor as well.

Overrides:
createEditor in class javax.swing.plaf.basic.BasicSpinnerUI
Returns:
the JSpinners editor JComponent, spinner.getEditor() by default
See Also:
installUI(javax.swing.JComponent), replaceEditor(javax.swing.JComponent, javax.swing.JComponent), JSpinner.getEditor()

replaceEditor

protected void replaceEditor(javax.swing.JComponent oldEditor,
                             javax.swing.JComponent newEditor)
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.

Overrides:
replaceEditor in class javax.swing.plaf.basic.BasicSpinnerUI
See Also:
createEditor(), createPropertyChangeListener()

paint

public void paint(java.awt.Graphics g,
                  javax.swing.JComponent c)
Overrides:
paint in class javax.swing.plaf.ComponentUI

installUI

public void installUI(javax.swing.JComponent c)
Calls installDefaults, installListeners, and then adds the components returned by createNextButton, createPreviousButton, and createEditor.

Overrides:
installUI in class javax.swing.plaf.basic.BasicSpinnerUI
Parameters:
c - the JSpinner
See Also:
BasicSpinnerUI.installDefaults(), installListeners(), createNextButton(), createPreviousButton(), createEditor()

installListeners

protected void installListeners()
Initializes propertyChangeListener with a shared object that delegates interesting PropertyChangeEvents to protected methods.

This method is called by installUI.

Overrides:
installListeners in class javax.swing.plaf.basic.BasicSpinnerUI
See Also:
replaceEditor(javax.swing.JComponent, javax.swing.JComponent), uninstallListeners()

uninstallListeners

protected void uninstallListeners()
Removes the propertyChangeListener added by installListeners.

This method is called by uninstallUI.

Overrides:
uninstallListeners in class javax.swing.plaf.basic.BasicSpinnerUI
See Also:
installListeners()

getMargin

protected java.awt.Insets getMargin()

getBaseline

public int getBaseline(javax.swing.JComponent c,
                       int width,
                       int height)
Description copied from interface: VisuallyLayoutable
Returns the baseline for the specified component, or -1 if the baseline can not be determined. The baseline is measured from the top of the component.

Specified by:
getBaseline in interface VisuallyLayoutable
Parameters:
c - JComponent to calculate baseline for
width - Width of the component to determine baseline for.
height - Height of the component to determine baseline for.
Returns:
baseline for the specified component

getVisualBounds

public java.awt.Rectangle getVisualBounds(javax.swing.JComponent c,
                                          int layoutType,
                                          int width,
                                          int height)
Description copied from interface: VisuallyLayoutable
Returns the visual bounds for the specified component, or null if the visual bounds can not be determined.

Specified by:
getVisualBounds in interface VisuallyLayoutable
Parameters:
c - JComponent to calculate visual margin for
layoutType - The type of the visual margin.
width - Width of the component
height - Height of the component
Returns:
The visual bounds in component coordinates.

Copyright 2003-2007 (c) Werner Randelshofer.
All rights reserved.