1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.commons.settings;
21
22 import java.awt.Window;
23
24 /***
25 * @author Steffen Pingel
26 */
27 public class WindowSettingDirector
28 {
29
30 private IntSetting xSetting;
31 private IntSetting ySetting;
32 private IntSetting widthSetting;
33 private IntSetting heightSetting;
34
35 public WindowSettingDirector(SettingResource backend, String key,
36 int defaultX, int defaultY, int defaultWidth, int defaultHeight)
37 {
38 xSetting = new IntSetting(backend, key + ".x", defaultX);
39 ySetting = new IntSetting(backend, key + ".y", defaultY);
40 widthSetting = new IntSetting(backend, key + ".width", defaultWidth);
41 heightSetting = new IntSetting(backend, key + ".height", defaultHeight);
42 }
43
44 public WindowSettingDirector(SettingResource backend, String key)
45 {
46 this(backend, key, 0, 0, 0, 0);
47 }
48
49 public void save(Window window) {
50 xSetting.setValue(window.getX());
51 ySetting.setValue(window.getY());
52 widthSetting.setValue(window.getWidth());
53 heightSetting.setValue(window.getHeight());
54 }
55
56 public void restore(Window window) {
57 window.setLocation(xSetting.getValue(), ySetting.getValue());
58 window.setSize(widthSetting.getValue(), heightSetting.getValue());
59 }
60
61 }