2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.java.swing.plaf.windows;
|
|
27 |
|
4225
|
28 |
import sun.awt.AppContext;
|
|
29 |
|
2
|
30 |
import javax.swing.plaf.basic.*;
|
|
31 |
import javax.swing.*;
|
|
32 |
import javax.swing.plaf.*;
|
|
33 |
|
|
34 |
import java.awt.*;
|
|
35 |
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Windows rendition of the component.
|
|
39 |
* <p>
|
|
40 |
* <strong>Warning:</strong>
|
|
41 |
* Serialized objects of this class will not be compatible with
|
|
42 |
* future Swing releases. The current serialization support is appropriate
|
|
43 |
* for short term storage or RMI between applications running the same
|
|
44 |
* version of Swing. A future release of Swing will provide support for
|
|
45 |
* long term persistence.
|
|
46 |
*/
|
|
47 |
public class WindowsRadioButtonUI extends BasicRadioButtonUI
|
|
48 |
{
|
4225
|
49 |
private static final Object WINDOWS_RADIO_BUTTON_UI_KEY = new Object();
|
2
|
50 |
|
|
51 |
protected int dashedRectGapX;
|
|
52 |
protected int dashedRectGapY;
|
|
53 |
protected int dashedRectGapWidth;
|
|
54 |
protected int dashedRectGapHeight;
|
|
55 |
|
|
56 |
protected Color focusColor;
|
|
57 |
|
|
58 |
private boolean initialized = false;
|
|
59 |
|
|
60 |
// ********************************
|
|
61 |
// Create PLAF
|
|
62 |
// ********************************
|
|
63 |
public static ComponentUI createUI(JComponent c) {
|
4225
|
64 |
AppContext appContext = AppContext.getAppContext();
|
|
65 |
WindowsRadioButtonUI windowsRadioButtonUI =
|
|
66 |
(WindowsRadioButtonUI) appContext.get(WINDOWS_RADIO_BUTTON_UI_KEY);
|
|
67 |
if (windowsRadioButtonUI == null) {
|
|
68 |
windowsRadioButtonUI = new WindowsRadioButtonUI();
|
|
69 |
appContext.put(WINDOWS_RADIO_BUTTON_UI_KEY, windowsRadioButtonUI);
|
|
70 |
}
|
2
|
71 |
return windowsRadioButtonUI;
|
|
72 |
}
|
|
73 |
|
|
74 |
// ********************************
|
|
75 |
// Defaults
|
|
76 |
// ********************************
|
|
77 |
public void installDefaults(AbstractButton b) {
|
|
78 |
super.installDefaults(b);
|
|
79 |
if(!initialized) {
|
|
80 |
dashedRectGapX = ((Integer)UIManager.get("Button.dashedRectGapX")).intValue();
|
|
81 |
dashedRectGapY = ((Integer)UIManager.get("Button.dashedRectGapY")).intValue();
|
|
82 |
dashedRectGapWidth = ((Integer)UIManager.get("Button.dashedRectGapWidth")).intValue();
|
|
83 |
dashedRectGapHeight = ((Integer)UIManager.get("Button.dashedRectGapHeight")).intValue();
|
|
84 |
focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
|
|
85 |
initialized = true;
|
|
86 |
}
|
|
87 |
if (XPStyle.getXP() != null) {
|
|
88 |
LookAndFeel.installProperty(b, "rolloverEnabled", Boolean.TRUE);
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
protected Color getFocusColor() {
|
|
93 |
return focusColor;
|
|
94 |
}
|
|
95 |
|
|
96 |
// ********************************
|
|
97 |
// Paint Methods
|
|
98 |
// ********************************
|
|
99 |
|
|
100 |
/**
|
|
101 |
* Overridden method to render the text without the mnemonic
|
|
102 |
*/
|
|
103 |
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
|
|
104 |
WindowsGraphicsUtils.paintText(g, b, textRect, text, getTextShiftOffset());
|
|
105 |
}
|
|
106 |
|
|
107 |
|
|
108 |
protected void paintFocus(Graphics g, Rectangle textRect, Dimension d){
|
|
109 |
g.setColor(getFocusColor());
|
|
110 |
BasicGraphicsUtils.drawDashedRect(g, textRect.x, textRect.y, textRect.width, textRect.height);
|
|
111 |
}
|
|
112 |
|
|
113 |
// ********************************
|
|
114 |
// Layout Methods
|
|
115 |
// ********************************
|
|
116 |
public Dimension getPreferredSize(JComponent c) {
|
|
117 |
Dimension d = super.getPreferredSize(c);
|
|
118 |
|
|
119 |
/* Ensure that the width and height of the button is odd,
|
|
120 |
* to allow for the focus line if focus is painted
|
|
121 |
*/
|
|
122 |
AbstractButton b = (AbstractButton)c;
|
|
123 |
if (d != null && b.isFocusPainted()) {
|
|
124 |
if(d.width % 2 == 0) { d.width += 1; }
|
|
125 |
if(d.height % 2 == 0) { d.height += 1; }
|
|
126 |
}
|
|
127 |
return d;
|
|
128 |
}
|
|
129 |
|
|
130 |
}
|