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: */package javax.swing.plaf.basic;
021:
022: import java.awt.AWTError;
023: import java.awt.Container;
024: import java.awt.Dimension;
025: import javax.swing.BoxLayout;
026: import javax.swing.JComponent;
027: import javax.swing.JPanel;
028: import javax.swing.SwingTestCase;
029:
030: public class DefaultMenuLayoutTest extends SwingTestCase {
031: protected BoxLayout layout = null;
032:
033: @Override
034: protected void setUp() throws Exception {
035: super .setUp();
036: }
037:
038: @Override
039: protected void tearDown() throws Exception {
040: super .tearDown();
041: }
042:
043: /*
044: * Test method for 'javax.swing.plaf.basic.DefaultMenuLayout.preferredLayoutSize(Container)'
045: */
046: public void testPreferredLayoutSize() {
047: JComponent container1 = new JPanel();
048: JComponent component11 = new JPanel();
049: JComponent component21 = new JPanel();
050: JComponent component31 = new JPanel();
051: BoxLayout layout1 = new DefaultMenuLayout(container1,
052: BoxLayout.X_AXIS);
053: BoxLayout layout2 = new DefaultMenuLayout(container1,
054: BoxLayout.Y_AXIS);
055: component11.setMinimumSize(new Dimension(5, 5));
056: component21.setMinimumSize(new Dimension(6, 6));
057: component31.setMinimumSize(new Dimension(7, 7));
058: component11.setPreferredSize(new Dimension(50, 50));
059: component21.setPreferredSize(new Dimension(60, 60));
060: component31.setPreferredSize(new Dimension(70, 70));
061: container1.add(component11);
062: container1.add(component21);
063: assertEquals(new Dimension(110, 60), layout1
064: .preferredLayoutSize(container1));
065: assertEquals(new Dimension(60, 110), layout2
066: .preferredLayoutSize(container1));
067: layout1.invalidateLayout(container1);
068: layout2.invalidateLayout(container1);
069: container1.add(component31);
070: assertEquals(new Dimension(180, 70), layout1
071: .preferredLayoutSize(container1));
072: assertEquals(new Dimension(70, 180), layout2
073: .preferredLayoutSize(container1));
074: }
075:
076: /*
077: * Test method for 'javax.swing.plaf.basic.DefaultMenuLayout.DefaultMenuLayout(Container, int)'
078: */
079: public void testDefaultMenuLayout() {
080: Container container = new JPanel();
081: boolean thrown = false;
082: String text = null;
083: try {
084: layout = new DefaultMenuLayout(container,
085: BoxLayout.LINE_AXIS);
086: } catch (AWTError e) {
087: thrown = true;
088: }
089: assertFalse("No exception thrown", thrown);
090: thrown = false;
091: text = null;
092: try {
093: layout = new DefaultMenuLayout(container, 300);
094: } catch (AWTError e) {
095: thrown = true;
096: text = e.getMessage();
097: }
098: assertTrue("AWTError exception thrown", thrown);
099: assertEquals(text, "Invalid axis");
100: thrown = false;
101: text = null;
102: try {
103: layout = new BoxLayout(null, BoxLayout.Y_AXIS);
104: } catch (AWTError e) {
105: thrown = true;
106: }
107: assertFalse("No exception thrown", thrown);
108: }
109: }
|