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 Vadim L. Bogdanov
019: * @version $Revision$
020: */package javax.swing.plaf.basic;
021:
022: import java.awt.Dimension;
023: import java.awt.LayoutManager;
024: import java.awt.Rectangle;
025: import javax.swing.BorderFactory;
026: import javax.swing.JComponent;
027: import javax.swing.JInternalFrame;
028: import javax.swing.JPanel;
029: import javax.swing.SwingTestCase;
030:
031: /**
032: * Test BasicInternalFrameUI.InternalFrameLayout class
033: *
034: */
035: public class BasicInternalFrameUI$InternalFrameLayoutTest extends
036: SwingTestCase {
037: private JInternalFrame frame;
038:
039: private BasicInternalFrameUI ui;
040:
041: private LayoutManager layout;
042:
043: private JComponent titlePane;
044:
045: @Override
046: protected void setUp() throws Exception {
047: super .setUp();
048: frame = new JInternalFrame();
049: frame.setBorder(BorderFactory.createEmptyBorder(5, 10, 15, 20));
050: ui = new BasicInternalFrameUI(frame);
051: frame.setUI(ui);
052: layout = frame.getLayout();
053: titlePane = (JComponent) frame.getComponent(1);
054: titlePane.setPreferredSize(new Dimension(100, 20));
055: titlePane.setMinimumSize(new Dimension(80, 10));
056: }
057:
058: @Override
059: protected void tearDown() throws Exception {
060: titlePane = null;
061: ui = null;
062: layout = null;
063: frame.dispose();
064: frame = null;
065: super .tearDown();
066: }
067:
068: public void testPreferredLayoutSize() {
069: Dimension rootPanePreferredSize = new Dimension(32, 21);
070: frame.getRootPane().setPreferredSize(rootPanePreferredSize);
071: // only northPane is set
072: // 1.5 seems to add Insests before calculating max between TitlePane width
073: // and RootPane width which is likely a bug.
074: if (isHarmony()) {
075: assertEquals("1 pane", new Dimension(130, 61), layout
076: .preferredLayoutSize(frame));
077: } else {
078: assertEquals("1 pane", new Dimension(100, 61), layout
079: .preferredLayoutSize(frame));
080: }
081: assertEquals("rootPane's preferred size not changed",
082: rootPanePreferredSize, frame.getRootPane()
083: .getPreferredSize());
084: titlePane.setPreferredSize(new Dimension(10, 20));
085: assertEquals("1 pane", new Dimension(62, 61), layout
086: .preferredLayoutSize(frame));
087: assertEquals("rootPane's preferred size not changed",
088: rootPanePreferredSize, frame.getRootPane()
089: .getPreferredSize());
090: // all panes are set
091: ui.getNorthPane().setPreferredSize(new Dimension(14, 18));
092: ui.setWestPane(new JPanel());
093: ui.getWestPane().setPreferredSize(new Dimension(11, 22));
094: ui.setSouthPane(new JPanel());
095: ui.getSouthPane().setPreferredSize(new Dimension(12, 23));
096: ui.setEastPane(new JPanel());
097: ui.getEastPane().setPreferredSize(new Dimension(13, 24));
098: assertEquals("all panes", new Dimension(86, 82), layout
099: .preferredLayoutSize(frame));
100: }
101:
102: /*
103: * Class under test for Dimension minimumLayoutSize(Container)
104: */
105: public void testMinimumLayoutSize() {
106: frame.getRootPane().setMinimumSize(new Dimension(32, 21));
107: // only northPane is set
108: assertEquals("1 pane", new Dimension(110, 30), layout
109: .minimumLayoutSize(frame));
110: // all panes are set
111: ui.getNorthPane().setMinimumSize(new Dimension(14, 18));
112: ui.setWestPane(new JPanel());
113: ui.getWestPane().setMinimumSize(new Dimension(11, 22));
114: ui.setSouthPane(new JPanel());
115: ui.getSouthPane().setMinimumSize(new Dimension(12, 23));
116: ui.setEastPane(new JPanel());
117: ui.getEastPane().setMinimumSize(new Dimension(13, 24));
118: assertEquals("all panes", new Dimension(44, 38), layout
119: .minimumLayoutSize(frame));
120: }
121:
122: /*
123: * Class under test for void layoutContainer(Container)
124: */
125: public void testLayoutContainer() {
126: frame.getRootPane().setPreferredSize(new Dimension(9, 21));
127: frame.setSize(100, 200);
128: // only northPane is set
129: layout.layoutContainer(frame);
130: assertEquals(new Rectangle(10, 25, 70, 160), frame
131: .getRootPane().getBounds());
132: assertEquals(new Rectangle(10, 5, 70, 20), ui.getNorthPane()
133: .getBounds());
134: // all panes are set
135: JPanel button = new JPanel();
136: button.setPreferredSize(new Dimension(11, 12));
137: ui.setWestPane(button);
138: button = new JPanel();
139: button.setPreferredSize(new Dimension(11, 12));
140: ui.setSouthPane(button);
141: button = new JPanel();
142: button.setPreferredSize(new Dimension(11, 12));
143: ui.setEastPane(button);
144: layout.layoutContainer(frame);
145: assertEquals(new Rectangle(21, 25, 48, 148), frame
146: .getRootPane().getBounds());
147: assertEquals(new Rectangle(10, 5, 70, 20), ui.getNorthPane()
148: .getBounds());
149: assertEquals(new Rectangle(10, 25, 11, 148), ui.getWestPane()
150: .getBounds());
151: assertEquals(new Rectangle(10, 173, 70, 12), ui.getSouthPane()
152: .getBounds());
153: // 1.5 fails because of its bug in layout
154: if (isHarmony()) {
155: assertEquals(new Rectangle(69, 25, 11, 148), ui
156: .getEastPane().getBounds());
157: } else {
158: assertEquals(new Rectangle(48, 25, 11, 148), ui
159: .getEastPane().getBounds());
160: }
161: }
162:
163: /*
164: * Class under test for void addLayoutComponent(String, Component)
165: */
166: public void testAddLayoutComponent() {
167: JPanel button = new JPanel();
168: layout.addLayoutComponent("ok", button);
169: assertFalse("not added", frame.isAncestorOf(button));
170: }
171:
172: /*
173: * Class under test for void removeLayoutComponent(Component)
174: */
175: public void testRemoveLayoutComponent() {
176: layout.layoutContainer(frame);
177: Rectangle bounds = frame.getRootPane().getBounds();
178: layout.removeLayoutComponent(ui.getNorthPane());
179: layout.layoutContainer(frame);
180: assertEquals("nothing changed", bounds, frame.getRootPane()
181: .getBounds());
182: }
183: }
|