001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.swing.plaf.multi;
019:
020: import java.util.Vector;
021:
022: import javax.swing.JComponent;
023: import javax.swing.LookAndFeel;
024: import javax.swing.UIDefaults;
025: import javax.swing.UIManager;
026: import javax.swing.plaf.ComponentUI;
027:
028: import org.apache.harmony.x.swing.internal.nls.Messages;
029:
030: public class MultiLookAndFeel extends LookAndFeel {
031:
032: private static final String prefix = "javax.swing.plaf.multi.Multi"; //$NON-NLS-1$
033:
034: @SuppressWarnings("nls")
035: private static final UIDefaults classDefaults = new UIDefaults(
036: new Object[] { "InternalFrameUI",
037: prefix + "InternalFrameUI", "ViewportUI",
038: prefix + "ViewportUI", "ScrollBarUI",
039: prefix + "ScrollBarUI", "ToolTipUI",
040: prefix + "ToolTipUI", "MenuItemUI",
041: prefix + "MenuItemUI", "MenuUI", prefix + "MenuUI",
042: "TextAreaUI", prefix + "TextAreaUI", "PopupMenuUI",
043: prefix + "PopupMenuUI", "ScrollPaneUI",
044: prefix + "ScrollPaneUI", "SliderUI",
045: prefix + "SliderUI", "ComboBoxUI",
046: prefix + "ComboBoxUI", "RadioButtonUI",
047: prefix + "RadioButtonUI", "FormattedTextFieldUI",
048: prefix + "FormattedTextFieldUI", "TreeUI",
049: prefix + "TreeUI", "MenuBarUI",
050: prefix + "MenuBarUI", "RadioButtonMenuItemUI",
051: prefix + "RadioButtonMenuItemUI", "ProgressBarUI",
052: prefix + "ProgressBarUI", "ToolBarUI",
053: prefix + "ToolBarUI", "ColorChooserUI",
054: prefix + "ColorChooserUI", "ToolBarSeparatorUI",
055: prefix + "ToolBarSeparatorUI", "TabbedPaneUI",
056: prefix + "TabbedPaneUI", "DesktopPaneUI",
057: prefix + "DesktopPaneUI", "TableUI",
058: prefix + "TableUI", "PanelUI", prefix + "PanelUI",
059: "CheckBoxMenuItemUI",
060: prefix + "CheckBoxMenuItemUI", "PasswordFieldUI",
061: prefix + "PasswordFieldUI", "CheckBoxUI",
062: prefix + "CheckBoxUI", "TableHeaderUI",
063: prefix + "TableHeaderUI", "SplitPaneUI",
064: prefix + "SplitPaneUI", "EditorPaneUI",
065: prefix + "EditorPaneUI", "ListUI",
066: prefix + "ListUI", "SpinnerUI",
067: prefix + "SpinnerUI", "DesktopIconUI",
068: prefix + "DesktopIconUI", "TextFieldUI",
069: prefix + "TextFieldUI", "TextPaneUI",
070: prefix + "TextPaneUI", "LabelUI",
071: prefix + "LabelUI", "ButtonUI",
072: prefix + "ButtonUI", "ToggleButtonUI",
073: prefix + "ToggleButtonUI", "OptionPaneUI",
074: prefix + "OptionPaneUI", "PopupMenuSeparatorUI",
075: prefix + "PopupMenuSeparatorUI", "RootPaneUI",
076: prefix + "RootPaneUI", "SeparatorUI",
077: prefix + "SeparatorUI" });
078:
079: @Override
080: public String getName() {
081: return "Multiplexing Look and Feel"; //$NON-NLS-1$
082: }
083:
084: @Override
085: public String getID() {
086: return "Multiplex"; //$NON-NLS-1$
087: }
088:
089: @Override
090: public String getDescription() {
091: return Messages.getString("swing.B5"); //$NON-NLS-1$
092: }
093:
094: @Override
095: public boolean isNativeLookAndFeel() {
096: return false;
097: }
098:
099: @Override
100: public boolean isSupportedLookAndFeel() {
101: return true;
102: }
103:
104: @SuppressWarnings("unchecked")
105: public static ComponentUI createUIs(ComponentUI mui, Vector uis,
106: JComponent target) {
107:
108: LookAndFeel[] auxLafs = UIManager.getAuxiliaryLookAndFeels();
109: ComponentUI primaryUI = UIManager.getLookAndFeel()
110: .getDefaults().getUI(target);
111: ComponentUI auxiliaryUI;
112:
113: if (auxLafs != null) {
114: for (LookAndFeel l : auxLafs) {
115: auxiliaryUI = l.getDefaults().getUI(target);
116: if (auxiliaryUI != null) {
117: uis.add(auxiliaryUI);
118: }
119: }
120: }
121: if (uis.isEmpty()) {
122: return primaryUI;
123: }
124: uis.add(0, primaryUI);
125: return mui;
126: }
127:
128: @Override
129: public UIDefaults getDefaults() {
130: return classDefaults;
131: }
132:
133: @SuppressWarnings("unchecked")
134: protected static ComponentUI[] uisToArray(Vector uis) {
135: if (uis == null) {
136: return new ComponentUI[] {};
137: }
138: if (uis.isEmpty()) {
139: return null;
140: }
141:
142: return (ComponentUI[]) uis.toArray(new ComponentUI[0]);
143:
144: }
145: }
|