1 7 package javax.swing.plaf.multi; 8 9 import java.util.Vector ; 10 import java.lang.reflect.Method ; 11 import javax.swing.*; 12 import javax.swing.plaf.*; 13 14 42 public class MultiLookAndFeel extends LookAndFeel { 43 44 48 54 public String getName() { 55 return "Multiplexing Look and Feel"; 56 } 57 58 64 public String getID() { 65 return "Multiplex"; 66 } 67 68 73 public String getDescription() { 74 return "Allows multiple UI instances per component instance"; 75 } 76 77 83 public boolean isNativeLookAndFeel() { 84 return false; 85 } 86 87 93 public boolean isSupportedLookAndFeel() { 94 return true; 95 } 96 97 110 public UIDefaults getDefaults() { 111 UIDefaults table = new MultiUIDefaults(); 112 String packageName = "javax.swing.plaf.multi.Multi"; 113 Object [] uiDefaults = { 114 "ButtonUI", packageName + "ButtonUI", 115 "CheckBoxMenuItemUI", packageName + "MenuItemUI", 116 "CheckBoxUI", packageName + "ButtonUI", 117 "ColorChooserUI", packageName + "ColorChooserUI", 118 "ComboBoxUI", packageName + "ComboBoxUI", 119 "DesktopIconUI", packageName + "DesktopIconUI", 120 "DesktopPaneUI", packageName + "DesktopPaneUI", 121 "EditorPaneUI", packageName + "TextUI", 122 "FileChooserUI", packageName + "FileChooserUI", 123 "FormattedTextFieldUI", packageName + "TextUI", 124 "InternalFrameUI", packageName + "InternalFrameUI", 125 "LabelUI", packageName + "LabelUI", 126 "ListUI", packageName + "ListUI", 127 "MenuBarUI", packageName + "MenuBarUI", 128 "MenuItemUI", packageName + "MenuItemUI", 129 "MenuUI", packageName + "MenuItemUI", 130 "OptionPaneUI", packageName + "OptionPaneUI", 131 "PanelUI", packageName + "PanelUI", 132 "PasswordFieldUI", packageName + "TextUI", 133 "PopupMenuSeparatorUI", packageName + "SeparatorUI", 134 "PopupMenuUI", packageName + "PopupMenuUI", 135 "ProgressBarUI", packageName + "ProgressBarUI", 136 "RadioButtonMenuItemUI", packageName + "MenuItemUI", 137 "RadioButtonUI", packageName + "ButtonUI", 138 "RootPaneUI", packageName + "RootPaneUI", 139 "ScrollBarUI", packageName + "ScrollBarUI", 140 "ScrollPaneUI", packageName + "ScrollPaneUI", 141 "SeparatorUI", packageName + "SeparatorUI", 142 "SliderUI", packageName + "SliderUI", 143 "SpinnerUI", packageName + "SpinnerUI", 144 "SplitPaneUI", packageName + "SplitPaneUI", 145 "TabbedPaneUI", packageName + "TabbedPaneUI", 146 "TableHeaderUI", packageName + "TableHeaderUI", 147 "TableUI", packageName + "TableUI", 148 "TextAreaUI", packageName + "TextUI", 149 "TextFieldUI", packageName + "TextUI", 150 "TextPaneUI", packageName + "TextUI", 151 "ToggleButtonUI", packageName + "ButtonUI", 152 "ToolBarSeparatorUI", packageName + "SeparatorUI", 153 "ToolBarUI", packageName + "ToolBarUI", 154 "ToolTipUI", packageName + "ToolTipUI", 155 "TreeUI", packageName + "TreeUI", 156 "ViewportUI", packageName + "ViewportUI", 157 }; 158 159 table.putDefaults(uiDefaults); 160 return table; 161 } 162 163 167 205 public static ComponentUI createUIs(ComponentUI mui, 206 Vector uis, 207 JComponent target) { 208 ComponentUI ui; 209 210 ui = UIManager.getDefaults().getUI(target); 213 if (ui != null) { 214 uis.addElement(ui); 215 LookAndFeel[] auxiliaryLookAndFeels; 216 auxiliaryLookAndFeels = UIManager.getAuxiliaryLookAndFeels(); 217 if (auxiliaryLookAndFeels != null) { 218 for (int i = 0; i < auxiliaryLookAndFeels.length; i++) { 219 ui = auxiliaryLookAndFeels[i].getDefaults().getUI(target); 220 if (ui != null) { 221 uis.addElement(ui); 222 } 223 } 224 } 225 } else { 226 return null; 227 } 228 229 if (uis.size() == 1) { 233 return (ComponentUI) uis.elementAt(0); 234 } else { 235 return mui; 236 } 237 } 238 239 254 protected static ComponentUI[] uisToArray(Vector uis) { 255 if (uis == null) { 256 return new ComponentUI[0]; 257 } else { 258 int count = uis.size(); 259 if (count > 0) { 260 ComponentUI[] u = new ComponentUI[count]; 261 for (int i = 0; i < count; i++) { 262 u[i] = (ComponentUI)uis.elementAt(i); 263 } 264 return u; 265 } else { 266 return null; 267 } 268 } 269 } 270 } 271 272 279 class MultiUIDefaults extends UIDefaults { 280 protected void getUIError(String msg) { 281 System.err.println("Multiplexing LAF: " + msg); 282 } 283 } 284 | Popular Tags |