jdk/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthLookAndFeel.java
author alexsch
Fri, 15 Apr 2016 19:15:12 +0400
changeset 37698 4d798c873df0
parent 34407 2b40f400a30b
child 43308 cff6230190e5
permissions -rw-r--r--
8132791: No access to SynthContext.getContext() Reviewed-by: serb, ssadetsky
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
32870
b73c8ff78c80 8135122: The SwingUtilities2.COMPONENT_UI_PROPERTY_KEY can be removed
serb
parents: 32485
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5133
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5133
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5133
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5133
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5133
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.plaf.synth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.ref.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.action.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.swing.plaf.synth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * SynthLookAndFeel provides the basis for creating a customized look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * feel. SynthLookAndFeel does not directly provide a look, all painting is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * delegated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * You need to either provide a configuration file, by way of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * {@link #load} method, or provide your own {@link SynthStyleFactory}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * to {@link #setStyleFactory}. Refer to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <a href="package-summary.html">package summary</a> for an example of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * loading a file, and {@link javax.swing.plaf.synth.SynthStyleFactory} for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * an example of providing your own <code>SynthStyleFactory</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <code>setStyleFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
34407
2b40f400a30b 8081411: Add an API for painting an icon with a SynthContext
alexsch
parents: 32870
diff changeset
    56
 * {@link SynthIcon} interface provides
2b40f400a30b 8081411: Add an API for painting an icon with a SynthContext
alexsch
parents: 32870
diff changeset
    57
 * {@code paintIcon(synthContext, graphics, x, y, width, height)} method that
2b40f400a30b 8081411: Add an API for painting an icon with a SynthContext
alexsch
parents: 32870
diff changeset
    58
 * allows to draw the icon with the given {@code SynthContext}.
2b40f400a30b 8081411: Add an API for painting an icon with a SynthContext
alexsch
parents: 32870
diff changeset
    59
 * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * This class implements {@link Serializable} as a side effect of it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * extending {@link BasicLookAndFeel}. It is not intended to be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * An attempt to serialize it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * result in {@link NotSerializableException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @serial exclude
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 23010
diff changeset
    70
@SuppressWarnings("serial") // Per above comment, not actually serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public class SynthLookAndFeel extends BasicLookAndFeel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Used in a handful of places where we need an empty Insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static final Insets EMPTY_UIRESOURCE_INSETS = new InsetsUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                                            0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * AppContext key to get the current SynthStyleFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final Object STYLE_FACTORY_KEY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                  new StringBuffer("com.sun.java.swing.plaf.gtk.StyleCache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
13037
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
    85
     * AppContext key to get selectedUI.
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
    86
     */
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
    87
    private static final Object SELECTED_UI_KEY = new StringBuilder("selectedUI");
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
    88
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
    89
    /**
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
    90
     * AppContext key to get selectedUIState.
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
    91
     */
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
    92
    private static final Object SELECTED_UI_STATE_KEY = new StringBuilder("selectedUIState");
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
    93
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
    94
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * The last SynthStyleFactory that was asked for from AppContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <code>lastContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static SynthStyleFactory lastFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * AppContext lastLAF came from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static AppContext lastContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * SynthStyleFactory for the this SynthLookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private SynthStyleFactory factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Map of defaults table entries. This is populated via the load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   113
    private Map<String, Object> defaultsMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private Handler _handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
13037
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   117
    static ComponentUI getSelectedUI() {
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   118
        return (ComponentUI) AppContext.getAppContext().get(SELECTED_UI_KEY);
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   119
    }
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   120
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Used by the renderers. For the most part the renderers are implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * as Labels, which is problematic in so far as they are never selected.
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 13037
diff changeset
   124
     * To accommodate this SynthLabelUI checks if the current
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * UI matches that of <code>selectedUI</code> (which this methods sets), if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * it does, then a state as set by this method is returned. This provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * a way for labels to have a state other than selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    static void setSelectedUI(ComponentUI uix, boolean selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                              boolean focused, boolean enabled,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                              boolean rollover) {
13037
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   132
        int selectedUIState = 0;
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   133
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (selected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            selectedUIState = SynthConstants.SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            if (focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                selectedUIState |= SynthConstants.FOCUSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        else if (rollover && enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            selectedUIState |=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    SynthConstants.MOUSE_OVER | SynthConstants.ENABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                selectedUIState |= SynthConstants.FOCUSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                selectedUIState |= SynthConstants.ENABLED;
13037
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   150
                if (focused) {
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   151
                    selectedUIState |= SynthConstants.FOCUSED;
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   152
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                selectedUIState |= SynthConstants.DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
13037
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   158
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   159
        AppContext context = AppContext.getAppContext();
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   160
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   161
        context.put(SELECTED_UI_KEY, uix);
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   162
        context.put(SELECTED_UI_STATE_KEY, Integer.valueOf(selectedUIState));
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   163
    }
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   164
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   165
    static int getSelectedUIState() {
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   166
        Integer result = (Integer) AppContext.getAppContext().get(SELECTED_UI_STATE_KEY);
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   167
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   168
        return result == null ? 0 : result.intValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Clears out the selected UI that was last set in setSelectedUI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    static void resetSelectedUI() {
13037
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   175
        AppContext.getAppContext().remove(SELECTED_UI_KEY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Sets the SynthStyleFactory that the UI classes provided by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * synth will use to obtain a SynthStyle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param cache SynthStyleFactory the UIs should use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public static void setStyleFactory(SynthStyleFactory cache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        // We assume the setter is called BEFORE the getter has been invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // for a particular AppContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        synchronized(SynthLookAndFeel.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            AppContext context = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            lastFactory = cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            lastContext = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            context.put(STYLE_FACTORY_KEY, cache);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Returns the current SynthStyleFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return SynthStyleFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public static SynthStyleFactory getStyleFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        synchronized(SynthLookAndFeel.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            AppContext context = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            if (lastContext == context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                return lastFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            lastContext = context;
13037
99200b262b30 7143614: SynthLookAndFeel stability improvement
rupashka
parents: 7668
diff changeset
   209
            lastFactory = (SynthStyleFactory) context.get(STYLE_FACTORY_KEY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return lastFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Returns the component state for the specified component. This should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * only be used for Components that don't have any special state beyond
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * that of ENABLED, DISABLED or FOCUSED. For example, buttons shouldn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * call into this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    static int getComponentState(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (c.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (c.isFocusOwner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                return SynthUI.ENABLED | SynthUI.FOCUSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return SynthUI.ENABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return SynthUI.DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Gets a SynthStyle for the specified region of the specified component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * This is not for general consumption, only custom UIs should call this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param c JComponent to get the SynthStyle for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param region Identifies the region of the specified component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @return SynthStyle to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public static SynthStyle getStyle(JComponent c, Region region) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return getStyleFactory().getStyle(c, region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Returns true if the Style should be updated in response to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * specified PropertyChangeEvent. This forwards to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <code>shouldUpdateStyleOnAncestorChanged</code> as necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    static boolean shouldUpdateStyle(PropertyChangeEvent event) {
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   249
        LookAndFeel laf = UIManager.getLookAndFeel();
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   250
        return (laf instanceof SynthLookAndFeel &&
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   251
                ((SynthLookAndFeel) laf).shouldUpdateStyleOnEvent(event));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * A convience method that will reset the Style of StyleContext if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return newStyle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    static SynthStyle updateStyle(SynthContext context, SynthUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        SynthStyle newStyle = getStyle(context.getComponent(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                       context.getRegion());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        SynthStyle oldStyle = context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (newStyle != oldStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (oldStyle != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                oldStyle.uninstallDefaults(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            context.setStyle(newStyle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            newStyle.installDefaults(context, ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return newStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Updates the style associated with <code>c</code>, and all its children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * This is a lighter version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <code>SwingUtilities.updateComponentTreeUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param c Component to update style for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public static void updateStyles(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (c instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            // Yes, this is hacky. A better solution is to get the UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            // and cast, but JComponent doesn't expose a getter for the UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            // (each of the UIs do), making that approach impractical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            String name = c.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            c.setName(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            if (name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                c.setName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            ((JComponent)c).revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        Component[] children = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (c instanceof JMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            children = ((JMenu)c).getMenuComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        else if (c instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            children = ((Container)c).getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (children != null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   302
            for (Component child : children) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   303
                updateStyles(child);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   306
        c.repaint();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Returns the Region for the JComponent <code>c</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @param c JComponent to fetch the Region for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @return Region corresponding to <code>c</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public static Region getRegion(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return Region.getRegion(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * A convenience method to return where the foreground should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * painted for the Component identified by the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * AbstractSynthContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    static Insets getPaintingInsets(SynthContext state, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (state.isSubregion()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            insets = state.getStyle().getInsets(state, insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            insets = state.getComponent().getInsets(insets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * A convenience method that handles painting of the background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * All SynthUI implementations should override update and invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    static void update(SynthContext state, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        paintRegion(state, g, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * A convenience method that handles painting of the background for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * subregions. All SynthUI's that have subregions should invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * this method, than paint the foreground.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    static void updateSubregion(SynthContext state, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                                Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        paintRegion(state, g, bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    private static void paintRegion(SynthContext state, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                    Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        JComponent c = state.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        SynthStyle style = state.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        int x, y, width, height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (bounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            width = c.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            height = c.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            x = bounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            y = bounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            width = bounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            height = bounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        // Fill in the background, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        boolean subregion = state.isSubregion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if ((subregion && style.isOpaque(state)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                          (!subregion && c.isOpaque())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            g.setColor(style.getColor(state, ColorType.BACKGROUND));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            g.fillRect(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    static boolean isLeftToRight(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return c.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Returns the ui that is of type <code>klass</code>, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * one can not be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23632
diff changeset
   389
    static Object getUIOfType(ComponentUI ui, Class<?> klass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (klass.isInstance(ui)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            return ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Creates the Synth look and feel <code>ComponentUI</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * the passed in <code>JComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @param c JComponent to create the <code>ComponentUI</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @return ComponentUI to use for <code>c</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        String key = c.getUIClassID().intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (key == "ButtonUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            return SynthButtonUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        else if (key == "CheckBoxUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            return SynthCheckBoxUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        else if (key == "CheckBoxMenuItemUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            return SynthCheckBoxMenuItemUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        else if (key == "ColorChooserUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            return SynthColorChooserUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        else if (key == "ComboBoxUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return SynthComboBoxUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        else if (key == "DesktopPaneUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            return SynthDesktopPaneUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        else if (key == "DesktopIconUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            return SynthDesktopIconUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        else if (key == "EditorPaneUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return SynthEditorPaneUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        else if (key == "FileChooserUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return SynthFileChooserUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        else if (key == "FormattedTextFieldUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            return SynthFormattedTextFieldUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        else if (key == "InternalFrameUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return SynthInternalFrameUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        else if (key == "LabelUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            return SynthLabelUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        else if (key == "ListUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            return SynthListUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        else if (key == "MenuBarUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            return SynthMenuBarUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        else if (key == "MenuUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            return SynthMenuUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        else if (key == "MenuItemUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            return SynthMenuItemUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        else if (key == "OptionPaneUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            return SynthOptionPaneUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        else if (key == "PanelUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            return SynthPanelUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        else if (key == "PasswordFieldUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return SynthPasswordFieldUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        else if (key == "PopupMenuSeparatorUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            return SynthSeparatorUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        else if (key == "PopupMenuUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            return SynthPopupMenuUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        else if (key == "ProgressBarUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            return SynthProgressBarUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        else if (key == "RadioButtonUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            return SynthRadioButtonUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        else if (key == "RadioButtonMenuItemUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            return SynthRadioButtonMenuItemUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        else if (key == "RootPaneUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return SynthRootPaneUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        else if (key == "ScrollBarUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            return SynthScrollBarUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        else if (key == "ScrollPaneUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            return SynthScrollPaneUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        else if (key == "SeparatorUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            return SynthSeparatorUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        else if (key == "SliderUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            return SynthSliderUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        else if (key == "SpinnerUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return SynthSpinnerUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        else if (key == "SplitPaneUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            return SynthSplitPaneUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        else if (key == "TabbedPaneUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            return SynthTabbedPaneUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        else if (key == "TableUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            return SynthTableUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        else if (key == "TableHeaderUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            return SynthTableHeaderUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        else if (key == "TextAreaUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            return SynthTextAreaUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        else if (key == "TextFieldUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            return SynthTextFieldUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        else if (key == "TextPaneUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            return SynthTextPaneUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        else if (key == "ToggleButtonUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            return SynthToggleButtonUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        else if (key == "ToolBarSeparatorUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            return SynthSeparatorUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        else if (key == "ToolBarUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            return SynthToolBarUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        else if (key == "ToolTipUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            return SynthToolTipUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        else if (key == "TreeUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            return SynthTreeUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        else if (key == "ViewportUI") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            return SynthViewportUI.createUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Creates a SynthLookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * For the returned <code>SynthLookAndFeel</code> to be useful you need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * invoke <code>load</code> to specify the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * <code>SynthStyle</code>s, or invoke <code>setStyleFactory</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @see #load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @see #setStyleFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    public SynthLookAndFeel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        factory = new DefaultSynthStyleFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        _handler = new Handler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Loads the set of <code>SynthStyle</code>s that will be used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * this <code>SynthLookAndFeel</code>. <code>resourceBase</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * used to resolve any path based resources, for example an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * <code>Image</code> would be resolved by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * <code>resourceBase.getResource(path)</code>. Refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * <a href="doc-files/synthFileFormat.html">Synth File Format</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @param input InputStream to load from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @param resourceBase used to resolve any images or other resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @throws ParseException if there is an error in parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @throws IllegalArgumentException if input or resourceBase is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public void load(InputStream input, Class<?> resourceBase) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                       ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        if (resourceBase == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                "You must supply a valid resource base Class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        if (defaultsMap == null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   576
            defaultsMap = new HashMap<String, Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        new SynthParser().parse(input, (DefaultSynthStyleFactory) factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                null, resourceBase, defaultsMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * Loads the set of <code>SynthStyle</code>s that will be used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * this <code>SynthLookAndFeel</code>. Path based resources are resolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * relatively to the specified <code>URL</code> of the style. For example
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * an <code>Image</code> would be resolved by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * <code>new URL(synthFile, path)</code>. Refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * <a href="doc-files/synthFileFormat.html">Synth File Format</a> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @param url the <code>URL</code> to load the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *     <code>SynthStyle</code> from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @throws ParseException if there is an error in parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @throws IllegalArgumentException if synthSet is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @throws IOException if synthSet cannot be opened as an <code>InputStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    public void load(URL url) throws ParseException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        if (url == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                "You must supply a valid Synth set URL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if (defaultsMap == null) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   606
            defaultsMap = new HashMap<String, Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        InputStream input = url.openStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        new SynthParser().parse(input, (DefaultSynthStyleFactory) factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                                url, null, defaultsMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * Called by UIManager when this look and feel is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   617
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public void initialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        super.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        DefaultLookup.setDefaultLookup(new SynthDefaultLookup());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        setStyleFactory(factory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            addPropertyChangeListener(_handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * Called by UIManager when this look and feel is uninstalled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   629
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public void uninitialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            removePropertyChangeListener(_handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        // We should uninstall the StyleFactory here, but unfortunately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        // there are a handful of things that retain references to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        // LookAndFeel and expect things to work
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        super.uninitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * Returns the defaults for this SynthLookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @return Defaults table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   644
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    public UIDefaults getDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        UIDefaults table = new UIDefaults(60, 0.75f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        Region.registerUIs(table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        table.setDefaultLocale(Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        table.addResourceBundle(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
              "com.sun.swing.internal.plaf.basic.resources.basic" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        table.addResourceBundle("com.sun.swing.internal.plaf.synth.resources.synth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        // SynthTabbedPaneUI supports rollover on tabs, GTK does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        table.put("TabbedPane.isTabRollover", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        // These need to be defined for JColorChooser to work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        table.put("ColorChooser.swatchesRecentSwatchSize",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                  new Dimension(10, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        table.put("ColorChooser.swatchesDefaultRecentColor", Color.RED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        table.put("ColorChooser.swatchesSwatchSize", new Dimension(10, 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
5133
0a1777c5b601 6933784: NIMBUS: ImageView getNoImageIcon and getLoadingImageIcon returns nulls instead of an icon
rupashka
parents: 4394
diff changeset
   663
        // These need to be defined for ImageView.
0a1777c5b601 6933784: NIMBUS: ImageView getNoImageIcon and getLoadingImageIcon returns nulls instead of an icon
rupashka
parents: 4394
diff changeset
   664
        table.put("html.pendingImage", SwingUtilities2.makeIcon(getClass(),
0a1777c5b601 6933784: NIMBUS: ImageView getNoImageIcon and getLoadingImageIcon returns nulls instead of an icon
rupashka
parents: 4394
diff changeset
   665
                                BasicLookAndFeel.class,
0a1777c5b601 6933784: NIMBUS: ImageView getNoImageIcon and getLoadingImageIcon returns nulls instead of an icon
rupashka
parents: 4394
diff changeset
   666
                                "icons/image-delayed.png"));
0a1777c5b601 6933784: NIMBUS: ImageView getNoImageIcon and getLoadingImageIcon returns nulls instead of an icon
rupashka
parents: 4394
diff changeset
   667
        table.put("html.missingImage", SwingUtilities2.makeIcon(getClass(),
0a1777c5b601 6933784: NIMBUS: ImageView getNoImageIcon and getLoadingImageIcon returns nulls instead of an icon
rupashka
parents: 4394
diff changeset
   668
                                BasicLookAndFeel.class,
0a1777c5b601 6933784: NIMBUS: ImageView getNoImageIcon and getLoadingImageIcon returns nulls instead of an icon
rupashka
parents: 4394
diff changeset
   669
                                "icons/image-failed.png"));
0a1777c5b601 6933784: NIMBUS: ImageView getNoImageIcon and getLoadingImageIcon returns nulls instead of an icon
rupashka
parents: 4394
diff changeset
   670
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        // These are needed for PopupMenu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        table.put("PopupMenu.selectedWindowInputMapBindings", new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                  "ESCAPE", "cancel",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    "DOWN", "selectNext",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                 "KP_DOWN", "selectNext",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                      "UP", "selectPrevious",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                   "KP_UP", "selectPrevious",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    "LEFT", "selectParent",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                 "KP_LEFT", "selectParent",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                   "RIGHT", "selectChild",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                "KP_RIGHT", "selectChild",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                   "ENTER", "return",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                   "SPACE", "return"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        table.put("PopupMenu.selectedWindowInputMapBindings.RightToLeft",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                  new Object[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    "LEFT", "selectChild",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                 "KP_LEFT", "selectChild",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                   "RIGHT", "selectParent",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                "KP_RIGHT", "selectParent",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                  });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        // enabled antialiasing depending on desktop settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        flushUnreferenced();
32485
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
   695
        SwingUtilities2.putAATextInfo(useLAFConditions(), table);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        new AATextListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        if (defaultsMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            table.putAll(defaultsMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        return table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * Returns true, SynthLookAndFeel is always supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   709
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    public boolean isSupportedLookAndFeel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * Returns false, SynthLookAndFeel is not a native look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   719
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    public boolean isNativeLookAndFeel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * Returns a textual description of SynthLookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @return textual description of synth.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   729
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    public String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        return "Synth look and feel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * Return a short string that identifies this look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @return a short string identifying this look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   739
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        return "Synth look and feel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * Return a string that identifies this look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @return a short string identifying this look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   749
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    public String getID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        return "Synth";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * Returns whether or not the UIs should update their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * <code>SynthStyles</code> from the <code>SynthStyleFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * when the ancestor of the <code>JComponent</code> changes. A subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * that provided a <code>SynthStyleFactory</code> that based the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * return value from <code>getStyle</code> off the containment hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * would override this method to return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * @return whether or not the UIs should update their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * <code>SynthStyles</code> from the <code>SynthStyleFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * when the ancestor changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public boolean shouldUpdateStyleOnAncestorChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    /**
4394
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   771
     * Returns whether or not the UIs should update their styles when a
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   772
     * particular event occurs.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   773
     *
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   774
     * @param ev a {@code PropertyChangeEvent}
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   775
     * @return whether or not the UIs should update their styles
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   776
     * @since 1.7
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   777
     */
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   778
    protected boolean shouldUpdateStyleOnEvent(PropertyChangeEvent ev) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   779
        String eName = ev.getPropertyName();
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   780
        if ("name" == eName || "componentOrientation" == eName) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   781
            return true;
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   782
        }
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   783
        if ("ancestor" == eName && ev.getNewValue() != null) {
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   784
            // Only update on an ancestor change when getting a valid
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   785
            // parent and the LookAndFeel wants this.
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   786
            return shouldUpdateStyleOnAncestorChanged();
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   787
        }
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   788
        return false;
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   789
    }
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   790
92a8ec883f5d 6827653: Make Synth UI classes public
peterz
parents: 2658
diff changeset
   791
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * Returns the antialiasing information as specified by the host desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * Antialiasing might be forced off if the desktop is GNOME and the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * has set his locale to Chinese, Japanese or Korean. This is consistent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * with what GTK does. See com.sun.java.swing.plaf.gtk.GtkLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * for more information about CJK and antialiased fonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @return the text antialiasing information associated to the desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     */
32485
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
   800
    private static boolean useLAFConditions() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        String language = Locale.getDefault().getLanguage();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   802
        String desktop =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            AccessController.doPrivileged(new GetPropertyAction("sun.desktop"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        boolean isCjkLocale = (Locale.CHINESE.getLanguage().equals(language) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                Locale.JAPANESE.getLanguage().equals(language) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                Locale.KOREAN.getLanguage().equals(language));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        boolean isGnome = "gnome".equals(desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        boolean isLocal = SwingUtilities2.isLocalDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
32485
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
   811
        return isLocal && (!isGnome || !isCjkLocale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   814
    private static ReferenceQueue<LookAndFeel> queue = new ReferenceQueue<LookAndFeel>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    private static void flushUnreferenced() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        AATextListener aatl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        while ((aatl = (AATextListener) queue.poll()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            aatl.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    private static class AATextListener
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   824
        extends WeakReference<LookAndFeel> implements PropertyChangeListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        private String key = SunToolkit.DESKTOPFONTHINTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        AATextListener(LookAndFeel laf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            super(laf, queue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            tk.addPropertyChangeListener(key, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   833
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        public void propertyChange(PropertyChangeEvent pce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            UIDefaults defaults = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            if (defaults.getBoolean("Synth.doNotSetTextAA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   841
            LookAndFeel laf = get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            if (laf == null || laf != UIManager.getLookAndFeel()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
32485
e00f713e6103 6302464: Allow programmatic enabling of subpixel anti-aliasing in Swing on ANY platform
alexsch
parents: 25859
diff changeset
   847
            SwingUtilities2.putAATextInfo(useLAFConditions(), defaults);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            tk.removePropertyChangeListener(key, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
         * Updates the UI of the passed in window and all its children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        private static void updateWindowUI(Window window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            updateStyles(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            Window ownedWins[] = window.getOwnedWindows();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   863
            for (Window w : ownedWins) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   864
                updateWindowUI(w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
         * Updates the UIs of all the known Frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        private static void updateAllUIs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            Frame appFrames[] = Frame.getFrames();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   873
            for (Frame frame : appFrames) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   874
                updateWindowUI(frame);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
         * Indicates if an updateUI call is pending.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        private static boolean updatePending;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         * Sets whether or not an updateUI call is pending.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        private static synchronized void setUpdatePending(boolean update) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            updatePending = update;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
         * Returns true if a UI update is pending.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        private static synchronized boolean isUpdatePending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            return updatePending;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        protected void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            if (!isUpdatePending()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                setUpdatePending(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                Runnable uiUpdater = new Runnable() {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   901
                    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                        updateAllUIs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                        setUpdatePending(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                SwingUtilities.invokeLater(uiUpdater);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    private void writeObject(java.io.ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        throw new NotSerializableException(this.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    private class Handler implements PropertyChangeListener {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 1639
diff changeset
   918
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        public void propertyChange(PropertyChangeEvent evt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            String propertyName = evt.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            Object newValue = evt.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            Object oldValue = evt.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            if ("focusOwner" == propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                if (oldValue instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                    repaintIfBackgroundsDiffer((JComponent)oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                if (newValue instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                    repaintIfBackgroundsDiffer((JComponent)newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            else if ("managingFocus" == propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                // De-register listener on old keyboard focus manager and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                // register it on the new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                KeyboardFocusManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                    (KeyboardFocusManager)evt.getSource();
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 2
diff changeset
   939
                if (newValue.equals(Boolean.FALSE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                    manager.removePropertyChangeListener(_handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                    manager.addPropertyChangeListener(_handler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
         * This is a support method that will check if the background colors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
         * the specified component differ between focused and unfocused states.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
         * If the color differ the component will then repaint itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
         * @comp the component to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        private void repaintIfBackgroundsDiffer(JComponent comp) {
32870
b73c8ff78c80 8135122: The SwingUtilities2.COMPONENT_UI_PROPERTY_KEY can be removed
serb
parents: 32485
diff changeset
   956
            ComponentUI ui = comp.getUI();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            if (ui instanceof SynthUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                SynthUI synthUI = (SynthUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                SynthContext context = synthUI.getContext(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                SynthStyle style = context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                // Get the current background color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                Color currBG = style.getColor(context, ColorType.BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                // Get the last background color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                state ^= SynthConstants.FOCUSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                context.setComponentState(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                Color lastBG = style.getColor(context, ColorType.BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                // Reset the component state back to original.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                state ^= SynthConstants.FOCUSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                context.setComponentState(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                // Repaint the component if the backgrounds differed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                if (currBG != null && !currBG.equals(lastBG)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                    comp.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
}