FileDocCategorySizeDatePackage
SynthSpinnerUI.javaAPI DocJava SE 6 API12321Tue Jun 10 00:26:54 BST 2008javax.swing.plaf.synth

SynthSpinnerUI

public class SynthSpinnerUI extends BasicSpinnerUI implements sun.swing.plaf.synth.SynthUI, PropertyChangeListener
Synth's SpinnerUI.
version
1.14, 04/10/06
author
Hans Muller
author
Joshua Outwater

Fields Summary
private SynthStyle
style
Constructors Summary
Methods Summary
protected javax.swing.JComponentcreateEditor()
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.

return
the JSpinners editor JComponent, spinner.getEditor() by default
see
#installUI
see
#replaceEditor
see
JSpinner#getEditor

        JComponent editor = spinner.getEditor();
        editor.setName("Spinner.editor");
        updateEditorAlignment(editor);
	return editor;
    
protected java.awt.LayoutManagercreateLayout()

        return new SpinnerLayout();
    
protected java.awt.ComponentcreateNextButton()
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.

return
a component that will replace the spinners model with the next value in the sequence, or null
see
#installUI
see
#createPreviousButton

	JButton b = new SynthArrowButton(SwingConstants.NORTH);
        b.setName("Spinner.nextButton");
        installNextButtonListeners(b);
	return b;
    
protected java.awt.ComponentcreatePreviousButton()
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.

return
a component that will replace the spinners model with the next value in the sequence, or null
see
#installUI
see
#createNextButton

	JButton b = new SynthArrowButton(SwingConstants.SOUTH);
        b.setName("Spinner.previousButton");
        installPreviousButtonListeners(b);
	return b;
    
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent c)
Returns a new instance of SynthSpinnerUI.

param
c the JSpinner (not used)
see
ComponentUI#createUI
return
a new SynthSpinnerUI object

        return new SynthSpinnerUI();
    
private intgetComponentState(javax.swing.JComponent c)

        return SynthLookAndFeel.getComponentState(c);
    
public javax.swing.plaf.synth.SynthContextgetContext(javax.swing.JComponent c)

        return getContext(c, getComponentState(c));
    
private javax.swing.plaf.synth.SynthContextgetContext(javax.swing.JComponent c, int state)

        return SynthContext.getContext(SynthContext.class, c,
                    SynthLookAndFeel.getRegion(c), style, state);
    
private javax.swing.plaf.synth.RegiongetRegion(javax.swing.JComponent c)

        return SynthLookAndFeel.getRegion(c);
    
protected voidinstallDefaults()
Initialize 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.

see
#uninstallDefaults
see
#installUI
see
#createLayout
see
LookAndFeel#installBorder
see
LookAndFeel#installColors

        LayoutManager layout = spinner.getLayout();

        if (layout == null || layout instanceof UIResource) {
            spinner.setLayout(createLayout());
        }
        updateStyle(spinner);
    
protected voidinstallListeners()

	super.installListeners();
        spinner.addPropertyChangeListener(this);
    
public voidpaint(java.awt.Graphics g, javax.swing.JComponent c)

        SynthContext context = getContext(c);

        paint(context, g);
        context.dispose();
    
protected voidpaint(javax.swing.plaf.synth.SynthContext context, java.awt.Graphics g)

    
public voidpaintBorder(javax.swing.plaf.synth.SynthContext context, java.awt.Graphics g, int x, int y, int w, int h)

        context.getPainter().paintSpinnerBorder(context, g, x, y, w, h);
    
public voidpropertyChange(java.beans.PropertyChangeEvent e)

        String propertyName = e.getPropertyName();
        JSpinner spinner = (JSpinner)(e.getSource());
        SpinnerUI spinnerUI = spinner.getUI();
    
        if (spinnerUI instanceof SynthSpinnerUI) {
            SynthSpinnerUI ui = (SynthSpinnerUI)spinnerUI;
    
            if (SynthLookAndFeel.shouldUpdateStyle(e)) {
                ui.updateStyle(spinner);
            }
        }
    
protected voidreplaceEditor(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.

see
#createEditor
see
#createPropertyChangeListener

	spinner.remove(oldEditor);
        updateEditorAlignment(newEditor);
	spinner.add(newEditor, "Editor");
    
protected voiduninstallDefaults()
Sets the JSpinner's layout manager to null. This method is called by uninstallUI.

see
#installDefaults
see
#uninstallUI

        if (spinner.getLayout() instanceof UIResource) {
            spinner.setLayout(null);
        }

        SynthContext context = getContext(spinner, ENABLED);

        style.uninstallDefaults(context);
        context.dispose();
        style = null;
    
protected voiduninstallListeners()
Removes the propertyChangeListener added by installListeners.

This method is called by uninstallUI.

see
#installListeners

	super.uninstallListeners();
	spinner.removePropertyChangeListener(this);
    
public voidupdate(java.awt.Graphics g, javax.swing.JComponent c)

        SynthContext context = getContext(c);

        SynthLookAndFeel.update(context, g);
        context.getPainter().paintSpinnerBackground(context,
                          g, 0, 0, c.getWidth(), c.getHeight());
        paint(context, g);
        context.dispose();
    
private voidupdateEditorAlignment(javax.swing.JComponent editor)

        if (editor instanceof JSpinner.DefaultEditor) {
            SynthContext context = getContext(spinner);
            Integer alignment = (Integer)context.getStyle().get(
                    context, "Spinner.editorAlignment");
            if (alignment != null) {
                JTextField text = ((JSpinner.DefaultEditor)editor).getTextField();
                text.setHorizontalAlignment(alignment);
            }
        }
    
private voidupdateStyle(javax.swing.JSpinner c)

        SynthContext context = getContext(c, ENABLED);
        SynthStyle oldStyle = style;
        style = SynthLookAndFeel.updateStyle(context, this);
        if (style != oldStyle) {
            if (oldStyle != null) {
                // Only call installKeyboardActions as uninstall is not
                // public.
                installKeyboardActions();
            }
        }
        context.dispose();