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