1. /*
  2. * @(#)MetalCheckBoxIcon.java 1.10 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.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 appropriate
  19. * for short term storage or RMI between applications running the same
  20. * version of Swing. A future release of Swing will provide support for
  21. * long term persistence.
  22. *
  23. * @version 1.10 11/29/01
  24. * @author Steve Wilson
  25. */
  26. public class MetalCheckBoxIcon implements Icon, UIResource, Serializable {
  27. protected int getControlSize() { return 13; }
  28. public void paintIcon(Component c, Graphics g, int x, int y) {
  29. JCheckBox cb = (JCheckBox)c;
  30. ButtonModel model = cb.getModel();
  31. int controlSize = getControlSize();
  32. boolean drawCheck = model.isSelected();
  33. if ( model.isEnabled() ) {
  34. if (model.isPressed() && model.isArmed()) {
  35. g.setColor( MetalLookAndFeel.getControlShadow() );
  36. g.fillRect( x, y, controlSize-1, controlSize-1);
  37. MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize);
  38. } else {
  39. MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize);
  40. }
  41. g.setColor( MetalLookAndFeel.getControlInfo() );
  42. } else {
  43. g.setColor( MetalLookAndFeel.getControlShadow() );
  44. g.drawRect( x, y, controlSize-1, controlSize-1);
  45. }
  46. if (model.isSelected()) {
  47. drawCheck(c,g,x,y);
  48. }
  49. }
  50. protected void drawCheck(Component c, Graphics g, int x, int y) {
  51. int controlSize = getControlSize();
  52. g.fillRect( x+3, y+5, 2, controlSize-8 );
  53. g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) );
  54. g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) );
  55. }
  56. public int getIconWidth() {
  57. return getControlSize();
  58. }
  59. public int getIconHeight() {
  60. return getControlSize();
  61. }
  62. }