svn-gvsig-desktop / tags / v1_0_RELEASE / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / manager / GeoprocessManager.java @ 9167
History | View | Annotate | Download (11.8 KB)
1 | 6018 | azabala | /*
|
---|---|---|---|
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$
|
||
47 | * $Log$
|
||
48 | 9128 | azabala | * 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 | 8765 | jjdelcerro | * *** empty log message ***
|
53 | 7308 | azabala | *
|
54 | 8765 | jjdelcerro | * 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 | 7308 | azabala | * Revision 1.8 2006/08/29 07:56:30 cesar
|
64 | 6880 | cesar | * 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 | 6877 | cesar | * 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 | 6749 | azabala | * *** empty log message ***
|
71 | *
|
||
72 | * Revision 1.5 2006/07/21 09:32:01 azabala
|
||
73 | 6490 | azabala | * fixed bug 644: disabling ok button untill user select a geoprocess
|
74 | *
|
||
75 | * Revision 1.4 2006/07/04 16:42:37 azabala
|
||
76 | 6179 | azabala | * *** empty log message ***
|
77 | *
|
||
78 | * Revision 1.3 2006/06/27 16:16:49 azabala
|
||
79 | 6060 | azabala | * imports organization
|
80 | *
|
||
81 | * Revision 1.2 2006/06/27 16:15:08 azabala
|
||
82 | 6058 | azabala | * solved bug of packages replication (when added multiple geoprocesses to them)
|
83 | *
|
||
84 | * Revision 1.1 2006/06/23 19:03:52 azabala
|
||
85 | 6018 | azabala | * 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 | 7308 | azabala | import java.awt.event.ComponentAdapter; |
94 | import java.awt.event.ComponentEvent; |
||
95 | 6058 | azabala | import java.awt.event.MouseAdapter; |
96 | import java.awt.event.MouseEvent; |
||
97 | 6018 | azabala | import java.io.IOException; |
98 | 8765 | jjdelcerro | import java.net.URL; |
99 | 6058 | azabala | import java.util.TreeMap; |
100 | 6018 | azabala | |
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 | 6058 | azabala | import javax.swing.JScrollPane; |
107 | 6018 | azabala | import javax.swing.JSeparator; |
108 | import javax.swing.JSplitPane; |
||
109 | 6058 | azabala | import javax.swing.JTree; |
110 | 6018 | azabala | 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 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
118 | 9128 | azabala | import com.iver.andami.ui.mdiManager.SingletonWindow; |
119 | 6880 | cesar | import com.iver.andami.ui.mdiManager.WindowInfo; |
120 | 6018 | azabala | 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 | 6490 | azabala | /**
|
127 | * Main panel of the Geoprocess Manager gui component.
|
||
128 | 8765 | jjdelcerro | *
|
129 | 6490 | azabala | * It has a tree where shows all geoprocesses structure, and
|
130 | * buttons to open geoprocess' panel, and to close itself.
|
||
131 | 8765 | jjdelcerro | *
|
132 | 6490 | azabala | * It also listens for tree selection events.
|
133 | 8765 | jjdelcerro | *
|
134 | 6490 | azabala | * @author azabala
|
135 | *
|
||
136 | */
|
||
137 | 8765 | jjdelcerro | public class GeoprocessManager extends JPanel |
138 | 9128 | azabala | implements SingletonWindow, TreeSelectionListener { |
139 | 8765 | jjdelcerro | |
140 | 6018 | azabala | /**
|
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 | 8765 | jjdelcerro | |
150 | 6018 | azabala | /**
|
151 | 6058 | azabala | * It wraps htmlPane
|
152 | */
|
||
153 | private JScrollPane scrollHtml; |
||
154 | /**
|
||
155 | 8765 | jjdelcerro | * Panel wich shows description of selected packages or
|
156 | 6018 | azabala | * geoprocesess
|
157 | */
|
||
158 | 8765 | jjdelcerro | private MyJEditorPane htmlPane;
|
159 | 6018 | azabala | /**
|
160 | * It has the button "open geoprocess" and "close view"
|
||
161 | */
|
||
162 | private JPanel jPanelButtons; |
||
163 | 8765 | jjdelcerro | |
164 | 6018 | azabala | /**
|
165 | * Button to close the andami view
|
||
166 | */
|
||
167 | private JButton jButtonClose; |
||
168 | 8765 | jjdelcerro | |
169 | 6018 | azabala | /**
|
170 | * Button to open the selected geoprocess panel
|
||
171 | */
|
||
172 | private JButton openGeoprocess; |
||
173 | 8765 | jjdelcerro | |
174 | |||
175 | 6018 | azabala | /**
|
176 | * ViewInfo of andami
|
||
177 | */
|
||
178 | 6880 | cesar | private WindowInfo viewInfo;
|
179 | 8765 | jjdelcerro | |
180 | 6018 | azabala | /**
|
181 | 8765 | jjdelcerro | * It has all package descriptions
|
182 | 6058 | azabala | * (new plugins must register package descriptions
|
183 | * here)
|
||
184 | */
|
||
185 | private static TreeMap packageDescriptions = |
||
186 | new TreeMap(); |
||
187 | 8765 | jjdelcerro | |
188 | 6058 | azabala | public static void registerPackageDescription(String pkgName, |
189 | String description){
|
||
190 | packageDescriptions.put(pkgName, description); |
||
191 | } |
||
192 | 8765 | jjdelcerro | |
193 | 6058 | azabala | public static String getDescriptionFor(String pkgName){ |
194 | return (String) packageDescriptions.get(pkgName); |
||
195 | } |
||
196 | 8765 | jjdelcerro | |
197 | 6058 | azabala | /**
|
198 | 6018 | azabala | * This is the default constructor
|
199 | */
|
||
200 | public GeoprocessManager() {
|
||
201 | super();
|
||
202 | initialize(); |
||
203 | } |
||
204 | 8765 | jjdelcerro | |
205 | |||
206 | 6880 | cesar | public WindowInfo getWindowInfo() {
|
207 | 6018 | azabala | if (viewInfo == null) { |
208 | 8765 | jjdelcerro | viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG |
|
209 | WindowInfo.RESIZABLE | |
||
210 | 6880 | cesar | WindowInfo.PALETTE); |
211 | 6179 | azabala | viewInfo.setTitle(PluginServices. |
212 | getText(this, "Gestor_de_Geoprocesos")); |
||
213 | 6749 | azabala | viewInfo.setWidth(700);
|
214 | viewInfo.setHeight(465);
|
||
215 | 6018 | azabala | } |
216 | return viewInfo;
|
||
217 | } |
||
218 | |||
219 | /**
|
||
220 | * This method initializes this
|
||
221 | 8765 | jjdelcerro | *
|
222 | 6018 | azabala | * @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 | 6749 | azabala | this.setSize(700, 525); |
231 | 7308 | azabala | /*
|
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 | 8765 | jjdelcerro | *
|
236 | 7308 | azabala | * */
|
237 | getJSplitPaneCenter().addComponentListener( new ComponentAdapter() { |
||
238 | public void componentResized( ComponentEvent event ) { |
||
239 | getJSplitPaneCenter().setDividerLocation(0.35);
|
||
240 | getJSplitPaneCenter().removeComponentListener( this );
|
||
241 | } |
||
242 | } ); |
||
243 | 8765 | jjdelcerro | |
244 | 6018 | azabala | } |
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 | 6058 | azabala | tree.addMouseListener(new GeopTreeMouseListener());
|
259 | 6018 | azabala | } |
260 | return tree;
|
||
261 | } |
||
262 | 8765 | jjdelcerro | |
263 | 6058 | azabala | 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 | 8765 | jjdelcerro | IGeoprocessPlugin geoprocess = |
278 | 6058 | azabala | (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 | 8765 | jjdelcerro | IGeoprocessPanel panel = |
289 | 6058 | azabala | geoprocess.getGeoprocessPanel(); |
290 | 8765 | jjdelcerro | GeoprocessPaneContainer container = new
|
291 | 6058 | azabala | GeoprocessPaneContainer((JPanel)panel);
|
292 | IGeoprocessController controller = |
||
293 | geoprocess.getGpController(); |
||
294 | controller.setView(panel); |
||
295 | container.setCommand(controller); |
||
296 | container.validate(); |
||
297 | container.repaint(); |
||
298 | 6880 | cesar | PluginServices.getMDIManager().addWindow(container); |
299 | 6058 | azabala | }//if
|
300 | } |
||
301 | } |
||
302 | |||
303 | 8765 | jjdelcerro | |
304 | 6058 | azabala | private JScrollPane getHtmlPane(){ |
305 | if(scrollHtml == null){ |
||
306 | scrollHtml = new JScrollPane(); |
||
307 | 8765 | jjdelcerro | htmlPane = new MyJEditorPane();
|
308 | 6018 | azabala | htmlPane.setEditable(false);
|
309 | htmlPane.setEditorKit(new HTMLEditorKit()); |
||
310 | 6058 | azabala | scrollHtml.setViewportView(htmlPane); |
311 | 8765 | jjdelcerro | |
312 | 6018 | azabala | } |
313 | 6058 | azabala | return scrollHtml;
|
314 | 6018 | azabala | } |
315 | 8765 | jjdelcerro | |
316 | 6018 | azabala | 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 | 8765 | jjdelcerro | |
332 | 6018 | azabala | public void openGeoprocessPanel(){ |
333 | 8765 | jjdelcerro | IGeoprocessPlugin geoprocess = |
334 | 6018 | azabala | 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 | 6490 | azabala | return;
|
343 | 6018 | azabala | } |
344 | 8765 | jjdelcerro | IGeoprocessPanel panel = |
345 | 6018 | azabala | geoprocess.getGeoprocessPanel(); |
346 | 8765 | jjdelcerro | GeoprocessPaneContainer container = new
|
347 | 6018 | azabala | GeoprocessPaneContainer((JPanel)panel);
|
348 | IGeoprocessController controller = |
||
349 | geoprocess.getGpController(); |
||
350 | controller.setView(panel); |
||
351 | container.setCommand(controller); |
||
352 | container.validate(); |
||
353 | container.repaint(); |
||
354 | 6880 | cesar | PluginServices.getMDIManager().addWindow(container); |
355 | 6018 | azabala | } |
356 | 8765 | jjdelcerro | |
357 | 6018 | azabala | 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 | 6490 | azabala | //it will be disabled until user select a geoprocess
|
367 | //in the tree
|
||
368 | openGeoprocess.setEnabled(false);
|
||
369 | 6018 | azabala | } |
370 | return openGeoprocess;
|
||
371 | } |
||
372 | 8765 | jjdelcerro | |
373 | |||
374 | 6018 | azabala | 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 | 6880 | cesar | closeWindow(GeoprocessManager.this); |
383 | 8765 | jjdelcerro | |
384 | 6018 | azabala | } |
385 | }); |
||
386 | } |
||
387 | return jButtonClose;
|
||
388 | } |
||
389 | 8765 | jjdelcerro | |
390 | |||
391 | |||
392 | 6490 | azabala | /**
|
393 | * processes tree selection events.
|
||
394 | */
|
||
395 | 6018 | azabala | 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 | 8765 | jjdelcerro | IGeoprocessPlugin metadata = |
402 | 6018 | azabala | (IGeoprocessPlugin)userObject; |
403 | try {
|
||
404 | 8765 | jjdelcerro | htmlPane.setPage(metadata.getHtmlDescription().toString()); |
405 | } catch (Exception e) { |
||
406 | 6058 | azabala | htmlPane.setText("<p>Descripcion no disponible</p>");
|
407 | 6018 | azabala | } |
408 | 6490 | azabala | getJButtonOpenGeop().setEnabled(true);
|
409 | 6018 | azabala | }else{
|
410 | GeoprocessTreeDirectory directory = |
||
411 | (GeoprocessTreeDirectory)userObject; |
||
412 | 6058 | azabala | htmlPane.setText("<p>"+
|
413 | 6018 | azabala | directory.getDescription()+ |
414 | "</p>");
|
||
415 | 6490 | azabala | getJButtonOpenGeop().setEnabled(false);
|
416 | 6018 | azabala | } |
417 | } |
||
418 | 8765 | jjdelcerro | private class MyJEditorPane extends JEditorPane{ |
419 | 6018 | azabala | |
420 | 8765 | jjdelcerro | public URL getPage() { |
421 | return null; |
||
422 | } |
||
423 | |||
424 | } |
||
425 | |||
426 | 9128 | azabala | |
427 | public Object getWindowModel() { |
||
428 | return getClass();
|
||
429 | } |
||
430 | |||
431 | 6018 | azabala | } // @jve:decl-index=0:visual-constraint="10,10" |