1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.guilayer.swing.extensions;
17
18 import java.awt.Color;
19 import java.awt.Component;
20 import java.awt.Graphics;
21
22 import javax.swing.Icon;
23 import javax.swing.JRadioButton;
24
25
26
27
28
29
30 public class NyxJRadioButton extends JRadioButton {
31
32
33
34
35 private Color realBg;
36
37
38
39 private boolean returnRealBackground;
40
41
42
43
44 public NyxJRadioButton() {
45 super();
46 }
47
48
49
50
51
52 public void setRealBackground(Color color) {
53 this.realBg = color;
54 }
55
56
57
58
59
60 public Color getRealBackground() {
61 return this.realBg;
62 }
63
64
65
66
67
68 public void setIcon(Icon defaultIcon) {
69 super.setIcon(new IconStub(defaultIcon));
70 }
71
72
73
74
75
76 public void setSelectedIcon(Icon selectedIcon) {
77 super.setSelectedIcon(new IconStub(selectedIcon));
78 }
79
80
81
82
83
84
85 public class IconStub implements Icon {
86
87
88
89 private Icon icon;
90
91
92
93
94
95 public IconStub(Icon icon) {
96 this.icon = icon;
97 }
98
99
100
101
102 public int getIconHeight() {
103 if (icon == null) {
104 return 0;
105 }
106 return icon.getIconHeight();
107 }
108
109
110
111
112 public int getIconWidth() {
113 if (icon == null) {
114 return 0;
115 }
116 return icon.getIconWidth();
117 }
118
119
120
121
122
123 public void paintIcon(Component c, Graphics g, int x, int y) {
124 JRadioButton cc = new JRadioButton();
125 cc.setSelected(isSelected());
126 if (NyxJRadioButton.this.getRealBackground() != null) {
127 cc.setBackground(getRealBackground());
128 } else {
129 cc.setBackground(getBackground());
130 }
131 icon.paintIcon(cc, g, x, y);
132 cc = null;
133 }
134 }
135
136
137 }