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