Statistics
| Revision:

root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / manager / GeoprocessManager.java @ 6877

History | View | Annotate | Download (10.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 6877 2006-08-29 07:13:58Z cesar $
47
 * $Log$
48
 * Revision 1.7  2006-08-29 07:13:56  cesar
49
 * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
50
 *
51
 * Revision 1.6  2006/08/11 16:30:38  azabala
52
 * *** empty log message ***
53
 *
54
 * Revision 1.5  2006/07/21 09:32:01  azabala
55
 * fixed bug 644: disabling ok button untill user select a geoprocess
56
 *
57
 * Revision 1.4  2006/07/04 16:42:37  azabala
58
 * *** empty log message ***
59
 *
60
 * Revision 1.3  2006/06/27 16:16:49  azabala
61
 * imports organization
62
 *
63
 * Revision 1.2  2006/06/27 16:15:08  azabala
64
 * solved bug of packages replication (when added multiple geoprocesses to them)
65
 *
66
 * Revision 1.1  2006/06/23 19:03:52  azabala
67
 * first version in cvs
68
 *
69
 *
70
 */
71
package com.iver.cit.gvsig.geoprocess.manager;
72

    
73
import java.awt.BorderLayout;
74
import java.awt.Dimension;
75
import java.awt.event.MouseAdapter;
76
import java.awt.event.MouseEvent;
77
import java.io.IOException;
78
import java.util.Locale;
79
import java.util.TreeMap;
80

    
81
import javax.swing.JButton;
82
import javax.swing.JEditorPane;
83
import javax.swing.JLabel;
84
import javax.swing.JOptionPane;
85
import javax.swing.JPanel;
86
import javax.swing.JScrollPane;
87
import javax.swing.JSeparator;
88
import javax.swing.JSplitPane;
89
import javax.swing.JTree;
90
import javax.swing.event.TreeSelectionEvent;
91
import javax.swing.event.TreeSelectionListener;
92
import javax.swing.text.html.HTMLEditorKit;
93
import javax.swing.tree.DefaultMutableTreeNode;
94
import javax.swing.tree.TreePath;
95

    
96
import com.iver.andami.PluginServices;
97
import com.iver.andami.ui.mdiManager.IWindow;
98
import com.iver.andami.ui.mdiManager.ViewInfo;
99
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessController;
100
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessPlugin;
101
import com.iver.cit.gvsig.geoprocess.core.gui.GeoprocessPaneContainer;
102
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel;
103
import com.iver.cit.gvsig.geoprocess.manager.GeoprocessTree.GeoprocessTreeDirectory;
104

    
105
/**
106
 * Main panel of the Geoprocess Manager gui component.
107
 * 
108
 * It has a tree where shows all geoprocesses structure, and
109
 * buttons to open geoprocess' panel, and to close itself.
110
 * 
111
 * It also listens for tree selection events.
112
 * 
113
 * @author azabala
114
 *
115
 */
116
public class GeoprocessManager extends JPanel 
117
        implements IWindow, TreeSelectionListener {
118
        
119
        /**
120
         * Central panel wich has the geoprocess tree on left and
121
         * the description panel on right
122
         */
123
        JSplitPane jSplitPaneCenter;
124
        /**
125
         * Tree wich shows all registered geoprocesses
126
         */
127
        private GeoprocessTree tree;
128
        
129
        /**
130
         * It wraps htmlPane
131
         */
132
        private JScrollPane scrollHtml;
133
        /**
134
         * Panel wich shows description of selected packages or 
135
         * geoprocesess
136
         */
137
        private JEditorPane htmlPane;
138
        /**
139
         * It has the button "open geoprocess" and "close view"
140
         */
141
        private JPanel jPanelButtons;
142
        
143
        /**
144
         * Button to close the andami view
145
         */
146
        private JButton jButtonClose;
147
        
148
        /**
149
         * Button to open the selected geoprocess panel
150
         */
151
        private JButton openGeoprocess;
152
        
153
        
154
        /**
155
         * ViewInfo of andami
156
         */
157
        private ViewInfo viewInfo;
158
        
159
        /**
160
         * It has all package descriptions 
161
         * (new plugins must register package descriptions
162
         * here)
163
         */
164
        private static TreeMap packageDescriptions =
165
                new TreeMap();
166
        
167
        public static void registerPackageDescription(String pkgName,
168
                        String description){
169
                packageDescriptions.put(pkgName, description);
170
        }
171
        
172
        public static String getDescriptionFor(String pkgName){
173
                return (String) packageDescriptions.get(pkgName);
174
        }
175
        
176
        /**
177
         * This is the default constructor
178
         */
179
        public GeoprocessManager() {
180
                super();
181
                initialize();
182
        }
183
        
184
        
185
        public ViewInfo getViewInfo() {
186
                if (viewInfo == null) {
187
                        viewInfo = new ViewInfo(ViewInfo.MODELESSDIALOG | 
188
                                                                                ViewInfo.RESIZABLE | 
189
                                                                                ViewInfo.PALETTE);
190
                        viewInfo.setTitle(PluginServices.
191
                                        getText(this, "Gestor_de_Geoprocesos"));
192
                        viewInfo.setWidth(700);
193
                        viewInfo.setHeight(465);
194
                }
195
                return viewInfo;
196
        }
197

    
198
        /**
199
         * This method initializes this
200
         * 
201
         * @return void
202
         */
203
        private void initialize() {
204
                this.setLayout(new BorderLayout());
205
                add(getJSplitPaneCenter(), BorderLayout.CENTER);
206
                getJSplitPaneCenter().setLeftComponent(getGeoprocessTree());
207
                getJSplitPaneCenter().setRightComponent(getHtmlPane());
208
                getJSplitPaneCenter().setDividerLocation(0.4d);
209
                add(getJPanelButtons(), BorderLayout.SOUTH);
210
                this.setSize(700, 525);
211
        }
212

    
213
        private JSplitPane getJSplitPaneCenter() {
214
                if (jSplitPaneCenter == null) {
215
                        jSplitPaneCenter = new JSplitPane();
216
                }
217
                return jSplitPaneCenter;
218
        }
219

    
220

    
221
        private GeoprocessTree getGeoprocessTree() {
222
                if(tree == null){
223
                        tree = new GeoprocessTree();
224
                        tree.addTreeSelectionListener(this);
225
                        tree.addMouseListener(new GeopTreeMouseListener());
226
                }
227
                return tree;
228
        }
229
        
230
        class GeopTreeMouseListener extends MouseAdapter{
231

    
232
                public void mousePressed(MouseEvent e){
233
                        JTree tree = (JTree) e.getSource();
234
                        TreePath tp = tree.getPathForLocation(e.getX(),e.getY());
235
                        if (tp == null) return;
236
                        int clicks = e.getClickCount();
237
                        if (clicks == 2)
238
                        {
239
                                Object o = ((DefaultMutableTreeNode)tp.
240
                                                getLastPathComponent()).
241
                                                getUserObject();
242
                                if(!(o instanceof IGeoprocessPlugin))
243
                                        return;
244
                                IGeoprocessPlugin geoprocess = 
245
                                        (IGeoprocessPlugin) o;
246
                                if(geoprocess == null){
247
                                        String error = PluginServices.
248
                                                getText(this, "Error_seleccionar_gp");
249
                                        String errorDescription = PluginServices.
250
                                        getText(this, "Error_seleccionar_gp_desc");
251
                                        JOptionPane.showMessageDialog(GeoprocessManager.this,
252
                                                        errorDescription, error,
253
                                                        JOptionPane.ERROR_MESSAGE);
254
                                }
255
                                IGeoprocessPanel panel = 
256
                                        geoprocess.getGeoprocessPanel();
257
                        GeoprocessPaneContainer container = new 
258
                                        GeoprocessPaneContainer((JPanel)panel);
259
                        IGeoprocessController controller =
260
                                geoprocess.getGpController();
261
                        controller.setView(panel);
262
                        container.setCommand(controller);
263
                        container.validate();
264
                        container.repaint();
265
                        PluginServices.getMDIManager().addView(container);
266
                        }//if
267
                }
268
        }
269

    
270
        
271
        private JScrollPane getHtmlPane(){
272
                if(scrollHtml == null){
273
                        scrollHtml = new JScrollPane();
274
                        htmlPane = new JEditorPane();
275
                htmlPane.setEditable(false);
276
                htmlPane.setEditorKit(new HTMLEditorKit());
277
                scrollHtml.setViewportView(htmlPane);
278
                        
279
                }
280
                return scrollHtml;
281
        }
282
        
283
        private JPanel getJPanelButtons() {
284
                if (jPanelButtons == null) {
285
                        jPanelButtons = new JPanel(new BorderLayout());
286
                        JPanel jPanelAux = new JPanel();
287
                        JLabel l = new JLabel();
288
                        l.setPreferredSize(new Dimension(40, 20));
289
                        jPanelButtons.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.NORTH);
290
                        jPanelAux.add(getJButtonOpenGeop(), BorderLayout.WEST);
291
                        jPanelAux.add(l, BorderLayout.CENTER);
292
                        jPanelAux.add(getJButtonClose(), BorderLayout.EAST);
293

    
294
                        jPanelButtons.add(jPanelAux);
295
                }
296
                return jPanelButtons;
297
        }
298
        
299
        public void openGeoprocessPanel(){
300
                IGeoprocessPlugin geoprocess = 
301
                        tree.getGeoprocess();
302
                if(geoprocess == null){
303
                        String error = PluginServices.
304
                                getText(this, "Error_seleccionar_gp");
305
                        String errorDescription = PluginServices.
306
                        getText(this, "Error_seleccionar_gp_desc");
307
                        JOptionPane.showMessageDialog(this, errorDescription, error,
308
                                        JOptionPane.ERROR_MESSAGE);
309
                        return;
310
                }
311
                IGeoprocessPanel panel = 
312
                        geoprocess.getGeoprocessPanel();
313
        GeoprocessPaneContainer container = new 
314
                        GeoprocessPaneContainer((JPanel)panel);
315
        IGeoprocessController controller =
316
                geoprocess.getGpController();
317
        controller.setView(panel);
318
        container.setCommand(controller);
319
        container.validate();
320
        container.repaint();
321
        PluginServices.getMDIManager().addView(container);
322
        }
323
        
324
        private JButton getJButtonOpenGeop() {
325
                if (openGeoprocess == null) {
326
                        openGeoprocess = new JButton();
327
                        openGeoprocess.setText(PluginServices.getText(this, "Abrir_Geoproceso"));
328
                        openGeoprocess.addActionListener(new java.awt.event.ActionListener() {
329
                                public void actionPerformed(java.awt.event.ActionEvent e) {
330
                                        openGeoprocessPanel();
331
                                }
332
                        });
333
                        //it will be disabled until user select a geoprocess
334
                        //in the tree
335
                        openGeoprocess.setEnabled(false);
336
                }
337
                return openGeoprocess;
338
        }
339
        
340
        
341
        private JButton getJButtonClose() {
342
                if (jButtonClose == null) {
343
                        jButtonClose = new JButton();
344
                        jButtonClose.setText(PluginServices.getText(this, "Cerrar"));
345
                        jButtonClose.addActionListener(new java.awt.event.ActionListener() {
346
                                public void actionPerformed(java.awt.event.ActionEvent e) {
347
                                                PluginServices.
348
                                                getMDIManager().
349
                                                        closeView(GeoprocessManager.this);
350
                                        
351
                                }
352
                        });
353
                }
354
                return jButtonClose;
355
        }
356
        
357
        
358
        
359
        /**
360
         * processes tree selection events.
361
         */
362
        public void valueChanged(TreeSelectionEvent event) {
363
                DefaultMutableTreeNode selectedNode =
364
                        (DefaultMutableTreeNode) event.getPath().
365
                                                                getLastPathComponent();
366
                Object userObject = selectedNode.getUserObject();
367
                if(userObject instanceof IGeoprocessPlugin){
368
                        IGeoprocessPlugin metadata = 
369
                                (IGeoprocessPlugin)userObject;
370
                        try {
371
                                htmlPane.setPage(metadata.getHtmlDescription());
372
                        } catch (IOException e) {
373
                                htmlPane.setText("<p>Descripcion no disponible</p>");
374
                        }
375
                        getJButtonOpenGeop().setEnabled(true);
376
                }else{
377
                        GeoprocessTreeDirectory directory =
378
                                (GeoprocessTreeDirectory)userObject;
379
                        htmlPane.setText("<p>"+
380
                                        directory.getDescription()+
381
                                        "</p>");
382
                        getJButtonOpenGeop().setEnabled(false);
383
                }
384
        }
385

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