jdk/src/share/classes/javax/swing/plaf/synth/SynthSpinnerUI.java
author darcy
Sun, 23 Mar 2014 13:49:48 -0700
changeset 23697 e556a715949f
parent 23010 6dadb192ad81
child 25100 d527cc827d7d
permissions -rw-r--r--
8034169: Fix serial lint warnings in javax.swing Reviewed-by: alanb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20168
diff changeset
     2
 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4848
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.plaf.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.basic.BasicSpinnerUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
    35
 * Provides the Synth L&F UI delegate for
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    36
 * {@link javax.swing.JSpinner}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author Joshua Outwater
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    40
 * @since 1.7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    42
public class SynthSpinnerUI extends BasicSpinnerUI
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    43
                            implements PropertyChangeListener, SynthUI {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private SynthStyle style;
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    45
    /**
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    46
     * A FocusListener implementation which causes the entire spinner to be
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    47
     * repainted whenever the editor component (typically a text field) becomes
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    48
     * focused, or loses focus. This is necessary because since SynthSpinnerUI
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    49
     * is composed of an editor and two buttons, it is necessary that all three
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    50
     * components indicate that they are "focused" so that they can be drawn
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    51
     * appropriately. The repaint is used to ensure that the buttons are drawn
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    52
     * in the new focused or unfocused state, mirroring that of the editor.
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    53
     */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    54
    private EditorFocusHandler editorFocusHandler = new EditorFocusHandler();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Returns a new instance of SynthSpinnerUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @param c the JSpinner (not used)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @see ComponentUI#createUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @return a new SynthSpinnerUI object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return new SynthSpinnerUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    67
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
    68
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
    69
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    70
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        spinner.addPropertyChangeListener(this);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    74
        JComponent editor = spinner.getEditor();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    75
        if (editor instanceof JSpinner.DefaultEditor) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    76
            JTextField tf = ((JSpinner.DefaultEditor)editor).getTextField();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    77
            if (tf != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    78
                tf.addFocusListener(editorFocusHandler);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    79
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    80
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
    84
     * {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    86
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        spinner.removePropertyChangeListener(this);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    90
        JComponent editor = spinner.getEditor();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    91
        if (editor instanceof JSpinner.DefaultEditor) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    92
            JTextField tf = ((JSpinner.DefaultEditor)editor).getTextField();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    93
            if (tf != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    94
                tf.removeFocusListener(editorFocusHandler);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    95
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
    96
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   100
     * Initializes the <code>JSpinner</code> <code>border</code>,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * <code>foreground</code>, and <code>background</code>, properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * based on the corresponding "Spinner.*" properties from defaults table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * The <code>JSpinners</code> layout is set to the value returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <code>createLayout</code>.  This method is called by <code>installUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #uninstallDefaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @see #installUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see #createLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @see LookAndFeel#installBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see LookAndFeel#installColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   112
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        LayoutManager layout = spinner.getLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (layout == null || layout instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            spinner.setLayout(createLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        updateStyle(spinner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private void updateStyle(JSpinner c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        SynthContext context = getContext(c, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        SynthStyle oldStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        style = SynthLookAndFeel.updateStyle(context, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (style != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                // Only call installKeyboardActions as uninstall is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                // public.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Sets the <code>JSpinner's</code> layout manager to null.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * method is called by <code>uninstallUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see #installDefaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @see #uninstallUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   145
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (spinner.getLayout() instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            spinner.setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        SynthContext context = getContext(spinner, ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        style.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        style = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   158
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   159
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   160
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   161
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    protected LayoutManager createLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return new SpinnerLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   168
     * {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   170
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    protected Component createPreviousButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        JButton b = new SynthArrowButton(SwingConstants.SOUTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        b.setName("Spinner.previousButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        installPreviousButtonListeners(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   180
     * {@inheritDoc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   182
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    protected Component createNextButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        JButton b = new SynthArrowButton(SwingConstants.NORTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        b.setName("Spinner.nextButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        installNextButtonListeners(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * This method is called by installUI to get the editor component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * of the <code>JSpinner</code>.  By default it just returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <code>JSpinner.getEditor()</code>.  Subclasses can override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <code>createEditor</code> to return a component that contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * the spinner's editor or null, if they're going to handle adding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * the editor to the <code>JSpinner</code> in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * <code>installUI</code> override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Typically this method would be overridden to wrap the editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * with a container with a custom border, since one can't assume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * that the editors border can be set directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * The <code>replaceEditor</code> method is called when the spinners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * editor is changed with <code>JSpinner.setEditor</code>.  If you've
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * overriden this method, then you'll probably want to override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <code>replaceEditor</code> as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @return the JSpinners editor JComponent, spinner.getEditor() by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @see #installUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @see #replaceEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see JSpinner#getEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   214
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    protected JComponent createEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        JComponent editor = spinner.getEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        editor.setName("Spinner.editor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        updateEditorAlignment(editor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Called by the <code>PropertyChangeListener</code> when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <code>JSpinner</code> editor property changes.  It's the responsibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * of this method to remove the old editor and add the new one.  By
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * default this operation is just:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * spinner.remove(oldEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * spinner.add(newEditor, "Editor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * The implementation of <code>replaceEditor</code> should be coordinated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * with the <code>createEditor</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @see #createEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @see #createPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   238
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    protected void replaceEditor(JComponent oldEditor, JComponent newEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        spinner.remove(oldEditor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        spinner.add(newEditor, "Editor");
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   242
        if (oldEditor instanceof JSpinner.DefaultEditor) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   243
            JTextField tf = ((JSpinner.DefaultEditor)oldEditor).getTextField();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   244
            if (tf != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   245
                tf.removeFocusListener(editorFocusHandler);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   246
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   247
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   248
        if (newEditor instanceof JSpinner.DefaultEditor) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   249
            JTextField tf = ((JSpinner.DefaultEditor)newEditor).getTextField();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   250
            if (tf != null) {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   251
                tf.addFocusListener(editorFocusHandler);
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   252
            }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   253
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    private void updateEditorAlignment(JComponent editor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (editor instanceof JSpinner.DefaultEditor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            SynthContext context = getContext(spinner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            Integer alignment = (Integer)context.getStyle().get(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    context, "Spinner.editorAlignment");
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   261
            JTextField text = ((JSpinner.DefaultEditor)editor).getTextField();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            if (alignment != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                text.setHorizontalAlignment(alignment);
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   264
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   266
            // copy across the sizeVariant property to the editor
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   267
            text.putClientProperty("JComponent.sizeVariant",
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   268
                    spinner.getClientProperty("JComponent.sizeVariant"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   272
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   273
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   274
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   275
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public SynthContext getContext(JComponent c) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   277
        return getContext(c, SynthLookAndFeel.getComponentState(c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private SynthContext getContext(JComponent c, int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return SynthContext.getContext(SynthContext.class, c,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    SynthLookAndFeel.getRegion(c), style, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   285
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   286
     * Notifies this UI delegate to repaint the specified component.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   287
     * This method paints the component background, then calls
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   288
     * the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   289
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   290
     * <p>In general, this method does not need to be overridden by subclasses.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   291
     * All Look and Feel rendering code should reside in the {@code paint} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   292
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   293
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   294
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   295
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   296
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   297
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public void update(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        SynthLookAndFeel.update(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        context.getPainter().paintSpinnerBackground(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                          g, 0, 0, c.getWidth(), c.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   309
    /**
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   310
     * Paints the specified component according to the Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   311
     * <p>This method is not used by Synth Look and Feel.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   312
     * Painting is handled by the {@link #paint(SynthContext,Graphics)} method.
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   313
     *
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   314
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   315
     * @param c the component being painted
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   316
     * @see #paint(SynthContext,Graphics)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   317
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   318
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        paint(context, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        context.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   326
    /**
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   327
     * Paints the specified component. This implementation does nothing.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   328
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   329
     * @param context context for the component being painted
4848
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   330
     * @param g the {@code Graphics} object used for painting
ffcc849b9351 6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents: 4394
diff changeset
   331
     * @see #update(Graphics,JComponent)
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   332
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    protected void paint(SynthContext context, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   336
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   337
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   338
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   339
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public void paintBorder(SynthContext context, Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                            int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        context.getPainter().paintSpinnerBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * A simple layout manager for the editor and the next/previous buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * See the SynthSpinnerUI javadoc for more information about exactly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * how the components are arranged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    private static class SpinnerLayout implements LayoutManager, UIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        private Component nextButton = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        private Component previousButton = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        private Component editor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        public void addLayoutComponent(String name, Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if ("Next".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                nextButton = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            else if ("Previous".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                previousButton = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            else if ("Editor".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                editor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        public void removeLayoutComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if (c == nextButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                nextButton = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            else if (c == previousButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                previousButton = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            else if (c == editor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                editor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        private Dimension preferredSize(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return (c == null) ? new Dimension(0, 0) : c.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        public Dimension preferredLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            Dimension nextD = preferredSize(nextButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            Dimension previousD = preferredSize(previousButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            Dimension editorD = preferredSize(editor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            /* Force the editors height to be a multiple of 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            editorD.height = ((editorD.height + 1) / 2) * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            Dimension size = new Dimension(editorD.width, editorD.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            size.width += Math.max(nextD.width, previousD.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            Insets insets = parent.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            size.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            size.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        public Dimension minimumLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            return preferredLayoutSize(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        private void setBounds(Component c, int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                c.setBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        public void layoutContainer(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            Insets insets = parent.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            int availWidth = parent.getWidth() - (insets.left + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            int availHeight = parent.getHeight() - (insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            Dimension nextD = preferredSize(nextButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            Dimension previousD = preferredSize(previousButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            int nextHeight = availHeight / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            int previousHeight = availHeight - nextHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            int buttonsWidth = Math.max(nextD.width, previousD.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            int editorWidth = availWidth - buttonsWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            /* Deal with the spinners componentOrientation property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            int editorX, buttonsX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            if (parent.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                editorX = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                buttonsX = editorX + editorWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                buttonsX = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                editorX = buttonsX + buttonsWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            int previousY = insets.top + nextHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            setBounds(editor, editorX, insets.top, editorWidth, availHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            setBounds(nextButton, buttonsX, insets.top, buttonsWidth, nextHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            setBounds(previousButton, buttonsX, previousY, buttonsWidth, previousHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   441
    /**
20168
137788883a22 8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents: 7668
diff changeset
   442
     * {@inheritDoc}
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   443
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   444
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        JSpinner spinner = (JSpinner)(e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        SpinnerUI spinnerUI = spinner.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if (spinnerUI instanceof SynthSpinnerUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            SynthSpinnerUI ui = (SynthSpinnerUI)spinnerUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            if (SynthLookAndFeel.shouldUpdateStyle(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                ui.updateStyle(spinner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   457
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   458
    /** Listen to editor text field focus changes and repaint whole spinner */
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   459
    private class EditorFocusHandler implements FocusListener{
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   460
        /** Invoked when a editor text field gains the keyboard focus. */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   461
        @Override public void focusGained(FocusEvent e) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   462
            spinner.repaint();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   463
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   464
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   465
        /** Invoked when a editor text field loses the keyboard focus. */
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   466
        @Override public void focusLost(FocusEvent e) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   467
            spinner.repaint();
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   468
        }
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 2
diff changeset
   469
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
}