blob: 01a078ba67275207e19feeb0bd166cdbc17e9f1e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package org.reprap.gui;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import javax.swing.JFrame;
import org.reprap.Preferences;
public class Utility {
public static void centerWindowOnScreen(Window w) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
w.setLocation((screenSize.width - w.getSize().width) / 2,
(screenSize.height - w.getSize().height) / 2);
}
public static Dimension getDefaultAppSize() {
try {
Preferences prefs = Preferences.getGlobalPreferences();
if (prefs.loadBool("RememberWindowPosition")) {
int width = prefs.loadInt("MainWindowWidth");
int height = prefs.loadInt("MainWindowHeight");
return new Dimension(width, height);
}
} catch (Exception ex) {
// Ignore exception and continue with defaults
}
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
return new Dimension(4 * screenSize.width / 5, 4 * screenSize.height / 5);
}
public static void positionWindowOnScreen(Window w) {
try {
Preferences prefs = Preferences.getGlobalPreferences();
if (prefs.loadBool("RememberWindowPosition")) {
int left = prefs.loadInt("MainWindowLeft");
int top = prefs.loadInt("MainWindowTop");
w.setLocation(left, top);
return;
}
} catch (Exception ex) {
// Ignore exception and continue with defaults
}
centerWindowOnScreen(w);
}
public static void centerWindowOnParent(Window w, JFrame parent) {
Rectangle bounds = parent.getBounds();
int cx = bounds.x + bounds.width / 2;
int cy = bounds.y + bounds.height / 2;
Dimension mySize = w.getSize();
w.setLocation(cx - mySize.width / 2, cy - mySize.height / 2);
}
}
|