Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / manager / GeoprocessManager.java @ 8236

History | View | Annotate | Download (11.4 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 8236 2006-10-23 10:30:09Z caballero $
47
 * $Log$
48
 * Revision 1.10  2006-10-23 10:30:09  caballero
49
 * soluci?n refresco selecci?n por segunda vez un mismo control
50
 *
51
 * Revision 1.9  2006/09/21 18:17:48  azabala
52
 * fixed bug in JSplitPanel
53
 *
54
 * Revision 1.8  2006/08/29 07:56:30  cesar
55
 * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
56
 *
57
 * Revision 1.7  2006/08/29 07:13:56  cesar
58
 * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
59
 *
60
 * Revision 1.6  2006/08/11 16:30:38  azabala
61
 * *** empty log message ***
62
 *
63
 * Revision 1.5  2006/07/21 09:32:01  azabala
64
 * fixed bug 644: disabling ok button untill user select a geoprocess
65
 *
66
 * Revision 1.4  2006/07/04 16:42:37  azabala
67
 * *** empty log message ***
68
 *
69
 * Revision 1.3  2006/06/27 16:16:49  azabala
70
 * imports organization
71
 *
72
 * Revision 1.2  2006/06/27 16:15:08  azabala
73
 * solved bug of packages replication (when added multiple geoprocesses to them)
74
 *
75
 * Revision 1.1  2006/06/23 19:03:52  azabala
76
 * first version in cvs
77
 *
78
 *
79
 */
80
package com.iver.cit.gvsig.geoprocess.manager;
81

    
82
import java.awt.BorderLayout;
83
import java.awt.Dimension;
84
import java.awt.event.ComponentAdapter;
85
import java.awt.event.ComponentEvent;
86
import java.awt.event.MouseAdapter;
87
import java.awt.event.MouseEvent;
88
import java.io.IOException;
89
import java.net.URL;
90
import java.util.TreeMap;
91

    
92
import javax.swing.JButton;
93
import javax.swing.JEditorPane;
94
import javax.swing.JLabel;
95
import javax.swing.JOptionPane;
96
import javax.swing.JPanel;
97
import javax.swing.JScrollPane;
98
import javax.swing.JSeparator;
99
import javax.swing.JSplitPane;
100
import javax.swing.JTree;
101
import javax.swing.event.TreeSelectionEvent;
102
import javax.swing.event.TreeSelectionListener;
103
import javax.swing.text.html.HTMLEditorKit;
104
import javax.swing.tree.DefaultMutableTreeNode;
105
import javax.swing.tree.TreePath;
106

    
107
import com.iver.andami.PluginServices;
108
import com.iver.andami.ui.mdiManager.IWindow;
109
import com.iver.andami.ui.mdiManager.WindowInfo;
110
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessController;
111
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessPlugin;
112
import com.iver.cit.gvsig.geoprocess.core.gui.GeoprocessPaneContainer;
113
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel;
114
import com.iver.cit.gvsig.geoprocess.manager.GeoprocessTree.GeoprocessTreeDirectory;
115

    
116
/**
117
 * Main panel of the Geoprocess Manager gui component.
118
 *
119
 * It has a tree where shows all geoprocesses structure, and
120
 * buttons to open geoprocess' panel, and to close itself.
121
 *
122
 * It also listens for tree selection events.
123
 *
124
 * @author azabala
125
 *
126
 */
127
public class GeoprocessManager extends JPanel
128
        implements IWindow, TreeSelectionListener {
129

    
130
        /**
131
         * Central panel wich has the geoprocess tree on left and
132
         * the description panel on right
133
         */
134
        JSplitPane jSplitPaneCenter;
135
        /**
136
         * Tree wich shows all registered geoprocesses
137
         */
138
        private GeoprocessTree tree;
139

    
140
        /**
141
         * It wraps htmlPane
142
         */
143
        private JScrollPane scrollHtml;
144
        /**
145
         * Panel wich shows description of selected packages or
146
         * geoprocesess
147
         */
148
        private MyJEditorPane htmlPane;
149
        /**
150
         * It has the button "open geoprocess" and "close view"
151
         */
152
        private JPanel jPanelButtons;
153

    
154
        /**
155
         * Button to close the andami view
156
         */
157
        private JButton jButtonClose;
158

    
159
        /**
160
         * Button to open the selected geoprocess panel
161
         */
162
        private JButton openGeoprocess;
163

    
164

    
165
        /**
166
         * ViewInfo of andami
167
         */
168
        private WindowInfo viewInfo;
169

    
170
        /**
171
         * It has all package descriptions
172
         * (new plugins must register package descriptions
173
         * here)
174
         */
175
        private static TreeMap packageDescriptions =
176
                new TreeMap();
177

    
178
        public static void registerPackageDescription(String pkgName,
179
                        String description){
180
                packageDescriptions.put(pkgName, description);
181
        }
182

    
183
        public static String getDescriptionFor(String pkgName){
184
                return (String) packageDescriptions.get(pkgName);
185
        }
186

    
187
        /**
188
         * This is the default constructor
189
         */
190
        public GeoprocessManager() {
191
                super();
192
                initialize();
193
        }
194

    
195

    
196
        public WindowInfo getWindowInfo() {
197
                if (viewInfo == null) {
198
                        viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG |
199
                                                                                WindowInfo.RESIZABLE |
200
                                                                                WindowInfo.PALETTE);
201
                        viewInfo.setTitle(PluginServices.
202
                                        getText(this, "Gestor_de_Geoprocesos"));
203
                        viewInfo.setWidth(700);
204
                        viewInfo.setHeight(465);
205
                }
206
                return viewInfo;
207
        }
208

    
209
        /**
210
         * This method initializes this
211
         *
212
         * @return void
213
         */
214
        private void initialize() {
215
                this.setLayout(new BorderLayout());
216
                add(getJSplitPaneCenter(), BorderLayout.CENTER);
217
                getJSplitPaneCenter().setLeftComponent(getGeoprocessTree());
218
                getJSplitPaneCenter().setRightComponent(getHtmlPane());
219
                add(getJPanelButtons(), BorderLayout.SOUTH);
220
                this.setSize(700, 525);
221
                /*
222
                 * see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4182558
223
                 * JSplitPane doesnt care setDividerLocation calls before
224
                 * its container would be visible
225
                 *
226
                 * */
227
                getJSplitPaneCenter().addComponentListener( new ComponentAdapter() {
228
                          public void componentResized( ComponentEvent event ) {
229
                                  getJSplitPaneCenter().setDividerLocation(0.35);
230
                                  getJSplitPaneCenter().removeComponentListener( this );
231
                          }
232
                        } );
233

    
234
        }
235

    
236
        private JSplitPane getJSplitPaneCenter() {
237
                if (jSplitPaneCenter == null) {
238
                        jSplitPaneCenter = new JSplitPane();
239
                }
240
                return jSplitPaneCenter;
241
        }
242

    
243

    
244
        private GeoprocessTree getGeoprocessTree() {
245
                if(tree == null){
246
                        tree = new GeoprocessTree();
247
                        tree.addTreeSelectionListener(this);
248
                        tree.addMouseListener(new GeopTreeMouseListener());
249
                }
250
                return tree;
251
        }
252

    
253
        class GeopTreeMouseListener extends MouseAdapter{
254

    
255
                public void mousePressed(MouseEvent e){
256
                        JTree tree = (JTree) e.getSource();
257
                        TreePath tp = tree.getPathForLocation(e.getX(),e.getY());
258
                        if (tp == null) return;
259
                        int clicks = e.getClickCount();
260
                        if (clicks == 2)
261
                        {
262
                                Object o = ((DefaultMutableTreeNode)tp.
263
                                                getLastPathComponent()).
264
                                                getUserObject();
265
                                if(!(o instanceof IGeoprocessPlugin))
266
                                        return;
267
                                IGeoprocessPlugin geoprocess =
268
                                        (IGeoprocessPlugin) o;
269
                                if(geoprocess == null){
270
                                        String error = PluginServices.
271
                                                getText(this, "Error_seleccionar_gp");
272
                                        String errorDescription = PluginServices.
273
                                        getText(this, "Error_seleccionar_gp_desc");
274
                                        JOptionPane.showMessageDialog(GeoprocessManager.this,
275
                                                        errorDescription, error,
276
                                                        JOptionPane.ERROR_MESSAGE);
277
                                }
278
                                IGeoprocessPanel panel =
279
                                        geoprocess.getGeoprocessPanel();
280
                        GeoprocessPaneContainer container = new
281
                                        GeoprocessPaneContainer((JPanel)panel);
282
                        IGeoprocessController controller =
283
                                geoprocess.getGpController();
284
                        controller.setView(panel);
285
                        container.setCommand(controller);
286
                        container.validate();
287
                        container.repaint();
288
                        PluginServices.getMDIManager().addWindow(container);
289
                        }//if
290
                }
291
        }
292

    
293

    
294
        private JScrollPane getHtmlPane(){
295
                if(scrollHtml == null){
296
                        scrollHtml = new JScrollPane();
297
                        htmlPane = new MyJEditorPane();
298
                htmlPane.setEditable(false);
299
                htmlPane.setEditorKit(new HTMLEditorKit());
300
                scrollHtml.setViewportView(htmlPane);
301

    
302
                }
303
                return scrollHtml;
304
        }
305

    
306
        private JPanel getJPanelButtons() {
307
                if (jPanelButtons == null) {
308
                        jPanelButtons = new JPanel(new BorderLayout());
309
                        JPanel jPanelAux = new JPanel();
310
                        JLabel l = new JLabel();
311
                        l.setPreferredSize(new Dimension(40, 20));
312
                        jPanelButtons.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.NORTH);
313
                        jPanelAux.add(getJButtonOpenGeop(), BorderLayout.WEST);
314
                        jPanelAux.add(l, BorderLayout.CENTER);
315
                        jPanelAux.add(getJButtonClose(), BorderLayout.EAST);
316

    
317
                        jPanelButtons.add(jPanelAux);
318
                }
319
                return jPanelButtons;
320
        }
