KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > metal > MetalCheckBoxIcon


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
8 package javax.swing.plaf.metal;
9
10 import javax.swing.*;
11
12 import java.awt.*;
13 import java.awt.event.*;
14 import java.io.*;
15 import javax.swing.plaf.*;
16
17 /**
18  * CheckboxIcon implementation for OrganicCheckBoxUI
19  * <p>
20  * <strong>Warning:</strong>
21  * Serialized objects of this class will not be compatible with
22  * future Swing releases. The current serialization support is
23  * appropriate for short term storage or RMI between applications running
24  * the same version of Swing. As of 1.4, support for long term storage
25  * of all JavaBeans<sup><font size="-2">TM</font></sup>
26  * has been added to the <code>java.beans</code> package.
27  * Please see {@link java.beans.XMLEncoder}.
28  *
29  * @version 1.17 12/19/03
30  * @author Steve Wilson
31  */

32 public class MetalCheckBoxIcon implements Icon, UIResource, Serializable {
33
34     protected int getControlSize() { return 13; }
35
36     public void paintIcon(Component c, Graphics g, int x, int y) {
37
38         JCheckBox cb = (JCheckBox)c;
39     ButtonModel model = cb.getModel();
40     int controlSize = getControlSize();
41
42         boolean drawCheck = model.isSelected();
43
44     if (model.isEnabled()) {
45         if(cb.isBorderPaintedFlat()) {
46         g.setColor(MetalLookAndFeel.getControlDarkShadow());
47         g.drawRect(x+1, y, controlSize-1, controlSize-1);
48         }
49         if (model.isPressed() && model.isArmed()) {
50         if(cb.isBorderPaintedFlat()) {
51             g.setColor(MetalLookAndFeel.getControlShadow());
52             g.fillRect(x+2, y+1, controlSize-2, controlSize-2);
53         } else {
54             g.setColor(MetalLookAndFeel.getControlShadow());
55             g.fillRect(x, y, controlSize-1, controlSize-1);
56             MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize);
57         }
58         } else if(!cb.isBorderPaintedFlat()) {
59             MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize);
60         }
61         g.setColor( MetalLookAndFeel.getControlInfo() );
62         } else {
63         g.setColor( MetalLookAndFeel.getControlShadow() );
64         g.drawRect( x, y, controlSize-1, controlSize-1);
65     }
66
67     
68     if(drawCheck) {
69         if (cb.isBorderPaintedFlat()) {
70         x++;
71         }
72         drawCheck(c,g,x,y);
73     }
74     }
75
76     protected void drawCheck(Component c, Graphics g, int x, int y) {
77     int controlSize = getControlSize();
78     g.fillRect( x+3, y+5, 2, controlSize-8 );
79     g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) );
80     g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) );
81     }
82
83     public int getIconWidth() {
84         return getControlSize();
85     }
86        
87     public int getIconHeight() {
88         return getControlSize();
89     }
90  }
91
Popular Tags