jdk/src/share/classes/javax/swing/plaf/multi/MultiLookAndFeel.java
author darcy
Sun, 23 Mar 2014 13:49:48 -0700
changeset 23697 e556a715949f
parent 22574 7f8ce0c8c20a
child 25565 ce603b34c98d
permissions -rw-r--r--
8034169: Fix serial lint warnings in javax.swing Reviewed-by: alanb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1997, 2014, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.multi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <p>A multiplexing look and feel that allows more than one UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * to be associated with a component at the same time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * The primary look and feel is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * the <em>default</em> look and feel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * and the other look and feels are called <em>auxiliary</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * For further information, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <a href="doc-files/multi_tsc.html" target="_top">Using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Multiplexing Look and Feel.</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 5506
diff changeset
    50
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see UIManager#addAuxiliaryLookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see javax.swing.plaf.multi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author Willie Walker
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    59
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class MultiLookAndFeel extends LookAndFeel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
//////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
// LookAndFeel methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
//////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Returns a string, suitable for use in menus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * that identifies this look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @return a string such as "Multiplexing Look and Feel"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        return "Multiplexing Look and Feel";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Returns a string, suitable for use by applications/services,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * that identifies this look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @return "Multiplex"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public String getID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return "Multiplex";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Returns a one-line description of this look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @return a descriptive string such as "Allows multiple UI instances per component instance"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return "Allows multiple UI instances per component instance";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Returns <code>false</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * this look and feel is not native to any platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @return <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public boolean isNativeLookAndFeel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Returns <code>true</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * every platform permits this look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @return <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public boolean isSupportedLookAndFeel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Creates, initializes, and returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * the look and feel specific defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * For this look and feel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * the defaults consist solely of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * mappings of UI class IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * (such as "ButtonUI")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * to <code>ComponentUI</code> class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * (such as "javax.swing.plaf.multi.MultiButtonUI").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @return an initialized <code>UIDefaults</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see javax.swing.JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public UIDefaults getDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        String packageName = "javax.swing.plaf.multi.Multi";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        Object[] uiDefaults = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                   "ButtonUI", packageName + "ButtonUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         "CheckBoxMenuItemUI", packageName + "MenuItemUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                 "CheckBoxUI", packageName + "ButtonUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
             "ColorChooserUI", packageName + "ColorChooserUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                 "ComboBoxUI", packageName + "ComboBoxUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
              "DesktopIconUI", packageName + "DesktopIconUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
              "DesktopPaneUI", packageName + "DesktopPaneUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
               "EditorPaneUI", packageName + "TextUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
              "FileChooserUI", packageName + "FileChooserUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
       "FormattedTextFieldUI", packageName + "TextUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            "InternalFrameUI", packageName + "InternalFrameUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    "LabelUI", packageName + "LabelUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                     "ListUI", packageName + "ListUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                  "MenuBarUI", packageName + "MenuBarUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                 "MenuItemUI", packageName + "MenuItemUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                     "MenuUI", packageName + "MenuItemUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
               "OptionPaneUI", packageName + "OptionPaneUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    "PanelUI", packageName + "PanelUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            "PasswordFieldUI", packageName + "TextUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
       "PopupMenuSeparatorUI", packageName + "SeparatorUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                "PopupMenuUI", packageName + "PopupMenuUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
              "ProgressBarUI", packageName + "ProgressBarUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
      "RadioButtonMenuItemUI", packageName + "MenuItemUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
              "RadioButtonUI", packageName + "ButtonUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                 "RootPaneUI", packageName + "RootPaneUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                "ScrollBarUI", packageName + "ScrollBarUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
               "ScrollPaneUI", packageName + "ScrollPaneUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                "SeparatorUI", packageName + "SeparatorUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                   "SliderUI", packageName + "SliderUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                  "SpinnerUI", packageName + "SpinnerUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                "SplitPaneUI", packageName + "SplitPaneUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
               "TabbedPaneUI", packageName + "TabbedPaneUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
              "TableHeaderUI", packageName + "TableHeaderUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    "TableUI", packageName + "TableUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                 "TextAreaUI", packageName + "TextUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                "TextFieldUI", packageName + "TextUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                 "TextPaneUI", packageName + "TextUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
             "ToggleButtonUI", packageName + "ButtonUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         "ToolBarSeparatorUI", packageName + "SeparatorUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                  "ToolBarUI", packageName + "ToolBarUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                  "ToolTipUI", packageName + "ToolTipUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                     "TreeUI", packageName + "TreeUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                 "ViewportUI", packageName + "ViewportUI",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        UIDefaults table = new MultiUIDefaults(uiDefaults.length / 2, 0.75f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        table.putDefaults(uiDefaults);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