321

    
322
        public void openGeoprocessPanel(){
323
                IGeoprocessPlugin geoprocess =
324
                        tree.getGeoprocess();
325
                if(geoprocess == null){
326
                        String error = PluginServices.
327
                                getText(this, "Error_seleccionar_gp");
328
                        String errorDescription = PluginServices.
329
                        getText(this, "Error_seleccionar_gp_desc");
330
                        JOptionPane.showMessageDialog(this, errorDescription, error,
331
                                        JOptionPane.ERROR_MESSAGE);
332
                        return;
333
                }
334
                IGeoprocessPanel panel =
335
                        geoprocess.getGeoprocessPanel();
336
        GeoprocessPaneContainer container = new
337
                        GeoprocessPaneContainer((JPanel)panel);
338
        IGeoprocessController controller =
339
                geoprocess.getGpController();
340
        controller.setView(panel);
341
        container.setCommand(controller);
342
        container.validate();
343
        container.repaint();
344
        PluginServices.getMDIManager().addWindow(container);
345
        }
346

    
347
        private JButton getJButtonOpenGeop() {
348
                if (openGeoprocess == null) {
349
                        openGeoprocess = new JButton();
350
                        openGeoprocess.setText(PluginServices.getText(this, "Abrir_Geoproceso"));
351
                        openGeoprocess.addActionListener(new java.awt.event.ActionListener() {
352
                                public void actionPerformed(java.awt.event.ActionEvent e) {
353
                                        openGeoprocessPanel();
354
                                }
355
                        });
356
                        //it will be disabled until user select a geoprocess
357
                        //in the tree
358
                        openGeoprocess.setEnabled(false);
359
                }
360
                return openGeoprocess;
361
        }
