1. /*
  2. * @(#)WindowsIconFactory.java 1.14 00/02/02
  3. *
  4. * Copyright 1998-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 com.sun.java.swing.plaf.windows;
  11. import javax.swing.*;
  12. import javax.swing.plaf.UIResource;
  13. import java.awt.Graphics;
  14. import java.awt.Color;
  15. import java.awt.Component;
  16. import java.awt.Polygon;
  17. import java.io.Serializable;
  18. /**
  19. * Factory object that can vend Icons appropriate for the Windows L & F.
  20. * <p>
  21. * <strong>Warning:</strong>
  22. * Serialized objects of this class will not be compatible with
  23. * future Swing releases. The current serialization support is appropriate
  24. * for short term storage or RMI between applications running the same
  25. * version of Swing. A future release of Swing will provide support for
  26. * long term persistence.
  27. *
  28. * @version 1.14 02/02/00
  29. * @author David Kloba
  30. * @author Georges Saab
  31. * @author Rich Schiavi
  32. */
  33. public class WindowsIconFactory implements Serializable
  34. {
  35. private static Icon frame_closeIcon;
  36. private static Icon frame_iconifyIcon;
  37. private static Icon frame_maxIcon;
  38. private static Icon frame_minIcon;
  39. private static Icon frame_resizeIcon;
  40. private static Icon checkBoxIcon;
  41. private static Icon radioButtonIcon;
  42. private static Icon checkBoxMenuItemIcon;
  43. private static Icon radioButtonMenuItemIcon;
  44. private static Icon menuItemCheckIcon;
  45. private static Icon menuItemArrowIcon;
  46. private static Icon menuArrowIcon;
  47. public static Icon getMenuItemCheckIcon() {
  48. if (menuItemCheckIcon == null) {
  49. menuItemCheckIcon = new MenuItemCheckIcon();
  50. }
  51. return menuItemCheckIcon;
  52. }
  53. public static Icon getMenuItemArrowIcon() {
  54. if (menuItemArrowIcon == null) {
  55. menuItemArrowIcon = new MenuItemArrowIcon();
  56. }
  57. return menuItemArrowIcon;
  58. }
  59. public static Icon getMenuArrowIcon() {
  60. if (menuArrowIcon == null) {
  61. menuArrowIcon = new MenuArrowIcon();
  62. }
  63. return menuArrowIcon;
  64. }
  65. public static Icon getCheckBoxIcon() {
  66. if (checkBoxIcon == null) {
  67. checkBoxIcon = new CheckBoxIcon();
  68. }
  69. return checkBoxIcon;
  70. }
  71. public static Icon getRadioButtonIcon() {
  72. if (radioButtonIcon == null) {
  73. radioButtonIcon = new RadioButtonIcon();
  74. }
  75. return radioButtonIcon;
  76. }
  77. public static Icon getCheckBoxMenuItemIcon() {
  78. if (checkBoxMenuItemIcon == null) {
  79. checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
  80. }
  81. return checkBoxMenuItemIcon;
  82. }
  83. public static Icon getRadioButtonMenuItemIcon() {
  84. if (radioButtonMenuItemIcon == null) {
  85. radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
  86. }
  87. return radioButtonMenuItemIcon;
  88. }
  89. public static Icon createFrameCloseIcon() {
  90. if(frame_closeIcon == null)
  91. frame_closeIcon = new CloseIcon();
  92. return frame_closeIcon;
  93. }
  94. public static Icon createFrameIconifyIcon() {
  95. if(frame_iconifyIcon == null)
  96. frame_iconifyIcon = new IconifyIcon();
  97. return frame_iconifyIcon;
  98. }
  99. public static Icon createFrameMaximizeIcon() {
  100. if(frame_maxIcon == null)
  101. frame_maxIcon = new MaximizeIcon();
  102. return frame_maxIcon;
  103. }
  104. public static Icon createFrameMinimizeIcon() {
  105. if(frame_minIcon == null)
  106. frame_minIcon = new MinimizeIcon();
  107. return frame_minIcon;
  108. }
  109. public static Icon createFrameResizeIcon() {
  110. if(frame_resizeIcon == null)
  111. frame_resizeIcon = new ResizeIcon();
  112. return frame_resizeIcon;
  113. }
  114. private static class CloseIcon implements Icon, Serializable {
  115. int height = 16;
  116. int width = 14;
  117. public void paintIcon(Component c, Graphics g, int x, int y) {
  118. g.setColor(Color.black);
  119. g.drawLine(4, 3, 10, 9);
  120. g.drawLine(5, 3, 11, 9);
  121. g.drawLine(10, 3, 4, 9);
  122. g.drawLine(11, 3, 5, 9);
  123. }
  124. public int getIconWidth() { return width; }
  125. public int getIconHeight() { return height; }
  126. };
  127. private static class IconifyIcon implements Icon, Serializable {
  128. int height = 16;
  129. int width = 14;
  130. public void paintIcon(Component c, Graphics g, int x, int y) {
  131. g.setColor(Color.black);
  132. g.drawRect(4, height - 7, 6, 1);
  133. }
  134. public int getIconWidth() { return width; }
  135. public int getIconHeight() { return height; }
  136. };
  137. private static class MaximizeIcon implements Icon, Serializable {
  138. int height = 16;
  139. int width = 14;
  140. public void paintIcon(Component c, Graphics g, int x, int y) {
  141. g.setColor(Color.black);
  142. g.drawRect(3, 2, 8, 8);
  143. g.drawLine(3, 3, 11, 3);
  144. }
  145. public int getIconWidth() { return width; }
  146. public int getIconHeight() { return height; }
  147. };
  148. private static class MinimizeIcon implements Icon, Serializable {
  149. int height = 16;
  150. int width = 14;
  151. public void paintIcon(Component c, Graphics g, int x, int y) {
  152. g.setColor(Color.black);
  153. g.drawRect(5, 2, 5, 5);
  154. g.drawLine(5, 3, 10, 3);
  155. g.drawRect(3, 5, 5, 5);
  156. g.drawLine(3, 6, 7, 6);
  157. g.setColor(UIManager.getColor("InternalFrame.minimizeIconBackground"));
  158. g.fillRect(4, 7, 4, 3);
  159. }
  160. public int getIconWidth() { return width; }
  161. public int getIconHeight() { return height; }
  162. };
  163. private static class ResizeIcon implements Icon, Serializable {
  164. public void paintIcon(Component c, Graphics g, int x, int y) {
  165. g.setColor(UIManager.getColor("InternalFrame.resizeIconHighlight"));
  166. g.drawLine(0, 11, 11, 0);
  167. g.drawLine(4, 11, 11, 4);
  168. g.drawLine(8, 11, 11, 8);
  169. g.setColor(UIManager.getColor("InternalFrame.resizeIconShadow"));
  170. g.drawLine(1, 11, 11, 1);
  171. g.drawLine(2, 11, 11, 2);
  172. g.drawLine(5, 11, 11, 5);
  173. g.drawLine(6, 11, 11, 6);
  174. g.drawLine(9, 11, 11, 9);
  175. g.drawLine(10, 11, 11, 10);
  176. }
  177. public int getIconWidth() { return 13; }
  178. public int getIconHeight() { return 13; }
  179. };
  180. private static class CheckBoxIcon implements Icon, Serializable
  181. {
  182. final static int csize = 13;
  183. public void paintIcon(Component c, Graphics g, int x, int y) {
  184. JCheckBox cb = (JCheckBox) c;
  185. ButtonModel model = cb.getModel();
  186. // outer bevel
  187. if(!cb.isBorderPaintedFlat()) {
  188. g.setColor(UIManager.getColor("CheckBox.background"));
  189. g.fill3DRect(x, y, csize, csize, false);
  190. // inner bevel
  191. g.setColor(UIManager.getColor("CheckBox.shadow"));
  192. g.fill3DRect(x+1, y+1, csize-2, csize-2, false);
  193. // inside box
  194. if((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
  195. g.setColor(UIManager.getColor("CheckBox.background"));
  196. } else {
  197. g.setColor(UIManager.getColor("CheckBox.highlight"));
  198. }
  199. g.fillRect(x+2, y+2, csize-4, csize-4);
  200. } else {
  201. g.setColor(UIManager.getColor("CheckBox.shadow"));
  202. g.drawRect(x+1, y+1, csize-3, csize-3);
  203. if((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
  204. g.setColor(UIManager.getColor("CheckBox.background"));
  205. } else {
  206. g.setColor(UIManager.getColor("CheckBox.highlight"));
  207. }
  208. g.fillRect(x+2, y+2, csize-4, csize-4);
  209. }
  210. if(model.isEnabled()) {
  211. g.setColor(UIManager.getColor("CheckBox.darkShadow"));
  212. } else {
  213. g.setColor(UIManager.getColor("CheckBox.shadow"));
  214. }
  215. // paint check
  216. if (model.isSelected()) {
  217. g.drawLine(x+9, y+3, x+9, y+3);
  218. g.drawLine(x+8, y+4, x+9, y+4);
  219. g.drawLine(x+7, y+5, x+9, y+5);
  220. g.drawLine(x+6, y+6, x+8, y+6);
  221. g.drawLine(x+3, y+7, x+7, y+7);
  222. g.drawLine(x+4, y+8, x+6, y+8);
  223. g.drawLine(x+5, y+9, x+5, y+9);
  224. g.drawLine(x+3, y+5, x+3, y+5);
  225. g.drawLine(x+3, y+6, x+4, y+6);
  226. }
  227. }
  228. public int getIconWidth() {
  229. return csize;
  230. }
  231. public int getIconHeight() {
  232. return csize;
  233. }
  234. }
  235. private static class RadioButtonIcon implements Icon, UIResource, Serializable
  236. {
  237. public void paintIcon(Component c, Graphics g, int x, int y) {
  238. AbstractButton b = (AbstractButton) c;
  239. ButtonModel model = b.getModel();
  240. // fill interior
  241. if((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
  242. g.setColor(UIManager.getColor("RadioButton.background"));
  243. } else {
  244. g.setColor(UIManager.getColor("RadioButton.highlight"));
  245. }
  246. g.fillRect(x+2, y+2, 8, 8);
  247. // outter left arc
  248. g.setColor(UIManager.getColor("RadioButton.shadow"));
  249. g.drawLine(x+4, y+0, x+7, y+0);
  250. g.drawLine(x+2, y+1, x+3, y+1);
  251. g.drawLine(x+8, y+1, x+9, y+1);
  252. g.drawLine(x+1, y+2, x+1, y+3);
  253. g.drawLine(x+0, y+4, x+0, y+7);
  254. g.drawLine(x+1, y+8, x+1, y+9);
  255. // outter right arc
  256. g.setColor(UIManager.getColor("RadioButton.highlight"));
  257. g.drawLine(x+2, y+10, x+3, y+10);
  258. g.drawLine(x+4, y+11, x+7, y+11);
  259. g.drawLine(x+8, y+10, x+9, y+10);
  260. g.drawLine(x+10, y+9, x+10, y+8);
  261. g.drawLine(x+11, y+7, x+11, y+4);
  262. g.drawLine(x+10, y+3, x+10, y+2);
  263. // inner left arc
  264. g.setColor(UIManager.getColor("RadioButton.darkShadow"));
  265. g.drawLine(x+4, y+1, x+7, y+1);
  266. g.drawLine(x+2, y+2, x+3, y+2);
  267. g.drawLine(x+8, y+2, x+9, y+2);
  268. g.drawLine(x+2, y+3, x+2, y+3);
  269. g.drawLine(x+1, y+4, x+1, y+7);
  270. g.drawLine(x+2, y+8, x+2, y+8);
  271. // inner right arc
  272. g.setColor(UIManager.getColor("RadioButton.background"));
  273. g.drawLine(x+2, y+9, x+3, y+9);
  274. g.drawLine(x+4, y+10, x+7, y+10);
  275. g.drawLine(x+8, y+9, x+9, y+9);
  276. g.drawLine(x+9, y+8, x+9, y+8);
  277. g.drawLine(x+10, y+7, x+10, y+4);
  278. g.drawLine(x+9, y+3, x+9, y+3);
  279. // indicate whether selected or not
  280. if(model.isSelected()) {
  281. g.setColor(UIManager.getColor("RadioButton.darkShadow"));
  282. g.fillRect(x+4, y+5, 4, 2);
  283. g.fillRect(x+5, y+4, 2, 4);
  284. }
  285. }
  286. public int getIconWidth() {
  287. return 13;
  288. }
  289. public int getIconHeight() {
  290. return 13;
  291. }
  292. } // end class RadioButtonIcon
  293. private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable
  294. {
  295. public void paintIcon(Component c, Graphics g, int x, int y) {
  296. AbstractButton b = (AbstractButton) c;
  297. ButtonModel model = b.getModel();
  298. boolean isSelected = model.isSelected();
  299. if (isSelected) {
  300. y = y - getIconHeight() / 2;
  301. g.drawLine(x+9, y+3, x+9, y+3);
  302. g.drawLine(x+8, y+4, x+9, y+4);
  303. g.drawLine(x+7, y+5, x+9, y+5);
  304. g.drawLine(x+6, y+6, x+8, y+6);
  305. g.drawLine(x+3, y+7, x+7, y+7);
  306. g.drawLine(x+4, y+8, x+6, y+8);
  307. g.drawLine(x+5, y+9, x+5, y+9);
  308. g.drawLine(x+3, y+5, x+3, y+5);
  309. g.drawLine(x+3, y+6, x+4, y+6);
  310. }
  311. }
  312. public int getIconWidth() { return 9; }
  313. public int getIconHeight() { return 9; }
  314. } // End class CheckBoxMenuItemIcon
  315. private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable
  316. {
  317. public void paintIcon(Component c, Graphics g, int x, int y) {
  318. AbstractButton b = (AbstractButton) c;
  319. ButtonModel model = b.getModel();
  320. if (b.isSelected() == true) {
  321. g.fillArc(0,0,getIconWidth()-2, getIconHeight()-2, 0, 360);
  322. }
  323. }
  324. public int getIconWidth() { return 12; }
  325. public int getIconHeight() { return 12; }
  326. } // End class RadioButtonMenuItemIcon
  327. private static class MenuItemCheckIcon implements Icon, UIResource, Serializable{
  328. public void paintIcon(Component c, Graphics g, int x, int y) {
  329. /* For debugging:
  330. Color oldColor = g.getColor();
  331. g.setColor(Color.orange);
  332. g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true);
  333. g.setColor(oldColor);
  334. */
  335. }
  336. public int getIconWidth() { return 9; }
  337. public int getIconHeight() { return 9; }
  338. } // End class MenuItemCheckIcon
  339. private static class MenuItemArrowIcon implements Icon, UIResource, Serializable {
  340. public void paintIcon(Component c, Graphics g, int x, int y) {
  341. /* For debugging:
  342. Color oldColor = g.getColor();
  343. g.setColor(Color.green);
  344. g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true);
  345. g.setColor(oldColor);
  346. */
  347. }
  348. public int getIconWidth() { return 4; }
  349. public int getIconHeight() { return 8; }
  350. } // End class MenuItemArrowIcon
  351. private static class MenuArrowIcon implements Icon, UIResource, Serializable {
  352. public void paintIcon(Component c, Graphics g, int x, int y) {
  353. g.translate(x,y);
  354. if( WindowsUtils.isLeftToRight(c) ) {
  355. g.drawLine( 0, 0, 0, 7 );
  356. g.drawLine( 1, 1, 1, 6 );
  357. g.drawLine( 2, 2, 2, 5 );
  358. g.drawLine( 3, 3, 3, 4 );
  359. } else {
  360. g.drawLine( 4, 0, 4, 7 );
  361. g.drawLine( 3, 1, 3, 6 );
  362. g.drawLine( 2, 2, 2, 5 );
  363. g.drawLine( 1, 3, 1, 4 );
  364. }
  365. g.translate(-x,-y);
  366. }
  367. public int getIconWidth() { return 4; }
  368. public int getIconHeight() { return 8; }
  369. } // End class MenuArrowIcon
  370. }