jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaSpinnerUI.java
author aniyogi
Mon, 18 Jan 2016 14:20:39 +0530
changeset 35674 8ac51e1179da
parent 32669 8ff453aa551b
permissions -rw-r--r--
8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac Reviewed-by: serb, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
30921
cb07b8856f61 5036022: JSpinner does not reflect new font on subsequent calls to setFont
serb
parents: 25859
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
package com.apple.laf;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
import java.awt.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
import java.awt.event.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
import java.beans.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
import java.text.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
import java.text.AttributedCharacterIterator.Attribute;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
import java.text.Format.Field;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
import java.util.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
import javax.swing.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
import javax.swing.JSpinner.DefaultEditor;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
import javax.swing.plaf.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
import javax.swing.text.InternationalFormatter;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
import apple.laf.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
import apple.laf.JRSUIConstants.*;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
import com.apple.laf.AquaUtils.RecyclableSingleton;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
/**
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    47
 * This is originally derived from BasicSpinnerUI, but they made everything
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    48
 * private so we can't subclass!
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
public class AquaSpinnerUI extends SpinnerUI {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    51
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    52
    private static final RecyclableSingleton<? extends PropertyChangeListener> propertyChangeListener
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    53
            = new RecyclableSingletonFromDefaultConstructor<>(PropertyChangeHandler.class);
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    54
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
    static PropertyChangeListener getPropertyChangeListener() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
        return propertyChangeListener.get();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    59
    private static final RecyclableSingleton<ArrowButtonHandler> nextButtonHandler
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    60
            = new RecyclableSingleton<ArrowButtonHandler>() {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    61
                @Override
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    62
                protected ArrowButtonHandler getInstance() {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    63
                    return new ArrowButtonHandler("increment", true);
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    64
                }
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    65
            };
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    66
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
    static ArrowButtonHandler getNextButtonHandler() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
        return nextButtonHandler.get();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    }
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    70
    private static final RecyclableSingleton<ArrowButtonHandler> previousButtonHandler
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    71
            = new RecyclableSingleton<ArrowButtonHandler>() {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    72
                @Override
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    73
                protected ArrowButtonHandler getInstance() {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    74
                    return new ArrowButtonHandler("decrement", false);
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    75
                }
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    76
            };
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    77
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
    static ArrowButtonHandler getPreviousButtonHandler() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
        return previousButtonHandler.get();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    82
    private JSpinner spinner;
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    83
    private SpinPainter spinPainter;
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    84
    private TransparentButton next;
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    85
    private TransparentButton prev;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
    public static ComponentUI createUI(final JComponent c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
        return new AquaSpinnerUI();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
    private void maybeAdd(final Component c, final String s) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
        if (c != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
            spinner.add(c, s);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
    boolean wasOpaque;
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
    98
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
    99
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
    public void installUI(final JComponent c) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   101
        this.spinner = (JSpinner) c;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
        installDefaults();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
        installListeners();
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   104
        next = createNextButton();
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   105
        prev = createPreviousButton();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
        spinPainter = new SpinPainter(next, prev);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
        maybeAdd(next, "Next");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
        maybeAdd(prev, "Previous");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
        maybeAdd(createEditor(), "Editor");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
        maybeAdd(spinPainter, "Painter");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
        updateEnabledState();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
        installKeyboardActions();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
        // this doesn't work because JSpinner calls setOpaque(true) directly in it's constructor
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   117
        //    LookAndFeel.installProperty(spinner, "opaque", Boolean.FALSE);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
        // ...so we have to handle the is/was opaque ourselves
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
        wasOpaque = spinner.isOpaque();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
        spinner.setOpaque(false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   123
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
    public void uninstallUI(final JComponent c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
        uninstallDefaults();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
        uninstallListeners();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
        spinner.setOpaque(wasOpaque);
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   128
        spinPainter = null;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
        spinner = null;
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   130
        // AquaButtonUI install some listeners to all parents, which means that
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   131
        // we need to uninstall UI here to remove those listeners, because after
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   132
        // we remove them from spinner we lost the latest reference to them,
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   133
        // and our standard uninstallUI machinery will not call them.
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   134
        next.getUI().uninstallUI(next);
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   135
        prev.getUI().uninstallUI(prev);
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   136
        next = null;
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   137
        prev = null;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
        c.removeAll();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
    protected void installListeners() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
        spinner.addPropertyChangeListener(getPropertyChangeListener());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
    protected void uninstallListeners() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
        spinner.removePropertyChangeListener(getPropertyChangeListener());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
    protected void installDefaults() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
        spinner.setLayout(createLayout());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
        LookAndFeel.installBorder(spinner, "Spinner.border");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
        LookAndFeel.installColorsAndFont(spinner, "Spinner.background", "Spinner.foreground", "Spinner.font");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
    protected void uninstallDefaults() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
        spinner.setLayout(null);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
    protected LayoutManager createLayout() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
        return new SpinnerLayout();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
    protected PropertyChangeListener createPropertyChangeListener() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
        return new PropertyChangeHandler();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
    protected TransparentButton createPreviousButton() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
        final TransparentButton b = new TransparentButton();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
        b.addActionListener(getPreviousButtonHandler());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
        b.addMouseListener(getPreviousButtonHandler());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
        b.setInheritsPopupMenu(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
        return b;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
    protected TransparentButton createNextButton() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
        final TransparentButton b = new TransparentButton();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
        b.addActionListener(getNextButtonHandler());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
        b.addMouseListener(getNextButtonHandler());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
        b.setInheritsPopupMenu(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
        return b;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
     * {@inheritDoc}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
     */
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   186
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
    public int getBaseline(JComponent c, int width, int height) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
        super.getBaseline(c, width, height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
        JComponent editor = spinner.getEditor();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
        Insets insets = spinner.getInsets();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
        width = width - insets.left - insets.right;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
        height = height - insets.top - insets.bottom;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
        if (width >= 0 && height >= 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
            int baseline = editor.getBaseline(width, height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
            if (baseline >= 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
                return insets.top + baseline;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
        return -1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
    /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
     * {@inheritDoc}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
     */
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   205
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
            JComponent c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
        super.getBaselineResizeBehavior(c);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
        return spinner.getEditor().getBaselineResizeBehavior();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
23649
f4f882f0056b 8035692: Fix serial lint warnings in mac-specific code
darcy
parents: 23010
diff changeset
   212
    @SuppressWarnings("serial") // Superclass is not serializable across versions
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
    class TransparentButton extends JButton implements SwingConstants {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   214
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
        boolean interceptRepaints = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
        public TransparentButton() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
            super();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
            setFocusable(false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
            // only intercept repaints if we are after this has been initialized
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
            // otherwise we can't talk to our containing class
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
            interceptRepaints = true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   225
        @Override
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   226
        public void paint(final Graphics g) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   227
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   229
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
        public void repaint() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
            // only intercept repaints if we are after this has been initialized
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
            // otherwise we can't talk to our containing class
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
            if (interceptRepaints) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   234
                if (spinPainter == null) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   235
                    return;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   236
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
                spinPainter.repaint();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
            super.repaint();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    protected JComponent createEditor() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
        final JComponent editor = spinner.getEditor();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
        fixupEditor(editor);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
        return editor;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
    protected void replaceEditor(final JComponent oldEditor, final JComponent newEditor) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
        spinner.remove(oldEditor);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
        fixupEditor(newEditor);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
        spinner.add(newEditor, "Editor");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
    protected void fixupEditor(final JComponent editor) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   256
        if (!(editor instanceof DefaultEditor)) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   257
            return;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   258
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
        editor.setOpaque(false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
        editor.setInheritsPopupMenu(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
        if (editor.getFont() instanceof UIResource) {
30921
cb07b8856f61 5036022: JSpinner does not reflect new font on subsequent calls to setFont
serb
parents: 25859
diff changeset
   264
            editor.setFont(new FontUIResource(spinner.getFont()));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   267
        final JFormattedTextField editorTextField = ((DefaultEditor) editor).getTextField();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
        if (editorTextField.getFont() instanceof UIResource) {
30921
cb07b8856f61 5036022: JSpinner does not reflect new font on subsequent calls to setFont
serb
parents: 25859
diff changeset
   269
            editorTextField.setFont(new FontUIResource(spinner.getFont()));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
        final InputMap spinnerInputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
        final InputMap editorInputMap = editorTextField.getInputMap();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
        final KeyStroke[] keys = spinnerInputMap.keys();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
        for (final KeyStroke k : keys) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
            editorInputMap.put(k, spinnerInputMap.get(k));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
    void updateEnabledState() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
        updateEnabledState(spinner, spinner.isEnabled());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
    private void updateEnabledState(final Container c, final boolean enabled) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
        for (int counter = c.getComponentCount() - 1; counter >= 0; counter--) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
            final Component child = c.getComponent(counter);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
            child.setEnabled(enabled);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
            if (child instanceof Container) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   289
                updateEnabledState((Container) child, enabled);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
    private void installKeyboardActions() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
        final InputMap iMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
        SwingUtilities.replaceUIInputMap(spinner, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, iMap);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
        SwingUtilities.replaceUIActionMap(spinner, getActionMap());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
    private InputMap getInputMap(final int condition) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
        if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   302
            return (InputMap) UIManager.get("Spinner.ancestorInputMap");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
        return null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
    private ActionMap getActionMap() {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   308
        ActionMap map = (ActionMap) UIManager.get("Spinner.actionMap");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
        if (map == null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
            map = createActionMap();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
            if (map != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
                UIManager.getLookAndFeelDefaults().put("Spinner.actionMap", map);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
        return map;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
    private ActionMap createActionMap() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
        final ActionMap map = new ActionMapUIResource();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
        map.put("increment", getNextButtonHandler());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
        map.put("decrement", getPreviousButtonHandler());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
        return map;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
23649
f4f882f0056b 8035692: Fix serial lint warnings in mac-specific code
darcy
parents: 23010
diff changeset
   326
    @SuppressWarnings("serial") // Superclass is not serializable across versions
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
    private static class ArrowButtonHandler extends AbstractAction implements MouseListener {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   328
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
        final javax.swing.Timer autoRepeatTimer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
        final boolean isNext;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
        JSpinner spinner = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
        ArrowButtonHandler(final String name, final boolean isNext) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
            super(name);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
            this.isNext = isNext;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
            autoRepeatTimer = new javax.swing.Timer(60, this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
            autoRepeatTimer.setInitialDelay(300);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
        private JSpinner eventToSpinner(final AWTEvent e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
            Object src = e.getSource();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
            while ((src instanceof Component) && !(src instanceof JSpinner)) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   343
                src = ((Component) src).getParent();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
            }
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   345
            return (src instanceof JSpinner) ? (JSpinner) src : null;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   348
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
        public void actionPerformed(final ActionEvent e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
            if (!(e.getSource() instanceof javax.swing.Timer)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
                // Most likely resulting from being in ActionMap.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
                spinner = eventToSpinner(e);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   355
            if (spinner == null) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   356
                return;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   357
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
            try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
                final int calendarField = getCalendarField(spinner);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
                spinner.commitEdit();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
                if (calendarField != -1) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   363
                    ((SpinnerDateModel) spinner.getModel()).setCalendarField(calendarField);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
                final Object value = (isNext) ? spinner.getNextValue() : spinner.getPreviousValue();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
                if (value != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
                    spinner.setValue(value);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
                    select(spinner);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
            } catch (final IllegalArgumentException iae) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
                UIManager.getLookAndFeel().provideErrorFeedback(spinner);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
            } catch (final ParseException pe) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
                UIManager.getLookAndFeel().provideErrorFeedback(spinner);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
        /**
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
         * If the spinner's editor is a DateEditor, this selects the field
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
         * associated with the value that is being incremented.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
         */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
        private void select(final JSpinner spinnerComponent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
            final JComponent editor = spinnerComponent.getEditor();
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   383
            if (!(editor instanceof JSpinner.DateEditor)) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   384
                return;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   385
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   387
            final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
            final JFormattedTextField ftf = dateEditor.getTextField();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
            final Format format = dateEditor.getFormat();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
            Object value;
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   391
            if (format == null || (value = spinnerComponent.getValue()) == null) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   392
                return;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   393
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   394
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   395
            final SpinnerDateModel model = dateEditor.getModel();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   396
            final DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   397
            if (field == null) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   398
                return;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   399
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   400
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   401
            try {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   402
                final AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   403
                if (!select(ftf, iterator, field) && field == DateFormat.Field.HOUR0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   404
                    select(ftf, iterator, DateFormat.Field.HOUR1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   405
                }
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   406
            } catch (final IllegalArgumentException iae) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   407
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   408
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   409
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   410
        /**
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   411
         * Selects the passed in field, returning true if it is found, false
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   412
         * otherwise.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
         */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   414
        private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   415
            final int max = ftf.getDocument().getLength();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   416
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   417
            iterator.first();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
            do {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   419
                final Map<Attribute, Object> attrs = iterator.getAttributes();
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   420
                if (attrs == null || !attrs.containsKey(field)) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   421
                    continue;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   422
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   423
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
                final int start = iterator.getRunStart(field);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
                final int end = iterator.getRunLimit(field);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
                if (start != -1 && end != -1 && start <= max && end <= max) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
                    ftf.select(start, end);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
                return true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   431
            } while (iterator.next() != CharacterIterator.DONE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   432
            return false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   434
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   435
        /**
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   436
         * Returns the calendarField under the start of the selection, or -1 if
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   437
         * there is no valid calendar field under the selection (or the spinner
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   438
         * isn't editing dates.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   439
         */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   440
        private int getCalendarField(final JSpinner spinnerComponent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
            final JComponent editor = spinnerComponent.getEditor();
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   442
            if (!(editor instanceof JSpinner.DateEditor)) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   443
                return -1;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   444
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   446
            final JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
            final JFormattedTextField ftf = dateEditor.getTextField();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
            final int start = ftf.getSelectionStart();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   449
            final JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   450
            if (!(formatter instanceof InternationalFormatter)) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   451
                return -1;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   452
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   453
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   454
            final Format.Field[] fields = ((InternationalFormatter) formatter).getFields(start);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
            for (final Field element : fields) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   456
                if (!(element instanceof DateFormat.Field)) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   457
                    continue;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   458
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   459
                int calendarField;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
                if (element == DateFormat.Field.HOUR1) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
                    calendarField = Calendar.HOUR;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   463
                } else {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   464
                    calendarField = ((DateFormat.Field) element).getCalendarField();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   465
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   466
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   467
                if (calendarField != -1) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   468
                    return calendarField;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   469
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   470
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   471
            return -1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   472
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   473
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   474
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   475
        public void mousePressed(final MouseEvent e) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   476
            if (!SwingUtilities.isLeftMouseButton(e) || !e.getComponent().isEnabled()) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   477
                return;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   478
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   479
            spinner = eventToSpinner(e);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   480
            autoRepeatTimer.start();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   481
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
            focusSpinnerIfNecessary();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   483
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   484
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   485
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   486
        public void mouseReleased(final MouseEvent e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   487
            autoRepeatTimer.stop();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   488
            spinner = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   489
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   490
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   491
        @Override
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   492
        public void mouseClicked(final MouseEvent e) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   493
        }
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   494
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   495
        @Override
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   496
        public void mouseEntered(final MouseEvent e) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   497
        }
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   498
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   499
        @Override
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   500
        public void mouseExited(final MouseEvent e) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   501
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   502
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   503
        /**
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   504
         * Requests focus on a child of the spinner if the spinner doesn't have
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   505
         * focus.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   506
         */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   507
        private void focusSpinnerIfNecessary() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   508
            final Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   509
            if (!spinner.isRequestFocusEnabled() || (fo != null && (SwingUtilities.isDescendingFrom(fo, spinner)))) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   510
                return;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   511
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   512
            Container root = spinner;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   513
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   514
            if (!root.isFocusCycleRoot()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   515
                root = root.getFocusCycleRootAncestor();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   516
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   517
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   518
            if (root == null) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   519
                return;
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   520
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   521
            final FocusTraversalPolicy ftp = root.getFocusTraversalPolicy();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   522
            final Component child = ftp.getComponentAfter(root, spinner);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   523
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   524
            if (child != null && SwingUtilities.isDescendingFrom(child, spinner)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   525
                child.requestFocus();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   526
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   527
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   528
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   529
23649
f4f882f0056b 8035692: Fix serial lint warnings in mac-specific code
darcy
parents: 23010
diff changeset
   530
    @SuppressWarnings("serial") // Superclass is not serializable across versions
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   531
    class SpinPainter extends JComponent {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   532
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   533
        final AquaPainter<JRSUIState> painter = AquaPainter.create(JRSUIStateFactory.getSpinnerArrows());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   534
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   535
        ButtonModel fTopModel;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   536
        ButtonModel fBottomModel;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   537
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   538
        boolean fPressed = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   539
        boolean fTopPressed = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   540
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   541
        Dimension kPreferredSize = new Dimension(15, 24); // 19,27 before trimming
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   542
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   543
        public SpinPainter(final AbstractButton top, final AbstractButton bottom) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   544
            if (top != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   545
                fTopModel = top.getModel();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   546
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   547
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   548
            if (bottom != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   549
                fBottomModel = bottom.getModel();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   550
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   551
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   552
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   553
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   554
        public void paint(final Graphics g) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   555
            if (spinner.isOpaque()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   556
                g.setColor(spinner.getBackground());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   557
                g.fillRect(0, 0, getWidth(), getHeight());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   558
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   559
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   560
            AquaUtilControlSize.applySizeForControl(spinner, painter);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   561
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   562
            if (isEnabled()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   563
                if (fTopModel != null && fTopModel.isPressed()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   564
                    painter.state.set(State.PRESSED);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   565
                    painter.state.set(BooleanValue.NO);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   566
                } else if (fBottomModel != null && fBottomModel.isPressed()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   567
                    painter.state.set(State.PRESSED);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   568
                    painter.state.set(BooleanValue.YES);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   569
                } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   570
                    painter.state.set(State.ACTIVE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   571
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   572
            } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   573
                painter.state.set(State.DISABLED);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   574
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   575
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   576
            final Rectangle bounds = getBounds();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   577
            painter.paint(g, spinner, 0, 0, bounds.width, bounds.height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   578
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   579
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   580
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   581
        public Dimension getPreferredSize() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   582
            final Size size = AquaUtilControlSize.getUserSizeFrom(this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   583
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   584
            if (size == Size.MINI) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   585
                return new Dimension(kPreferredSize.width, kPreferredSize.height - 8);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   586
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   587
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   588
            return kPreferredSize;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   589
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   590
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   591
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   592
    /**
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   593
     * A simple layout manager for the editor and the next/previous buttons. See
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   594
     * the AquaSpinnerUI javadoc for more information about exactly how the
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   595
     * components are arranged.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   596
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   597
    static class SpinnerLayout implements LayoutManager {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   598
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   599
        private Component nextButton = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   600
        private Component previousButton = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   601
        private Component editor = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   602
        private Component painter = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   603
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   604
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   605
        public void addLayoutComponent(final String name, final Component c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   606
            if ("Next".equals(name)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   607
                nextButton = c;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   608
            } else if ("Previous".equals(name)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   609
                previousButton = c;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   610
            } else if ("Editor".equals(name)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   611
                editor = c;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   612
            } else if ("Painter".equals(name)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   613
                painter = c;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   614
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   615
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   616
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   617
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
        public void removeLayoutComponent(Component c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   619
            if (c == nextButton) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   620
                c = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   621
            } else if (c == previousButton) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   622
                previousButton = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   623
            } else if (c == editor) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   624
                editor = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   625
            } else if (c == painter) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   626
                painter = null;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   627
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   628
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   629
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   630
        private Dimension preferredSize(final Component c) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   631
            return (c == null) ? new Dimension(0, 0) : c.getPreferredSize();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   632
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   633
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   634
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   635
        public Dimension preferredLayoutSize(final Container parent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   636
//            Dimension nextD = preferredSize(nextButton);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   637
//            Dimension previousD = preferredSize(previousButton);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   638
            final Dimension editorD = preferredSize(editor);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   639
            final Dimension painterD = preferredSize(painter);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   640
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   641
            /* Force the editors height to be a multiple of 2
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   642
             */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   643
            editorD.height = ((editorD.height + 1) / 2) * 2;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   644
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   645
            final Dimension size = new Dimension(editorD.width, Math.max(painterD.height, editorD.height));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   646
            size.width += painterD.width; //Math.max(nextD.width, previousD.width);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   647
            final Insets insets = parent.getInsets();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   648
            size.width += insets.left + insets.right;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   649
            size.height += insets.top + insets.bottom;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   650
            return size;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   651
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   652
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   653
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   654
        public Dimension minimumLayoutSize(final Container parent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   655
            return preferredLayoutSize(parent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   656
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   657
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   658
        private void setBounds(final Component c, final int x, final int y, final int width, final int height) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   659
            if (c != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   660
                c.setBounds(x, y, width, height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   661
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   662
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   663
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   664
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   665
        public void layoutContainer(final Container parent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   666
            final Insets insets = parent.getInsets();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   667
            final int availWidth = parent.getWidth() - (insets.left + insets.right);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   668
            final int availHeight = parent.getHeight() - (insets.top + insets.bottom);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   669
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   670
            final Dimension painterD = preferredSize(painter);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   671
//            Dimension nextD = preferredSize(nextButton);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   672
//            Dimension previousD = preferredSize(previousButton);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   673
            final int nextHeight = availHeight / 2;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   674
            final int previousHeight = availHeight - nextHeight;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   675
            final int buttonsWidth = painterD.width; //Math.max(nextD.width, previousD.width);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   676
            final int editorWidth = availWidth - buttonsWidth;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   677
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   678
            /* Deal with the spinners componentOrientation property.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   679
             */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   680
            int editorX, buttonsX;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   681
            if (parent.getComponentOrientation().isLeftToRight()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   682
                editorX = insets.left;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   683
                buttonsX = editorX + editorWidth;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   684
            } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   685
                buttonsX = insets.left;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   686
                editorX = buttonsX + buttonsWidth;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   687
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   688
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   689
            final int previousY = insets.top + nextHeight;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   690
            final int painterTop = previousY - (painterD.height / 2);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   691
            setBounds(editor, editorX, insets.top, editorWidth, availHeight);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   692
            setBounds(nextButton, buttonsX, insets.top, buttonsWidth, nextHeight);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   693
            setBounds(previousButton, buttonsX, previousY, buttonsWidth, previousHeight);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   694
            setBounds(painter, buttonsX, painterTop, buttonsWidth, painterD.height);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   695
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   696
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   697
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   698
    /**
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   699
     * Detect JSpinner property changes we're interested in and delegate.
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   700
     * Subclasses shouldn't need to replace the default propertyChangeListener
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   701
     * (although they can by overriding createPropertyChangeListener) since all
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   702
     * of the interesting property changes are delegated to protected methods.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   703
     */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   704
    static class PropertyChangeHandler implements PropertyChangeListener {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   705
32669
8ff453aa551b 8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents: 30921
diff changeset
   706
        @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   707
        public void propertyChange(final PropertyChangeEvent e) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   708
            final String propertyName = e.getPropertyName();
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   709
            final JSpinner spinner = (JSpinner) (e.getSource());
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   710
            final SpinnerUI spinnerUI = spinner.getUI();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   711
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   712
            if (spinnerUI instanceof AquaSpinnerUI) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   713
                final AquaSpinnerUI ui = (AquaSpinnerUI) spinnerUI;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   714
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   715
                if ("editor".equals(propertyName)) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   716
                    final JComponent oldEditor = (JComponent) e.getOldValue();
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   717
                    final JComponent newEditor = (JComponent) e.getNewValue();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   718
                    ui.replaceEditor(oldEditor, newEditor);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   719
                    ui.updateEnabledState();
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   720
                } else if ("componentOrientation".equals(propertyName)) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   721
                    ComponentOrientation o
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   722
                            = (ComponentOrientation) e.getNewValue();
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   723
                    if (o != e.getOldValue()) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   724
                        JComponent editor = spinner.getEditor();
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   725
                        if (editor != null) {
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   726
                            editor.applyComponentOrientation(o);
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   727
                        }
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   728
                        spinner.revalidate();
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   729
                        spinner.repaint();
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   730
                    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   731
                } else if ("enabled".equals(propertyName)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   732
                    ui.updateEnabledState();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   733
                } else if (JComponent.TOOL_TIP_TEXT_KEY.equals(propertyName)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   734
                    ui.updateToolTipTextForChildren(spinner);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   735
                } else if ("font".equals(propertyName)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   736
                    JComponent editor = spinner.getEditor();
30921
cb07b8856f61 5036022: JSpinner does not reflect new font on subsequent calls to setFont
serb
parents: 25859
diff changeset
   737
                    if (editor instanceof JSpinner.DefaultEditor) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   738
                        JTextField tf
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   739
                                = ((JSpinner.DefaultEditor) editor).getTextField();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   740
                        if (tf != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   741
                            if (tf.getFont() instanceof UIResource) {
30921
cb07b8856f61 5036022: JSpinner does not reflect new font on subsequent calls to setFont
serb
parents: 25859
diff changeset
   742
                                tf.setFont(new FontUIResource(spinner.getFont()));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   743
                            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   744
                        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   745
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   746
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   747
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   748
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   749
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   750
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   751
    // Syncronizes the ToolTip text for the components within the spinner
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   752
    // to be the same value as the spinner ToolTip text.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   753
    void updateToolTipTextForChildren(final JComponent spinnerComponent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   754
        final String toolTipText = spinnerComponent.getToolTipText();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   755
        final Component[] children = spinnerComponent.getComponents();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   756
        for (final Component element : children) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   757
            if (element instanceof JSpinner.DefaultEditor) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   758
                final JTextField tf = ((JSpinner.DefaultEditor) element).getTextField();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   759
                if (tf != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   760
                    tf.setToolTipText(toolTipText);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   761
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   762
            } else if (element instanceof JComponent) {
35674
8ac51e1179da 8041894: [macosx] Test javax/swing/JSpinner/8008657/bug8008657.java failed on Mac
aniyogi
parents: 32669
diff changeset
   763
                ((JComponent) element).setToolTipText(toolTipText);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   764
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   765
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   766
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   767
}