1. /*
  2. * @(#)WindowsLookAndFeel.java 1.57 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.windows;
  8. import java.awt.*;
  9. import javax.swing.plaf.*;
  10. import javax.swing.*;
  11. import javax.swing.plaf.basic.*;
  12. import javax.swing.border.*;
  13. import javax.swing.text.JTextComponent;
  14. import javax.swing.text.DefaultEditorKit;
  15. import java.awt.Font;
  16. import java.awt.Color;
  17. import java.awt.SystemColor;
  18. import java.awt.event.KeyEvent;
  19. import java.awt.event.InputEvent;
  20. import java.net.URL;
  21. import java.io.Serializable;
  22. import java.util.*;
  23. /**
  24. * Implements the Windows95 Look and Feel.
  25. * UI classes not implemented specifically for Windows will
  26. * default to those implemented in Basic.
  27. * <p>
  28. * For the keyboard keys defined for each component in this Look and
  29. * Feel (L&F), see
  30. * <a href="../../../../../../javax/swing/doc-files/Key-Win32.html">Component Keystroke Actions for the Windows L&F</a>.
  31. * <p>
  32. * <strong>Warning:</strong>
  33. * Serialized objects of this class will not be compatible with
  34. * future Swing releases. The current serialization support is appropriate
  35. * for short term storage or RMI between applications running the same
  36. * version of Swing. A future release of Swing will provide support for
  37. * long term persistence.
  38. *
  39. * @version 1.50 11/20/98
  40. * @author unattributed
  41. */
  42. public class WindowsLookAndFeel extends BasicLookAndFeel
  43. {
  44. public String getName() {
  45. return "Windows";
  46. }
  47. public String getDescription() {
  48. return "The Microsoft Windows Look and Feel";
  49. }
  50. public String getID() {
  51. return "Windows";
  52. }
  53. public boolean isNativeLookAndFeel() {
  54. String osName = System.getProperty("os.name");
  55. return (osName != null) && (osName.indexOf("Windows") != -1);
  56. }
  57. public boolean isSupportedLookAndFeel() {
  58. return isNativeLookAndFeel();
  59. }
  60. /**
  61. * Initialize the uiClassID to BasicComponentUI mapping.
  62. * The JComponent classes define their own uiClassID constants
  63. * (see AbstractComponent.getUIClassID). This table must
  64. * map those constants to a BasicComponentUI class of the
  65. * appropriate type.
  66. *
  67. * @see BasicLookAndFeel#getDefaults
  68. */
  69. protected void initClassDefaults(UIDefaults table)
  70. {
  71. super.initClassDefaults(table);
  72. String windowsPackageName = "com.sun.java.swing.plaf.windows.";
  73. Object[] uiDefaults = {
  74. "ButtonUI", windowsPackageName + "WindowsButtonUI",
  75. "CheckBoxUI", windowsPackageName + "WindowsCheckBoxUI",
  76. "RadioButtonUI", windowsPackageName + "WindowsRadioButtonUI",
  77. "ToggleButtonUI", windowsPackageName + "WindowsToggleButtonUI",
  78. "ProgressBarUI", windowsPackageName + "WindowsProgressBarUI",
  79. "SplitPaneUI", windowsPackageName + "WindowsSplitPaneUI",
  80. "TextAreaUI", windowsPackageName + "WindowsTextAreaUI",
  81. "TextFieldUI", windowsPackageName + "WindowsTextFieldUI",
  82. "PasswordFieldUI", windowsPackageName + "WindowsPasswordFieldUI",
  83. "TextPaneUI", windowsPackageName + "WindowsTextPaneUI",
  84. "EditorPaneUI", windowsPackageName + "WindowsEditorPaneUI",
  85. "TreeUI", windowsPackageName + "WindowsTreeUI",
  86. "ComboBoxUI", windowsPackageName + "WindowsComboBoxUI",
  87. "InternalFrameUI", windowsPackageName + "WindowsInternalFrameUI",
  88. "DesktopPaneUI", windowsPackageName + "WindowsDesktopPaneUI",
  89. "FileChooserUI", windowsPackageName + "WindowsFileChooserUI",
  90. };
  91. table.putDefaults(uiDefaults);
  92. }
  93. /**
  94. * Load the SystemColors into the defaults table. The keys
  95. * for SystemColor defaults are the same as the names of
  96. * the public fields in SystemColor. If the table is being
  97. * created on a native Windows platform we use the SystemColor
  98. * values, otherwise we create color objects whose values match
  99. * the defaults Windows95 colors.
  100. */
  101. protected void initSystemColorDefaults(UIDefaults table)
  102. {
  103. String[] defaultSystemColors = {
  104. "desktop", "#005C5C", /* Color of the desktop background */
  105. "activeCaption", "#000080", /* Color for captions (title bars) when they are active. */
  106. "activeCaptionText", "#FFFFFF", /* Text color for text in captions (title bars). */
  107. "activeCaptionBorder", "#C0C0C0", /* Border color for caption (title bar) window borders. */
  108. "inactiveCaption", "#808080", /* Color for captions (title bars) when not active. */
  109. "inactiveCaptionText", "#C0C0C0", /* Text color for text in inactive captions (title bars). */
  110. "inactiveCaptionBorder", "#C0C0C0", /* Border color for inactive caption (title bar) window borders. */
  111. "window", "#FFFFFF", /* Default color for the interior of windows */
  112. "windowBorder", "#000000", /* ??? */
  113. "windowText", "#000000", /* ??? */
  114. "menu", "#C0C0C0", /* Background color for menus */
  115. "menuPressedItemB", "#000080", /* LightShadow of menubutton highlight */
  116. "menuPressedItemF", "#FFFFFF", /* Default color for foreground "text" in menu item */
  117. "menuText", "#000000", /* Text color for menus */
  118. "text", "#C0C0C0", /* Text background color */
  119. "textText", "#000000", /* Text foreground color */
  120. "textHighlight", "#000080", /* Text background color when selected */
  121. "textHighlightText", "#FFFFFF", /* Text color when selected */
  122. "textInactiveText", "#808080", /* Text color when disabled */
  123. "control", "#C0C0C0", /* Default color for controls (buttons, sliders, etc) */
  124. "controlText", "#000000", /* Default color for text in controls */
  125. "controlHighlight", "#C0C0C0",
  126. /*"controlHighlight", "#E0E0E0",*/ /* Specular highlight (opposite of the shadow) */
  127. "controlLtHighlight", "#FFFFFF", /* Highlight color for controls */
  128. "controlShadow", "#808080", /* Shadow color for controls */
  129. "controlDkShadow", "#000000", /* Dark shadow color for controls */
  130. "scrollbar", "#E0E0E0", /* Scrollbar background (usually the "track") */
  131. "info", "#FFFFE1", /* ??? */
  132. "infoText", "#000000" /* ??? */
  133. };
  134. loadSystemColors(table, defaultSystemColors, isNativeLookAndFeel());
  135. }
  136. private void loadResourceBundle(UIDefaults table) {
  137. ResourceBundle bundle = ResourceBundle.getBundle("com.sun.java.swing.plaf.windows.resources.windows");
  138. Enumeration iter = bundle.getKeys();
  139. while(iter.hasMoreElements()) {
  140. String key = (String)iter.nextElement();
  141. //System.out.println("key :" +key+ " value: " + bundle.getObject(key));
  142. table.put( key, bundle.getObject(key) );
  143. }
  144. }
  145. protected void initComponentDefaults(UIDefaults table)
  146. {
  147. super.initComponentDefaults( table );
  148. loadResourceBundle(table);
  149. // *** Fonts
  150. FontUIResource dialogPlain12 = new FontUIResource("Dialog", Font.PLAIN, 12);
  151. FontUIResource serifPlain12 = new FontUIResource("Serif", Font.PLAIN, 12);
  152. FontUIResource sansSerifPlain12 = new FontUIResource("SansSerif", Font.PLAIN, 12);
  153. FontUIResource monospacedPlain12 = new FontUIResource("Monospaced", Font.PLAIN, 12);
  154. // *** Colors
  155. ColorUIResource red = new ColorUIResource(Color.red);
  156. ColorUIResource black = new ColorUIResource(Color.black);
  157. ColorUIResource white = new ColorUIResource(Color.white);
  158. ColorUIResource yellow = new ColorUIResource(Color.yellow);
  159. ColorUIResource gray = new ColorUIResource(Color.gray);
  160. ColorUIResource lightGray = new ColorUIResource(Color.lightGray);
  161. ColorUIResource darkGray = new ColorUIResource(Color.darkGray);
  162. ColorUIResource scrollBarTrack = new ColorUIResource(224, 224, 224);
  163. // *** Tree
  164. ColorUIResource treeSelection = new ColorUIResource(0, 0, 128);
  165. Object treeExpandedIcon = WindowsTreeUI.ExpandedIcon.createExpandedIcon();
  166. Object treeCollapsedIcon = WindowsTreeUI.CollapsedIcon.createCollapsedIcon();
  167. // *** Text
  168. JTextComponent.KeyBinding[] fieldBindings = makeKeyBindings( new Object[]{
  169. "control C", DefaultEditorKit.copyAction,
  170. "control V", DefaultEditorKit.pasteAction,
  171. "control X", DefaultEditorKit.cutAction,
  172. "control INSERT", DefaultEditorKit.copyAction,
  173. "shift INSERT", DefaultEditorKit.pasteAction,
  174. "shift DELETE", DefaultEditorKit.cutAction,
  175. "control A", DefaultEditorKit.selectAllAction,
  176. "control BACK_SLASH", "unselect"/*DefaultEditorKit.unselectAction*/,
  177. "shift LEFT", DefaultEditorKit.selectionBackwardAction,
  178. "shift RIGHT", DefaultEditorKit.selectionForwardAction,
  179. "control LEFT", DefaultEditorKit.previousWordAction,
  180. "control RIGHT", DefaultEditorKit.nextWordAction,
  181. "control shift LEFT", DefaultEditorKit.selectionPreviousWordAction,
  182. "control shift RIGHT", DefaultEditorKit.selectionNextWordAction,
  183. "HOME", DefaultEditorKit.beginLineAction,
  184. "END", DefaultEditorKit.endLineAction,
  185. "shift HOME", DefaultEditorKit.selectionBeginLineAction,
  186. "shift END", DefaultEditorKit.selectionEndLineAction,
  187. "ENTER", JTextField.notifyAction,
  188. });
  189. JTextComponent.KeyBinding[] multilineBindings = makeKeyBindings( new Object[]{
  190. "control C", DefaultEditorKit.copyAction,
  191. "control V", DefaultEditorKit.pasteAction,
  192. "control X", DefaultEditorKit.cutAction,
  193. "control INSERT", DefaultEditorKit.copyAction,
  194. "shift INSERT", DefaultEditorKit.pasteAction,
  195. "shift DELETE", DefaultEditorKit.cutAction,
  196. "shift LEFT", DefaultEditorKit.selectionBackwardAction,
  197. "shift RIGHT", DefaultEditorKit.selectionForwardAction,
  198. "control LEFT", DefaultEditorKit.previousWordAction,
  199. "control RIGHT", DefaultEditorKit.nextWordAction,
  200. "control shift LEFT", DefaultEditorKit.selectionPreviousWordAction,
  201. "control shift RIGHT", DefaultEditorKit.selectionNextWordAction,
  202. "control A", DefaultEditorKit.selectAllAction,
  203. "control BACK_SLASH", "unselect"/*DefaultEditorKit.unselectAction*/,
  204. "HOME", DefaultEditorKit.beginLineAction,
  205. "END", DefaultEditorKit.endLineAction,
  206. "shift HOME", DefaultEditorKit.selectionBeginLineAction,
  207. "shift END", DefaultEditorKit.selectionEndLineAction,
  208. "control HOME", DefaultEditorKit.beginAction,
  209. "control END", DefaultEditorKit.endAction,
  210. "control shift HOME", DefaultEditorKit.selectionBeginAction,
  211. "control shift END", DefaultEditorKit.selectionEndAction,
  212. "UP", DefaultEditorKit.upAction,
  213. "DOWN", DefaultEditorKit.downAction,
  214. "PAGE_UP", DefaultEditorKit.pageUpAction,
  215. "PAGE_DOWN", DefaultEditorKit.pageDownAction,
  216. "shift UP", DefaultEditorKit.selectionUpAction,
  217. "shift DOWN", DefaultEditorKit.selectionDownAction,
  218. "ENTER", DefaultEditorKit.insertBreakAction,
  219. "TAB", DefaultEditorKit.insertTabAction
  220. });
  221. Border marginBorder = new BasicBorders.MarginBorder();
  222. Object checkBoxIcon = WindowsIconFactory.getCheckBoxIcon();
  223. Object radioButtonIcon =WindowsIconFactory.getRadioButtonIcon();
  224. // *** ProgressBar
  225. Object progressBarBorder = new BorderUIResource.CompoundBorderUIResource(
  226. new WindowsBorders.ProgressBarBorder(
  227. table.getColor("controlShadow"),
  228. table.getColor("controlLtHighlight")),
  229. new EmptyBorder(1,1,1,1)
  230. );
  231. // *** ToolTips
  232. Object toolTipBorder = BorderUIResource.getBlackLineBorderUIResource();
  233. Object radioButtonBorder = new BorderUIResource.CompoundBorderUIResource(
  234. new BasicBorders.RadioButtonBorder(
  235. table.getColor("controlShadow"),
  236. table.getColor("controlDkShadow"),
  237. table.getColor("controlHighlight"),
  238. table.getColor("controlLtHighlight")),
  239. marginBorder);
  240. /*
  241. Object comboBoxBorder = new WindowsBorders.ComboBoxBorder(
  242. table.getColor("controlShadow"),
  243. table.getColor("controlDkShadow"),
  244. table.getColor("controlHighlight"));
  245. */
  246. Object comboBoxBorder = new BasicBorders.FieldBorder(
  247. table.getColor("controlShadow"),
  248. table.getColor("controlDkShadow"),
  249. table.getColor("controlHighlight"),
  250. table.getColor("controlLtHighlight"));
  251. Object menuItemCheckIcon = WindowsIconFactory.getMenuItemCheckIcon();
  252. Object menuItemArrowIcon = WindowsIconFactory.getMenuItemArrowIcon();
  253. Object menuArrowIcon = WindowsIconFactory.getMenuArrowIcon();
  254. Object menuItemAcceleratorDelimiter = new String("+");
  255. Object[] defaults = {
  256. "TextField.keyBindings", fieldBindings,
  257. "PasswordField.keyBindings", fieldBindings,
  258. "TextArea.keyBindings", multilineBindings,
  259. "TextPane.keyBindings", multilineBindings,
  260. "EditorPane.keyBindings", multilineBindings,
  261. // Buttons
  262. "Button.dashedRectGapX", new Integer(5),
  263. "Button.dashedRectGapY", new Integer(4),
  264. "Button.dashedRectGapWidth", new Integer(10),
  265. "Button.dashedRectGapHeight", new Integer(8),
  266. "Button.textShiftOffset", new Integer(1),
  267. "Button.focus", black,
  268. "CheckBox.background", table.get("control"),
  269. "CheckBox.shadow", table.get("controlShadow"),
  270. "CheckBox.darkShadow", table.get("controlDkShadow"),
  271. "CheckBox.highlight", table.get("controlLtHighlight"),
  272. "CheckBox.icon", checkBoxIcon,
  273. "CheckBox.border", radioButtonBorder,
  274. "CheckBox.focus", black,
  275. "RadioButton.background", table.get("control"),
  276. "RadioButton.shadow", table.get("controlShadow"),
  277. "RadioButton.darkShadow", table.get("controlDkShadow"),
  278. "RadioButton.highlight", table.get("controlLtHighlight"),
  279. "RadioButton.icon", radioButtonIcon,
  280. "RadioButton.border", radioButtonBorder,
  281. "RadioButton.focus", black,
  282. "ToggleButton.textShiftOffset", new Integer(1),
  283. "ToggleButton.focus", black,
  284. "ToggleButton.border", radioButtonBorder,
  285. "ToggleButton.background", table.get("control"),
  286. "ToggleButton.foreground", table.get("controlText"),
  287. "ToggleButton.focus", table.get("controlText"),
  288. "ToggleButton.font", dialogPlain12,
  289. "ComboBox.border", comboBoxBorder,
  290. // Menus
  291. "Menu.border", marginBorder,
  292. "Menu.font", dialogPlain12,
  293. "Menu.foreground", table.get("menuText"),
  294. "Menu.background", table.get("menu"),
  295. "Menu.selectionForeground", table.get("textHighlightText"),
  296. "Menu.selectionBackground", table.get("textHighlight"),
  297. "Menu.arrowIcon", menuArrowIcon,
  298. "MenuItem.border", marginBorder,
  299. "MenuItem.font", dialogPlain12,
  300. "MenuItem.foreground", table.get("menuText"),
  301. "MenuItem.background", table.get("menu"),
  302. "MenuItem.selectionForeground", table.get("textHighlightText"),
  303. "MenuItem.selectionBackground", table.get("textHighlight"),
  304. "MenuItem.acceleratorDelimiter", menuItemAcceleratorDelimiter,
  305. "MenuItem.checkIcon", menuItemCheckIcon,
  306. "MenuItem.arrowIcon", menuItemArrowIcon,
  307. "SplitPane.background", table.get("control"),
  308. "SplitPane.highlight", table.get("controllHighlight"),
  309. "SplitPane.shadow", table.get("controlShadow"),
  310. "SplitPane.dividerSize", new Integer(3),
  311. "ToolTip.font", sansSerifPlain12,
  312. "ToolTip.border", toolTipBorder,
  313. "ToolTip.background", table.get("info"),
  314. "ToolTip.foreground", table.get("infoText"),
  315. "ProgressBar.font", dialogPlain12,
  316. "ProgressBar.foreground", table.get("textHighlight"),
  317. "ProgressBar.background", table.get("control"),
  318. "ProgressBar.selectionForeground", table.get("control"),
  319. "ProgressBar.selectionBackground", table.get("textHighlight"),
  320. "ProgressBar.border", progressBarBorder,
  321. "ProgressBar.cellLength", new Integer(7),
  322. "ProgressBar.cellSpacing", new Integer(2),
  323. "Tree.font", dialogPlain12,
  324. "Tree.background", table.get("window"),
  325. "Tree.foreground", table.get("textText"),
  326. "Tree.hash", gray,
  327. "Tree.textForeground", table.get("textText"),
  328. "Tree.textBackground", table.get("window"),
  329. "Tree.selectionForeground", table.get("textHighlightText"),
  330. "Tree.selectionBackground", table.get("textHighlight"),
  331. "Tree.selectionBorderColor", yellow,
  332. "Tree.expandedIcon", treeExpandedIcon,
  333. "Tree.collapsedIcon", treeCollapsedIcon,
  334. "FileChooser.newFolderIcon", LookAndFeel.makeIcon(getClass(), "icons/NewFolder.gif"),
  335. "FileChooser.upFolderIcon", LookAndFeel.makeIcon(getClass(), "icons/UpFolder.gif"),
  336. "FileChooser.homeFolderIcon", LookAndFeel.makeIcon(getClass(), "icons/HomeFolder.gif"),
  337. "FileChooser.detailsViewIcon", LookAndFeel.makeIcon(getClass(), "icons/DetailsView.gif"),
  338. "FileChooser.listViewIcon", LookAndFeel.makeIcon(getClass(), "icons/ListView.gif"),
  339. "FileChooser.lookInLabelMnemonic", new Integer(KeyEvent.VK_I),
  340. "FileChooser.fileNameLabelMnemonic", new Integer(KeyEvent.VK_N),
  341. "FileChooser.filesOfTypeLabelMnemonic", new Integer(KeyEvent.VK_T),
  342. "FileView.directoryIcon", LookAndFeel.makeIcon(getClass(), "icons/Directory.gif"),
  343. "FileView.fileIcon", LookAndFeel.makeIcon(getClass(), "icons/File.gif"),
  344. "FileView.computerIcon", LookAndFeel.makeIcon(getClass(), "icons/Computer.gif"),
  345. "FileView.hardDriveIcon", LookAndFeel.makeIcon(getClass(), "icons/HardDrive.gif"),
  346. "FileView.floppyDriveIcon", LookAndFeel.makeIcon(getClass(), "icons/FloppyDrive.gif"),
  347. "InternalFrame.minimizeIconBackground", table.get("control"),
  348. "InternalFrame.resizeIconHighlight", table.get("controlHighlight"),
  349. "InternalFrame.resizeIconShadow", table.get("controlShadow"),
  350. "InternalFrame.maximizeIcon",
  351. WindowsIconFactory.createFrameMaximizeIcon(),
  352. "InternalFrame.minimizeIcon",
  353. WindowsIconFactory.createFrameMinimizeIcon(),
  354. "InternalFrame.iconifyIcon",
  355. WindowsIconFactory.createFrameIconifyIcon(),
  356. "InternalFrame.closeIcon",
  357. WindowsIconFactory.createFrameCloseIcon(),
  358. };
  359. table.putDefaults(defaults);
  360. }
  361. }