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 08.09.2004
021:
022: */package javax.swing.plaf.basic;
023:
024: import java.awt.Color;
025: import javax.swing.BorderFactory;
026: import javax.swing.JButton;
027: import javax.swing.JComponent;
028: import javax.swing.JPanel;
029: import javax.swing.JPanelTest;
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.ComponentUI;
035: import javax.swing.plaf.PanelUI;
036: import junit.framework.TestCase;
037:
038: public class BasicPanelUITest extends TestCase {
039: protected BasicPanelUI panelUI = null;
040:
041: public static void main(final String[] args) {
042: junit.textui.TestRunner.run(JPanelTest.class);
043: }
044:
045: /*
046: * @see TestCase#setUp()
047: */
048: @Override
049: protected void setUp() throws Exception {
050: super .setUp();
051: panelUI = new BasicPanelUI();
052: }
053:
054: /*
055: * @see TestCase#tearDown()
056: */
057: @Override
058: protected void tearDown() throws Exception {
059: super .tearDown();
060: }
061:
062: public void testUninstallUI() {
063: JPanel panel = new JPanel();
064: panel.setUI(panelUI);
065: Border border1 = BorderFactory.createEmptyBorder();
066: panel.setBorder(border1);
067: panelUI.uninstallUI(panel);
068: assertNotNull(panel.getBackground());
069: assertNotNull(panel.getForeground());
070: assertNotNull(panel.getBorder());
071: UIManager.put("Panel.background", Color.red);
072: Border border2 = new BorderUIResource(BorderFactory
073: .createEmptyBorder());
074: UIManager.put("Panel.border", border2);
075: panel.setUI(panelUI);
076: panelUI.uninstallUI(panel);
077: assertEquals(Color.red, panel.getBackground());
078: assertNotNull(panel.getForeground());
079: assertEquals(border1, panel.getBorder());
080: }
081:
082: public void testInstallUI() {
083: JPanel panel = new JPanel();
084: assertTrue("opaque", panel.isOpaque());
085: UIManager.put("Panel.background",
086: new ColorUIResource(Color.red));
087: UIManager.put("Panel.foreground", new ColorUIResource(
088: Color.yellow));
089: Border border2 = new BorderUIResource(BorderFactory
090: .createEmptyBorder());
091: UIManager.put("Panel.border", border2);
092: panel.setOpaque(false);
093: panel.setUI(panelUI);
094: panelUI.installUI(panel);
095: assertEquals(Color.red, panel.getBackground());
096: assertEquals(Color.yellow, panel.getForeground());
097: assertEquals(border2, panel.getBorder());
098: assertFalse("opaque", panel.isOpaque());
099: Border border1 = BorderFactory.createEmptyBorder();
100: panel.setBorder(border1);
101: panel.setUI(panelUI);
102: panelUI.installUI(panel);
103: assertEquals(border1, panel.getBorder());
104: }
105:
106: public void testCreateUI() {
107: JComponent component = new JPanel();
108: ComponentUI ui = BasicPanelUI.createUI(component);
109: assertTrue(ui != null && (ui instanceof PanelUI));
110: component = new JButton();
111: ui = BasicPanelUI.createUI(component);
112: assertTrue(ui != null);
113: }
114: }
|