1. /*
  2. * @(#)MetalCheckBoxIcon.java 1.17 03/12/19
  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 javax.swing.*;
  9. import java.awt.*;
  10. import java.awt.event.*;
  11. import java.io.*;
  12. import javax.swing.plaf.*;
  13. /**
  14. * CheckboxIcon implementation for OrganicCheckBoxUI
  15. * <p>
  16. * <strong>Warning:</strong>
  17. * Serialized objects of this class will not be compatible with
  18. * future Swing releases. The current serialization support is
  19. * appropriate for short term storage or RMI between applications running
  20. * the same version of Swing. As of 1.4, support for long term storage
  21. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  22. * has been added to the <code>java.beans</code> package.
  23. * Please see {@link java.beans.XMLEncoder}.
  24. *
  25. * @version 1.17 12/19/03
  26. * @author Steve Wilson
  27. */
  28. public class MetalCheckBoxIcon implements Icon, UIResource, Serializable {
  29. protected int getControlSize() { return 13; }
  30. public void paintIcon(Component c, Graphics g, int x, int y) {
  31. JCheckBox cb = (JCheckBox)c;
  32. ButtonModel model = cb.getModel();
  33. int controlSize = getControlSize();
  34. boolean drawCheck = model.isSelected();
  35. if (model.isEnabled()) {
  36. if(cb.isBorderPaintedFlat()) {
  37. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  38. g.drawRect(x+1, y, controlSize-1, controlSize-1);
  39. }
  40. if (model.isPressed() && model.isArmed()) {
  41. if(cb.isBorderPaintedFlat()) {
  42. g.setColor(MetalLookAndFeel.getControlShadow());
  43. g.fillRect(x+2, y+1, controlSize-2, controlSize-2);
  44. } else {
  45. g.setColor(MetalLookAndFeel.getControlShadow());
  46. g.fillRect(x, y, controlSize-1, controlSize-1);
  47. MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize);
  48. }
  49. } else if(!cb.isBorderPaintedFlat()) {
  50. MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize);
  51. }
  52. g.setColor( MetalLookAndFeel.getControlInfo() );
  53. } else {
  54. g.setColor( MetalLookAndFeel.getControlShadow() );
  55. g.drawRect( x, y, controlSize-1, controlSize-1);
  56. }
  57. if(drawCheck) {
  58. if (cb.isBorderPaintedFlat()) {
  59. x++;
  60. }
  61. drawCheck(c,g,x,y);
  62. }
  63. }
  64. protected void drawCheck(Component c, Graphics g, int x, int y) {
  65. int controlSize = getControlSize();
  66. g.fillRect( x+3, y+5, 2, controlSize-8 );
  67. g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) );
  68. g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) );
  69. }
  70. public int getIconWidth() {
  71. return getControlSize();
  72. }
  73. public int getIconHeight() {
  74. return getControlSize();
  75. }
  76. }