mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 19:44:41 +02:00
6848424: java/awt/Frame/FrameSize/TestFrameSize.java needs improvement
The test now thoroughly verifies the pack() method Reviewed-by: art, dcherepanov
This commit is contained in:
parent
6293f73bd8
commit
8440a8dba3
1 changed files with 51 additions and 23 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2009 Red Hat, Inc. All Rights Reserved.
|
* Copyright 2009 Red Hat, Inc. All Rights Reserved.
|
||||||
|
* Portions Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -37,35 +38,62 @@
|
||||||
* Test fails if size of window is wrong
|
* Test fails if size of window is wrong
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.*;
|
||||||
import java.awt.Frame;
|
|
||||||
|
|
||||||
public class TestFrameSize {
|
public class TestFrameSize {
|
||||||
|
|
||||||
static Dimension desiredDimensions = new Dimension(200, 200);
|
static Dimension desiredDimensions = new Dimension(200, 200);
|
||||||
static int ERROR_MARGIN = 15;
|
static Frame mainWindow;
|
||||||
static Frame mainWindow;
|
|
||||||
|
|
||||||
public static void drawGui() {
|
private static Dimension getClientSize(Frame window) {
|
||||||
mainWindow = new Frame("");
|
Dimension size = window.getSize();
|
||||||
mainWindow.setPreferredSize(desiredDimensions);
|
Insets insets = window.getInsets();
|
||||||
mainWindow.pack();
|
|
||||||
|
|
||||||
Dimension actualDimensions = mainWindow.getSize();
|
System.out.println("getClientSize() for " + window);
|
||||||
System.out.println("Desired dimensions: " + desiredDimensions.toString());
|
System.out.println(" size: " + size);
|
||||||
System.out.println("Actual dimensions: " + actualDimensions.toString());
|
System.out.println(" insets: " + insets);
|
||||||
if (Math.abs(actualDimensions.height - desiredDimensions.height) > ERROR_MARGIN) {
|
|
||||||
throw new RuntimeException("Incorrect widow size");
|
return new Dimension(
|
||||||
}
|
size.width - insets.left - insets.right,
|
||||||
|
size.height - insets.top - insets.bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawGui() {
|
||||||
|
mainWindow = new Frame("");
|
||||||
|
mainWindow.setPreferredSize(desiredDimensions);
|
||||||
|
mainWindow.pack();
|
||||||
|
|
||||||
|
Dimension actualDimensions = mainWindow.getSize();
|
||||||
|
System.out.println("Desired dimensions: " + desiredDimensions.toString());
|
||||||
|
System.out.println("Actual dimensions: " + actualDimensions.toString());
|
||||||
|
if (!actualDimensions.equals(desiredDimensions)) {
|
||||||
|
throw new RuntimeException("Incorrect widow size");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
// pack() guarantees to preserve the size of the client area after
|
||||||
try {
|
// showing the window.
|
||||||
drawGui();
|
Dimension clientSize1 = getClientSize(mainWindow);
|
||||||
} finally {
|
System.out.println("Client size before showing: " + clientSize1);
|
||||||
if (mainWindow != null) {
|
|
||||||
mainWindow.dispose();
|
mainWindow.setVisible(true);
|
||||||
}
|
|
||||||
}
|
((sun.awt.SunToolkit)Toolkit.getDefaultToolkit()).realSync();
|
||||||
|
|
||||||
|
Dimension clientSize2 = getClientSize(mainWindow);
|
||||||
|
System.out.println("Client size after showing: " + clientSize2);
|
||||||
|
|
||||||
|
if (!clientSize2.equals(clientSize1)) {
|
||||||
|
throw new RuntimeException("Incorrect client area size.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
drawGui();
|
||||||
|
} finally {
|
||||||
|
if (mainWindow != null) {
|
||||||
|
mainWindow.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue