1. /*
  2. * @(#)MetalLookAndFeel.java 1.95 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 javax.swing.plaf.metal;
  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.util.*;
  16. import java.awt.Font;
  17. import java.awt.Color;
  18. import java.awt.SystemColor;
  19. import java.awt.event.KeyEvent;
  20. import java.awt.event.InputEvent;
  21. import java.net.URL;
  22. import java.io.Serializable;
  23. /**
  24. * Implements The Metal Look and Feel.
  25. * <p>
  26. * For the keyboard keys defined for each component in this Look and
  27. * Feel (L&F), see
  28. * <a href="../../doc-files/Key-Metal.html">Component Keystroke Actions for the Metal L&F</a>.
  29. * <p>
  30. * <strong>Warning:</strong>
  31. * Serialized objects of this class will not be compatible with
  32. * future Swing releases. The current serialization support is appropriate
  33. * for short term storage or RMI between applications running the same
  34. * version of Swing. A future release of Swing will provide support for
  35. * long term persistence.
  36. *
  37. * @version 1.95 11/29/01
  38. * @author Steve Wilson
  39. */
  40. public class MetalLookAndFeel extends BasicLookAndFeel
  41. {
  42. private static MetalTheme currentTheme;
  43. public String getName() {
  44. return "Metal";
  45. }
  46. public String getID() {
  47. return "Metal";
  48. }
  49. public String getDescription() {
  50. return "The Java(tm) Look and Feel";
  51. }
  52. public boolean isNativeLookAndFeel() {
  53. return false;
  54. }
  55. public boolean isSupportedLookAndFeel() {
  56. return true;
  57. }
  58. /**
  59. * Initialize the uiClassID to BasicComponentUI mapping.
  60. * The JComponent classes define their own uiClassID constants
  61. * (see AbstractComponent.getUIClassID). This table must
  62. * map those constants to a BasicComponentUI class of the
  63. * appropriate type.
  64. *
  65. * @see BasicLookAndFeel#getDefaults
  66. */
  67. protected void initClassDefaults(UIDefaults table)
  68. {
  69. super.initClassDefaults(table);
  70. // String basicPackageName = "javax.swing.plaf.basic.";
  71. String metalPackageName = "javax.swing.plaf.metal.";
  72. Object[] uiDefaults = {
  73. "ButtonUI", metalPackageName + "MetalButtonUI",
  74. "CheckBoxUI", metalPackageName + "MetalCheckBoxUI",
  75. "RadioButtonUI", metalPackageName + "MetalRadioButtonUI",
  76. "ToggleButtonUI", metalPackageName + "MetalToggleButtonUI",
  77. "ProgressBarUI", metalPackageName + "MetalProgressBarUI",
  78. "ScrollBarUI", metalPackageName + "MetalScrollBarUI",
  79. "ScrollPaneUI", metalPackageName + "MetalScrollPaneUI",
  80. "SplitPaneUI", metalPackageName + "MetalSplitPaneUI",
  81. "SliderUI", metalPackageName + "MetalSliderUI",
  82. "SeparatorUI", metalPackageName + "MetalSeparatorUI",
  83. "PopupMenuSeparatorUI", metalPackageName + "MetalPopupMenuSeparatorUI",
  84. "TabbedPaneUI", metalPackageName + "MetalTabbedPaneUI",
  85. "TextFieldUI", metalPackageName + "MetalTextFieldUI",
  86. "TreeUI", metalPackageName + "MetalTreeUI",
  87. "LabelUI", metalPackageName + "MetalLabelUI",
  88. "ToolBarUI", metalPackageName + "MetalToolBarUI",
  89. "ToolTipUI", metalPackageName + "MetalToolTipUI",
  90. "ComboBoxUI", metalPackageName + "MetalComboBoxUI",
  91. "InternalFrameUI", metalPackageName + "MetalInternalFrameUI",
  92. "DesktopIconUI", metalPackageName + "MetalDesktopIconUI",
  93. "FileChooserUI", metalPackageName + "MetalFileChooserUI",
  94. };
  95. table.putDefaults(uiDefaults);
  96. }
  97. /**
  98. * Load the SystemColors into the defaults table. The keys
  99. * for SystemColor defaults are the same as the names of
  100. * the public fields in SystemColor.
  101. */
  102. protected void initSystemColorDefaults(UIDefaults table)
  103. {
  104. Object[] systemColors = {
  105. "desktop", getDesktopColor(), /* Color of the desktop background */
  106. "activeCaption", getWindowTitleBackground(), /* Color for captions (title bars) when they are active. */
  107. "activeCaptionText", getWindowTitleForeground(), /* Text color for text in captions (title bars). */
  108. "activeCaptionBorder", getPrimaryControlShadow(), /* Border color for caption (title bar) window borders. */
  109. "inactiveCaption", getWindowTitleInactiveBackground(), /* Color for captions (title bars) when not active. */
  110. "inactiveCaptionText", getWindowTitleInactiveForeground(), /* Text color for text in inactive captions (title bars). */
  111. "inactiveCaptionBorder", getControlShadow(), /* Border color for inactive caption (title bar) window borders. */
  112. "window", getWindowBackground(), /* Default color for the interior of windows */
  113. "windowBorder", getControl(), /* ??? */
  114. "windowText", getUserTextColor(), /* ??? */
  115. "menu", getMenuBackground(), /* Background color for menus */
  116. "menuText", getMenuForeground(), /* Text color for menus */
  117. "text", getWindowBackground(), /* Text background color */
  118. "textText", getUserTextColor(), /* Text foreground color */
  119. "textHighlight", getTextHighlightColor(), /* Text background color when selected */
  120. "textHighlightText", getHighlightedTextColor(), /* Text color when selected */
  121. "textInactiveText", getInactiveSystemTextColor(), /* Text color when disabled */
  122. "control", getControl(), /* Default color for controls (buttons, sliders, etc) */
  123. "controlText", getControlTextColor(), /* Default color for text in controls */
  124. "controlHighlight", getControlHighlight(), /* Specular highlight (opposite of the shadow) */
  125. "controlLtHighlight", getControlHighlight(), /* Highlight color for controls */
  126. "controlShadow", getControlShadow(), /* Shadow color for controls */
  127. "controlDkShadow", getControlDarkShadow(), /* Dark shadow color for controls */
  128. "scrollbar", getControl(), /* Scrollbar background (usually the "track") */
  129. "info", getPrimaryControl(), /* ToolTip Background */
  130. "infoText", getPrimaryControlInfo() /* ToolTip Text */
  131. };
  132. for(int i = 0; i < systemColors.length; i += 2) {
  133. table.put((String)systemColors[i], systemColors[i + 1]);
  134. }
  135. }
  136. private void loadResourceBundle(UIDefaults table) {
  137. ResourceBundle bundle = ResourceBundle.getBundle("javax.swing.plaf.metal.resources.metal");
  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. super.initComponentDefaults( table );
  147. loadResourceBundle(table);
  148. Border marginBorder = new BasicBorders.MarginBorder();
  149. Border flush3DBorder = new MetalBorders.Flush3DBorder();
  150. Border textFieldBorder = new BorderUIResource.CompoundBorderUIResource(
  151. new MetalBorders.TextFieldBorder(),
  152. marginBorder);
  153. Object textBorder = new BorderUIResource.CompoundBorderUIResource(
  154. flush3DBorder,
  155. marginBorder);
  156. JTextComponent.KeyBinding[] fieldBindings = {
  157. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_C,
  158. InputEvent.CTRL_MASK),
  159. DefaultEditorKit.copyAction),
  160. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V,
  161. InputEvent.CTRL_MASK),
  162. DefaultEditorKit.pasteAction),
  163. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_X,
  164. InputEvent.CTRL_MASK),
  165. DefaultEditorKit.cutAction),
  166. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
  167. InputEvent.SHIFT_MASK),
  168. DefaultEditorKit.selectionBackwardAction),
  169. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("shift KP_LEFT"),
  170. DefaultEditorKit.selectionBackwardAction),
  171. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
  172. InputEvent.SHIFT_MASK),
  173. DefaultEditorKit.selectionForwardAction),
  174. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("shift KP_RIGHT"),
  175. DefaultEditorKit.selectionForwardAction),
  176. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
  177. InputEvent.CTRL_MASK),
  178. DefaultEditorKit.previousWordAction),
  179. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("control KP_LEFT"),
  180. DefaultEditorKit.previousWordAction),
  181. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
  182. InputEvent.CTRL_MASK),
  183. DefaultEditorKit.nextWordAction),
  184. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("control KP_RIGHT"),
  185. DefaultEditorKit.nextWordAction),
  186. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
  187. InputEvent.CTRL_MASK |
  188. InputEvent.SHIFT_MASK),
  189. DefaultEditorKit.selectionPreviousWordAction),
  190. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("control shift KP_LEFT"),
  191. DefaultEditorKit.selectionPreviousWordAction),
  192. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
  193. InputEvent.CTRL_MASK |
  194. InputEvent.SHIFT_MASK),
  195. DefaultEditorKit.selectionNextWordAction),
  196. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("control shift KP_RIGHT"),
  197. DefaultEditorKit.selectionNextWordAction),
  198. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_A,
  199. InputEvent.CTRL_MASK),
  200. DefaultEditorKit.selectAllAction),
  201. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0),
  202. DefaultEditorKit.beginLineAction),
  203. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0),
  204. DefaultEditorKit.endLineAction),
  205. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_HOME,
  206. InputEvent.SHIFT_MASK),
  207. DefaultEditorKit.selectionBeginLineAction),
  208. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_END,
  209. InputEvent.SHIFT_MASK),
  210. DefaultEditorKit.selectionEndLineAction),
  211. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
  212. JTextField.notifyAction)
  213. };
  214. JTextComponent.KeyBinding[] multilineBindings = {
  215. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_C,
  216. InputEvent.CTRL_MASK),
  217. DefaultEditorKit.copyAction),
  218. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V,
  219. InputEvent.CTRL_MASK),
  220. DefaultEditorKit.pasteAction),
  221. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_X,
  222. InputEvent.CTRL_MASK),
  223. DefaultEditorKit.cutAction),
  224. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
  225. InputEvent.SHIFT_MASK),
  226. DefaultEditorKit.selectionBackwardAction),
  227. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("shift KP_LEFT"),
  228. DefaultEditorKit.selectionBackwardAction),
  229. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
  230. InputEvent.SHIFT_MASK),
  231. DefaultEditorKit.selectionForwardAction),
  232. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("shift KP_RIGHT"),
  233. DefaultEditorKit.selectionForwardAction),
  234. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
  235. InputEvent.CTRL_MASK),
  236. DefaultEditorKit.previousWordAction),
  237. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("control KP_LEFT"),
  238. DefaultEditorKit.previousWordAction),
  239. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
  240. InputEvent.CTRL_MASK),
  241. DefaultEditorKit.nextWordAction),
  242. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("control KP_RIGHT"),
  243. DefaultEditorKit.nextWordAction),
  244. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
  245. InputEvent.CTRL_MASK |
  246. InputEvent.SHIFT_MASK),
  247. DefaultEditorKit.selectionPreviousWordAction),
  248. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("control shift KP_LEFT"),
  249. DefaultEditorKit.selectionPreviousWordAction),
  250. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
  251. InputEvent.CTRL_MASK |
  252. InputEvent.SHIFT_MASK),
  253. DefaultEditorKit.selectionNextWordAction),
  254. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("control shift KP_RIGHT"),
  255. DefaultEditorKit.selectionNextWordAction),
  256. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_A,
  257. InputEvent.CTRL_MASK),
  258. DefaultEditorKit.selectAllAction),
  259. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0),
  260. DefaultEditorKit.beginLineAction),
  261. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0),
  262. DefaultEditorKit.endLineAction),
  263. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_HOME,
  264. InputEvent.SHIFT_MASK),
  265. DefaultEditorKit.selectionBeginLineAction),
  266. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_END,
  267. InputEvent.SHIFT_MASK),
  268. DefaultEditorKit.selectionEndLineAction),
  269. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0),
  270. DefaultEditorKit.upAction),
  271. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("KP_UP"),
  272. DefaultEditorKit.upAction),
  273. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0),
  274. DefaultEditorKit.downAction),
  275. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("KP_DOWN"),
  276. DefaultEditorKit.downAction),
  277. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0),
  278. DefaultEditorKit.pageUpAction),
  279. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0),
  280. DefaultEditorKit.pageDownAction),
  281. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_UP,
  282. InputEvent.SHIFT_MASK),
  283. DefaultEditorKit.selectionUpAction),
  284. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("shift KP_UP"),
  285. DefaultEditorKit.selectionUpAction),
  286. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,
  287. InputEvent.SHIFT_MASK),
  288. DefaultEditorKit.selectionDownAction),
  289. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke("shift KP_DOWN"),
  290. DefaultEditorKit.selectionDownAction),
  291. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
  292. DefaultEditorKit.insertBreakAction),
  293. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0),
  294. DefaultEditorKit.insertTabAction),
  295. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH,
  296. InputEvent.CTRL_MASK),
  297. "unselect"/*DefaultEditorKit.unselectAction*/),
  298. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_HOME,
  299. InputEvent.CTRL_MASK),
  300. DefaultEditorKit.beginAction),
  301. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_END,
  302. InputEvent.CTRL_MASK),
  303. DefaultEditorKit.endAction),
  304. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_HOME,
  305. InputEvent.CTRL_MASK |
  306. InputEvent.SHIFT_MASK),
  307. DefaultEditorKit.selectionBeginAction),
  308. new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_END,
  309. InputEvent.CTRL_MASK |
  310. InputEvent.SHIFT_MASK),
  311. DefaultEditorKit.selectionEndAction)
  312. };
  313. Object scrollPaneBorder = new MetalBorders.ScrollPaneBorder();
  314. Object buttonBorder = new BorderUIResource.CompoundBorderUIResource(
  315. new MetalBorders.ButtonBorder(),
  316. marginBorder);
  317. Object toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource(
  318. new MetalBorders.ToggleButtonBorder(),
  319. marginBorder);
  320. Object titledBorderBorder = new BorderUIResource.LineBorderUIResource(
  321. table.getColor("controlShadow"));
  322. Object desktopIconBorder = new BorderUIResource.CompoundBorderUIResource(
  323. new LineBorder(getControlDarkShadow(), 1),
  324. new MatteBorder (2,2,1,2, getControl()));
  325. // Object internalFrameBorder = new MetalBorders.InternalFrameBorder();
  326. Object menuBarBorder = new MetalBorders.MenuBarBorder();
  327. Object popupMenuBorder = new MetalBorders.PopupMenuBorder();
  328. Object menuItemBorder = new MetalBorders.MenuItemBorder();
  329. Object menuItemAcceleratorDelimiter = new String("-");
  330. Object toolBarBorder = new MetalBorders.ToolBarBorder();
  331. Object progressBarBorder = new BorderUIResource.LineBorderUIResource(
  332. getControlDarkShadow(), 1);
  333. Object toolTipBorder = new BorderUIResource.LineBorderUIResource(
  334. getPrimaryControlDarkShadow());
  335. Object focusCellHighlightBorder = new BorderUIResource.LineBorderUIResource(
  336. getFocusColor());
  337. Object tabbedPaneTabAreaInsets = new InsetsUIResource(4, 2, 0, 6);
  338. Object sliderFocusInsets = new InsetsUIResource( 0, 0, 0, 0 );
  339. //
  340. // DEFAULTS TABLE
  341. //
  342. final int internalFrameIconSize = 16;
  343. Object[] defaults = {
  344. // Text (Note: many are inherited)
  345. "TextField.border", textFieldBorder,
  346. "TextField.font", getUserTextFont(),
  347. "TextField.caretForeground", getUserTextColor(),
  348. "PasswordField.border", textBorder,
  349. "PasswordField.font", getUserTextFont(),
  350. "PasswordField.caretForeground", getUserTextColor(),
  351. "TextArea.font", getUserTextFont(),
  352. "TextArea.caretForeground", getUserTextColor(),
  353. "TextPane.selectionBackground", table.get("textHighlight"),
  354. "TextPane.selectionForeground", table.get("textHighlightText"),
  355. "TextPane.background", table.get("window"),
  356. "TextPane.foreground", table.get("textText"),
  357. "TextPane.font", getUserTextFont(),
  358. "TextPane.caretForeground", getUserTextColor(),
  359. "EditorPane.selectionBackground", table.get("textHighlight"),
  360. "EditorPane.selectionForeground", table.get("textHighlightText"),
  361. "EditorPane.background", table.get("window"),
  362. "EditorPane.foreground", table.get("textText"),
  363. "EditorPane.font", getUserTextFont(),
  364. "EditorPane.caretForeground", getUserTextColor(),
  365. "TextField.keyBindings", fieldBindings,
  366. "PasswordField.keyBindings", fieldBindings,
  367. "TextArea.keyBindings", multilineBindings,
  368. "TextPane.keyBindings", multilineBindings,
  369. "EditorPane.keyBindings", multilineBindings,
  370. // Buttons
  371. "Button.background", getControl(),
  372. "Button.foreground", getControlTextColor(),
  373. "Button.disabledText", getInactiveControlTextColor(),
  374. "Button.select", getControlShadow(),
  375. "Button.border", buttonBorder,
  376. "Button.font", getControlTextFont(),
  377. "Button.focus", getFocusColor(),
  378. "CheckBox.background", getControl(),
  379. "CheckBox.foreground", getControlTextColor(),
  380. "CheckBox.disabledText", getInactiveControlTextColor(),
  381. "Checkbox.select", getControlShadow(),
  382. "CheckBox.font", getControlTextFont(),
  383. "CheckBox.focus", getFocusColor(),
  384. "CheckBox.icon", new MetalCheckBoxIcon(),
  385. "RadioButton.background", getControl(),
  386. "RadioButton.foreground", getControlTextColor(),
  387. "RadioButton.disabledText", getInactiveControlTextColor(),
  388. "RadioButton.select", getControlShadow(),
  389. "RadioButton.icon", MetalIconFactory.getRadioButtonIcon(),
  390. "RadioButton.font", getControlTextFont(),
  391. "RadioButton.focus", getFocusColor(),
  392. "ToggleButton.background", getControl(),
  393. "ToggleButton.foreground", getControlTextColor(),
  394. "ToggleButton.select", getControlShadow(),
  395. "ToggleButton.text", getControl(),
  396. "ToggleButton.disabledText", getInactiveControlTextColor(),
  397. "ToggleButton.disabledSelectedText", getControlDarkShadow(),
  398. "ToggleButton.disabledBackground", getControl(),
  399. "ToggleButton.disabledSelectedBackground", getControlShadow(),
  400. "ToggleButton.focus", getFocusColor(),
  401. "ToggleButton.border", toggleButtonBorder,
  402. "ToggleButton.font", getControlTextFont(),
  403. // File View
  404. "FileView.directoryIcon", MetalIconFactory.getTreeFolderIcon(),
  405. "FileView.fileIcon", MetalIconFactory.getTreeLeafIcon(),
  406. "FileView.computerIcon", MetalIconFactory.getTreeComputerIcon(),
  407. "FileView.hardDriveIcon", MetalIconFactory.getTreeHardDriveIcon(),
  408. "FileView.floppyDriveIcon", MetalIconFactory.getTreeFloppyDriveIcon(),
  409. // File Chooser
  410. "FileChooser.detailsViewIcon", MetalIconFactory.getFileChooserDetailViewIcon(),
  411. "FileChooser.homeFolderIcon", MetalIconFactory.getFileChooserHomeFolderIcon(),
  412. "FileChooser.listViewIcon", MetalIconFactory.getFileChooserListViewIcon(),
  413. "FileChooser.newFolderIcon", MetalIconFactory.getFileChooserNewFolderIcon(),
  414. "FileChooser.upFolderIcon", MetalIconFactory.getFileChooserUpFolderIcon(),
  415. "FileChooser.lookInLabelMnemonic", new Integer(KeyEvent.VK_I),
  416. "FileChooser.fileNameLabelMnemonic", new Integer(KeyEvent.VK_N),
  417. "FileChooser.filesOfTypeLabelMnemonic", new Integer(KeyEvent.VK_T),
  418. // ToolTip
  419. "ToolTip.font", getSystemTextFont(),
  420. "ToolTip.border", toolTipBorder,
  421. "ToolTip.background", table.get("info"),
  422. "ToolTip.foreground", table.get("infoText"),
  423. // Slider Defaults
  424. "Slider.border", null,
  425. "Slider.foreground", getPrimaryControlShadow(),
  426. "Slider.background", getControl(),
  427. "Slider.focus", getFocusColor(),
  428. "Slider.focusInsets", sliderFocusInsets,
  429. "Slider.trackWidth", new Integer( 7 ),
  430. "Slider.majorTickLength", new Integer( 6 ),
  431. "Slider.horizontalThumbIcon", MetalIconFactory.getHorizontalSliderThumbIcon(),
  432. "Slider.verticalThumbIcon", MetalIconFactory.getVerticalSliderThumbIcon(),
  433. // Progress Bar
  434. "ProgressBar.font", getControlTextFont(),
  435. "ProgressBar.foreground", getPrimaryControlShadow(),
  436. "ProgressBar.background", getControl(),
  437. "ProgressBar.foregroundHighlight", getPrimaryControlShadow(),
  438. "ProgressBar.backgroundHighlight", getControl(),
  439. "ProgressBar.selectionForeground", getControl(),
  440. "ProgressBar.selectionBackground", getPrimaryControlDarkShadow(),
  441. "ProgressBar.border", progressBarBorder,
  442. "ProgressBar.cellSpacing", new Integer(0),
  443. "ProgressBar.cellLength", new Integer(1),
  444. // Combo Box
  445. "ComboBox.background", table.get("control"),
  446. "ComboBox.foreground", table.get("controlText"),
  447. "ComboBox.selectionBackground", getPrimaryControlShadow(),
  448. "ComboBox.selectionForeground", getControlTextColor(),
  449. "ComboBox.listBackground", getControl(),
  450. "ComboBox.listForeground", getControlTextColor(),
  451. "ComboBox.font", getControlTextFont(),
  452. // Internal Frame Defaults
  453. "InternalFrame.icon", MetalIconFactory.getInternalFrameDefaultMenuIcon(),
  454. "InternalFrame.border", new MetalBorders.InternalFrameBorder(),
  455. "InternalFrame.paletteBorder", new MetalBorders.PaletteBorder(),
  456. "InternalFrame.paletteTitleHeight", new Integer(11),
  457. "InternalFrame.paletteCloseIcon", new MetalIconFactory.PaletteCloseIcon(),
  458. "InternalFrame.closeIcon", MetalIconFactory.getInternalFrameCloseIcon(internalFrameIconSize),
  459. "InternalFrame.maximizeIcon", MetalIconFactory.getInternalFrameMaximizeIcon(internalFrameIconSize),
  460. "InternalFrame.iconizeIcon", MetalIconFactory.getInternalFrameMinimizeIcon(internalFrameIconSize),
  461. "InternalFrame.minimizeIcon", MetalIconFactory.getInternalFrameAltMaximizeIcon(internalFrameIconSize),
  462. "InternalFrame.font", getWindowTitleFont(),
  463. // Desktop Icon
  464. "DesktopIcon.border", desktopIconBorder,
  465. "DesktopIcon.font", getControlTextFont(),
  466. "DesktopIcon.foreground", getControlTextColor(),
  467. "DesktopIcon.background", getControl(),
  468. // Titled Border
  469. "TitledBorder.font", getControlTextFont(),
  470. "TitledBorder.titleColor", getSystemTextColor(),
  471. "TitledBorder.border", titledBorderBorder,
  472. // Label
  473. "Label.font", getControlTextFont(),
  474. "Label.background", table.get("control"),
  475. "Label.foreground", getSystemTextColor(),
  476. "Label.disabledForeground", getInactiveSystemTextColor(),
  477. // List
  478. "List.focusCellHighlightBorder", focusCellHighlightBorder,
  479. // ScrollBar
  480. "ScrollBar.background", getControl(),
  481. "ScrollBar.highlight", getControlHighlight(),
  482. "ScrollBar.shadow", getControlShadow(),
  483. "ScrollBar.darkShadow", getControlDarkShadow(),
  484. "ScrollBar.thumb", getPrimaryControlShadow(),
  485. "ScrollBar.thumbShadow", getPrimaryControlDarkShadow(),
  486. "ScrollBar.thumbHighlight", getPrimaryControl(),
  487. "ScrollBar.width", new Integer( 17 ),
  488. // ScrollPane
  489. "ScrollPane.border", scrollPaneBorder,
  490. "ScrollPane.background", table.get("control"/*"window"*/),
  491. // Tabbed Pane
  492. "TabbedPane.font", getControlTextFont(),
  493. "TabbedPane.tabAreaBackground", getControl(),
  494. "TabbedPane.background", getControlShadow(),
  495. "TabbedPane.foreground", getControlTextColor(),
  496. "TabbedPane.highlight", getControl(),
  497. "TabbedPane.lightHighlight", getControlHighlight(),
  498. "TabbedPane.darkShadow", getControlDarkShadow(),
  499. "TabbedPane.focus", getPrimaryControlDarkShadow(),
  500. "TabbedPane.selected", getControl(),
  501. "TabbedPane.selectHighlight", getControlHighlight(),
  502. "TabbedPane.tabAreaInsets", tabbedPaneTabAreaInsets,
  503. // Table
  504. "Table.font", getUserTextFont(),
  505. "Table.focusCellHighlightBorder", focusCellHighlightBorder,
  506. "Table.focusCellBackground", table.get("window"),
  507. "Table.scrollPaneBorder", scrollPaneBorder,
  508. "Table.gridColor", getControlShadow(), // grid line color
  509. "TableHeader.font", getUserTextFont(),
  510. "TableHeader.cellBorder", new MetalUtils.TableHeaderBorder(),
  511. // MenuBar
  512. "MenuBar.border", menuBarBorder,
  513. "MenuBar.font", getMenuTextFont(),
  514. "MenuBar.foreground", getMenuForeground(),
  515. "MenuBar.background", getMenuBackground(),
  516. // Menu
  517. "Menu.border", menuItemBorder,
  518. "Menu.borderPainted", Boolean.TRUE,
  519. "Menu.font", getMenuTextFont(),
  520. "Menu.foreground", getMenuForeground(),
  521. "Menu.background", getMenuBackground(),
  522. "Menu.selectionForeground", getMenuSelectedForeground(),
  523. "Menu.selectionBackground", getMenuSelectedBackground(),
  524. "Menu.disabledForeground", getMenuDisabledForeground(),
  525. "Menu.acceleratorFont", getSubTextFont(),
  526. "Menu.acceleratorForeground", getAcceleratorForeground(),
  527. "Menu.acceleratorSelectionForeground", getAcceleratorSelectedForeground(),
  528. "Menu.checkIcon", MetalIconFactory.getMenuItemCheckIcon(),
  529. "Menu.arrowIcon", MetalIconFactory.getMenuArrowIcon(),
  530. // Menu Item
  531. "MenuItem.border", menuItemBorder,
  532. "MenuItem.borderPainted", Boolean.TRUE,
  533. "MenuItem.font", getMenuTextFont(),
  534. "MenuItem.foreground", getMenuForeground(),
  535. "MenuItem.background", getMenuBackground(),
  536. "MenuItem.selectionForeground", getMenuSelectedForeground(),
  537. "MenuItem.selectionBackground", getMenuSelectedBackground(),
  538. "MenuItem.disabledForeground", getMenuDisabledForeground(),
  539. "MenuItem.acceleratorFont", getSubTextFont(),
  540. "MenuItem.acceleratorForeground", getAcceleratorForeground(),
  541. "MenuItem.acceleratorSelectionForeground", getAcceleratorSelectedForeground(),
  542. "MenuItem.acceleratorDelimiter", menuItemAcceleratorDelimiter,
  543. "MenuItem.checkIcon", MetalIconFactory.getMenuItemCheckIcon(),
  544. "MenuItem.arrowIcon", MetalIconFactory.getMenuItemArrowIcon(),
  545. // Separator
  546. "Separator.background", getSeparatorBackground(),
  547. "Separator.foreground", getSeparatorForeground(),
  548. // Popup Menu
  549. "PopupMenu.background", getMenuBackground(),
  550. "PopupMenu.border", popupMenuBorder,
  551. // CB & RB Menu Item
  552. "CheckBoxMenuItem.border", menuItemBorder,
  553. "CheckBoxMenuItem.borderPainted", Boolean.TRUE,
  554. "CheckBoxMenuItem.font", getMenuTextFont(),
  555. "CheckBoxMenuItem.foreground", getMenuForeground(),
  556. "CheckBoxMenuItem.background", getMenuBackground(),
  557. "CheckBoxMenuItem.selectionForeground", getMenuSelectedForeground(),
  558. "CheckBoxMenuItem.selectionBackground", getMenuSelectedBackground(),
  559. "CheckBoxMenuItem.disabledForeground", getMenuDisabledForeground(),
  560. "CheckBoxMenuItem.acceleratorFont", getSubTextFont(),
  561. "CheckBoxMenuItem.acceleratorForeground", getAcceleratorForeground(),
  562. "CheckBoxMenuItem.acceleratorSelectionForeground", getAcceleratorSelectedForeground(),
  563. "CheckBoxMenuItem.checkIcon", MetalIconFactory.getCheckBoxMenuItemIcon(),
  564. "CheckBoxMenuItem.arrowIcon", MetalIconFactory.getMenuItemArrowIcon(),
  565. "RadioButtonMenuItem.border", menuItemBorder,
  566. "RadioButtonMenuItem.borderPainted", Boolean.TRUE,
  567. "RadioButtonMenuItem.font", getMenuTextFont(),
  568. "RadioButtonMenuItem.foreground", getMenuForeground(),
  569. "RadioButtonMenuItem.background", getMenuBackground(),
  570. "RadioButtonMenuItem.selectionForeground", getMenuSelectedForeground(),
  571. "RadioButtonMenuItem.selectionBackground", getMenuSelectedBackground(),
  572. "RadioButtonMenuItem.disabledForeground", getMenuDisabledForeground(),
  573. "RadioButtonMenuItem.acceleratorFont", getSubTextFont(),
  574. "RadioButtonMenuItem.acceleratorForeground", getAcceleratorForeground(),
  575. "RadioButtonMenuItem.acceleratorSelectionForeground", getAcceleratorSelectedForeground(),
  576. "RadioButtonMenuItem.checkIcon", MetalIconFactory.getRadioButtonMenuItemIcon(),
  577. "RadioButtonMenuItem.arrowIcon", MetalIconFactory.getMenuItemArrowIcon(),
  578. // SplitPane
  579. "SplitPane.dividerSize", new Integer(8),
  580. // Tree
  581. "Tree.background", getWindowBackground(),
  582. "Tree.font", getSystemTextFont(),
  583. "Tree.textForeground", table.get("textText"),
  584. "Tree.textBackground", getWindowBackground(),
  585. "Tree.selectionForeground", table.get("textHighlightText"),
  586. "Tree.selectionBackground", table.get("textHighlight"),
  587. "Tree.selectionBorderColor", MetalLookAndFeel.getFocusColor(),
  588. "Tree.openIcon", MetalIconFactory.getTreeFolderIcon(),
  589. "Tree.closedIcon", MetalIconFactory.getTreeFolderIcon(),
  590. "Tree.leafIcon", MetalIconFactory.getTreeLeafIcon(),
  591. "Tree.expandedIcon", MetalIconFactory.getTreeControlIcon( MetalIconFactory.DARK ),
  592. "Tree.collapsedIcon", MetalIconFactory.getTreeControlIcon( MetalIconFactory.LIGHT ),
  593. "Tree.line", getPrimaryControl(), // horiz lines
  594. "Tree.hash", getPrimaryControl(), // legs
  595. "Tree.rowHeight", new Integer(0),
  596. // ToolBar
  597. "ToolBar.border", toolBarBorder,
  598. "ToolBar.background", getMenuBackground(),
  599. "ToolBar.foreground", getMenuForeground(),
  600. "ToolBar.font", getMenuTextFont(),
  601. "ToolBar.dockingBackground", getMenuBackground(),
  602. "ToolBar.floatingBackground", getMenuBackground(),
  603. "ToolBar.dockingForeground", getPrimaryControlDarkShadow(),
  604. "ToolBar.floatingForeground", getPrimaryControl(),
  605. };
  606. table.putDefaults(defaults);
  607. }
  608. protected void createDefaultTheme() {
  609. if( currentTheme == null)
  610. currentTheme = new DefaultMetalTheme();
  611. }
  612. public UIDefaults getDefaults() {
  613. createDefaultTheme();
  614. UIDefaults table = super.getDefaults();
  615. currentTheme.addCustomEntriesToTable(table);
  616. return table;
  617. }
  618. public static void setCurrentTheme(MetalTheme theme) {
  619. if (theme == null) {
  620. throw new NullPointerException("Can't have null theme");
  621. }
  622. currentTheme = theme;
  623. }
  624. public static FontUIResource getControlTextFont() { return currentTheme.getControlTextFont();}
  625. public static FontUIResource getSystemTextFont() { return currentTheme.getSystemTextFont();}
  626. public static FontUIResource getUserTextFont() { return currentTheme.getUserTextFont();}
  627. public static FontUIResource getMenuTextFont() { return currentTheme.getMenuTextFont();}
  628. public static FontUIResource getWindowTitleFont() { return currentTheme.getWindowTitleFont();}
  629. public static FontUIResource getSubTextFont() { return currentTheme.getSubTextFont();}
  630. public static ColorUIResource getDesktopColor() { return currentTheme.getDesktopColor(); }
  631. public static ColorUIResource getFocusColor() { return currentTheme.getFocusColor(); }
  632. public static ColorUIResource getWhite() { return currentTheme.getWhite(); }
  633. public static ColorUIResource getBlack() { return currentTheme.getBlack(); }
  634. public static ColorUIResource getControl() { return currentTheme.getControl(); }
  635. public static ColorUIResource getControlShadow() { return currentTheme.getControlShadow(); }
  636. public static ColorUIResource getControlDarkShadow() { return currentTheme.getControlDarkShadow(); }
  637. public static ColorUIResource getControlInfo() { return currentTheme.getControlInfo(); }
  638. public static ColorUIResource getControlHighlight() { return currentTheme.getControlHighlight(); }
  639. public static ColorUIResource getControlDisabled() { return currentTheme.getControlDisabled(); }
  640. public static ColorUIResource getPrimaryControl() { return currentTheme.getPrimaryControl(); }
  641. public static ColorUIResource getPrimaryControlShadow() { return currentTheme.getPrimaryControlShadow(); }
  642. public static ColorUIResource getPrimaryControlDarkShadow() { return currentTheme.getPrimaryControlDarkShadow(); }
  643. public static ColorUIResource getPrimaryControlInfo() { return currentTheme.getPrimaryControlInfo(); }
  644. public static ColorUIResource getPrimaryControlHighlight() { return currentTheme.getPrimaryControlHighlight(); }
  645. public static ColorUIResource getSystemTextColor() { return currentTheme.getSystemTextColor(); }
  646. public static ColorUIResource getControlTextColor() { return currentTheme.getControlTextColor(); }
  647. public static ColorUIResource getInactiveControlTextColor() { return currentTheme.getInactiveControlTextColor(); }
  648. public static ColorUIResource getInactiveSystemTextColor() { return currentTheme.getInactiveSystemTextColor(); }
  649. public static ColorUIResource getUserTextColor() { return currentTheme.getUserTextColor(); }
  650. public static ColorUIResource getTextHighlightColor() { return currentTheme.getTextHighlightColor(); }
  651. public static ColorUIResource getHighlightedTextColor() { return currentTheme.getHighlightedTextColor(); }
  652. public static ColorUIResource getWindowBackground() { return currentTheme.getWindowBackground(); }
  653. public static ColorUIResource getWindowTitleBackground() { return currentTheme.getWindowTitleBackground(); }
  654. public static ColorUIResource getWindowTitleForeground() { return currentTheme.getWindowTitleForeground(); }
  655. public static ColorUIResource getWindowTitleInactiveBackground() { return currentTheme.getWindowTitleInactiveBackground(); }
  656. public static ColorUIResource getWindowTitleInactiveForeground() { return currentTheme.getWindowTitleInactiveForeground(); }
  657. public static ColorUIResource getMenuBackground() { return currentTheme.getMenuBackground(); }
  658. public static ColorUIResource getMenuForeground() { return currentTheme.getMenuForeground(); }
  659. public static ColorUIResource getMenuSelectedBackground() { return currentTheme.getMenuSelectedBackground(); }
  660. public static ColorUIResource getMenuSelectedForeground() { return currentTheme.getMenuSelectedForeground(); }
  661. public static ColorUIResource getMenuDisabledForeground() { return currentTheme.getMenuDisabledForeground(); }
  662. public static ColorUIResource getSeparatorBackground() { return currentTheme.getSeparatorBackground(); }
  663. public static ColorUIResource getSeparatorForeground() { return currentTheme.getSeparatorForeground(); }
  664. public static ColorUIResource getAcceleratorForeground() { return currentTheme.getAcceleratorForeground(); }
  665. public static ColorUIResource getAcceleratorSelectedForeground() { return currentTheme.getAcceleratorSelectedForeground(); }
  666. }