KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > java > swing > plaf > windows > WindowsRadioButtonUI


1 /*
2  * @(#)WindowsRadioButtonUI.java 1.24 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 com.sun.java.swing.plaf.windows;
9
10 import javax.swing.plaf.basic.*;
11 import javax.swing.*;
12 import javax.swing.plaf.*;
13
14 import java.awt.*;
15
16
17 /**
18  * Windows rendition of the component.
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 appropriate
23  * for short term storage or RMI between applications running the same
24  * version of Swing. A future release of Swing will provide support for
25  * long term persistence.
26  */

27 public class WindowsRadioButtonUI extends BasicRadioButtonUI
28 {
29     private static final WindowsRadioButtonUI windowsRadioButtonUI = new WindowsRadioButtonUI();
30
31     protected int dashedRectGapX;
32     protected int dashedRectGapY;
33     protected int dashedRectGapWidth;
34     protected int dashedRectGapHeight;
35
36     protected Color focusColor;
37
38     private boolean initialized = false;
39     
40     // ********************************
41
// Create PLAF
42
// ********************************
43
public static ComponentUI createUI(JComponent c) {
44     return windowsRadioButtonUI;
45     }
46
47     // ********************************
48
// Defaults
49
// ********************************
50
public void installDefaults(AbstractButton b) {
51     super.installDefaults(b);
52     if(!initialized) {
53         dashedRectGapX = ((Integer JavaDoc)UIManager.get("Button.dashedRectGapX")).intValue();
54         dashedRectGapY = ((Integer JavaDoc)UIManager.get("Button.dashedRectGapY")).intValue();
55         dashedRectGapWidth = ((Integer JavaDoc)UIManager.get("Button.dashedRectGapWidth")).intValue();
56         dashedRectGapHeight = ((Integer JavaDoc)UIManager.get("Button.dashedRectGapHeight")).intValue();
57         focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
58         initialized = true;
59     }
60     if (XPStyle.getXP() != null) {
61         LookAndFeel.installProperty(b, "rolloverEnabled", Boolean.TRUE);
62     }
63     }
64
65     protected Color getFocusColor() {
66     return focusColor;
67     }
68     
69     // ********************************
70
// Paint Methods
71
// ********************************
72

73     /**
74      * Overridden method to render the text without the mnemonic
75      */

76     protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String JavaDoc text) {
77     WindowsGraphicsUtils.paintText(g, b, textRect, text, getTextShiftOffset());
78     }
79
80
81     protected void paintFocus(Graphics g, Rectangle textRect, Dimension d){
82     g.setColor(getFocusColor());
83     BasicGraphicsUtils.drawDashedRect(g, textRect.x, textRect.y, textRect.width, textRect.height);
84     }
85
86     // ********************************
87
// Layout Methods
88
// ********************************
89
public Dimension getPreferredSize(JComponent c) {
90     Dimension d = super.getPreferredSize(c);
91
92     /* Ensure that the width and height of the button is odd,
93      * to allow for the focus line if focus is painted
94      */

95         AbstractButton b = (AbstractButton)c;
96     if (d != null && b.isFocusPainted()) {
97         if(d.width % 2 == 0) { d.width += 1; }
98         if(d.height % 2 == 0) { d.height += 1; }
99     }
100     return d;
101     }
102
103 }
104
105
Popular Tags