Statistics
| Revision:

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

History | View | Annotate | Download (7.62 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 6018 2006-06-23 19:03:52Z azabala $
47
 * $Log$
48
 * Revision 1.1  2006-06-23 19:03:52  azabala
49
 * first version in cvs
50
 *
51
 *
52
 */
53
package com.iver.cit.gvsig.geoprocess.manager;
54

    
55
import java.awt.BorderLayout;
56
import java.awt.Dimension;
57
import java.io.IOException;
58

    
59
import javax.swing.JButton;
60
import javax.swing.JEditorPane;
61
import javax.swing.JLabel;
62
import javax.swing.JOptionPane;
63
import javax.swing.JPanel;
64
import javax.swing.JSeparator;
65
import javax.swing.JSplitPane;
66
import javax.swing.border.Border;
67
import javax.swing.event.TreeSelectionEvent;
68
import javax.swing.event.TreeSelectionListener;
69
import javax.swing.text.html.HTMLEditorKit;
70
import javax.swing.tree.DefaultMutableTreeNode;
71
import javax.swing.tree.TreePath;
72

    
73
import org.cresques.cts.IProjection;
74

    
75
import com.iver.andami.PluginServices;
76
import com.iver.andami.preferences.IPreference;
77
import com.iver.andami.ui.mdiManager.View;
78
import com.iver.andami.ui.mdiManager.ViewInfo;
79
import com.iver.cit.gvsig.fmap.FMap;
80
import com.iver.cit.gvsig.fmap.layers.FLayers;
81
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessController;
82
import com.iver.cit.gvsig.geoprocess.core.IGeoprocessPlugin;
83
import com.iver.cit.gvsig.geoprocess.core.gui.GeoProcessingOverlayPanel;
84
import com.iver.cit.gvsig.geoprocess.core.gui.GeoprocessPaneContainer;
85
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel;
86
import com.iver.cit.gvsig.geoprocess.impl.clip.ClipGeoprocessController;
87
import com.iver.cit.gvsig.geoprocess.manager.GeoprocessTree.GeoprocessTreeDirectory;
88

    
89
public class GeoprocessManager extends JPanel 
90
        implements View, TreeSelectionListener {
91
        
92
        /**
93
         * Central panel wich has the geoprocess tree on left and
94
         * the description panel on right
95
         */
96
        JSplitPane jSplitPaneCenter;
97
        /**
98
         * Tree wich shows all registered geoprocesses
99
         */
100
        private GeoprocessTree tree;
101
        /**
102
         * Panel wich shows description of selected packages or 
103
         * geoprocesess
104
         */
105
        private JEditorPane htmlPane;
106
        /**
107
         * It has the button "open geoprocess" and "close view"
108
         */
109
        private JPanel jPanelButtons;
110
        
111
        /**
112
         * Button to close the andami view
113
         */
114
        private JButton jButtonClose;
115
        
116
        /**
117
         * Button to open the selected geoprocess panel
118
         */
119
        private JButton openGeoprocess;
120
        
121
        
122
        /**
123
         * ViewInfo of andami
124
         */
125
        private ViewInfo viewInfo;
126
        /**
127
         * This is the default constructor
128
         */
129
        public GeoprocessManager() {
130
                super();
131
                initialize();
132
        }
133
        
134
        
135
        public ViewInfo getViewInfo() {
136
                if (viewInfo == null) {
137
                        viewInfo = new ViewInfo(ViewInfo.MODALDIALOG | 
138
                                                                                ViewInfo.RESIZABLE | 
139
                                                                                ViewInfo.PALETTE);
140
                        viewInfo.setTitle("Gestor de Geoprocesos");
141
                        viewInfo.setWidth(this.getWidth()+8);
142
                        viewInfo.setHeight(this.getHeight());
143
                }
144
                return viewInfo;
145
        }
146

    
147
        /**
148
         * This method initializes this
149
         * 
150
         * @return void
151
         */
152
        private void initialize() {
153
                this.setLayout(new BorderLayout());
154
                add(getJSplitPaneCenter(), BorderLayout.CENTER);
155
                getJSplitPaneCenter().setLeftComponent(getGeoprocessTree());
156
                getJSplitPaneCenter().setRightComponent(getHtmlPane());
157
                add(getJPanelButtons(), BorderLayout.SOUTH);
158
                this.setSize(413, 266);
159
        }
160

    
161
        private JSplitPane getJSplitPaneCenter() {
162
                if (jSplitPaneCenter == null) {
163
                        jSplitPaneCenter = new JSplitPane();
164
                }
165
                return jSplitPaneCenter;
166
        }
167

    
168

    
169
        private GeoprocessTree getGeoprocessTree() {
170
                if(tree == null){
171
                        tree = new GeoprocessTree();
172
                        tree.addTreeSelectionListener(this);
173
                }
174
                return tree;
175
        }
176
        
177
        private JEditorPane getHtmlPane(){
178
                if(htmlPane == null){ 
179
                        htmlPane = new JEditorPane();
180
                htmlPane.setEditable(false);
181
                htmlPane.setEditorKit(new HTMLEditorKit());
182
                }
183
                return htmlPane;
184
        }
185
        
186
        private JPanel getJPanelButtons() {
187
                if (jPanelButtons == null) {
188
                        jPanelButtons = new JPanel(new BorderLayout());
189
                        JPanel jPanelAux = new JPanel();
190
                        JLabel l = new JLabel();
191
                        l.setPreferredSize(new Dimension(40, 20));
192
                        jPanelButtons.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.NORTH);
193
                        jPanelAux.add(getJButtonOpenGeop(), BorderLayout.WEST);
194
                        jPanelAux.add(l, BorderLayout.CENTER);
195
                        jPanelAux.add(getJButtonClose(), BorderLayout.EAST);
196

    
197
                        jPanelButtons.add(jPanelAux);
198
                }
199
                return jPanelButtons;
200
        }
201
        
202
        public void openGeoprocessPanel(){
203
                IGeoprocessPlugin geoprocess = 
204
                        tree.getGeoprocess();
205
                if(geoprocess == null){
206
                        String error = PluginServices.
207
                                getText(this, "Error_seleccionar_gp");
208
                        String errorDescription = PluginServices.
209
                        getText(this, "Error_seleccionar_gp_desc");
210
                        JOptionPane.showMessageDialog(this, errorDescription, error,
211
                                        JOptionPane.ERROR_MESSAGE);
212
                }
213
                IGeoprocessPanel panel = 
214
                        geoprocess.getGeoprocessPanel();
215
        GeoprocessPaneContainer container = new 
216
                        GeoprocessPaneContainer((JPanel)panel);
217
        IGeoprocessController controller =
218
                geoprocess.getGpController();
219
        controller.setView(panel);
220
        container.setCommand(controller);
221
        container.validate();
222
        container.repaint();
223
        PluginServices.getMDIManager().addView(container);
224
        }
225
        
226
        private JButton getJButtonOpenGeop() {
227
                if (openGeoprocess == null) {
228
                        openGeoprocess = new JButton();
229
                        openGeoprocess.setText(PluginServices.getText(this, "Abrir_Geoproceso"));
230
                        openGeoprocess.addActionListener(new java.awt.event.ActionListener() {
231
                                public void actionPerformed(java.awt.event.ActionEvent e) {
232
                                        openGeoprocessPanel();
233
                                }
234
                        });
235
                }
236
                return openGeoprocess;
237
        }
238
        
239
        
240
        private JButton getJButtonClose() {
241
                if (jButtonClose == null) {
242
                        jButtonClose = new JButton();
243
                        jButtonClose.setText(PluginServices.getText(this, "Cerrar"));
244
                        jButtonClose.addActionListener(new java.awt.event.ActionListener() {
245
                                public void actionPerformed(java.awt.event.ActionEvent e) {
246
                                                PluginServices.
247
                                                getMDIManager().
248
                                                        closeView(GeoprocessManager.this);
249
                                        
250
                                }
251
                        });
252
                }
253
                return jButtonClose;
254
        }
255
        
256
        
257

    
258

    
259
        public void valueChanged(TreeSelectionEvent event) {
260
                DefaultMutableTreeNode selectedNode =
261
                        (DefaultMutableTreeNode) event.getPath().
262
                                                                getLastPathComponent();
263
                Object userObject = selectedNode.getUserObject();
264
                if(userObject instanceof IGeoprocessPlugin){
265
                        IGeoprocessPlugin metadata = 
266
                                (IGeoprocessPlugin)userObject;
267
                        try {
268
                                getHtmlPane().setPage(metadata.getHtmlDescription());
269
                        } catch (IOException e) {
270
                                getHtmlPane().setText("<p>Descripcion no disponible</p>");
271
                        }
272
                }else{
273
                        GeoprocessTreeDirectory directory =
274
                                (GeoprocessTreeDirectory)userObject;
275
                        getHtmlPane().setText("<p>"+
276
                                        directory.getDescription()+
277
                                        "</p>");
278
                }
279
        }
280

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