svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / manager / GeoprocessManager.java @ 10626
History | View | Annotate | Download (11.5 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 10626 2007-03-06 16:55:54Z caballero $
|
47 |
* $Log$
|
48 |
* Revision 1.13 2007-03-06 16:47:58 caballero
|
49 |
* Exceptions
|
50 |
*
|
51 |
* Revision 1.12 2006/11/30 18:26:04 azabala
|
52 |
* bug fixed (this component must be SingletonView)
|
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.net.URL; |
98 |
import java.util.TreeMap; |
99 |
|
100 |
import javax.swing.JButton; |
101 |
import javax.swing.JEditorPane; |
102 |
import javax.swing.JLabel; |
103 |
import javax.swing.JOptionPane; |
104 |
import javax.swing.JPanel; |
105 |
import javax.swing.JScrollPane; |
106 |
import javax.swing.JSeparator; |
107 |
import javax.swing.JSplitPane; |
108 |
import javax.swing.JTree; |
109 |
import javax.swing.event.TreeSelectionEvent; |
110 |
import javax.swing.event.TreeSelectionListener; |
111 |
import javax.swing.text.html.HTMLEditorKit; |
112 |
import javax.swing.tree.DefaultMutableTreeNode; |
113 |
import javax.swing.tree.TreePath; |
114 |
|
115 |
import com.iver.andami.PluginServices; |
116 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
117 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
118 |
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessController; |
119 |
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessPlugin; |
120 |
import com.iver.cit.gvsig.geoprocess.core.gui.GeoprocessPaneContainer; |
121 |
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
122 |
import com.iver.cit.gvsig.geoprocess.manager.GeoprocessTree.GeoprocessTreeDirectory; |
123 |
|
124 |
/**
|
125 |
* Main panel of the Geoprocess Manager gui component.
|
126 |
*
|
127 |
* It has a tree where shows all geoprocesses structure, and buttons to open
|
128 |
* geoprocess' panel, and to close itself.
|
129 |
*
|
130 |
* It also listens for tree selection events.
|
131 |
*
|
132 |
* @author azabala
|
133 |
*
|
134 |
*/
|
135 |
public class GeoprocessManager extends JPanel implements SingletonWindow, |
136 |
TreeSelectionListener {
|
137 |
|
138 |
/**
|
139 |
* Central panel wich has the geoprocess tree on left and the description
|
140 |
* panel on right
|
141 |
*/
|
142 |
JSplitPane jSplitPaneCenter;
|
143 |
|
144 |
/**
|
145 |
* Tree wich shows all registered geoprocesses
|
146 |
*/
|
147 |
private GeoprocessTree tree;
|
148 |
|
149 |
/**
|
150 |
* It wraps htmlPane
|
151 |
*/
|
152 |
private JScrollPane scrollHtml; |
153 |
|
154 |
/**
|
155 |
* Panel wich shows description of selected packages or geoprocesess
|
156 |
*/
|
157 |
private MyJEditorPane htmlPane;
|
158 |
|
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 |
* ViewInfo of andami
|
176 |
*/
|
177 |
private WindowInfo viewInfo;
|
178 |
|
179 |
/**
|
180 |
* It has all package descriptions (new plugins must register package
|
181 |
* descriptions here)
|
182 |
*/
|
183 |
private static TreeMap packageDescriptions = new TreeMap(); |
184 |
|
185 |
public static void registerPackageDescription(String pkgName, |
186 |
String description) {
|
187 |
packageDescriptions.put(pkgName, description); |
188 |
} |
189 |
|
190 |
public static String getDescriptionFor(String pkgName) { |
191 |
return (String) packageDescriptions.get(pkgName); |
192 |
} |
193 |
|
194 |
/**
|
195 |
* This is the default constructor
|
196 |
*/
|
197 |
public GeoprocessManager() {
|
198 |
super();
|
199 |
initialize(); |
200 |
} |
201 |
|
202 |
public WindowInfo getWindowInfo() {
|
203 |
if (viewInfo == null) { |
204 |
viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG
|
205 |
| WindowInfo.RESIZABLE | WindowInfo.PALETTE); |
206 |
viewInfo.setTitle(PluginServices.getText(this,
|
207 |
"Gestor_de_Geoprocesos"));
|
208 |
viewInfo.setWidth(700);
|
209 |
viewInfo.setHeight(465);
|
210 |
} |
211 |
return viewInfo;
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* This method initializes this
|
216 |
*
|
217 |
* @return void
|
218 |
*/
|
219 |
private void initialize() { |
220 |
this.setLayout(new BorderLayout()); |
221 |
add(getJSplitPaneCenter(), BorderLayout.CENTER);
|
222 |
getJSplitPaneCenter().setLeftComponent(getGeoprocessTree()); |
223 |
getJSplitPaneCenter().setRightComponent(getHtmlPane()); |
224 |
add(getJPanelButtons(), BorderLayout.SOUTH);
|
225 |
this.setSize(700, 525); |
226 |
/*
|
227 |
* see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4182558
|
228 |
* JSplitPane doesnt care setDividerLocation calls before its container
|
229 |
* would be visible
|
230 |
*
|
231 |
*/
|
232 |
getJSplitPaneCenter().addComponentListener(new ComponentAdapter() { |
233 |
public void componentResized(ComponentEvent event) { |
234 |
getJSplitPaneCenter().setDividerLocation(0.35);
|
235 |
getJSplitPaneCenter().removeComponentListener(this);
|
236 |
} |
237 |
}); |
238 |
|
239 |
} |
240 |
|
241 |
private JSplitPane getJSplitPaneCenter() { |
242 |
if (jSplitPaneCenter == null) { |
243 |
jSplitPaneCenter = new JSplitPane(); |
244 |
} |
245 |
return jSplitPaneCenter;
|
246 |
} |
247 |
|
248 |
private GeoprocessTree getGeoprocessTree() {
|
249 |
if (tree == null) { |
250 |
tree = new GeoprocessTree();
|
251 |
tree.addTreeSelectionListener(this);
|
252 |
tree.addMouseListener(new GeopTreeMouseListener());
|
253 |
} |
254 |
return tree;
|
255 |
} |
256 |
|
257 |
class GeopTreeMouseListener extends MouseAdapter { |
258 |
|
259 |
public void mousePressed(MouseEvent e) { |
260 |
JTree tree = (JTree) e.getSource(); |
261 |
TreePath tp = tree.getPathForLocation(e.getX(), e.getY());
|
262 |
if (tp == null) |
263 |
return;
|
264 |
int clicks = e.getClickCount();
|
265 |
if (clicks == 2) { |
266 |
Object o = ((DefaultMutableTreeNode) tp.getLastPathComponent()) |
267 |
.getUserObject(); |
268 |
if (!(o instanceof IGeoprocessPlugin)) |
269 |
return;
|
270 |
IGeoprocessPlugin geoprocess = (IGeoprocessPlugin) o; |
271 |
if (geoprocess == null) { |
272 |
String error = PluginServices.getText(this, |
273 |
"Error_seleccionar_gp");
|
274 |
String errorDescription = PluginServices.getText(this, |
275 |
"Error_seleccionar_gp_desc");
|
276 |
JOptionPane.showMessageDialog(GeoprocessManager.this,
|
277 |
errorDescription, error, JOptionPane.ERROR_MESSAGE);
|
278 |
} |
279 |
IGeoprocessPanel panel = geoprocess.getGeoprocessPanel(); |
280 |
GeoprocessPaneContainer container = new GeoprocessPaneContainer(
|
281 |
(JPanel) panel);
|
282 |
IGeoprocessController controller = geoprocess.getGpController(); |
283 |
controller.setView(panel); |
284 |
container.setCommand(controller); |
285 |
container.validate(); |
286 |
container.repaint(); |
287 |
PluginServices.getMDIManager().addWindow(container); |
288 |
}// if
|
289 |
} |
290 |
} |
291 |
|
292 |
private JScrollPane getHtmlPane() { |
293 |
if (scrollHtml == null) { |
294 |
scrollHtml = new JScrollPane(); |
295 |
htmlPane = new MyJEditorPane();
|
296 |
htmlPane.setEditable(false);
|
297 |
htmlPane.setEditorKit(new HTMLEditorKit()); |
298 |
scrollHtml.setViewportView(htmlPane); |
299 |
|
300 |
} |
301 |
return scrollHtml;
|
302 |
} |
303 |
|
304 |
private JPanel getJPanelButtons() { |
305 |
if (jPanelButtons == null) { |
306 |
jPanelButtons = new JPanel(new BorderLayout()); |
307 |
JPanel jPanelAux = new JPanel(); |
308 |
JLabel l = new JLabel(); |
309 |
l.setPreferredSize(new Dimension(40, 20)); |
310 |
jPanelButtons.add(new JSeparator(JSeparator.HORIZONTAL), |
311 |
BorderLayout.NORTH);
|
312 |
jPanelAux.add(getJButtonOpenGeop(), BorderLayout.WEST);
|
313 |
jPanelAux.add(l, BorderLayout.CENTER);
|
314 |
jPanelAux.add(getJButtonClose(), BorderLayout.EAST);
|
315 |
|
316 |
jPanelButtons.add(jPanelAux); |
317 |
} |
318 |
return jPanelButtons;
|
319 |
} |
320 |
|
321 |
public void openGeoprocessPanel() { |
322 |
IGeoprocessPlugin geoprocess = tree.getGeoprocess(); |
323 |
if (geoprocess == null) { |
324 |
String error = PluginServices.getText(this, "Error_seleccionar_gp"); |
325 |
String errorDescription = PluginServices.getText(this, |
326 |
"Error_seleccionar_gp_desc");
|
327 |
JOptionPane.showMessageDialog(this, errorDescription, error, |
328 |
JOptionPane.ERROR_MESSAGE);
|
329 |
return;
|
330 |
} |
331 |
IGeoprocessPanel panel = geoprocess.getGeoprocessPanel(); |
332 |
GeoprocessPaneContainer container = new GeoprocessPaneContainer(
|
333 |
(JPanel) panel);
|
334 |
IGeoprocessController controller = geoprocess.getGpController(); |
335 |
controller.setView(panel); |
336 |
container.setCommand(controller); |
337 |
container.validate(); |
338 |
container.repaint(); |
339 |
PluginServices.getMDIManager().addWindow(container); |
340 |
} |
341 |
|
342 |
private JButton getJButtonOpenGeop() { |
343 |
if (openGeoprocess == null) { |
344 |
openGeoprocess = new JButton(); |
345 |
openGeoprocess.setText(PluginServices.getText(this,
|
346 |
"Abrir_Geoproceso"));
|
347 |
openGeoprocess |
348 |
.addActionListener(new java.awt.event.ActionListener() {
|
349 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
350 |
openGeoprocessPanel(); |
351 |
} |
352 |
}); |
353 |
// it will be disabled until user select a geoprocess
|
354 |
// in the tree
|
355 |
openGeoprocess.setEnabled(false);
|
356 |
} |
357 |
return openGeoprocess;
|
358 |
} |
359 |
|
360 |
private JButton getJButtonClose() { |
361 |
if (jButtonClose == null) { |
362 |
jButtonClose = new JButton(); |
363 |
jButtonClose.setText(PluginServices.getText(this, "Cerrar")); |
364 |
jButtonClose.addActionListener(new java.awt.event.ActionListener() {
|
365 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
366 |
PluginServices.getMDIManager().closeWindow( |
367 |
GeoprocessManager.this); |
368 |
|
369 |
} |
370 |
}); |
371 |
} |
372 |
return jButtonClose;
|
373 |
} |
374 |
|
375 |
/**
|
376 |
* processes tree selection events.
|
377 |
*/
|
378 |
public void valueChanged(TreeSelectionEvent event) { |
379 |
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) event |
380 |
.getPath().getLastPathComponent(); |
381 |
Object userObject = selectedNode.getUserObject();
|
382 |
if (userObject instanceof IGeoprocessPlugin) { |
383 |
IGeoprocessPlugin metadata = (IGeoprocessPlugin) userObject; |
384 |
try {
|
385 |
htmlPane.setPage(metadata.getHtmlDescription().toString()); |
386 |
} catch (Exception e) { |
387 |
htmlPane.setText("<p>Descripcion no disponible</p>");
|
388 |
} |
389 |
getJButtonOpenGeop().setEnabled(true);
|
390 |
} else {
|
391 |
GeoprocessTreeDirectory directory = (GeoprocessTreeDirectory) userObject; |
392 |
htmlPane.setText("<p>" + directory.getDescription() + "</p>"); |
393 |
getJButtonOpenGeop().setEnabled(false);
|
394 |
} |
395 |
} |
396 |
|
397 |
private class MyJEditorPane extends JEditorPane { |
398 |
|
399 |
public URL getPage() { |
400 |
return null; |
401 |
} |
402 |
|
403 |
} |
404 |
|
405 |
public Object getWindowModel() { |
406 |
return this.getClass(); |
407 |
} |
408 |
|
409 |
} // @jve:decl-index=0:visual-constraint="10,10"
|