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