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 22.02.2005
021:
022: */package javax.swing.plaf.metal;
023:
024: import java.awt.Color;
025: import java.awt.Font;
026: import javax.swing.AbstractButton;
027: import javax.swing.BorderFactory;
028: import javax.swing.JButton;
029: import javax.swing.JToggleButton;
030: import javax.swing.UIManager;
031: import javax.swing.border.Border;
032: import javax.swing.plaf.BorderUIResource;
033: import javax.swing.plaf.ColorUIResource;
034: import javax.swing.plaf.FontUIResource;
035: import javax.swing.plaf.basic.BasicToggleButtonUITest;
036:
037: public class MetalToggleButtonUITest extends BasicToggleButtonUITest {
038: public static void main(final String[] args) {
039: junit.textui.TestRunner.run(MetalToggleButtonUITest.class);
040: }
041:
042: @Override
043: protected void setUp() throws Exception {
044: super .setUp();
045: }
046:
047: @Override
048: public void testCreateUI() {
049: assertTrue("created UI is not null",
050: null != MetalToggleButtonUI.createUI(new JButton()));
051: assertTrue(
052: "created UI is of the proper class",
053: MetalToggleButtonUI.createUI(null) instanceof MetalToggleButtonUI);
054: assertTrue("created UI is not shared", MetalToggleButtonUI
055: .createUI(null) == MetalToggleButtonUI.createUI(null));
056: }
057:
058: public void testPaintFocus() {
059: }
060:
061: public void testPaintTextGraphicsJComponentRectangleString() {
062: }
063:
064: public void testPaintButtonPressed() {
065: }
066:
067: public void testMetalButtonUI() {
068: }
069:
070: class PublicMetalToggleButtonUI extends MetalToggleButtonUI {
071: public void setDisabledTextColor(final Color color) {
072: disabledTextColor = color;
073: }
074:
075: @Override
076: public Color getDisabledTextColor() {
077: return super .getDisabledTextColor();
078: }
079:
080: public void setFocusColor(final Color color) {
081: focusColor = color;
082: }
083:
084: @Override
085: public Color getFocusColor() {
086: return super .getFocusColor();
087: }
088:
089: public void setSelectColor(final Color color) {
090: selectColor = color;
091: }
092:
093: @Override
094: public Color getSelectColor() {
095: return super .getSelectColor();
096: }
097:
098: @Override
099: public void uninstallDefaults(final AbstractButton b) {
100: super .uninstallDefaults(b);
101: }
102: }
103:
104: public void testGetDisabledTextColor() {
105: PublicMetalToggleButtonUI publicUI = new PublicMetalToggleButtonUI();
106: assertNull("DisabledTextColor is null", publicUI
107: .getDisabledTextColor());
108: publicUI.setDisabledTextColor(Color.WHITE);
109: assertEquals("DisabledTextColor ", Color.WHITE, publicUI
110: .getDisabledTextColor());
111: }
112:
113: public void testGetFocusColor() {
114: PublicMetalToggleButtonUI publicUI = new PublicMetalToggleButtonUI();
115: assertNull("FocusColor is null", publicUI.getFocusColor());
116: publicUI.setFocusColor(Color.WHITE);
117: assertEquals("FocusColor ", Color.WHITE, publicUI
118: .getFocusColor());
119: }
120:
121: public void testGetSelectColor() {
122: PublicMetalToggleButtonUI publicUI = new PublicMetalToggleButtonUI();
123: assertNull("SelectedColor is null", publicUI.getSelectColor());
124: publicUI.setSelectColor(Color.WHITE);
125: assertEquals("SelectedColor ", Color.WHITE, publicUI
126: .getSelectColor());
127: }
128:
129: public void testInstallDefaults() throws Exception {
130: PublicMetalToggleButtonUI publicUI = new PublicMetalToggleButtonUI();
131: JToggleButton button = new JToggleButton();
132: UIManager.put("ToggleButton.disabledText", new ColorUIResource(
133: Color.red));
134: UIManager.put("ToggleButton.focus", new ColorUIResource(
135: Color.yellow));
136: UIManager.put("ToggleButton.select", new ColorUIResource(
137: Color.green));
138: UIManager.put("ToggleButton.foreground", new ColorUIResource(
139: Color.cyan));
140: UIManager.put("ToggleButton.background", new ColorUIResource(
141: Color.blue));
142: Font font = new FontUIResource(button.getFont()
143: .deriveFont(100f));
144: UIManager.put("ToggleButton.font", font);
145: Border border = new BorderUIResource(BorderFactory
146: .createEmptyBorder(0, 0, 0, 0));
147: UIManager.put("ToggleButton.border", border);
148: button.setUI(publicUI);
149: publicUI.installDefaults(button);
150: assertEquals(Color.blue, button.getBackground());
151: assertEquals(Color.cyan, button.getForeground());
152: assertEquals("SelectedColor ", Color.green, publicUI
153: .getSelectColor());
154: assertEquals("focusColor ", Color.yellow, publicUI
155: .getFocusColor());
156: assertEquals("disabledTextColor ", Color.red, publicUI
157: .getDisabledTextColor());
158: assertEquals(font, button.getFont());
159: assertEquals(border, button.getBorder());
160: }
161:
162: public void testUninstallDefaults() throws Exception {
163: PublicMetalToggleButtonUI publicUI = new PublicMetalToggleButtonUI();
164: JToggleButton button = new JToggleButton();
165: UIManager.put("ToggleButton.disabledText", new ColorUIResource(
166: Color.red));
167: UIManager.put("ToggleButton.focus", new ColorUIResource(
168: Color.yellow));
169: UIManager.put("ToggleButton.select", new ColorUIResource(
170: Color.green));
171: UIManager.put("ToggleButton.foreground", new ColorUIResource(
172: Color.cyan));
173: UIManager.put("ToggleButton.background", new ColorUIResource(
174: Color.blue));
175: Font font = new FontUIResource(button.getFont()
176: .deriveFont(100f));
177: UIManager.put("ToggleButton.font", font);
178: Border border = new BorderUIResource(BorderFactory
179: .createEmptyBorder(0, 0, 0, 0));
180: UIManager.put("ToggleButton.border", border);
181: button.setUI(publicUI);
182: publicUI.installDefaults(button);
183: publicUI.uninstallDefaults(button);
184: assertEquals(Color.blue, button.getBackground());
185: assertEquals(Color.cyan, button.getForeground());
186: assertEquals("SelectedColor ", Color.green, publicUI
187: .getSelectColor());
188: assertEquals("focusColor ", Color.yellow, publicUI
189: .getFocusColor());
190: assertEquals("disabledTextColor ", Color.red, publicUI
191: .getDisabledTextColor());
192: assertEquals("font", font, button.getFont());
193: assertNull("border", button.getBorder());
194: }
195: }
|