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 21.12.2004
021:
022: */package javax.swing;
023:
024: import java.awt.AWTError;
025: import java.awt.Component;
026: import java.awt.Dimension;
027: import java.awt.GridLayout;
028: import javax.accessibility.AccessibleContext;
029:
030: public class BoxTest extends SwingTestCase {
031: /*
032: * Class under test for AccessibleContext getAccessibleContext()
033: */
034: public void testGetAccessibleContext() {
035: Component box = new Box(BoxLayout.LINE_AXIS);
036: AccessibleContext accessible = box.getAccessibleContext();
037: assertEquals("Accessible context is correct ",
038: Box.AccessibleBox.class, accessible.getClass());
039: }
040:
041: /*
042: * Class under test for void setLayout(LayoutManager)
043: */
044: public void testSetLayoutLayoutManager() {
045: Box box = new Box(BoxLayout.X_AXIS);
046: boolean thrown = false;
047: try {
048: box.setLayout(new GridLayout(3, 3));
049: } catch (AWTError err) {
050: thrown = true;
051: }
052: assertTrue("Exception is thrown ", thrown);
053: }
054:
055: public void testCreateRigidArea() throws NullPointerException {
056: Dimension size = new Dimension(100, 100);
057: Component box = Box.createRigidArea(size);
058: assertEquals("Minimum size initialized ", size, box
059: .getMinimumSize());
060: assertEquals("Preferred size initialized ", size, box
061: .getPreferredSize());
062: assertEquals("Maximum size initialized ", size, box
063: .getMaximumSize());
064: assertFalse("Opaqueness initialized ", box.isOpaque());
065:
066: Box.createRigidArea(null);
067: }
068:
069: public void testCreateVerticalBox() {
070: Box box = Box.createVerticalBox();
071: assertFalse("Opaqueness initialized ", box.isOpaque());
072: JPanel panel1 = new JPanel();
073: JPanel panel2 = new JPanel();
074: panel1.setMinimumSize(new Dimension(10, 10));
075: panel2.setMinimumSize(new Dimension(10, 10));
076: panel1.setPreferredSize(new Dimension(100, 200));
077: panel2.setPreferredSize(new Dimension(1000, 2000));
078: box.add(panel1);
079: box.add(panel2);
080: assertEquals("Minimum size ", new Dimension(10, 20), box
081: .getMinimumSize());
082: assertEquals("Preferred size ", new Dimension(1000, 2200), box
083: .getPreferredSize());
084: assertEquals("Maximum size ", new Dimension(Short.MAX_VALUE,
085: 2 * Short.MAX_VALUE), box.getMaximumSize());
086: }
087:
088: public void testCreateHorizontalBox() {
089: Box box = Box.createHorizontalBox();
090: assertFalse("Opaqueness initialized ", box.isOpaque());
091: JPanel panel1 = new JPanel();
092: JPanel panel2 = new JPanel();
093: panel1.setMinimumSize(new Dimension(10, 10));
094: panel2.setMinimumSize(new Dimension(10, 10));
095: panel1.setPreferredSize(new Dimension(100, 200));
096: panel2.setPreferredSize(new Dimension(1000, 2000));
097: box.add(panel1);
098: box.add(panel2);
099: assertEquals("Minimum size ", new Dimension(20, 10), box
100: .getMinimumSize());
101: assertEquals("Preferred size ", new Dimension(1100, 2000), box
102: .getPreferredSize());
103: assertEquals("Maximum size ", new Dimension(
104: 2 * Short.MAX_VALUE, Short.MAX_VALUE), box
105: .getMaximumSize());
106: }
107:
108: public void testCreateVerticalStrut() {
109: int height = 100;
110: Dimension size = new Dimension(0, height);
111: Dimension maxSize = new Dimension(Short.MAX_VALUE, height);
112: Component box = Box.createVerticalStrut(height);
113: assertEquals("Minimum size initialized correctly ", size, box
114: .getMinimumSize());
115: assertEquals("Preferred size initialized correctly ", size, box
116: .getPreferredSize());
117: assertEquals("Maximum size initialized correctly ", maxSize,
118: box.getMaximumSize());
119: assertFalse("Opaqueness initialized correctly", box.isOpaque());
120: }
121:
122: public void testCreateHorizontalStrut() {
123: int width = 100;
124: Dimension size = new Dimension(width, 0);
125: Dimension maxSize = new Dimension(width, Short.MAX_VALUE);
126: Component box = Box.createHorizontalStrut(width);
127: assertEquals("Minimum size initialized correctly ", size, box
128: .getMinimumSize());
129: assertEquals("Preferred size initialized correctly ", size, box
130: .getPreferredSize());
131: assertEquals("Maximum size initialized correctly ", maxSize,
132: box.getMaximumSize());
133: assertFalse("Opaqueness initialized correctly", box.isOpaque());
134: }
135:
136: public void testCreateVerticalGlue() {
137: Dimension nullSize = new Dimension(0, 0);
138: Dimension maximumSize = new Dimension(0, Short.MAX_VALUE);
139: Component box = Box.createVerticalGlue();
140: assertEquals("Minimum size initialized correctly ", nullSize,
141: box.getMinimumSize());
142: assertEquals("Preferred size initialized correctly ", nullSize,
143: box.getPreferredSize());
144: assertEquals("Maximum size initialized correctly ",
145: maximumSize, box.getMaximumSize());
146: assertFalse("Opaqueness initialized correctly", box.isOpaque());
147: }
148:
149: public void testCreateHorizontalGlue() {
150: Dimension nullSize = new Dimension(0, 0);
151: Dimension maximumSize = new Dimension(Short.MAX_VALUE, 0);
152: Component box = Box.createHorizontalGlue();
153: assertEquals("Minimum size initialized correctly ", nullSize,
154: box.getMinimumSize());
155: assertEquals("Preferred size initialized correctly ", nullSize,
156: box.getPreferredSize());
157: assertEquals("Maximum size initialized correctly ",
158: maximumSize, box.getMaximumSize());
159: assertFalse("Opaqueness initialized correctly", box.isOpaque());
160: }
161:
162: public void testCreateGlue() {
163: Dimension nullSize = new Dimension(0, 0);
164: Dimension maximumSize = new Dimension(Short.MAX_VALUE,
165: Short.MAX_VALUE);
166: Component box = Box.createGlue();
167: assertEquals("Minimum size initialized correctly ", nullSize,
168: box.getMinimumSize());
169: assertEquals("Preferred size initialized correctly ", nullSize,
170: box.getPreferredSize());
171: assertEquals("Maximum size initialized correctly ",
172: maximumSize, box.getMaximumSize());
173: assertFalse("Opaqueness initialized correctly", box.isOpaque());
174: }
175: }
|