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