1 | |
package us.daveread.basicquery.gui; |
2 | |
|
3 | |
import java.awt.Dimension; |
4 | |
import java.awt.Point; |
5 | |
import java.awt.Toolkit; |
6 | |
import java.awt.Window; |
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
public class GUIUtility { |
19 | |
|
20 | |
|
21 | |
|
22 | 0 | private GUIUtility() { |
23 | 0 | } |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public static void center(Window winaChild, Window winaParent) { |
33 | |
Dimension dimlParentSize, dimlMySize; |
34 | |
Point ptlUpperLeft; |
35 | |
int ilX, ilY; |
36 | 11 | dimlMySize = winaChild.getSize(); |
37 | 11 | if (winaParent == null) { |
38 | 1 | dimlParentSize = Toolkit.getDefaultToolkit().getScreenSize(); |
39 | 1 | ptlUpperLeft = new Point(0, 0); |
40 | |
} else { |
41 | 10 | dimlParentSize = winaParent.getSize(); |
42 | 10 | ptlUpperLeft = winaParent.getLocation(); |
43 | |
|
44 | 10 | if (dimlMySize.width > dimlParentSize.width |
45 | |
|| dimlMySize.height > dimlParentSize.height) { |
46 | 9 | dimlParentSize = Toolkit.getDefaultToolkit().getScreenSize(); |
47 | 9 | ptlUpperLeft = new Point(0, 0); |
48 | |
} |
49 | |
} |
50 | 11 | if (dimlParentSize.width >= dimlMySize.width) { |
51 | 10 | ilX = (dimlParentSize.width - dimlMySize.width) / 2; |
52 | |
} else { |
53 | 1 | ilX = 0; |
54 | |
} |
55 | 11 | if (dimlParentSize.height >= dimlMySize.height) { |
56 | 10 | ilY = (dimlParentSize.height - dimlMySize.height) / 2; |
57 | |
} else { |
58 | 1 | ilY = 0; |
59 | |
} |
60 | 11 | ilX += ptlUpperLeft.x; |
61 | 11 | ilY += ptlUpperLeft.y; |
62 | 11 | winaChild.setLocation(ilX, ilY); |
63 | 11 | } |
64 | |
} |