1. /*
  2. * @(#)BasicIconFactory.java 1.22 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.basic;
  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 basic 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.22 11/29/01
  26. * @author David Kloba
  27. * @author Georges Saab
  28. */
  29. public class BasicIconFactory implements Serializable
  30. {
  31. private static Icon frame_icon;
  32. private static Icon checkBoxIcon;
  33. private static Icon radioButtonIcon;
  34. private static Icon checkBoxMenuItemIcon;
  35. private static Icon radioButtonMenuItemIcon;
  36. private static Icon menuItemCheckIcon;
  37. private static Icon menuItemArrowIcon;
  38. private static Icon menuArrowIcon;
  39. public static Icon getMenuItemCheckIcon() {
  40. if (menuItemCheckIcon == null) {
  41. menuItemCheckIcon = new MenuItemCheckIcon();
  42. }
  43. return menuItemCheckIcon;
  44. }
  45. public static Icon getMenuItemArrowIcon() {
  46. if (menuItemArrowIcon == null) {
  47. menuItemArrowIcon = new MenuItemArrowIcon();
  48. }
  49. return menuItemArrowIcon;
  50. }
  51. public static Icon getMenuArrowIcon() {
  52. if (menuArrowIcon == null) {
  53. menuArrowIcon = new MenuArrowIcon();
  54. }
  55. return menuArrowIcon;
  56. }
  57. public static Icon getCheckBoxIcon() {
  58. if (checkBoxIcon == null) {
  59. checkBoxIcon = new CheckBoxIcon();
  60. }
  61. return checkBoxIcon;
  62. }
  63. public static Icon getRadioButtonIcon() {
  64. if (radioButtonIcon == null) {
  65. radioButtonIcon = new RadioButtonIcon();
  66. }
  67. return radioButtonIcon;
  68. }
  69. public static Icon getCheckBoxMenuItemIcon() {
  70. if (checkBoxMenuItemIcon == null) {
  71. checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
  72. }
  73. return checkBoxMenuItemIcon;
  74. }
  75. public static Icon getRadioButtonMenuItemIcon() {
  76. if (radioButtonMenuItemIcon == null) {
  77. radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
  78. }
  79. return radioButtonMenuItemIcon;
  80. }
  81. public static Icon createEmptyFrameIcon() {
  82. if(frame_icon == null)
  83. frame_icon = new EmptyFrameIcon();
  84. return frame_icon;
  85. }
  86. private static class EmptyFrameIcon implements Icon, Serializable {
  87. int height = 16;
  88. int width = 14;
  89. public void paintIcon(Component c, Graphics g, int x, int y) {
  90. }
  91. public int getIconWidth() { return width; }
  92. public int getIconHeight() { return height; }
  93. };
  94. private static class CheckBoxIcon implements Icon, Serializable
  95. {
  96. final static int csize = 13;
  97. public void paintIcon(Component c, Graphics g, int x, int y) {
  98. }
  99. public int getIconWidth() {
  100. return csize;
  101. }
  102. public int getIconHeight() {
  103. return csize;
  104. }
  105. }
  106. private static class RadioButtonIcon implements Icon, UIResource, Serializable
  107. {
  108. public void paintIcon(Component c, Graphics g, int x, int y) {
  109. }
  110. public int getIconWidth() {
  111. return 13;
  112. }
  113. public int getIconHeight() {
  114. return 13;
  115. }
  116. } // end class RadioButtonIcon
  117. private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable
  118. {
  119. public void paintIcon(Component c, Graphics g, int x, int y) {
  120. AbstractButton b = (AbstractButton) c;
  121. ButtonModel model = b.getModel();
  122. boolean isSelected = model.isSelected();
  123. if (isSelected) {
  124. g.drawLine(x+7, y+1, x+7, y+3);
  125. g.drawLine(x+6, y+2, x+6, y+4);
  126. g.drawLine(x+5, y+3, x+5, y+5);
  127. g.drawLine(x+4, y+4, x+4, y+6);
  128. g.drawLine(x+3, y+5, x+3, y+7);
  129. g.drawLine(x+2, y+4, x+2, y+6);
  130. g.drawLine(x+1, y+3, x+1, y+5);
  131. }
  132. }
  133. public int getIconWidth() { return 9; }
  134. public int getIconHeight() { return 9; }
  135. } // End class CheckBoxMenuItemIcon
  136. private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable
  137. {
  138. public void paintIcon(Component c, Graphics g, int x, int y) {
  139. AbstractButton b = (AbstractButton) c;
  140. ButtonModel model = b.getModel();
  141. if (b.isSelected() == true) {
  142. g.fillArc(x+1,y+1,getIconWidth()-2, getIconHeight()-2, 0, 360);
  143. }
  144. }
  145. public int getIconWidth() { return 9; } // was 12
  146. public int getIconHeight() { return 9; }
  147. } // End class RadioButtonMenuItemIcon
  148. private static class MenuItemCheckIcon implements Icon, UIResource, Serializable{
  149. public void paintIcon(Component c, Graphics g, int x, int y) {
  150. }
  151. public int getIconWidth() { return 9; }
  152. public int getIconHeight() { return 9; }
  153. } // End class MenuItemCheckIcon
  154. private static class MenuItemArrowIcon implements Icon, UIResource, Serializable {
  155. public void paintIcon(Component c, Graphics g, int x, int y) {
  156. }
  157. public int getIconWidth() { return 4; }
  158. public int getIconHeight() { return 8; }
  159. } // End class MenuItemArrowIcon
  160. private static class MenuArrowIcon implements Icon, UIResource, Serializable {
  161. public void paintIcon(Component c, Graphics g, int x, int y) {
  162. Polygon p = new Polygon();
  163. p.addPoint(x, y);
  164. p.addPoint(x+getIconWidth(), y+getIconHeight()/2);
  165. p.addPoint(x, y+getIconHeight());
  166. g.fillPolygon(p);
  167. }
  168. public int getIconWidth() { return 4; }
  169. public int getIconHeight() { return 8; }
  170. } // End class MenuArrowIcon
  171. }