362

    
363

    
364
        private JButton getJButtonClose() {
365
                if (jButtonClose == null) {
366
                        jButtonClose = new JButton();
367
                        jButtonClose.setText(PluginServices.getText(this, "Cerrar"));
368
                        jButtonClose.addActionListener(new java.awt.event.ActionListener() {
369
                                public void actionPerformed(java.awt.event.ActionEvent e) {
370
                                                PluginServices.
371
                                                getMDIManager().
372
                                                        closeWindow(GeoprocessManager.this);
373

    
374
                                }
375
                        });
376
                }
377
                return jButtonClose;
378
        }
379

    
380

    
381

    
382
        /**
383
         * processes tree selection events.
384
         */
385
        public void valueChanged(TreeSelectionEvent event) {
386
                DefaultMutableTreeNode selectedNode =
387
                        (DefaultMutableTreeNode) event.getPath().
388
                                                                getLastPathComponent();
389
                Object userObject = selectedNode.getUserObject();
390
                if(userObject instanceof IGeoprocessPlugin){
391
                        IGeoprocessPlugin metadata =
392
                                (IGeoprocessPlugin)userObject;
393
                        try {
394
                                htmlPane.setPage(metadata.getHtmlDescription().toString());
395
                        } catch (IOException e) {
396
                                htmlPane.setText("<p>Descripcion no disponible</p>");
397
                        }
398
                        getJButtonOpenGeop().setEnabled(true);
399
                }else{
400
                        GeoprocessTreeDirectory directory =
401
                                (GeoprocessTreeDirectory)userObject;
402
                        htmlPane.setText("<p>"+
403
                                        directory.getDescription()+
404
                                        "</p>");
405
                        getJButtonOpenGeop().setEnabled(false);
406
                }
407
        }
408
private class MyJEditorPane extends JEditorPane{
409

    
410
        public URL getPage() {
411
                return null;
412
        }
413

    
414
}
415

    
416
}  //  @jve:decl-index=0:visual-constraint="10,10"