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.metal;
021:
022: import java.awt.Dimension;
023: import java.awt.LayoutManager2;
024: import java.awt.Rectangle;
025: import javax.swing.BorderFactory;
026: import javax.swing.JComponent;
027: import javax.swing.JFrame;
028: import javax.swing.JMenu;
029: import javax.swing.JMenuBar;
030: import javax.swing.JRootPane;
031: import javax.swing.SwingTestCase;
032:
033: public class MetalRootPaneUI$MetalRootLayoutTest extends SwingTestCase {
034: private JRootPane rootPane;
035:
036: private MetalRootPaneUI ui;
037:
038: private JFrame frame;
039:
040: private LayoutManager2 layout;
041:
042: private JComponent titlePane;
043:
044: @Override
045: protected void setUp() throws Exception {
046: super .setUp();
047: MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
048: JFrame.setDefaultLookAndFeelDecorated(true);
049: frame = new JFrame();
050: rootPane = frame.getRootPane();
051: ((JComponent) rootPane).setBorder(BorderFactory
052: .createEmptyBorder(5, 10, 15, 20));
053: ui = new MetalRootPaneUI();
054: rootPane.setUI(ui);
055: layout = (LayoutManager2) rootPane.getLayout();
056: titlePane = (JComponent) rootPane.getLayeredPane()
057: .getComponent(1);
058: }
059:
060: public MetalRootPaneUI$MetalRootLayoutTest(final String name) {
061: super (name);
062: }
063:
064: public void testPreferredLayoutSize() {
065: ((JComponent) frame.getContentPane())
066: .setPreferredSize(new Dimension(200, 300));
067: titlePane.setPreferredSize(new Dimension(20, 20));
068: assertEquals(new Dimension(230, 340), layout
069: .preferredLayoutSize(rootPane));
070: }
071:
072: public void testMinimumLayoutSize() {
073: ((JComponent) frame.getContentPane())
074: .setMinimumSize(new Dimension(200, 300));
075: titlePane.setMinimumSize(new Dimension(20, 20));
076: assertEquals(new Dimension(230, 340), layout
077: .minimumLayoutSize(rootPane));
078: }
079:
080: public void testMaximumLayoutSize() {
081: ((JComponent) frame.getContentPane())
082: .setMaximumSize(new Dimension(200, 300));
083: titlePane.setMaximumSize(new Dimension(30, 400));
084: if (isHarmony()) {
085: assertEquals(new Dimension(230, 720), layout
086: .maximumLayoutSize(rootPane));
087: } else {
088: assertEquals(new Dimension(Integer.MAX_VALUE,
089: Integer.MAX_VALUE), layout
090: .maximumLayoutSize(rootPane));
091: }
092: }
093:
094: public void testLayoutContainer() {
095: final Dimension rootPaneDimension = new Dimension(640, 480);
096: final Rectangle glassPaneBounds = new Rectangle(10, 5, 610, 460);
097: final Rectangle titlePaneBounds = new Rectangle(0, 0, 610, 20);
098: frame.setSize(rootPaneDimension);
099: rootPane.setSize(rootPaneDimension);
100: titlePane.setPreferredSize(new Dimension(100, 20));
101: layout.layoutContainer(rootPane);
102: // test without menu
103: assertEquals(glassPaneBounds, rootPane.getGlassPane()
104: .getBounds());
105: assertEquals(glassPaneBounds, rootPane.getLayeredPane()
106: .getBounds());
107: assertEquals(titlePaneBounds, titlePane.getBounds());
108: assertEquals(new Rectangle(0, 20, 610, 440), rootPane
109: .getContentPane().getBounds());
110: // test with menu
111: JMenuBar menuBar = new JMenuBar();
112: menuBar.setPreferredSize(new Dimension(150, 30));
113: menuBar.add(new JMenu("Menu"));
114: rootPane.setJMenuBar(menuBar);
115: layout.layoutContainer(rootPane);
116: assertEquals(glassPaneBounds, rootPane.getGlassPane()
117: .getBounds());
118: assertEquals(glassPaneBounds, rootPane.getLayeredPane()
119: .getBounds());
120: assertEquals(titlePaneBounds, titlePane.getBounds());
121: assertEquals(new Rectangle(0, 20, 610, 30), rootPane
122: .getJMenuBar().getBounds());
123: assertEquals(new Rectangle(0, 50, 610, 410), rootPane
124: .getContentPane().getBounds());
125: }
126: }
|