gvsig-projects-pool / org.gvsig.winmgr / trunk / org.gvsig.winmgr.app / org.gvsig.winmgr.app.mainplugin / src / main / java / org / gvsig / coreplugin / mdiManager / frames / ExternalFrame.java @ 682
History | View | Annotate | Download (11.3 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program 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
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.coreplugin.mdiManager.frames; |
25 |
|
26 |
import java.awt.Dialog; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.Frame; |
29 |
import java.awt.HeadlessException; |
30 |
import java.awt.event.ComponentEvent; |
31 |
import java.awt.event.ComponentListener; |
32 |
|
33 |
import javax.swing.JComponent; |
34 |
import javax.swing.JDialog; |
35 |
|
36 |
/**
|
37 |
* @author Cesar Martinez Izquierdo <cesar.martinez@iver.es>
|
38 |
*
|
39 |
*/
|
40 |
public class ExternalFrame extends JDialog implements IFrame, ComponentListener { |
41 |
private static final long serialVersionUID = 1L; |
42 |
|
43 |
private void initFrame() { |
44 |
addComponentListener(this);
|
45 |
} |
46 |
|
47 |
/**
|
48 |
* Creates a non-modal dialog without a title and without a specified
|
49 |
* <code>Frame</code> owner. A shared, hidden frame will be
|
50 |
* set as the owner of the dialog.
|
51 |
* <p>
|
52 |
* This constructor sets the component's locale property to the value
|
53 |
* returned by <code>JComponent.getDefaultLocale</code>.
|
54 |
*
|
55 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
56 |
* returns true.
|
57 |
* @see java.awt.GraphicsEnvironment#isHeadless
|
58 |
* @see JComponent#getDefaultLocale
|
59 |
*/
|
60 |
public ExternalFrame() throws HeadlessException { |
61 |
super();
|
62 |
initFrame(); |
63 |
} |
64 |
|
65 |
/**
|
66 |
* Creates a non-modal dialog without a title with the
|
67 |
* specified <code>Frame</code> as its owner. If <code>owner</code>
|
68 |
* is <code>null</code>, a shared, hidden frame will be set as the
|
69 |
* owner of the dialog.
|
70 |
* <p>
|
71 |
* This constructor sets the component's locale property to the value
|
72 |
* returned by <code>JComponent.getDefaultLocale</code>.
|
73 |
*
|
74 |
* @param owner the <code>Frame</code> from which the dialog is displayed
|
75 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
76 |
* returns true.
|
77 |
* @see java.awt.GraphicsEnvironment#isHeadless
|
78 |
* @see JComponent#getDefaultLocale
|
79 |
*/
|
80 |
public ExternalFrame(Frame owner) throws HeadlessException { |
81 |
super(owner);
|
82 |
initFrame(); |
83 |
} |
84 |
|
85 |
/**
|
86 |
* Creates a modal or non-modal dialog without a title and
|
87 |
* with the specified owner <code>Frame</code>. If <code>owner</code>
|
88 |
* is <code>null</code>, a shared, hidden frame will be set as the
|
89 |
* owner of the dialog.
|
90 |
* <p>
|
91 |
* This constructor sets the component's locale property to the value
|
92 |
* returned by <code>JComponent.getDefaultLocale</code>.
|
93 |
*
|
94 |
* @param owner the <code>Frame</code> from which the dialog is displayed
|
95 |
* @param modal true for a modal dialog, false for one that allows
|
96 |
* others windows to be active at the same time
|
97 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
98 |
* returns true.
|
99 |
* @see java.awt.GraphicsEnvironment#isHeadless
|
100 |
* @see JComponent#getDefaultLocale
|
101 |
*/
|
102 |
public ExternalFrame(Frame owner, boolean modal) throws HeadlessException { |
103 |
super(owner, modal);
|
104 |
initFrame(); |
105 |
} |
106 |
|
107 |
/**
|
108 |
* Creates a non-modal dialog with the specified title and
|
109 |
* with the specified owner frame. If <code>owner</code>
|
110 |
* is <code>null</code>, a shared, hidden frame will be set as the
|
111 |
* owner of the dialog.
|
112 |
* <p>
|
113 |
* This constructor sets the component's locale property to the value
|
114 |
* returned by <code>JComponent.getDefaultLocale</code>.
|
115 |
*
|
116 |
* @param owner the <code>Frame</code> from which the dialog is displayed
|
117 |
* @param title the <code>String</code> to display in the dialog's
|
118 |
* title bar
|
119 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
120 |
* returns true.
|
121 |
* @see java.awt.GraphicsEnvironment#isHeadless
|
122 |
* @see JComponent#getDefaultLocale
|
123 |
*/
|
124 |
public ExternalFrame(Frame owner, String title) throws HeadlessException { |
125 |
super(owner, title);
|
126 |
initFrame(); |
127 |
} |
128 |
|
129 |
/**
|
130 |
* Creates a modal or non-modal dialog with the specified title
|
131 |
* and the specified owner <code>Frame</code>. If <code>owner</code>
|
132 |
* is <code>null</code>, a shared, hidden frame will be set as the
|
133 |
* owner of this dialog. All constructors defer to this one.
|
134 |
* <p>
|
135 |
* NOTE: Any popup components (<code>JComboBox</code>,
|
136 |
* <code>JPopupMenu</code>, <code>JMenuBar</code>)
|
137 |
* created within a modal dialog will be forced to be lightweight.
|
138 |
* <p>
|
139 |
* This constructor sets the component's locale property to the value
|
140 |
* returned by <code>JComponent.getDefaultLocale</code>.
|
141 |
*
|
142 |
* @param owner the <code>Frame</code> from which the dialog is displayed
|
143 |
* @param title the <code>String</code> to display in the dialog's
|
144 |
* title bar
|
145 |
* @param modal true for a modal dialog, false for one that allows
|
146 |
* other windows to be active at the same time
|
147 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
148 |
* returns true.
|
149 |
* @see java.awt.GraphicsEnvironment#isHeadless
|
150 |
* @see JComponent#getDefaultLocale
|
151 |
*/
|
152 |
public ExternalFrame(Frame owner, String title, boolean modal) |
153 |
throws HeadlessException { |
154 |
super(owner, title, modal);
|
155 |
initFrame(); |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Creates a non-modal dialog without a title with the
|
160 |
* specified <code>Dialog</code> as its owner.
|
161 |
* <p>
|
162 |
* This constructor sets the component's locale property to the value
|
163 |
* returned by <code>JComponent.getDefaultLocale</code>.
|
164 |
*
|
165 |
* @param owner the non-null <code>Dialog</code> from which the dialog is displayed
|
166 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
167 |
* returns true.
|
168 |
* @see java.awt.GraphicsEnvironment#isHeadless
|
169 |
* @see JComponent#getDefaultLocale
|
170 |
*/
|
171 |
public ExternalFrame(Dialog owner) throws HeadlessException { |
172 |
super(owner);
|
173 |
initFrame(); |
174 |
} |
175 |
|
176 |
/**
|
177 |
* Creates a modal or non-modal dialog without a title and
|
178 |
* with the specified owner dialog.
|
179 |
* <p>
|
180 |
* This constructor sets the component's locale property to the value
|
181 |
* returned by <code>JComponent.getDefaultLocale</code>.
|
182 |
*
|
183 |
* @param owner the non-null <code>Dialog</code> from which the dialog is displayed
|
184 |
* @param modal true for a modal dialog, false for one that allows
|
185 |
* other windows to be active at the same time
|
186 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
187 |
* returns true.
|
188 |
* @see java.awt.GraphicsEnvironment#isHeadless
|
189 |
* @see JComponent#getDefaultLocale
|
190 |
*/
|
191 |
public ExternalFrame(Dialog owner, boolean modal) throws HeadlessException { |
192 |
super(owner, modal);
|
193 |
initFrame(); |
194 |
} |
195 |
|
196 |
/**
|
197 |
* Creates a non-modal dialog with the specified title and
|
198 |
* with the specified owner dialog.
|
199 |
* <p>
|
200 |
* This constructor sets the component's locale property to the value
|
201 |
* returned by <code>JComponent.getDefaultLocale</code>.
|
202 |
*
|
203 |
* @param owner the non-null <code>Dialog</code> from which the dialog is displayed
|
204 |
* @param title the <code>String</code> to display in the dialog's
|
205 |
* title bar
|
206 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
207 |
* returns true.
|
208 |
* @see java.awt.GraphicsEnvironment#isHeadless
|
209 |
* @see JComponent#getDefaultLocale
|
210 |
*/
|
211 |
public ExternalFrame(Dialog owner, String title) throws HeadlessException { |
212 |
super(owner, title);
|
213 |
initFrame(); |
214 |
} |
215 |
|
216 |
/**
|
217 |
* Creates a modal or non-modal dialog with the specified title
|
218 |
* and the specified owner frame.
|
219 |
* <p>
|
220 |
* This constructor sets the component's locale property to the value
|
221 |
* returned by <code>JComponent.getDefaultLocale</code>.
|
222 |
*
|
223 |
* @param owner the non-null <code>Dialog</code> from which the dialog is displayed
|
224 |
* @param title the <code>String</code> to display in the dialog's
|
225 |
* title bar
|
226 |
* @param modal true for a modal dialog, false for one that allows
|
227 |
* other windows to be active at the same time
|
228 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
|
229 |
* returns true.
|
230 |
* @see java.awt.GraphicsEnvironment#isHeadless
|
231 |
* @see JComponent#getDefaultLocale
|
232 |
*/
|
233 |
public ExternalFrame(Dialog owner, String title, boolean modal) |
234 |
throws HeadlessException { |
235 |
super(owner, title, modal);
|
236 |
initFrame(); |
237 |
} |
238 |
|
239 |
/**
|
240 |
* Stores the minimum allowed size for this JDialog. If it is null, there
|
241 |
* is no minimum size for this window.
|
242 |
*/
|
243 |
Dimension minimumSize = null; |
244 |
|
245 |
/* (non-Javadoc)
|
246 |
* @see com.iver.core.mdiManager.frames.IFrame#setHeight(int)
|
247 |
*/
|
248 |
public void setHeight(int height) { |
249 |
super.setSize(getWidth(), height);
|
250 |
} |
251 |
|
252 |
/* (non-Javadoc)
|
253 |
* @see com.iver.core.mdiManager.frames.IFrame#setWidth(int)
|
254 |
*/
|
255 |
public void setWidth(int width) { |
256 |
super.setSize(width, getHeight());
|
257 |
} |
258 |
|
259 |
/* (non-Javadoc)
|
260 |
* @see com.iver.core.mdiManager.frames.IFrame#setX(int)
|
261 |
*/
|
262 |
public void setX(int x) { |
263 |
super.setLocation(x, getX());
|
264 |
} |
265 |
|
266 |
/* (non-Javadoc)
|
267 |
* @see com.iver.core.mdiManager.frames.IFrame#setY(int)
|
268 |
*/
|
269 |
public void setY(int y) { |
270 |
super.setLocation(y, getY());
|
271 |
} |
272 |
|
273 |
/* (non-Javadoc)
|
274 |
* @see com.iver.core.mdiManager.frames.IFrame#getMinimumSize()
|
275 |
*/
|
276 |
public Dimension getMinimumSize() { |
277 |
return minimumSize;
|
278 |
} |
279 |
|
280 |
/* (non-Javadoc)
|
281 |
* @see com.iver.core.mdiManager.frames.IFrame#setMinimumSize(java.awt.Dimension)
|
282 |
*/
|
283 |
public void setMinimumSize(Dimension minSize) { |
284 |
minimumSize = minSize; |
285 |
adjustToMinSize(); |
286 |
} |
287 |
|
288 |
/**
|
289 |
* Adjust the window to the minimum size, if necessary.
|
290 |
*/
|
291 |
private void adjustToMinSize() { |
292 |
if (minimumSize==null) return; |
293 |
int height, width;
|
294 |
Dimension currentSize = getSize();
|
295 |
boolean modified=false; |
296 |
|
297 |
if (currentSize.height < minimumSize.height) {
|
298 |
height = minimumSize.height; |
299 |
modified = true;
|
300 |
} |
301 |
else {
|
302 |
height = currentSize.height; |
303 |
} |
304 |
|
305 |
if (currentSize.width < minimumSize.width) {
|
306 |
width = minimumSize.width; |
307 |
modified = true;
|
308 |
} |
309 |
else {
|
310 |
width = currentSize.width; |
311 |
} |
312 |
if (modified) {
|
313 |
boolean isResizable = isResizable();
|
314 |
setResizable(false);
|
315 |
setSize(width, height); |
316 |
setResizable(isResizable); |
317 |
show(); |
318 |
} |
319 |
} |
320 |
|
321 |
public void componentHidden(ComponentEvent e) { |
322 |
// TODO Auto-generated method stub
|
323 |
|
324 |
} |
325 |
|
326 |
public void componentMoved(ComponentEvent e) { |
327 |
// TODO Auto-generated method stub
|
328 |
|
329 |
} |
330 |
|
331 |
public void componentResized(ComponentEvent e) { |
332 |
// this is necessary because in Java 1.4/1.5, JDialog doesn't have a
|
333 |
// setMinimum method. It's solved in 1.6, we'll remove this after migration.
|
334 |
adjustToMinSize(); |
335 |
|
336 |
} |
337 |
|
338 |
public void componentShown(ComponentEvent e) { |
339 |
// TODO Auto-generated method stub
|
340 |
|
341 |
} |
342 |
|
343 |
} |