svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / ToolsWindowManager.java @ 42266
History | View | Annotate | Download (5.79 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.andami.ui; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.GridBagConstraints; |
29 |
import java.awt.event.ComponentEvent; |
30 |
import java.awt.event.ComponentListener; |
31 |
import java.lang.reflect.InvocationTargetException; |
32 |
|
33 |
import javax.swing.JComponent; |
34 |
import javax.swing.JPanel; |
35 |
import javax.swing.SwingUtilities; |
36 |
|
37 |
import org.gvsig.andami.PluginServices; |
38 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
39 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
40 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
41 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
42 |
|
43 |
|
44 |
/**
|
45 |
* @author gvSIG Team
|
46 |
* @version $Id$
|
47 |
*
|
48 |
*/
|
49 |
public class ToolsWindowManager implements WindowManager { |
50 |
|
51 |
public void showWindow(JComponent contents, String title, MODE mode) { |
52 |
int align;
|
53 |
switch(mode) {
|
54 |
case DIALOG:
|
55 |
align = GridBagConstraints.CENTER;
|
56 |
break;
|
57 |
case TOOL:
|
58 |
align = GridBagConstraints.FIRST_LINE_END;
|
59 |
break;
|
60 |
case WINDOW:
|
61 |
default:
|
62 |
align = GridBagConstraints.FIRST_LINE_START;
|
63 |
break;
|
64 |
} |
65 |
showWindow(contents, title, mode, align); |
66 |
} |
67 |
|
68 |
public void showWindow(final JComponent contents, final String title, final MODE mode, final int align ) { |
69 |
if( !SwingUtilities.isEventDispatchThread() ) { |
70 |
switch(mode) {
|
71 |
case DIALOG:
|
72 |
{ |
73 |
try {
|
74 |
SwingUtilities.invokeAndWait(new Runnable() { |
75 |
public void run() { |
76 |
showWindow(contents, title, mode, align); |
77 |
} |
78 |
}); |
79 |
} catch (InterruptedException ex) { |
80 |
} catch (InvocationTargetException ex) { |
81 |
} |
82 |
} |
83 |
break;
|
84 |
case TOOL:
|
85 |
case WINDOW:
|
86 |
default:
|
87 |
SwingUtilities.invokeLater(new Runnable() { |
88 |
public void run() { |
89 |
showWindow(contents, title, mode, align); |
90 |
} |
91 |
}); |
92 |
break;
|
93 |
} |
94 |
return;
|
95 |
} |
96 |
MDIManager manager = PluginServices.getMDIManager(); |
97 |
IWindow window = new Window(contents, title, mode); |
98 |
manager.addWindow(window,align); |
99 |
} |
100 |
|
101 |
public class Window extends JPanel implements IWindow, ComponentListener { |
102 |
|
103 |
/**
|
104 |
*
|
105 |
*/
|
106 |
private static final long serialVersionUID = -6688594664366192449L; |
107 |
protected WindowInfo windowInfo;
|
108 |
protected Object profile; |
109 |
protected JComponent contents; |
110 |
|
111 |
public Window(JComponent contents, String title, MODE mode) { |
112 |
int code = WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE | WindowInfo.ICONIFIABLE;
|
113 |
switch(mode) {
|
114 |
case DIALOG:
|
115 |
code |= WindowInfo.MODALDIALOG; |
116 |
profile = WindowInfo.DIALOG_PROFILE; |
117 |
break;
|
118 |
case TOOL:
|
119 |
code |= WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE; |
120 |
profile = WindowInfo.TOOL_PROFILE; |
121 |
break;
|
122 |
case WINDOW:
|
123 |
default:
|
124 |
profile = WindowInfo.EDITOR_PROFILE; |
125 |
break;
|
126 |
} |
127 |
|
128 |
this.contents = contents;
|
129 |
|
130 |
this.windowInfo = new WindowInfo(code); |
131 |
this.windowInfo.setTitle(title);
|
132 |
this.windowInfo.setNeedPack(true); |
133 |
|
134 |
Dimension size = this.contents.getPreferredSize(); |
135 |
this.windowInfo.setHeight(size.height);
|
136 |
this.windowInfo.setWidth(size.width);
|
137 |
|
138 |
this.setLayout(new BorderLayout()); |
139 |
this.add(this.contents,BorderLayout.CENTER); |
140 |
|
141 |
this.contents.addComponentListener(this); |
142 |
} |
143 |
|
144 |
public void fireClosingWindow() { |
145 |
this.contents.removeComponentListener(this); |
146 |
ComponentListener[] l = this.contents.getComponentListeners(); |
147 |
for( int i=0; i<l.length; i++) { |
148 |
l[i].componentHidden(new ComponentEvent(this, i)); |
149 |
} |
150 |
} |
151 |
|
152 |
public WindowInfo getWindowInfo() {
|
153 |
return this.windowInfo; |
154 |
} |
155 |
|
156 |
public Object getWindowProfile() { |
157 |
return this.profile; |
158 |
} |
159 |
|
160 |
public void componentHidden(ComponentEvent arg0) { |
161 |
// Close window when hide contents panel.
|
162 |
MDIManager manager = PluginServices.getMDIManager(); |
163 |
manager.closeWindow(this);
|
164 |
} |
165 |
|
166 |
public void componentMoved(ComponentEvent arg0) { |
167 |
// Do nothing
|
168 |
} |
169 |
|
170 |
public void componentResized(ComponentEvent arg0) { |
171 |
// Do nothing
|
172 |
} |
173 |
|
174 |
public void componentShown(ComponentEvent arg0) { |
175 |
// Do nothing
|
176 |
} |
177 |
|
178 |
public JComponent getContents() { |
179 |
return this.contents; |
180 |
} |
181 |
|
182 |
} |
183 |
} |