001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexander T. Simbirtsev
019: * @version $Revision$
020: * Created on 29.04.2005
021:
022: */package javax.swing.plaf.metal;
023:
024: import java.awt.Color;
025: import java.awt.Font;
026: import java.awt.image.BufferedImage;
027: import javax.swing.AbstractButton;
028: import javax.swing.BorderFactory;
029: import javax.swing.Icon;
030: import javax.swing.ImageIcon;
031: import javax.swing.JButton;
032: import javax.swing.JRadioButton;
033: import javax.swing.UIManager;
034: import javax.swing.border.Border;
035: import javax.swing.plaf.BorderUIResource;
036: import javax.swing.plaf.ColorUIResource;
037: import javax.swing.plaf.FontUIResource;
038: import javax.swing.plaf.IconUIResource;
039: import junit.framework.TestCase;
040:
041: public class MetalRadioButtonUITest extends TestCase {
042: PublicMetalRadioButtonUI publicUI;
043:
044: public static void main(final String[] args) {
045: junit.textui.TestRunner.run(MetalRadioButtonUITest.class);
046: }
047:
048: /*
049: * @see TestCase#setUp()
050: */
051: @Override
052: protected void setUp() throws Exception {
053: super .setUp();
054: publicUI = new PublicMetalRadioButtonUI();
055: }
056:
057: public void testCreateUI() {
058: assertTrue("created UI is not null", null != MetalRadioButtonUI
059: .createUI(new JButton()));
060: assertTrue(
061: "created UI is of the proper class",
062: MetalRadioButtonUI.createUI(null) instanceof MetalRadioButtonUI);
063: assertTrue("created UI is not shared", MetalRadioButtonUI
064: .createUI(null) == MetalRadioButtonUI.createUI(null));
065: }
066:
067: class PublicMetalRadioButtonUI extends MetalRadioButtonUI {
068: public void setDisabledTextColor(final Color color) {
069: disabledTextColor = color;
070: }
071:
072: @Override
073: public Color getDisabledTextColor() {
074: return super .getDisabledTextColor();
075: }
076:
077: public void setFocusColor(final Color color) {
078: focusColor = color;
079: }
080:
081: @Override
082: public Color getFocusColor() {
083: return super .getFocusColor();
084: }
085:
086: public void setSelectColor(final Color color) {
087: selectColor = color;
088: }
089:
090: @Override
091: public Color getSelectColor() {
092: return super .getSelectColor();
093: }
094:
095: @Override
096: public void uninstallDefaults(final AbstractButton b) {
097: super .uninstallDefaults(b);
098: }
099: }
100:
101: public void testUninstallDefaults() {
102: JRadioButton button = new JRadioButton();
103: UIManager.put("RadioButton.disabledText", new ColorUIResource(
104: Color.red));
105: UIManager.put("RadioButton.focus", new ColorUIResource(
106: Color.yellow));
107: UIManager.put("RadioButton.select", new ColorUIResource(
108: Color.green));
109: UIManager.put("RadioButton.foreground", new ColorUIResource(
110: Color.cyan));
111: UIManager.put("RadioButton.background", new ColorUIResource(
112: Color.blue));
113: Font font = new FontUIResource(button.getFont()
114: .deriveFont(100f));
115: UIManager.put("RadioButton.font", font);
116: Border border = new BorderUIResource(BorderFactory
117: .createEmptyBorder(0, 0, 0, 0));
118: UIManager.put("RadioButton.border", border);
119: Icon icon = new IconUIResource(new ImageIcon(new BufferedImage(
120: 10, 10, BufferedImage.TYPE_INT_RGB)));
121: UIManager.put("RadioButton.icon", icon);
122: button.setUI(publicUI);
123: publicUI.installDefaults(button);
124: publicUI.uninstallDefaults(button);
125: assertEquals(Color.blue, button.getBackground());
126: assertEquals(Color.cyan, button.getForeground());
127: assertEquals("SelectedColor ", Color.green, publicUI
128: .getSelectColor());
129: assertEquals("focusColor ", Color.yellow, publicUI
130: .getFocusColor());
131: assertEquals("disabledTextColor ", Color.red, publicUI
132: .getDisabledTextColor());
133: assertEquals("font", font, button.getFont());
134: assertNull("border", button.getBorder());
135: assertEquals("icon", icon, publicUI.getDefaultIcon());
136: }
137:
138: public void testInstallDefaults() {
139: JRadioButton button = new JRadioButton();
140: UIManager.put("RadioButton.disabledText", new ColorUIResource(
141: Color.red));
142: UIManager.put("RadioButton.focus", new ColorUIResource(
143: Color.yellow));
144: UIManager.put("RadioButton.select", new ColorUIResource(
145: Color.green));
146: UIManager.put("RadioButton.foreground", new ColorUIResource(
147: Color.cyan));
148: UIManager.put("RadioButton.background", new ColorUIResource(
149: Color.blue));
150: Font font = new FontUIResource(button.getFont()
151: .deriveFont(100f));
152: UIManager.put("RadioButton.font", font);
153: Border border = new BorderUIResource(BorderFactory
154: .createEmptyBorder(0, 0, 0, 0));
155: UIManager.put("RadioButton.border", border);
156: Icon icon = new IconUIResource(new ImageIcon(new BufferedImage(
157: 10, 10, BufferedImage.TYPE_INT_RGB)));
158: UIManager.put("RadioButton.icon", icon);
159: button.setUI(publicUI);
160: publicUI.installDefaults(button);
161: assertEquals(Color.blue, button.getBackground());
162: assertEquals(Color.cyan, button.getForeground());
163: assertEquals("SelectedColor ", Color.green, publicUI
164: .getSelectColor());
165: assertEquals("focusColor ", Color.yellow, publicUI
166: .getFocusColor());
167: assertEquals("disabledTextColor ", Color.red, publicUI
168: .getDisabledTextColor());
169: assertEquals("font", font, button.getFont());
170: assertEquals("border", border, button.getBorder());
171: assertEquals("icon", icon, publicUI.getDefaultIcon());
172: }
173:
174: public void testGetSelectColor() {
175: assertNull("SelectedColor is null", publicUI.getSelectColor());
176: publicUI.setSelectColor(Color.WHITE);
177: assertEquals("SelectedColor ", Color.WHITE, publicUI
178: .getSelectColor());
179: }
180:
181: public void testGetDisabledTextColor() {
182: assertNull("DisabledTextColor is null", publicUI
183: .getDisabledTextColor());
184: publicUI.setDisabledTextColor(Color.WHITE);
185: assertEquals("DisabledTextColor ", Color.WHITE, publicUI
186: .getDisabledTextColor());
187: }
188:
189: public void testGetFocusColor() {
190: assertNull("FocusColor is null", publicUI.getFocusColor());
191: publicUI.setFocusColor(Color.WHITE);
192: assertEquals("FocusColor ", Color.WHITE, publicUI
193: .getFocusColor());
194: }
195: }
|