1. /*
  2. * @(#)OceanTheme.java 1.13 04/03/17
  3. *
  4. * Copyright 2004 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 java.net.URL;
  10. import java.util.*;
  11. import javax.swing.*;
  12. import javax.swing.plaf.*;
  13. /**
  14. * This class provides an updated look for applications using
  15. * <code>MetalLookAndFeel<code>. The designers of the Metal
  16. * Look and Feel strive to keep the default look up to date,
  17. * possibly through the use of new themes in the future.
  18. * Therefore, developers should only use this class directly
  19. * when they wish to customize the "Ocean" look, or force
  20. * it to be the current theme, regardless of future updates.
  21. *
  22. * @version 1.13 03/17/04
  23. * @since 1.5
  24. * @see MetalLookAndFeel#setCurrentTheme
  25. */
  26. public class OceanTheme extends DefaultMetalTheme {
  27. private static final ColorUIResource PRIMARY1 =
  28. new ColorUIResource(0x6382BF);
  29. private static final ColorUIResource PRIMARY2 =
  30. new ColorUIResource(0xA3B8CC);
  31. private static final ColorUIResource PRIMARY3 =
  32. new ColorUIResource(0xB8CFE5);
  33. private static final ColorUIResource SECONDARY1 =
  34. new ColorUIResource(0x7A8A99);
  35. private static final ColorUIResource SECONDARY2 =
  36. new ColorUIResource(0xB8CFE5);
  37. private static final ColorUIResource SECONDARY3 =
  38. new ColorUIResource(0xEEEEEE);
  39. private static final ColorUIResource CONTROL_TEXT_COLOR =
  40. new ColorUIResource(0x333333);
  41. private static final ColorUIResource INACTIVE_CONTROL_TEXT_COLOR =
  42. new ColorUIResource(0x999999);
  43. private static final ColorUIResource MENU_DISABLED_FOREGROUND =
  44. new ColorUIResource(0x999999);
  45. private static final ColorUIResource OCEAN_BLACK =
  46. new ColorUIResource(0x333333);
  47. // ComponentOrientation Icon
  48. // Delegates to different icons based on component orientation
  49. private static class COIcon extends IconUIResource {
  50. private Icon rtl;
  51. public COIcon(Icon ltr, Icon rtl) {
  52. super(ltr);
  53. this.rtl = rtl;
  54. }
  55. public void paintIcon(Component c, Graphics g, int x, int y) {
  56. if (MetalUtils.isLeftToRight(c)) {
  57. super.paintIcon(c, g, x, y);
  58. } else {
  59. rtl.paintIcon(c, g, x, y);
  60. }
  61. }
  62. }
  63. // InternalFrame Icon
  64. // Delegates to different icons based on button state
  65. private static class IFIcon extends IconUIResource {
  66. private Icon pressed;
  67. public IFIcon(Icon normal, Icon pressed) {
  68. super(normal);
  69. this.pressed = pressed;
  70. }
  71. public void paintIcon(Component c, Graphics g, int x, int y) {
  72. ButtonModel model = ((AbstractButton)c).getModel();
  73. if (model.isPressed() && model.isArmed()) {
  74. pressed.paintIcon(c, g, x, y);
  75. } else {
  76. super.paintIcon(c, g, x, y);
  77. }
  78. }
  79. }
  80. /**
  81. * Construct an instance of <code>OceanTheme</code>
  82. */
  83. public OceanTheme() {
  84. }
  85. /**
  86. * Add this theme's custom entries to the defaults table.
  87. *
  88. * @param table the defaults table, non-null
  89. * @throws NullPointerException if the parameter is null
  90. */
  91. public void addCustomEntriesToTable(UIDefaults table) {
  92. Object focusBorder = new UIDefaults.ProxyLazyValue(
  93. "javax.swing.plaf.BorderUIResource$LineBorderUIResource",
  94. new Object[] {getPrimary1()});
  95. // .30 0 DDE8F3 white secondary2
  96. java.util.List buttonGradient = Arrays.asList(
  97. new Object[] {new Float(.3f), new Float(0f),
  98. new ColorUIResource(0xDDE8F3), getWhite(), getSecondary2() });
  99. // Other possible properties that aren't defined:
  100. //
  101. // Used when generating the disabled Icons, provides the region to
  102. // constrain grays to.
  103. // Button.disabledGrayRange -> Object[] of Integers giving min/max
  104. // InternalFrame.inactiveTitleGradient -> Gradient when the
  105. // internal frame is inactive.
  106. Color cccccc = new ColorUIResource(0xCCCCCC);
  107. Color dadada = new ColorUIResource(0xDADADA);
  108. Color c8ddf2 = new ColorUIResource(0xC8DDF2);
  109. Object directoryIcon = getIconResource("icons/ocean/directory.gif");
  110. Object fileIcon = getIconResource("icons/ocean/file.gif");
  111. java.util.List sliderGradient = Arrays.asList(new Object[] {
  112. new Float(.3f), new Float(.2f),
  113. c8ddf2, getWhite(), new ColorUIResource(SECONDARY2) });
  114. Object[] defaults = new Object[] {
  115. "Button.gradient", buttonGradient,
  116. "Button.rollover", Boolean.TRUE,
  117. "Button.toolBarBorderBackground", INACTIVE_CONTROL_TEXT_COLOR,
  118. "Button.disabledToolBarBorderBackground", cccccc,
  119. "Button.rolloverIconType", "ocean",
  120. "CheckBox.rollover", Boolean.TRUE,
  121. "CheckBox.gradient", buttonGradient,
  122. "CheckBoxMenuItem.gradient", buttonGradient,
  123. // home2
  124. "FileChooser.homeFolderIcon",
  125. getIconResource("icons/ocean/homeFolder.gif"),
  126. // directory2
  127. "FileChooser.newFolderIcon",
  128. getIconResource("icons/ocean/newFolder.gif"),
  129. // updir2
  130. "FileChooser.upFolderIcon",
  131. getIconResource("icons/ocean/upFolder.gif"),
  132. // computer2
  133. "FileView.computerIcon",
  134. getIconResource("icons/ocean/computer.gif"),
  135. "FileView.directoryIcon", directoryIcon,
  136. // disk2
  137. "FileView.hardDriveIcon",
  138. getIconResource("icons/ocean/hardDrive.gif"),
  139. "FileView.fileIcon", fileIcon,
  140. // floppy2
  141. "FileView.floppyDriveIcon",
  142. getIconResource("icons/ocean/floppy.gif"),
  143. "Label.disabledForeground", getInactiveControlTextColor(),
  144. "Menu.opaque", Boolean.FALSE,
  145. "MenuBar.gradient", Arrays.asList(new Object[] {
  146. new Float(1f), new Float(0f),
  147. getWhite(), dadada,
  148. new ColorUIResource(dadada) }),
  149. "MenuBar.borderColor", cccccc,
  150. "InternalFrame.activeTitleGradient", buttonGradient,
  151. // close2
  152. "InternalFrame.closeIcon",
  153. new UIDefaults.LazyValue() {
  154. public Object createValue(UIDefaults table) {
  155. return new IFIcon(getHastenedIcon("icons/ocean/close.gif", table),
  156. getHastenedIcon("icons/ocean/close-pressed.gif", table));
  157. }
  158. },
  159. // minimize
  160. "InternalFrame.iconifyIcon",
  161. new UIDefaults.LazyValue() {
  162. public Object createValue(UIDefaults table) {
  163. return new IFIcon(getHastenedIcon("icons/ocean/iconify.gif", table),
  164. getHastenedIcon("icons/ocean/iconify-pressed.gif", table));
  165. }
  166. },
  167. // restore
  168. "InternalFrame.minimizeIcon",
  169. new UIDefaults.LazyValue() {
  170. public Object createValue(UIDefaults table) {
  171. return new IFIcon(getHastenedIcon("icons/ocean/minimize.gif", table),
  172. getHastenedIcon("icons/ocean/minimize-pressed.gif", table));
  173. }
  174. },
  175. // menubutton3
  176. "InternalFrame.menuIcon",
  177. getIconResource("icons/ocean/menu.gif"),
  178. // maximize2
  179. "InternalFrame.maximizeIcon",
  180. new UIDefaults.LazyValue() {
  181. public Object createValue(UIDefaults table) {
  182. return new IFIcon(getHastenedIcon("icons/ocean/maximize.gif", table),
  183. getHastenedIcon("icons/ocean/maximize-pressed.gif", table));
  184. }
  185. },
  186. // paletteclose
  187. "InternalFrame.paletteCloseIcon",
  188. new UIDefaults.LazyValue() {
  189. public Object createValue(UIDefaults table) {
  190. return new IFIcon(getHastenedIcon("icons/ocean/paletteClose.gif", table),
  191. getHastenedIcon("icons/ocean/paletteClose-pressed.gif", table));
  192. }
  193. },
  194. "List.focusCellHighlightBorder", focusBorder,
  195. "MenuBarUI", "javax.swing.plaf.metal.MetalMenuBarUI",
  196. "OptionPane.errorIcon",
  197. getIconResource("icons/ocean/error.png"),
  198. "OptionPane.informationIcon",
  199. getIconResource("icons/ocean/info.png"),
  200. "OptionPane.questionIcon",
  201. getIconResource("icons/ocean/question.png"),
  202. "OptionPane.warningIcon",
  203. getIconResource("icons/ocean/warning.png"),
  204. "RadioButton.gradient", buttonGradient,
  205. "RadioButton.rollover", Boolean.TRUE,
  206. "RadioButtonMenuItem.gradient", buttonGradient,
  207. "ScrollBar.gradient", buttonGradient,
  208. "Slider.altTrackColor", new ColorUIResource(0xD2E2EF),
  209. "Slider.gradient", sliderGradient,
  210. "Slider.focusGradient", sliderGradient,
  211. "SplitPane.oneTouchButtonsOpaque", Boolean.FALSE,
  212. "SplitPane.dividerFocusColor", c8ddf2,
  213. "TabbedPane.borderHightlightColor", getPrimary1(),
  214. "TabbedPane.contentAreaColor", c8ddf2,
  215. "TabbedPane.contentBorderInsets", new Insets(4, 2, 3, 3),
  216. "TabbedPane.selected", c8ddf2,
  217. "TabbedPane.tabAreaBackground", dadada,
  218. "TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6),
  219. "TabbedPane.unselectedBackground", SECONDARY3,
  220. "Table.focusCellHighlightBorder", focusBorder,
  221. "Table.gridColor", SECONDARY1,
  222. "ToggleButton.gradient", buttonGradient,
  223. "ToolBar.borderColor", cccccc,
  224. "ToolBar.isRollover", Boolean.TRUE,
  225. "Tree.closedIcon", directoryIcon,
  226. "Tree.collapsedIcon",
  227. new UIDefaults.LazyValue() {
  228. public Object createValue(UIDefaults table) {
  229. return new COIcon(getHastenedIcon("icons/ocean/collapsed.gif", table),
  230. getHastenedIcon("icons/ocean/collapsed-rtl.gif", table));
  231. }
  232. },
  233. "Tree.expandedIcon",
  234. getIconResource("icons/ocean/expanded.gif"),
  235. "Tree.leafIcon", fileIcon,
  236. "Tree.openIcon", directoryIcon,
  237. "Tree.selectionBorderColor", getPrimary1()
  238. };
  239. table.putDefaults(defaults);
  240. }
  241. /**
  242. * Overriden to enable picking up the system fonts, if applicable.
  243. */
  244. boolean isSystemTheme() {
  245. return true;
  246. }
  247. /**
  248. * Return the name of this theme, "Ocean".
  249. *
  250. * @return "Ocean"
  251. */
  252. public String getName() {
  253. return "Ocean";
  254. }
  255. /**
  256. * Return the color that the Metal Look and Feel should use
  257. * as "Primary 1". The Look and Feel will use this color
  258. * in painting as it sees fit.
  259. *
  260. * @return the "Primary 1" color.
  261. */
  262. protected ColorUIResource getPrimary1() {
  263. return PRIMARY1;
  264. }
  265. /**
  266. * Return the color that the Metal Look and Feel should use
  267. * as "Primary 2". The Look and Feel will use this color
  268. * in painting as it sees fit.
  269. *
  270. * @return the "Primary 2" color.
  271. */
  272. protected ColorUIResource getPrimary2() {
  273. return PRIMARY2;
  274. }
  275. /**
  276. * Return the color that the Metal Look and Feel should use
  277. * as "Primary 3". The Look and Feel will use this color
  278. * in painting as it sees fit.
  279. *
  280. * @return the "Primary 3" color.
  281. */
  282. protected ColorUIResource getPrimary3() {
  283. return PRIMARY3;
  284. }
  285. /**
  286. * Return the color that the Metal Look and Feel should use
  287. * as "Secondary 1". The Look and Feel will use this color
  288. * in painting as it sees fit.
  289. *
  290. * @return the "Secondary 1" color.
  291. */
  292. protected ColorUIResource getSecondary1() {
  293. return SECONDARY1;
  294. }
  295. /**
  296. * Return the color that the Metal Look and Feel should use
  297. * as "Secondary 2". The Look and Feel will use this color
  298. * in painting as it sees fit.
  299. *
  300. * @return the "Secondary 2" color.
  301. */
  302. protected ColorUIResource getSecondary2() {
  303. return SECONDARY2;
  304. }
  305. /**
  306. * Return the color that the Metal Look and Feel should use
  307. * as "Secondary 3". The Look and Feel will use this color
  308. * in painting as it sees fit.
  309. *
  310. * @return the "Secondary 3" color.
  311. */
  312. protected ColorUIResource getSecondary3() {
  313. return SECONDARY3;
  314. }
  315. /**
  316. * Return the color that the Metal Look and Feel should use
  317. * as "Black". The Look and Feel will use this color
  318. * in painting as it sees fit. This color does not necessarily
  319. * synch up with the typical concept of black, nor is
  320. * it necessarily used for all black items.
  321. *
  322. * @return the "Black" color.
  323. */
  324. protected ColorUIResource getBlack() {
  325. return OCEAN_BLACK;
  326. }
  327. /**
  328. * Return the color that the Metal Look and Feel should use
  329. * for the desktop background. The Look and Feel will use this color
  330. * in painting as it sees fit.
  331. *
  332. * @return the "Desktop" color.
  333. */
  334. public ColorUIResource getDesktopColor() {
  335. return MetalTheme.white;
  336. }
  337. /**
  338. * Return the color that the Metal Look and Feel should use as the default
  339. * color for inactive controls. The Look and Feel will use this color
  340. * in painting as it sees fit.
  341. *
  342. * @return the "Inactive Control Text" color.
  343. */
  344. public ColorUIResource getInactiveControlTextColor() {
  345. return INACTIVE_CONTROL_TEXT_COLOR;
  346. }
  347. /**
  348. * Return the color that the Metal Look and Feel should use as the default
  349. * color for controls. The Look and Feel will use this color
  350. * in painting as it sees fit.
  351. *
  352. * @return the "Control Text" color.
  353. */
  354. public ColorUIResource getControlTextColor() {
  355. return CONTROL_TEXT_COLOR;
  356. }
  357. /**
  358. * Return the color that the Metal Look and Feel should use as the
  359. * foreground color for disabled menu items. The Look and Feel will use
  360. * this color in painting as it sees fit.
  361. *
  362. * @return the "Menu Disabled Foreground" color.
  363. */
  364. public ColorUIResource getMenuDisabledForeground() {
  365. return MENU_DISABLED_FOREGROUND;
  366. }
  367. private Object getIconResource(String iconID) {
  368. return LookAndFeel.makeIcon(getClass(), iconID);
  369. }
  370. // makes use of getIconResource() to fetch an icon and then hastens it
  371. // - calls createValue() on it and returns the actual icon
  372. private Icon getHastenedIcon(String iconID, UIDefaults table) {
  373. Object res = getIconResource(iconID);
  374. return (Icon)((UIDefaults.LazyValue)res).createValue(table);
  375. }
  376. }