01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Alexander T. Simbirtsev
19: * @version $Revision$
20: * Created on 25.04.2005
21:
22: */package javax.swing.plaf.basic;
23:
24: import java.awt.Dimension;
25: import java.awt.Graphics;
26: import java.awt.Rectangle;
27:
28: import javax.swing.AbstractButton;
29: import javax.swing.Icon;
30: import javax.swing.JComponent;
31: import javax.swing.LookAndFeel;
32: import javax.swing.UIManager;
33: import javax.swing.plaf.ComponentUI;
34:
35: import org.apache.harmony.x.swing.ButtonCommons;
36: import org.apache.harmony.x.swing.Utilities;
37:
38: public class BasicRadioButtonUI extends BasicToggleButtonUI {
39:
40: protected Icon icon;
41:
42: private static final String PROPERTY_PREFIX = "RadioButton.";
43: private static BasicRadioButtonUI basicRadioButtonUI;
44:
45: public static ComponentUI createUI(final JComponent b) {
46: if (basicRadioButtonUI == null) {
47: basicRadioButtonUI = new BasicRadioButtonUI();
48: }
49: return basicRadioButtonUI;
50: }
51:
52: protected String getPropertyPrefix() {
53: return PROPERTY_PREFIX;
54: }
55:
56: protected void installDefaults(final AbstractButton b) {
57: super .installDefaults(b);
58:
59: if (Utilities.isUIResource(icon)) {
60: icon = UIManager.getIcon(getPropertyPrefix() + "icon");
61: }
62: }
63:
64: protected void uninstallDefaults(final AbstractButton b) {
65: LookAndFeel.uninstallBorder(b);
66: }
67:
68: public Icon getDefaultIcon() {
69: return icon;
70: }
71:
72: protected void paintFocus(final Graphics g,
73: final Rectangle textRect, final Dimension size) {
74: }
75:
76: public Dimension getPreferredSize(final JComponent c) {
77: if (c instanceof AbstractButton) {
78: return ButtonCommons.getPreferredSize((AbstractButton) c,
79: getDefaultIcon());
80: } else {
81: return null;
82: }
83: }
84:
85: protected void paintIcon(final Graphics g, final JComponent c,
86: final Rectangle iconRect) {
87: AbstractButton button = (AbstractButton) c;
88: Icon icon = ButtonCommons.getCurrentIcon(button);
89:
90: if (icon == null) {
91: icon = getDefaultIcon();
92: }
93: if (icon != null) {
94: icon.paintIcon(button, g, iconRect.x, iconRect.y);
95: }
96: }
97:
98: }
|