1. /*
  2. * @(#)MultiLookAndFeel.java 1.28 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.plaf.multi;
  11. import java.util.Vector;
  12. import java.lang.reflect.Method;
  13. import javax.swing.*;
  14. import javax.swing.plaf.*;
  15. /**
  16. * <p>A Multiplexing UI Look and Feel that allows more than one UI
  17. * to be associated with a component at the same time.
  18. * <p>
  19. * <strong>Warning:</strong>
  20. * Serialized objects of this class will not be compatible with
  21. * future Swing releases. The current serialization support is appropriate
  22. * for short term storage or RMI between applications running the same
  23. * version of Swing. A future release of Swing will provide support for
  24. * long term persistence.
  25. *
  26. * @version 1.28 02/02/00
  27. * @author Willie Walker
  28. */
  29. public class MultiLookAndFeel extends LookAndFeel {
  30. //////////////////////////////
  31. // LookAndFeel methods
  32. //////////////////////////////
  33. public String getName() {
  34. return "Multiplexing Look and Feel";
  35. }
  36. public String getID() {
  37. return "Multiplex";
  38. }
  39. public String getDescription() {
  40. return "Allows multiple UI instances per component instance";
  41. }
  42. public boolean isNativeLookAndFeel() {
  43. return false;
  44. }
  45. public boolean isSupportedLookAndFeel() {
  46. return true;
  47. }
  48. public UIDefaults getDefaults() {
  49. UIDefaults table = new MultiUIDefaults();
  50. String packageName = "javax.swing.plaf.multi.Multi";
  51. Object[] uiDefaults = {
  52. "ButtonUI", packageName + "ButtonUI",
  53. "CheckBoxMenuItemUI", packageName + "MenuItemUI",
  54. "CheckBoxUI", packageName + "ButtonUI",
  55. "ColorChooserUI", packageName + "ColorChooserUI",
  56. "ComboBoxUI", packageName + "ComboBoxUI",
  57. "DesktopIconUI", packageName + "DesktopIconUI",
  58. "DesktopPaneUI", packageName + "DesktopPaneUI",
  59. "EditorPaneUI", packageName + "TextUI",
  60. "FileChooserUI", packageName + "FileChooserUI",
  61. "InternalFrameUI", packageName + "InternalFrameUI",
  62. "LabelUI", packageName + "LabelUI",
  63. "ListUI", packageName + "ListUI",
  64. "MenuBarUI", packageName + "MenuBarUI",
  65. "MenuItemUI", packageName + "MenuItemUI",
  66. "MenuUI", packageName + "MenuItemUI",
  67. "OptionPaneUI", packageName + "OptionPaneUI",
  68. "PanelUI", packageName + "PanelUI",
  69. "PasswordFieldUI", packageName + "TextUI",
  70. "PopupMenuSeparatorUI", packageName + "SeparatorUI",
  71. "PopupMenuUI", packageName + "PopupMenuUI",
  72. "ProgressBarUI", packageName + "ProgressBarUI",
  73. "RadioButtonMenuItemUI", packageName + "MenuItemUI",
  74. "RadioButtonUI", packageName + "ButtonUI",
  75. "ScrollBarUI", packageName + "ScrollBarUI",
  76. "ScrollPaneUI", packageName + "ScrollPaneUI",
  77. "SeparatorUI", packageName + "SeparatorUI",
  78. "SliderUI", packageName + "SliderUI",
  79. "SplitPaneUI", packageName + "SplitPaneUI",
  80. "TabbedPaneUI", packageName + "TabbedPaneUI",
  81. "TableHeaderUI", packageName + "TableHeaderUI",
  82. "TableUI", packageName + "TableUI",
  83. "TextAreaUI", packageName + "TextUI",
  84. "TextFieldUI", packageName + "TextUI",
  85. "TextPaneUI", packageName + "TextUI",
  86. "ToggleButtonUI", packageName + "ButtonUI",
  87. "ToolBarSeparatorUI", packageName + "SeparatorUI",
  88. "ToolBarUI", packageName + "ToolBarUI",
  89. "ToolTipUI", packageName + "ToolTipUI",
  90. "TreeUI", packageName + "TreeUI",
  91. "ViewportUI", packageName + "ViewportUI",
  92. };
  93. table.putDefaults(uiDefaults);
  94. return table;
  95. }
  96. ///////////////////////////////
  97. // Utility methods for the UI's
  98. ///////////////////////////////
  99. /**
  100. * Create the real UI's from the default and auxiliary look and feels,
  101. * placing the results in the uis vector passed in.
  102. * @return the ComponentUI for the component.
  103. */
  104. public static ComponentUI createUIs(ComponentUI mui,
  105. Vector uis,
  106. JComponent target) {
  107. ComponentUI ui;
  108. // Make sure we can at least get the default UI
  109. //
  110. ui = UIManager.getDefaults().getUI(target);
  111. if (ui != null) {
  112. uis.addElement(ui);
  113. LookAndFeel[] auxiliaryLookAndFeels;
  114. auxiliaryLookAndFeels = UIManager.getAuxiliaryLookAndFeels();
  115. if (auxiliaryLookAndFeels != null) {
  116. for (int i = 0; i < auxiliaryLookAndFeels.length; i++) {
  117. ui = auxiliaryLookAndFeels[i].getDefaults().getUI(target);
  118. if (ui != null) {
  119. uis.addElement(ui);
  120. }
  121. }
  122. }
  123. } else {
  124. return null;
  125. }
  126. // Don't bother returning the multiplexing UI if all we did was
  127. // get a UI from just the default look and feel.
  128. //
  129. if (uis.size() == 1) {
  130. return (ComponentUI) uis.elementAt(0);
  131. } else {
  132. return mui;
  133. }
  134. }
  135. /**
  136. * Turn the Vector of UI's into an array.
  137. */
  138. protected static ComponentUI[] uisToArray(Vector uis) {
  139. if (uis == null) {
  140. return new ComponentUI[0];
  141. } else {
  142. int count = uis.size();
  143. if (count > 0) {
  144. ComponentUI[] u = new ComponentUI[count];
  145. for (int i = 0; i < count; i++) {
  146. u[i] = (ComponentUI)uis.elementAt(i);
  147. }
  148. return u;
  149. } else {
  150. return null;
  151. }
  152. }
  153. }
  154. }
  155. /**
  156. * We want the Multiplexing LookAndFeel to be quiet and fallback
  157. * gracefully if it cannot find a UI. This class overrides the
  158. * getUIError method of UIDefaults, which is the method that
  159. * emits error messages when it cannot find a UI class in the
  160. * LAF.
  161. */
  162. class MultiUIDefaults extends UIDefaults {
  163. protected void getUIError(String msg) {
  164. System.err.println("Multiplexing LAF: " + msg);
  165. }
  166. }