svn-gvsig-desktop / tags / v1_1_Build_1013 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / manager / GeoprocessManager.java @ 13521
History | View | Annotate | Download (11.8 KB)
1 |
/*
|
---|---|
2 |
* Created on 23-jun-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: GeoprocessManager.java 13521 2007-09-04 14:02:46Z $
|
47 |
* $Log$
|
48 |
* Revision 1.8.2.3 2006-11-30 18:34:40 azabala
|
49 |
* bug fixed (This component must implements SingletonWindow instead of IWindow)
|
50 |
*
|
51 |
* Revision 1.8.2.2 2006/11/15 00:08:17 jjdelcerro
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.11 2006/11/14 18:46:36 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.10 2006/10/23 10:30:09 caballero
|
58 |
* soluci?n refresco selecci?n por segunda vez un mismo control
|
59 |
*
|
60 |
* Revision 1.9 2006/09/21 18:17:48 azabala
|
61 |
* fixed bug in JSplitPanel
|
62 |
*
|
63 |
* Revision 1.8 2006/08/29 07:56:30 cesar
|
64 |
* Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
65 |
*
|
66 |
* Revision 1.7 2006/08/29 07:13:56 cesar
|
67 |
* Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
|
68 |
*
|
69 |
* Revision 1.6 2006/08/11 16:30:38 azabala
|
70 |
* *** empty log message ***
|
71 |
*
|
72 |
* Revision 1.5 2006/07/21 09:32:01 azabala
|
73 |
* fixed bug 644: disabling ok button untill user select a geoprocess
|
74 |
*
|
75 |
* Revision 1.4 2006/07/04 16:42:37 azabala
|
76 |
* *** empty log message ***
|
77 |
*
|
78 |
* Revision 1.3 2006/06/27 16:16:49 azabala
|
79 |
* imports organization
|
80 |
*
|
81 |
* Revision 1.2 2006/06/27 16:15:08 azabala
|
82 |
* solved bug of packages replication (when added multiple geoprocesses to them)
|
83 |
*
|
84 |
* Revision 1.1 2006/06/23 19:03:52 azabala
|
85 |
* first version in cvs
|
86 |
*
|
87 |
*
|
88 |
*/
|
89 |
package com.iver.cit.gvsig.geoprocess.manager; |
90 |
|
91 |
import java.awt.BorderLayout; |
92 |
import java.awt.Dimension; |
93 |
import java.awt.event.ComponentAdapter; |
94 |
import java.awt.event.ComponentEvent; |
95 |
import java.awt.event.MouseAdapter; |
96 |
import java.awt.event.MouseEvent; |
97 |
import java.io.IOException; |
98 |
import java.net.URL; |
99 |
import java.util.TreeMap; |
100 |
|
101 |
import javax.swing.JButton; |
102 |
import javax.swing.JEditorPane; |
103 |
import javax.swing.JLabel; |
104 |
import javax.swing.JOptionPane; |
105 |
import javax.swing.JPanel; |
106 |
import javax.swing.JScrollPane; |
107 |
import javax.swing.JSeparator; |
108 |
import javax.swing.JSplitPane; |
109 |
import javax.swing.JTree; |
110 |
import javax.swing.event.TreeSelectionEvent; |
111 |
import javax.swing.event.TreeSelectionListener; |
112 |
import javax.swing.text.html.HTMLEditorKit; |
113 |
import javax.swing.tree.DefaultMutableTreeNode; |
114 |
import javax.swing.tree.TreePath; |
115 |
|
116 |
import com.iver.andami.PluginServices; |
117 |
import com.iver.andami.ui.mdiManager.IWindow; |
118 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
119 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
120 |
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessController; |
121 |
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessPlugin; |
122 |
import com.iver.cit.gvsig.geoprocess.core.gui.GeoprocessPaneContainer; |
123 |
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
124 |
import com.iver.cit.gvsig.geoprocess.manager.GeoprocessTree.GeoprocessTreeDirectory; |
125 |
|
126 |
/**
|
127 |
* Main panel of the Geoprocess Manager gui component.
|
128 |
*
|
129 |
* It has a tree where shows all geoprocesses structure, and
|
130 |
* buttons to open geoprocess' panel, and to close itself.
|
131 |
*
|
132 |
* It also listens for tree selection events.
|
133 |
*
|
134 |
* @author azabala
|
135 |
*
|
136 |
*/
|
137 |
public class GeoprocessManager extends JPanel |
138 |
implements SingletonWindow, TreeSelectionListener { |
139 |
|
140 |
/**
|
141 |
* Central panel wich has the geoprocess tree on left and
|
142 |
* the description panel on right
|
143 |
*/
|
144 |
JSplitPane jSplitPaneCenter;
|
145 |
/**
|
146 |
* Tree wich shows all registered geoprocesses
|
147 |
*/
|
148 |
private GeoprocessTree tree;
|
149 |
|
150 |
/**
|
151 |
* It wraps htmlPane
|
152 |
*/
|
153 |
private JScrollPane scrollHtml; |
154 |
/**
|
155 |
* Panel wich shows description of selected packages or
|
156 |
* geoprocesess
|
157 |
*/
|
158 |
private MyJEditorPane htmlPane;
|
159 |
/**
|
160 |
* It has the button "open geoprocess" and "close view"
|
161 |
*/
|
162 |
private JPanel jPanelButtons; |
163 |
|
164 |
/**
|
165 |
* Button to close the andami view
|
166 |
*/
|
167 |
private JButton jButtonClose; |
168 |
|
169 |
/**
|
170 |
* Button to open the selected geoprocess panel
|
171 |
*/
|
172 |
private JButton openGeoprocess; |
173 |
|
174 |
|
175 |
/**
|
176 |
* ViewInfo of andami
|
177 |
*/
|
178 |
private WindowInfo viewInfo;
|
179 |
|
180 |
/**
|
181 |
* It has all package descriptions
|
182 |
* (new plugins must register package descriptions
|
183 |
* here)
|
184 |
*/
|
185 |
private static TreeMap packageDescriptions = |
186 |
new TreeMap(); |
187 |
|
188 |
public static void registerPackageDescription(String pkgName, |
189 |
String description){
|
190 |
packageDescriptions.put(pkgName, description); |
191 |
} |
192 |
|
193 |
public static String getDescriptionFor(String pkgName){ |
194 |
return (String) packageDescriptions.get(pkgName); |
195 |
} |
196 |
|
197 |
/**
|
198 |
* This is the default constructor
|
199 |
*/
|
200 |
public GeoprocessManager() {
|
201 |
super();
|
202 |
initialize(); |
203 |
} |
204 |
|
205 |
|
206 |
public WindowInfo getWindowInfo() {
|
207 |
if (viewInfo == null) { |
208 |
viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG |
|
209 |
WindowInfo.RESIZABLE | |
210 |
WindowInfo.PALETTE); |
211 |
viewInfo.setTitle(PluginServices. |
212 |
getText(this, "Gestor_de_Geoprocesos")); |
213 |
viewInfo.setWidth(700);
|
214 |
viewInfo.setHeight(465);
|
215 |
} |
216 |
return viewInfo;
|
217 |
} |
218 |
|
219 |
/**
|
220 |
* This method initializes this
|
221 |
*
|
222 |
* @return void
|
223 |
*/
|
224 |
private void initialize() { |
225 |
this.setLayout(new BorderLayout()); |
226 |
add(getJSplitPaneCenter(), BorderLayout.CENTER);
|
227 |
getJSplitPaneCenter().setLeftComponent(getGeoprocessTree()); |
228 |
getJSplitPaneCenter().setRightComponent(getHtmlPane()); |
229 |
add(getJPanelButtons(), BorderLayout.SOUTH);
|
230 |
this.setSize(700, 525); |
231 |
/*
|
232 |
* see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4182558
|
233 |
* JSplitPane doesnt care setDividerLocation calls before
|
234 |
* its container would be visible
|
235 |
*
|
236 |
* */
|
237 |
getJSplitPaneCenter().addComponentListener( new ComponentAdapter() { |
238 |
public void componentResized( ComponentEvent event ) { |
239 |
getJSplitPaneCenter().setDividerLocation(0.35);
|
240 |
getJSplitPaneCenter().removeComponentListener( this );
|
241 |
} |
242 |
} ); |
243 |
|
244 |
} |
245 |
|
246 |
private JSplitPane getJSplitPaneCenter() { |
247 |
if (jSplitPaneCenter == null) { |
248 |
jSplitPaneCenter = new JSplitPane(); |
249 |
} |
250 |
return jSplitPaneCenter;
|
251 |
} |
252 |
|
253 |
|
254 |
private GeoprocessTree getGeoprocessTree() {
|
255 |
if(tree == null){ |
256 |
tree = new GeoprocessTree();
|
257 |
tree.addTreeSelectionListener(this);
|
258 |
tree.addMouseListener(new GeopTreeMouseListener());
|
259 |
} |
260 |
return tree;
|
261 |
} |
262 |
|
263 |
class GeopTreeMouseListener extends MouseAdapter{ |
264 |
|
265 |
public void mousePressed(MouseEvent e){ |
266 |
JTree tree = (JTree) e.getSource(); |
267 |
TreePath tp = tree.getPathForLocation(e.getX(),e.getY());
|
268 |
if (tp == null) return; |
269 |
int clicks = e.getClickCount();
|
270 |
if (clicks == 2) |
271 |
{ |
272 |
Object o = ((DefaultMutableTreeNode)tp. |
273 |
getLastPathComponent()). |
274 |
getUserObject(); |
275 |
if(!(o instanceof IGeoprocessPlugin)) |
276 |
return;
|
277 |
IGeoprocessPlugin geoprocess = |
278 |
(IGeoprocessPlugin) o; |
279 |
if(geoprocess == null){ |
280 |
String error = PluginServices.
|
281 |
getText(this, "Error_seleccionar_gp"); |
282 |
String errorDescription = PluginServices.
|
283 |
getText(this, "Error_seleccionar_gp_desc"); |
284 |
JOptionPane.showMessageDialog(GeoprocessManager.this,
|
285 |
errorDescription, error, |
286 |
JOptionPane.ERROR_MESSAGE);
|
287 |
} |
288 |
IGeoprocessPanel panel = |
289 |
geoprocess.getGeoprocessPanel(); |
290 |
GeoprocessPaneContainer container = new
|
291 |
GeoprocessPaneContainer((JPanel)panel);
|
292 |
IGeoprocessController controller = |
293 |
geoprocess.getGpController(); |
294 |
controller.setView(panel); |
295 |
container.setCommand(controller); |
296 |
container.validate(); |
297 |
container.repaint(); |
298 |
PluginServices.getMDIManager().addWindow(container); |
299 |
}//if
|
300 |
} |
301 |
} |
302 |
|
303 |
|
304 |
private JScrollPane getHtmlPane(){ |
305 |
if(scrollHtml == null){ |
306 |
scrollHtml = new JScrollPane(); |
307 |
htmlPane = new MyJEditorPane();
|
308 |
htmlPane.setEditable(false);
|
309 |
htmlPane.setEditorKit(new HTMLEditorKit()); |
310 |
scrollHtml.setViewportView(htmlPane); |
311 |
|
312 |
} |
313 |
return scrollHtml;
|
314 |
} |
315 |
|
316 |
private JPanel getJPanelButtons() { |
317 |
if (jPanelButtons == null) { |
318 |
jPanelButtons = new JPanel(new BorderLayout()); |
319 |
JPanel jPanelAux = new JPanel(); |
320 |
JLabel l = new JLabel(); |
321 |
l.setPreferredSize(new Dimension(40, 20)); |
322 |
jPanelButtons.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.NORTH); |
323 |
jPanelAux.add(getJButtonOpenGeop(), BorderLayout.WEST);
|
324 |
jPanelAux.add(l, BorderLayout.CENTER);
|
325 |
jPanelAux.add(getJButtonClose(), BorderLayout.EAST);
|
326 |
|
327 |
jPanelButtons.add(jPanelAux); |
328 |
} |
329 |
return jPanelButtons;
|
330 |
} |
331 |
|
332 |
public void openGeoprocessPanel(){ |
333 |
IGeoprocessPlugin geoprocess = |
334 |
tree.getGeoprocess(); |
335 |
if(geoprocess == null){ |
336 |
String error = PluginServices.
|
337 |
getText(this, "Error_seleccionar_gp"); |
338 |
String errorDescription = PluginServices.
|
339 |
getText(this, "Error_seleccionar_gp_desc"); |
340 |
JOptionPane.showMessageDialog(this, errorDescription, error, |
341 |
JOptionPane.ERROR_MESSAGE);
|
342 |
return;
|
343 |
} |
344 |
IGeoprocessPanel panel = |
345 |
geoprocess.getGeoprocessPanel(); |
346 |
GeoprocessPaneContainer container = new
|
347 |
GeoprocessPaneContainer((JPanel)panel);
|
348 |
IGeoprocessController controller = |
349 |
geoprocess.getGpController(); |
350 |
controller.setView(panel); |
351 |
container.setCommand(controller); |
352 |
container.validate(); |
353 |
container.repaint(); |
354 |
PluginServices.getMDIManager().addWindow(container); |
355 |
} |
356 |
|
357 |
private JButton getJButtonOpenGeop() { |
358 |
if (openGeoprocess == null) { |
359 |
openGeoprocess = new JButton(); |
360 |
openGeoprocess.setText(PluginServices.getText(this, "Abrir_Geoproceso")); |
361 |
openGeoprocess.addActionListener(new java.awt.event.ActionListener() {
|
362 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
363 |
openGeoprocessPanel(); |
364 |
} |
365 |
}); |
366 |
//it will be disabled until user select a geoprocess
|
367 |
//in the tree
|
368 |
openGeoprocess.setEnabled(false);
|
369 |
} |
370 |
return openGeoprocess;
|
371 |
} |
372 |
|
373 |
|
374 |
private JButton getJButtonClose() { |
375 |
if (jButtonClose == null) { |
376 |
jButtonClose = new JButton(); |
377 |
jButtonClose.setText(PluginServices.getText(this, "Cerrar")); |
378 |
jButtonClose.addActionListener(new java.awt.event.ActionListener() {
|
379 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
380 |
PluginServices. |
381 |
getMDIManager(). |
382 |
closeWindow(GeoprocessManager.this); |
383 |
|
384 |
} |
385 |
}); |
386 |
} |
387 |
return jButtonClose;
|
388 |
} |
389 |
|
390 |
|
391 |
|
392 |
/**
|
393 |
* processes tree selection events.
|
394 |
*/
|
395 |
public void valueChanged(TreeSelectionEvent event) { |
396 |
DefaultMutableTreeNode selectedNode =
|
397 |
(DefaultMutableTreeNode) event.getPath().
|
398 |
getLastPathComponent(); |
399 |
Object userObject = selectedNode.getUserObject();
|
400 |
if(userObject instanceof IGeoprocessPlugin){ |
401 |
IGeoprocessPlugin metadata = |
402 |
(IGeoprocessPlugin)userObject; |
403 |
try {
|
404 |
htmlPane.setPage(metadata.getHtmlDescription().toString()); |
405 |
} catch (Exception e) { |
406 |
htmlPane.setText("<p>Descripcion no disponible</p>");
|
407 |
} |
408 |
getJButtonOpenGeop().setEnabled(true);
|
409 |
}else{
|
410 |
GeoprocessTreeDirectory directory = |
411 |
(GeoprocessTreeDirectory)userObject; |
412 |
htmlPane.setText("<p>"+
|
413 |
directory.getDescription()+ |
414 |
"</p>");
|
415 |
getJButtonOpenGeop().setEnabled(false);
|
416 |
} |
417 |
} |
418 |
private class MyJEditorPane extends JEditorPane{ |
419 |
|
420 |
public URL getPage() { |
421 |
return null; |
422 |
} |
423 |
|
424 |
} |
425 |
|
426 |
|
427 |
public Object getWindowModel() { |
428 |
return getClass();
|
429 |
} |
430 |
|
431 |
} // @jve:decl-index=0:visual-constraint="10,10"
|