1 /* MultiLookAndFeel.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax
.swing
.plaf
.multi
;
40 import java
.util
.Vector
;
42 import javax
.swing
.JComponent
;
43 import javax
.swing
.LookAndFeel
;
44 import javax
.swing
.UIDefaults
;
45 import javax
.swing
.UIManager
;
46 import javax
.swing
.plaf
.ComponentUI
;
49 * A look and feel that provides the ability to use auxiliary look and feels
50 * in addition to the primary look and feel.
52 public class MultiLookAndFeel
extends LookAndFeel
{
55 * Creates a new instance of the look and feel.
57 public MultiLookAndFeel()
59 // Nothing to do here.
63 * Returns the name for the look and feel.
65 * @return "Multiplexing Look and Feel".
67 public String
getName()
69 return "Multiplexing Look and Feel";
73 * Returns an identifier for the look and feel.
75 * @return "Multiplex".
83 * Returns a description of the look and feel.
85 * @return A description of the look and feel.
87 public String
getDescription()
89 return "Allows multiple UI instances per component instance";
93 * Returns <code>false</code> to indicate that this look and feel is not
94 * native to any platform.
96 * @return <code>false</code>.
98 public boolean isNativeLookAndFeel()
104 * Returns <code>true</code> always, since this look and feel is supported on
107 * @return <code>true</code>.
109 public boolean isSupportedLookAndFeel()
115 * Creates and returns the UI defaults for this look and feel.
117 * @return The UI defaults.
119 public UIDefaults
getDefaults()
121 UIDefaults defaults
= new UIDefaults();
122 defaults
.put("ButtonUI", "javax.swing.plaf.multi.MultiButtonUI");
123 defaults
.put("CheckBoxUI", "javax.swing.plaf.multi.MultiButtonUI");
124 defaults
.put("CheckBoxMenuItemUI", "javax.swing.plaf.multi.MultiMenuItemUI");
125 defaults
.put("ColorChooserUI",
126 "javax.swing.plaf.multi.MultiColorChooserUI");
127 defaults
.put("ComboBoxUI", "javax.swing.plaf.multi.MultiComboBoxUI");
128 defaults
.put("DesktopPaneUI", "javax.swing.plaf.multi.MultiDesktopPaneUI");
129 defaults
.put("DesktopIconUI", "javax.swing.plaf.multi.MultiDesktopIconUI");
130 defaults
.put("EditorPaneUI", "javax.swing.plaf.multi.MultiTextUI");
131 defaults
.put("FileChooserUI", "javax.swing.plaf.multi.MultiFileChooserUI");
132 defaults
.put("FormattedTextFieldUI", "javax.swing.plaf.multi.MultiTextUI");
133 defaults
.put("InternalFrameUI",
134 "javax.swing.plaf.multi.MultiInternalFrameUI");
135 defaults
.put("LabelUI", "javax.swing.plaf.multi.MultiLabelUI");
136 defaults
.put("ListUI", "javax.swing.plaf.multi.MultiListUI");
137 defaults
.put("MenuItemUI", "javax.swing.plaf.multi.MultiMenuItemUI");
138 defaults
.put("MenuUI", "javax.swing.plaf.multi.MultiMenuItemUI");
139 defaults
.put("MenuBarUI", "javax.swing.plaf.multi.MultiMenuBarUI");
140 defaults
.put("OptionPaneUI", "javax.swing.plaf.multi.MultiOptionPaneUI");
141 defaults
.put("PanelUI", "javax.swing.plaf.multi.MultiPanelUI");
142 defaults
.put("PasswordFieldUI", "javax.swing.plaf.multi.MultiTextUI");
143 defaults
.put("PopupMenuUI", "javax.swing.plaf.multi.MultiPopupMenuUI");
144 defaults
.put("PopupMenuSeparatorUI",
145 "javax.swing.plaf.multi.MultiSeparatorUI");
146 defaults
.put("ProgressBarUI", "javax.swing.plaf.multi.MultiProgressBarUI");
147 defaults
.put("RadioButtonUI", "javax.swing.plaf.multi.MultiButtonUI");
148 defaults
.put("RadioButtonMenuItemUI",
149 "javax.swing.plaf.multi.MultiMenuItemUI");
150 defaults
.put("RootPaneUI", "javax.swing.plaf.multi.MultiRootPaneUI");
151 defaults
.put("ScrollBarUI", "javax.swing.plaf.multi.MultiScrollBarUI");
152 defaults
.put("ScrollPaneUI", "javax.swing.plaf.multi.MultiScrollPaneUI");
153 defaults
.put("SeparatorUI", "javax.swing.plaf.multi.MultiSeparatorUI");
154 defaults
.put("SliderUI", "javax.swing.plaf.multi.MultiSliderUI");
155 defaults
.put("SpinnerUI", "javax.swing.plaf.multi.MultiSpinnerUI");
156 defaults
.put("SplitPaneUI", "javax.swing.plaf.multi.MultiSplitPaneUI");
157 defaults
.put("TabbedPaneUI", "javax.swing.plaf.multi.MultiTabbedPaneUI");
158 defaults
.put("TableHeaderUI", "javax.swing.plaf.multi.MultiTableHeaderUI");
159 defaults
.put("TableUI", "javax.swing.plaf.multi.MultiTableUI");
160 defaults
.put("TextAreaUI", "javax.swing.plaf.multi.MultiTextUI");
161 defaults
.put("TextFieldUI", "javax.swing.plaf.multi.MultiTextUI");
162 defaults
.put("TextPaneUI", "javax.swing.plaf.multi.MultiTextUI");
163 defaults
.put("ToggleButtonUI", "javax.swing.plaf.multi.MultiButtonUI");
164 defaults
.put("ToolBarSeparatorUI",
165 "javax.swing.plaf.multi.MultiSeparatorUI");
166 defaults
.put("ToolBarUI", "javax.swing.plaf.multi.MultiToolBarUI");
167 defaults
.put("ToolTipUI", "javax.swing.plaf.multi.MultiToolTipUI");
168 defaults
.put("ViewportUI", "javax.swing.plaf.multi.MultiViewportUI");
173 * Creates the UI delegates for the <code>target</code> component and
174 * returns a multiplexing UI delegate (<code>mui</code>) if there are
175 * multiple delegates.
177 * @param mui a multiplexing UI delegate appropriate for the component.
178 * @param uis a vector into which the UI delegates will be added.
179 * @param target the target component.
181 * @return A UI delegate.
183 public static ComponentUI
createUIs(ComponentUI mui
, Vector uis
,
186 // get primary UI delegate for 'target', and add it to uis
187 ComponentUI ui
= null;
188 LookAndFeel primary
= UIManager
.getLookAndFeel();
191 ui
= UIManager
.getUI(target
);
194 // for any auxiliary look and feels in use, get the UI delegate and add
196 LookAndFeel
[] auxlafs
= UIManager
.getAuxiliaryLookAndFeels();
197 for (int i
= 0; i
< auxlafs
.length
; i
++)
199 LookAndFeel auxlaf
= auxlafs
[i
];
200 // FIXME: here I call getDefaults() to get the UI delegate from the
201 // auxiliary look and feel. But getDefaults() creates a new set of
202 // defaults every time it is called, which is wasteful. Unfortunately
203 // I cannot find another way to get the UI delegate, so I'm doing it
205 UIDefaults defaults
= auxlaf
.getDefaults();
206 ui
= defaults
.getUI(target
);
210 // if uis contains more than 1 delegate, return mui, otherwise return
211 // the primary delegate
219 * Returns an array containing the same {@link ComponentUI} instances as
220 * <code>uis</code>. If <code>uis</code> is <code>null</code>, a zero-length
223 * @param uis a list of {@link ComponentUI} references (<code>null</code>
226 * @return An array containing the same {@link ComponentUI} instances as
227 * <code>uis</code>, or <code>null</code> if <code>uis</code> is
230 protected static ComponentUI
[] uisToArray(Vector uis
)
233 return new ComponentUI
[0];
234 int size
= uis
.size();
237 ComponentUI
[] result
= new ComponentUI
[size
];
238 uis
.copyInto(result
);