1 /* |
1 /* |
2 * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
32 * Check if the compnents are correctly laid out. |
32 * Check if the compnents are correctly laid out. |
33 * The strategy followed is to calculate the component location |
33 * The strategy followed is to calculate the component location |
34 * depending on the preferred sizes and gaps and click the cornors |
34 * depending on the preferred sizes and gaps and click the cornors |
35 * of the components to check if events are triggered |
35 * of the components to check if events are triggered |
36 * @library ../../../../lib/testlibrary/ |
36 * @library ../../../../lib/testlibrary/ |
37 * @build ExtendedRobot |
|
38 * @run main ComponentPreferredSize |
37 * @run main ComponentPreferredSize |
39 * @run main ComponentPreferredSize -hg 20 -vg 20 |
38 * @run main ComponentPreferredSize -hg 20 -vg 20 |
40 */ |
39 */ |
41 |
40 |
42 public class ComponentPreferredSize { |
41 public class ComponentPreferredSize { |
43 |
42 |
44 private int width = 200; |
43 private int width = 300; |
45 private int height = 200; |
44 private int height = 200; |
46 private final int hGap, vGap; |
45 private final int hGap, vGap; |
47 private final int rows = 3; |
46 private final int rows = 3; |
48 private final int columns = 2; |
47 private final int columns = 2; |
49 private final int componentCount = 6; |
48 private final int componentCount = 6; |
50 |
49 |
51 private Button[] buttons; |
50 private Button[] buttons; |
52 private Frame frame; |
51 private Frame frame; |
53 |
52 |
54 private ExtendedRobot robot; |
53 private Robot robot; |
55 private GridLayout layout; |
54 private GridLayout layout; |
56 |
55 |
57 private volatile boolean actionPerformed = false; |
56 private volatile boolean actionPerformed = false; |
58 |
57 |
59 public ComponentPreferredSize(int hGap, int vGap) throws Exception { |
58 public ComponentPreferredSize(int hGap, int vGap) throws Exception { |
60 this.hGap = hGap; |
59 this.hGap = hGap; |
61 this.vGap = vGap; |
60 this.vGap = vGap; |
62 robot = new ExtendedRobot(); |
61 robot = new Robot(); |
63 EventQueue.invokeAndWait( () -> { |
62 EventQueue.invokeAndWait( () -> { |
64 frame = new Frame("Test frame"); |
63 frame = new Frame("Test frame"); |
65 frame.setSize(width, height); |
64 frame.setSize(width, height); |
66 layout = new GridLayout(rows, columns, hGap, vGap); |
65 layout = new GridLayout(rows, columns, hGap, vGap); |
67 frame.setLayout(layout); |
66 frame.setLayout(layout); |
114 robot.mouseMove(topLeftX, topLeftY); |
113 robot.mouseMove(topLeftX, topLeftY); |
115 robot.delay(500); |
114 robot.delay(500); |
116 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
115 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
117 robot.delay(500); |
116 robot.delay(500); |
118 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); |
117 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); |
119 robot.waitForIdle(3000); |
118 robot.delay(3000); |
120 |
119 |
121 if(!actionPerformed) |
120 if (!actionPerformed) { |
|
121 frame.dispose(); |
122 throw new RuntimeException("Clicking on the left top of button did not trigger action event"); |
122 throw new RuntimeException("Clicking on the left top of button did not trigger action event"); |
|
123 } |
123 |
124 |
124 actionPerformed = false; |
125 actionPerformed = false; |
125 robot.mouseMove(bottomRightX, bottomRightY); |
126 robot.mouseMove(bottomRightX, bottomRightY); |
126 robot.delay(500); |
127 robot.delay(500); |
127 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
128 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
128 robot.delay(500); |
129 robot.delay(500); |
129 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); |
130 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); |
130 robot.waitForIdle(3000); |
131 robot.delay(3000); |
131 |
132 |
132 if(!actionPerformed) |
133 if (!actionPerformed) { |
|
134 frame.dispose(); |
133 throw new RuntimeException("Clicking on the bottom right of button did not trigger action event"); |
135 throw new RuntimeException("Clicking on the bottom right of button did not trigger action event"); |
|
136 } |
134 } |
137 } |
135 |
138 |
136 private void doTest() throws Exception { |
139 private void doTest() throws Exception { |
137 robot.waitForIdle(); |
140 robot.waitForIdle(); |
138 resizeFrame(); |
141 resizeFrame(); |
145 int componentHeight = (availableHeight + vGap) / rows - vGap; |
148 int componentHeight = (availableHeight + vGap) / rows - vGap; |
146 |
149 |
147 for (int i = 0; i < buttons.length; i++) { |
150 for (int i = 0; i < buttons.length; i++) { |
148 if (buttons[i].getSize().width != componentWidth || |
151 if (buttons[i].getSize().width != componentWidth || |
149 buttons[i].getSize().height != componentHeight) { |
152 buttons[i].getSize().height != componentHeight) { |
|
153 frame.dispose(); |
150 throw new RuntimeException( |
154 throw new RuntimeException( |
151 "FAIL: Button " + i + " not of proper size" + |
155 "FAIL: Button " + i + " not of proper size" + |
152 "Expected: " + componentWidth + "*" + componentHeight + |
156 "Expected: " + componentWidth + "*" + componentHeight + |
153 "Actual: " + buttons[i].getSize().width + "*" + buttons[i].getSize().height); |
157 "Actual: " + buttons[i].getSize().width + "*" + buttons[i].getSize().height); |
154 } |
158 } |