root / tags / v10_RC2c / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / manager / GeoprocessManager.java @ 8745
History | View | Annotate | Download (11.3 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 8745 2006-11-14 13:14:23Z $
|
47 |
* $Log$
|
48 |
* Revision 1.8.2.1 2006-09-15 15:08:30 azabala
|
49 |
* a bug in JSplitPane makes it ignore setDividerLocation calls. fixed it with a tricky workaround
|
50 |
*
|
51 |
* Revision 1.8 2006/08/29 07:56:30 cesar
|
52 |
* Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
53 |
*
|
54 |
* Revision 1.7 2006/08/29 07:13:56 cesar
|
55 |
* Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
|
56 |
*
|
57 |
* Revision 1.6 2006/08/11 16:30:38 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.5 2006/07/21 09:32:01 azabala
|
61 |
* fixed bug 644: disabling ok button untill user select a geoprocess
|
62 |
*
|
63 |
* Revision 1.4 2006/07/04 16:42:37 azabala
|
64 |
* *** empty log message ***
|
65 |
*
|
66 |
* Revision 1.3 2006/06/27 16:16:49 azabala
|
67 |
* imports organization
|
68 |
*
|
69 |
* Revision 1.2 2006/06/27 16:15:08 azabala
|
70 |
* solved bug of packages replication (when added multiple geoprocesses to them)
|
71 |
*
|
72 |
* Revision 1.1 2006/06/23 19:03:52 azabala
|
73 |
* first version in cvs
|
74 |
*
|
75 |
*
|
76 |
*/
|
77 |
package com.iver.cit.gvsig.geoprocess.manager; |
78 |
|
79 |
import java.awt.BorderLayout; |
80 |
import java.awt.Dimension; |
81 |
import java.awt.event.ComponentAdapter; |
82 |
import java.awt.event.ComponentEvent; |
83 |
import java.awt.event.MouseAdapter; |
84 |
import java.awt.event.MouseEvent; |
85 |
import java.io.IOException; |
86 |
import java.util.TreeMap; |
87 |
|
88 |
import javax.swing.JButton; |
89 |
import javax.swing.JEditorPane; |
90 |
import javax.swing.JLabel; |
91 |
import javax.swing.JOptionPane; |
92 |
import javax.swing.JPanel; |
93 |
import javax.swing.JScrollPane; |
94 |
import javax.swing.JSeparator; |
95 |
import javax.swing.JSplitPane; |
96 |
import javax.swing.JTree; |
97 |
import javax.swing.event.TreeSelectionEvent; |
98 |
import javax.swing.event.TreeSelectionListener; |
99 |
import javax.swing.text.html.HTMLEditorKit; |
100 |
import javax.swing.tree.DefaultMutableTreeNode; |
101 |
import javax.swing.tree.TreePath; |
102 |
|
103 |
import com.iver.andami.PluginServices; |
104 |
import com.iver.andami.ui.mdiManager.IWindow; |
105 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
106 |
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessController; |
107 |
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessPlugin; |
108 |
import com.iver.cit.gvsig.geoprocess.core.gui.GeoprocessPaneContainer; |
109 |
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
110 |
import com.iver.cit.gvsig.geoprocess.manager.GeoprocessTree.GeoprocessTreeDirectory; |
111 |
|
112 |
/**
|
113 |
* Main panel of the Geoprocess Manager gui component.
|
114 |
*
|
115 |
* It has a tree where shows all geoprocesses structure, and
|
116 |
* buttons to open geoprocess' panel, and to close itself.
|
117 |
*
|
118 |
* It also listens for tree selection events.
|
119 |
*
|
120 |
* @author azabala
|
121 |
*
|
122 |
*/
|
123 |
public class GeoprocessManager extends JPanel |
124 |
implements IWindow, TreeSelectionListener { |
125 |
|
126 |
/**
|
127 |
* Central panel wich has the geoprocess tree on left and
|
128 |
* the description panel on right
|
129 |
*/
|
130 |
JSplitPane jSplitPaneCenter;
|
131 |
/**
|
132 |
* Tree wich shows all registered geoprocesses
|
133 |
*/
|
134 |
private GeoprocessTree tree;
|
135 |
|
136 |
/**
|
137 |
* It wraps htmlPane
|
138 |
*/
|
139 |
private JScrollPane scrollHtml; |
140 |
/**
|
141 |
* Panel wich shows description of selected packages or
|
142 |
* geoprocesess
|
143 |
*/
|
144 |
private JEditorPane htmlPane; |
145 |
/**
|
146 |
* It has the button "open geoprocess" and "close view"
|
147 |
*/
|
148 |
private JPanel jPanelButtons; |
149 |
|
150 |
/**
|
151 |
* Button to close the andami view
|
152 |
*/
|
153 |
private JButton jButtonClose; |
154 |
|
155 |
/**
|
156 |
* Button to open the selected geoprocess panel
|
157 |
*/
|
158 |
private JButton openGeoprocess; |
159 |
|
160 |
|
161 |
/**
|
162 |
* ViewInfo of andami
|
163 |
*/
|
164 |
private WindowInfo viewInfo;
|
165 |
|
166 |
/**
|
167 |
* It has all package descriptions
|
168 |
* (new plugins must register package descriptions
|
169 |
* here)
|
170 |
*/
|
171 |
private static TreeMap packageDescriptions = |
172 |
new TreeMap(); |
173 |
|
174 |
public static void registerPackageDescription(String pkgName, |
175 |
String description){
|
176 |
packageDescriptions.put(pkgName, description); |
177 |
} |
178 |
|
179 |
public static String getDescriptionFor(String pkgName){ |
180 |
return (String) packageDescriptions.get(pkgName); |
181 |
} |
182 |
|
183 |
/**
|
184 |
* This is the default constructor
|
185 |
*/
|
186 |
public GeoprocessManager() {
|
187 |
super();
|
188 |
initialize(); |
189 |
} |
190 |
|
191 |
|
192 |
public WindowInfo getWindowInfo() {
|
193 |
if (viewInfo == null) { |
194 |
viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG |
|
195 |
WindowInfo.RESIZABLE | |
196 |
WindowInfo.PALETTE); |
197 |
viewInfo.setTitle(PluginServices. |
198 |
getText(this, "Gestor_de_Geoprocesos")); |
199 |
viewInfo.setWidth(700);
|
200 |
viewInfo.setHeight(465);
|
201 |
} |
202 |
return viewInfo;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* This method initializes this
|
207 |
*
|
208 |
* @return void
|
209 |
*/
|
210 |
private void initialize() { |
211 |
this.setLayout(new BorderLayout()); |
212 |
add(getJSplitPaneCenter(), BorderLayout.CENTER);
|
213 |
getJSplitPaneCenter().setLeftComponent(getGeoprocessTree()); |
214 |
getJSplitPaneCenter().setRightComponent(getHtmlPane()); |
215 |
add(getJPanelButtons(), BorderLayout.SOUTH);
|
216 |
this.setSize(700, 525); |
217 |
/*
|
218 |
* see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4182558
|
219 |
* JSplitPane doesnt care setDividerLocation calls before
|
220 |
* its container would be visible
|
221 |
*
|
222 |
* */
|
223 |
getJSplitPaneCenter().addComponentListener( new ComponentAdapter() { |
224 |
public void componentResized( ComponentEvent event ) { |
225 |
getJSplitPaneCenter().setDividerLocation(0.35);
|
226 |
getJSplitPaneCenter().removeComponentListener( this );
|
227 |
} |
228 |
} ); |
229 |
|
230 |
} |
231 |
|
232 |
private JSplitPane getJSplitPaneCenter() { |
233 |
if (jSplitPaneCenter == null) { |
234 |
jSplitPaneCenter = new JSplitPane(); |
235 |
} |
236 |
return jSplitPaneCenter;
|
237 |
} |
238 |
|
239 |
|
240 |
private GeoprocessTree getGeoprocessTree() {
|
241 |
if(tree == null){ |
242 |
tree = new GeoprocessTree();
|
243 |
tree.addTreeSelectionListener(this);
|
244 |
tree.addMouseListener(new GeopTreeMouseListener());
|
245 |
} |
246 |
return tree;
|
247 |
} |
248 |
|
249 |
class GeopTreeMouseListener extends MouseAdapter{ |
250 |
|
251 |
public void mousePressed(MouseEvent e){ |
252 |
JTree tree = (JTree) e.getSource(); |
253 |
TreePath tp = tree.getPathForLocation(e.getX(),e.getY());
|
254 |
if (tp == null) return; |
255 |
int clicks = e.getClickCount();
|
256 |
if (clicks == 2) |
257 |
{ |
258 |
Object o = ((DefaultMutableTreeNode)tp. |
259 |
getLastPathComponent()). |
260 |
getUserObject(); |
261 |
if(!(o instanceof IGeoprocessPlugin)) |
262 |
return;
|
263 |
IGeoprocessPlugin geoprocess = |
264 |
(IGeoprocessPlugin) o; |
265 |
if(geoprocess == null){ |
266 |
String error = PluginServices.
|
267 |
getText(this, "Error_seleccionar_gp"); |
268 |
String errorDescription = PluginServices.
|
269 |
getText(this, "Error_seleccionar_gp_desc"); |
270 |
JOptionPane.showMessageDialog(GeoprocessManager.this,
|
271 |
errorDescription, error, |
272 |
JOptionPane.ERROR_MESSAGE);
|
273 |
} |
274 |
IGeoprocessPanel panel = |
275 |
geoprocess.getGeoprocessPanel(); |
276 |
GeoprocessPaneContainer container = new
|
277 |
GeoprocessPaneContainer((JPanel)panel);
|
278 |
IGeoprocessController controller = |
279 |
geoprocess.getGpController(); |
280 |
controller.setView(panel); |
281 |
container.setCommand(controller); |
282 |
container.validate(); |
283 |
container.repaint(); |
284 |
PluginServices.getMDIManager().addWindow(container); |
285 |
}//if
|
286 |
} |
287 |
} |
288 |
|
289 |
|
290 |
private JScrollPane getHtmlPane(){ |
291 |
if(scrollHtml == null){ |
292 |
scrollHtml = new JScrollPane(); |
293 |
htmlPane = new JEditorPane(); |
294 |
htmlPane.setEditable(false);
|
295 |
htmlPane.setEditorKit(new HTMLEditorKit()); |
296 |
scrollHtml.setViewportView(htmlPane); |
297 |
|
298 |
} |
299 |
return scrollHtml;
|
300 |
} |
301 |
|
302 |
private JPanel getJPanelButtons() { |
303 |
if (jPanelButtons == null) { |
304 |
jPanelButtons = new JPanel(new BorderLayout()); |
305 |
JPanel jPanelAux = new JPanel(); |
306 |
JLabel l = new JLabel(); |
307 |
l.setPreferredSize(new Dimension(40, 20)); |
308 |
jPanelButtons.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.NORTH); |
309 |
jPanelAux.add(getJButtonOpenGeop(), BorderLayout.WEST);
|
310 |
jPanelAux.add(l, BorderLayout.CENTER);
|
311 |
jPanelAux.add(getJButtonClose(), BorderLayout.EAST);
|
312 |
|
313 |
jPanelButtons.add(jPanelAux); |
314 |
} |
315 |
return jPanelButtons;
|
316 |
} |
317 |
|
318 |
public void openGeoprocessPanel(){ |
319 |
IGeoprocessPlugin geoprocess = |
320 |
tree.getGeoprocess(); |
321 |
if(geoprocess == null){ |
322 |
String error = PluginServices.
|
323 |
getText(this, "Error_seleccionar_gp"); |
324 |
String errorDescription = PluginServices.
|
325 |
getText(this, "Error_seleccionar_gp_desc"); |
326 |
JOptionPane.showMessageDialog(this, errorDescription, error, |
327 |
JOptionPane.ERROR_MESSAGE);
|
328 |
return;
|
329 |
} |
330 |
IGeoprocessPanel panel = |
331 |
geoprocess.getGeoprocessPanel(); |
332 |
GeoprocessPaneContainer container = new
|
333 |
GeoprocessPaneContainer((JPanel)panel);
|
334 |
IGeoprocessController controller = |
335 |
geoprocess.getGpController(); |
336 |
controller.setView(panel); |
337 |
container.setCommand(controller); |
338 |
container.validate(); |
339 |
container.repaint(); |
340 |
PluginServices.getMDIManager().addWindow(container); |
341 |
} |
342 |
|
343 |
private JButton getJButtonOpenGeop() { |
344 |
if (openGeoprocess == null) { |
345 |
openGeoprocess = new JButton(); |
346 |
openGeoprocess.setText(PluginServices.getText(this, "Abrir_Geoproceso")); |
347 |
openGeoprocess.addActionListener(new java.awt.event.ActionListener() {
|
348 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
349 |
openGeoprocessPanel(); |
350 |
} |
351 |
}); |
352 |
//it will be disabled until user select a geoprocess
|
353 |
//in the tree
|
354 |
openGeoprocess.setEnabled(false);
|
355 |
} |
356 |
return openGeoprocess;
|
357 |
} |
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. |
367 |
getMDIManager(). |
368 |
closeWindow(GeoprocessManager.this); |
369 |
|
370 |
} |
371 |
}); |
372 |
} |
373 |
return jButtonClose;
|
374 |
} |
375 |
|
376 |
|
377 |
|
378 |
/**
|
379 |
* processes tree selection events.
|
380 |
*/
|
381 |
public void valueChanged(TreeSelectionEvent event) { |
382 |
DefaultMutableTreeNode selectedNode =
|
383 |
(DefaultMutableTreeNode) event.getPath().
|
384 |
getLastPathComponent(); |
385 |
Object userObject = selectedNode.getUserObject();
|
386 |
if(userObject instanceof IGeoprocessPlugin){ |
387 |
IGeoprocessPlugin metadata = |
388 |
(IGeoprocessPlugin)userObject; |
389 |
try {
|
390 |
htmlPane.setPage(metadata.getHtmlDescription()); |
391 |
} catch (IOException e) { |
392 |
htmlPane.setText("<p>Descripcion no disponible</p>");
|
393 |
} |
394 |
getJButtonOpenGeop().setEnabled(true);
|
395 |
}else{
|
396 |
GeoprocessTreeDirectory directory = |
397 |
(GeoprocessTreeDirectory)userObject; |
398 |
htmlPane.setText("<p>"+
|
399 |
directory.getDescription()+ |
400 |
"</p>");
|
401 |
getJButtonOpenGeop().setEnabled(false);
|
402 |
} |
403 |
} |
404 |
|
405 |
} // @jve:decl-index=0:visual-constraint="10,10"
|