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.JCheckBox;
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:
040: public class MetalCheckBoxUITest extends MetalRadioButtonUITest {
041: PublicMetalCheckBoxUI publicUI;
042:
043: public static void main(final String[] args) {
044: junit.textui.TestRunner.run(MetalCheckBoxUITest.class);
045: }
046:
047: /*
048: * @see TestCase#setUp()
049: */
050: @Override
051: protected void setUp() throws Exception {
052: super .setUp();
053: publicUI = new PublicMetalCheckBoxUI();
054: }
055:
056: @Override
057: public void testCreateUI() {
058: assertTrue("created UI is not null", null != MetalCheckBoxUI
059: .createUI(new JButton()));
060: assertTrue("created UI is of the proper class", MetalCheckBoxUI
061: .createUI(null) instanceof MetalCheckBoxUI);
062: assertTrue("created UI is not shared", MetalCheckBoxUI
063: .createUI(null) == MetalCheckBoxUI.createUI(null));
064: }
065:
066: class PublicMetalCheckBoxUI extends MetalCheckBoxUI {
067: @Override
068: public String getPropertyPrefix() {
069: return super .getPropertyPrefix();
070: }
071:
072: public void setDisabledTextColor(final Color color) {
073: disabledTextColor = color;
074: }
075:
076: @Override
077: public Color getDisabledTextColor() {
078: return super .getDisabledTextColor();
079: }
080:
081: public void setFocusColor(final Color color) {
082: focusColor = color;
083: }
084:
085: @Override
086: public Color getFocusColor() {
087: return super .getFocusColor();
088: }
089:
090: public void setSelectColor(final Color color) {
091: selectColor = color;
092: }
093:
094: @Override
095: public Color getSelectColor() {
096: return super .getSelectColor();
097: }
098:
099: @Override
100: public void uninstallDefaults(final AbstractButton b) {
101: super .uninstallDefaults(b);
102: }
103: }
104:
105: @Override
106: public void testUninstallDefaults() {
107: JCheckBox button = new JCheckBox();
108: UIManager.put("CheckBox.disabledText", new ColorUIResource(
109: Color.red));
110: UIManager.put("CheckBox.focus", new ColorUIResource(
111: Color.yellow));
112: UIManager.put("CheckBox.select", new ColorUIResource(
113: Color.green));
114: UIManager.put("CheckBox.foreground", new ColorUIResource(
115: Color.cyan));
116: UIManager.put("CheckBox.background", new ColorUIResource(
117: Color.blue));
118: Font font = new FontUIResource(button.getFont()
119: .deriveFont(100f));
120: UIManager.put("CheckBox.font", font);
121: Border border = new BorderUIResource(BorderFactory
122: .createEmptyBorder(0, 0, 0, 0));
123: UIManager.put("CheckBox.border", border);
124: Icon icon = new IconUIResource(new ImageIcon(new BufferedImage(
125: 10, 10, BufferedImage.TYPE_INT_RGB)));
126: UIManager.put("CheckBox.icon", icon);
127: button.setUI(publicUI);
128: publicUI.installDefaults(button);
129: publicUI.uninstallDefaults(button);
130: assertEquals(Color.blue, button.getBackground());
131: assertEquals(Color.cyan, button.getForeground());
132: assertEquals("SelectedColor ", Color.green, publicUI
133: .getSelectColor());
134: assertEquals("focusColor ", Color.yellow, publicUI
135: .getFocusColor());
136: assertEquals("disabledTextColor ", Color.red, publicUI
137: .getDisabledTextColor());
138: assertEquals("font", font, button.getFont());
139: assertNull("border", button.getBorder());
140: assertEquals("icon", icon, publicUI.getDefaultIcon());
141: }
142:
143: @Override
144: public void testInstallDefaults() {
145: JCheckBox button = new JCheckBox();
146: UIManager.put("CheckBox.disabledText", new ColorUIResource(
147: Color.red));
148: UIManager.put("CheckBox.focus", new ColorUIResource(
149: Color.yellow));
150: UIManager.put("CheckBox.select", new ColorUIResource(
151: Color.green));
152: UIManager.put("CheckBox.foreground", new ColorUIResource(
153: Color.cyan));
154: UIManager.put("CheckBox.background", new ColorUIResource(
155: Color.blue));
156: Font font = new FontUIResource(button.getFont()
157: .deriveFont(100f));
158: UIManager.put("CheckBox.font", font);
159: Border border = new BorderUIResource(BorderFactory
160: .createEmptyBorder(0, 0, 0, 0));
161: UIManager.put("CheckBox.border", border);
162: Icon icon = new IconUIResource(new ImageIcon(new BufferedImage(
163: 10, 10, BufferedImage.TYPE_INT_RGB)));
164: UIManager.put("CheckBox.icon", icon);
165: button.setUI(publicUI);
166: publicUI.installDefaults(button);
167: assertEquals(Color.blue, button.getBackground());
168: assertEquals(Color.cyan, button.getForeground());
169: assertEquals("SelectedColor ", Color.green, publicUI
170: .getSelectColor());
171: assertEquals("focusColor ", Color.yellow, publicUI
172: .getFocusColor());
173: assertEquals("disabledTextColor ", Color.red, publicUI
174: .getDisabledTextColor());
175: assertEquals("font", font, button.getFont());
176: assertEquals("border", border, button.getBorder());
177: assertEquals("icon", icon, publicUI.getDefaultIcon());
178: }
179:
180: public void testGetPropertyPrefix() {
181: assertEquals("prefix ", "CheckBox.", publicUI
182: .getPropertyPrefix());
183: }
184: }
|