///////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
// Utility methods for the UI's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
///////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Creates the <code>ComponentUI</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * required to present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * the <code>target</code> component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * placing the objects in the <code>uis</code> vector and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * returning the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <code>ComponentUI</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * that best represents the component's UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * This method finds the <code>ComponentUI</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * by invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <code>getDefaults().getUI(target)</code> on each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * default and auxiliary look and feel currently in use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * The first UI object this method adds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * to the <code>uis</code> vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * is for the default look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * This method is invoked by the <code>createUI</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * of <code>MultiXxxxUI</code> classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param mui the <code>ComponentUI</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *            that represents the complete UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *            for the <code>target</code> component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *            this should be an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *            of one of the <code>MultiXxxxUI</code> classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param uis a <code>Vector</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *            generally this is the <code>uis</code> field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *            of the <code>mui</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param target a component whose UI is represented by <code>mui</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @return <code>mui</code> if the component has any auxiliary UI objects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *         otherwise, returns the UI object for the default look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *         or <code>null</code> if the default UI object couldn't be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @see javax.swing.UIManager#getAuxiliaryLookAndFeels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see javax.swing.UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see MultiButtonUI#uis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @see MultiButtonUI#createUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public static ComponentUI createUIs(ComponentUI mui,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                        Vector      uis,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                        JComponent  target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        ComponentUI ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        // Make sure we can at least get the default UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        ui = UIManager.getDefaults().getUI(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            uis.addElement(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            LookAndFeel[] auxiliaryLookAndFeels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            auxiliaryLookAndFeels = UIManager.getAuxiliaryLookAndFeels();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (auxiliaryLookAndFeels != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                for (int i = 0; i < auxiliaryLookAndFeels.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    ui = auxiliaryLookAndFeels[i].getDefaults().getUI(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        uis.addElement(ui);
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
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // Don't bother returning the multiplexing UI if all we did was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        // get a UI from just the default look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (uis.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            return (ComponentUI) uis.elementAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return mui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Creates an array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * populates it with UI objects from the passed-in vector,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * and returns the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * If <code>uis</code> is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * this method returns an array with zero elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * If <code>uis</code> is an empty vector,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * this method returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * A run-time error occurs if any objects in the <code>uis</code> vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * are not of type <code>ComponentUI</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param uis a vector containing <code>ComponentUI</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @return an array equivalent to the passed-in vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    protected static ComponentUI[] uisToArray(Vector uis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (uis == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return new ComponentUI[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            int count = uis.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                ComponentUI[] u = new ComponentUI[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    u[i] = (ComponentUI)uis.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                return u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * We want the Multiplexing LookAndFeel to be quiet and fallback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * gracefully if it cannot find a UI.  This class overrides the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 * getUIError method of UIDefaults, which is the method that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * emits error messages when it cannot find a UI class in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * LAF.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 22574
diff changeset
   297
@SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
class MultiUIDefaults extends UIDefaults {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    MultiUIDefaults(int initialCapacity, float loadFactor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        super(initialCapacity, loadFactor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    protected void getUIError(String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        System.err.println("Multiplexing LAF:  " + msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
}