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