View Javadoc

1   /*
2    *  XNap Commons
3    *
4    *  Copyright (C) 2005  Steffen Pingel
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or (at your option) any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  }