1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* JSampler is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with JSampler; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.jsampler.view.std; |
24 |
|
25 |
import java.awt.Dimension; |
26 |
import java.awt.Rectangle; |
27 |
|
28 |
import java.awt.event.WindowAdapter; |
29 |
import java.awt.event.WindowEvent; |
30 |
|
31 |
import javax.swing.JFrame; |
32 |
|
33 |
import org.jsampler.CC; |
34 |
|
35 |
/** |
36 |
* |
37 |
* @author Grigor Iliev |
38 |
*/ |
39 |
public class JSFrame extends JFrame { |
40 |
public |
41 |
JSFrame(String title, String name) { |
42 |
super(title); |
43 |
setName(name); |
44 |
|
45 |
setSavedSize(); |
46 |
|
47 |
addWindowListener(new WindowAdapter() { |
48 |
public void |
49 |
windowClosing(WindowEvent we) { onWindowClose(); } |
50 |
}); |
51 |
} |
52 |
|
53 |
/** Invoked when this window is about to close. */ |
54 |
private void |
55 |
onWindowClose() { |
56 |
boolean b = (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH; |
57 |
CC.preferences().setBoolProperty(getName() + ".windowMaximized", b); |
58 |
if(b) return; |
59 |
|
60 |
StdUtils.saveWindowBounds(getName(), getBounds());setName(""); |
61 |
} |
62 |
|
63 |
private void |
64 |
setDefaultSize() { |
65 |
Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); |
66 |
double width = dimension.getWidth(); |
67 |
double height = dimension.getHeight(); |
68 |
setBounds(100, 100, (int) width - 200, (int) height - 200); |
69 |
} |
70 |
|
71 |
private void |
72 |
setSavedSize() { |
73 |
Rectangle r = StdUtils.getWindowBounds(getName()); |
74 |
if(r == null) { |
75 |
setDefaultSize(); |
76 |
return; |
77 |
} |
78 |
|
79 |
setBounds(r); |
80 |
} |
81 |
|
82 |
@Override |
83 |
public void |
84 |
setVisible(boolean b) { |
85 |
if(b == isVisible()) return; |
86 |
|
87 |
super.setVisible(b); |
88 |
|
89 |
if(b && CC.preferences().getBoolProperty(getName() + ".windowMaximized")) { |
90 |
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
91 |
} |
92 |
} |
93 |
} |