2
|
1 |
/*
|
|
2 |
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
@test
|
|
26 |
@bug 4370316
|
|
27 |
@summary GridLayout does not fill its Container
|
|
28 |
@library ../../regtesthelpers
|
|
29 |
@build Util
|
|
30 |
@author Andrei Dmitriev : area=awt.layout
|
|
31 |
@run main LayoutExtraGaps
|
|
32 |
*/
|
|
33 |
|
|
34 |
import java.awt.*;
|
|
35 |
import java.awt.event.*;
|
|
36 |
import test.java.awt.regtesthelpers.Util;
|
|
37 |
|
|
38 |
public class LayoutExtraGaps extends Frame {
|
|
39 |
final static int compCount = 30;
|
|
40 |
|
|
41 |
public LayoutExtraGaps() {
|
|
42 |
super("GridLayoutTest");
|
|
43 |
Panel yellowPanel = new Panel(new GridLayout(compCount, 1, 3, 3));
|
|
44 |
yellowPanel.setBackground(Color.yellow);
|
|
45 |
|
|
46 |
for(int i = 0; i < compCount ; i++) {
|
|
47 |
Label redLabel = new Label(""+i);
|
|
48 |
redLabel.setBackground(Color.red);
|
|
49 |
yellowPanel.add(redLabel);
|
|
50 |
}
|
|
51 |
|
|
52 |
Panel bluePanel = new Panel(new GridLayout(1, compCount, 3, 3));
|
|
53 |
bluePanel.setBackground(Color.blue);
|
|
54 |
|
|
55 |
for(int i = 0; i < compCount; i++) {
|
|
56 |
Label greenLabel = new Label(""+i);
|
|
57 |
greenLabel.setBackground(Color.green);
|
|
58 |
bluePanel.add(greenLabel);
|
|
59 |
}
|
|
60 |
|
|
61 |
//RTL orientation
|
|
62 |
Panel blackPanel = new Panel(new GridLayout(compCount, 1, 3, 3));
|
|
63 |
blackPanel.setBackground(Color.black);
|
|
64 |
blackPanel.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
|
|
65 |
|
|
66 |
for(int i = 0; i < compCount ; i++) {
|
|
67 |
Label redLabel = new Label(""+i);
|
|
68 |
redLabel.setBackground(Color.red);
|
|
69 |
blackPanel.add(redLabel);
|
|
70 |
}
|
|
71 |
|
|
72 |
Panel redPanel = new Panel(new GridLayout(1, compCount, 3, 3));
|
|
73 |
redPanel.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
|
|
74 |
redPanel.setBackground(Color.red);
|
|
75 |
|
|
76 |
for(int i = 0; i < compCount; i++) {
|
|
77 |
Label greenLabel = new Label(""+i);
|
|
78 |
greenLabel.setBackground(Color.green);
|
|
79 |
redPanel.add(greenLabel);
|
|
80 |
}
|
|
81 |
|
|
82 |
setLayout(new GridLayout(2, 2, 20, 20));
|
|
83 |
|
|
84 |
add(yellowPanel);
|
|
85 |
add(bluePanel);
|
|
86 |
add(redPanel);
|
|
87 |
add(blackPanel);
|
|
88 |
pack();
|
|
89 |
setSize((int)getPreferredSize().getWidth() + 50, (int)getPreferredSize().getHeight() + 50);
|
|
90 |
setVisible(true);
|
|
91 |
|
|
92 |
Util.waitForIdle(Util.createRobot());
|
|
93 |
Rectangle r1 = yellowPanel.getComponent(0).getBounds();
|
|
94 |
Rectangle r2 = bluePanel.getComponent(0).getBounds();
|
|
95 |
Rectangle r3 = blackPanel.getComponent(0).getBounds();
|
|
96 |
Rectangle r4 = redPanel.getComponent(0).getBounds();
|
|
97 |
|
|
98 |
System.out.println("firstHorizLabel bounds ="+r1);
|
|
99 |
System.out.println("firstVertLabel bounds ="+r2);
|
|
100 |
System.out.println("firstHorizLabel_RTL bounds ="+r3);
|
|
101 |
System.out.println("firstVertLabel_RTL bounds ="+r4);
|
|
102 |
if ((r1.getX() == 0 && r1.getY() == 0) ||
|
|
103 |
(r2.getX() == 0 && r2.getY() == 0) ||
|
|
104 |
(r3.getX() == 0 && r3.getY() == 0) ||
|
|
105 |
// RTL only affects horizontal positioning and components lays out from top right corner
|
|
106 |
(r4.getX() == blackPanel.getWidth() && r4.getY() == 0))
|
|
107 |
{
|
|
108 |
throw new RuntimeException("Test failed. GridLayout doesn't center component.");
|
|
109 |
} else {
|
|
110 |
System.out.println("Test passed.");
|
|
111 |
}
|
|
112 |
}
|
|
113 |
|
|
114 |
public static void main(String[] args) {
|
|
115 |
new LayoutExtraGaps();
|
|
116 |
}
|
|
117 |
}
|