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