Statistics
| Revision:

gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.convexhull / src / main / java / org / gvsig / geoprocess / algorithm / convexhull / ConvexHullParametersPanel.java @ 237

History | View | Annotate | Download (4.87 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007,2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 */
21
package org.gvsig.geoprocess.algorithm.convexhull;
22

    
23
import java.awt.Dimension;
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.util.ArrayList;
30
import java.util.Iterator;
31
import java.util.List;
32

    
33
import javax.swing.JButton;
34
import javax.swing.JComboBox;
35

    
36
import es.unex.sextante.core.GeoAlgorithm;
37
import es.unex.sextante.core.Sextante;
38
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
39

    
40
import org.slf4j.Logger;
41
import org.slf4j.LoggerFactory;
42

    
43
import org.gvsig.fmap.dal.DALLocator;
44
import org.gvsig.fmap.dal.DataManager;
45
import org.gvsig.fmap.dal.DataStoreParameters;
46
import org.gvsig.fmap.dal.exception.InitializeException;
47
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
48
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor;
49
import org.gvsig.tools.service.ServiceException;
50

    
51
/**
52
 * @deprecated
53
 * @author Nacho Brodin (nachobrodin@gmail.com)
54
 */
55
public class ConvexHullParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener {
56

    
57
    private static final long serialVersionUID = 3260891769310434508L;
58

    
59
    private static final Logger LOG =
60
        LoggerFactory.getLogger(ConvexHullParametersPanel.class);
61
    
62
        private JComboBox                        combo               = null;
63
        private JButton                          button              = null;
64
        private ArrayList<DataStoreParameters>   paramList           = new ArrayList<DataStoreParameters>();
65
        
66
        public ConvexHullParametersPanel() {
67
                super();
68
        }
69

    
70
    public void init(GeoAlgorithm algorithm) {
71
            initGUI();
72
    }
73

    
74
        private void initGUI() {
75
                GridBagLayout gbl = new GridBagLayout();
76
                this.setLayout(gbl);
77
                
78
                GridBagConstraints gbc = new GridBagConstraints();
79
                gbc.fill = GridBagConstraints.HORIZONTAL;
80
                gbc.weightx = 1.0;
81
                gbc.gridx = 0;
82
                gbc.gridy = 0;
83
                gbc.insets = new Insets(0, 2, 0, 0);
84
                this.add(getCombo(), gbc);
85
                
86
                gbc.fill = GridBagConstraints.NONE;
87
                gbc.weightx = 0;
88
                gbc.gridx = 1;
89
                gbc.insets = new Insets(0, 5, 0, 2);
90
                this.add(getButton(), gbc);
91
        }
92

    
93
        /**
94
         * Gets a ComboBox
95
         * @return
96
         */
97
        public JComboBox getCombo() {
98
                if(combo == null) {
99
                        combo = new JComboBox();
100
                        loadProviderList(combo, paramList);
101
                        combo.addActionListener(this);
102
                        combo.setPreferredSize(new Dimension(0, 18));
103
                }
104
                return combo;
105
        }
106
        
107
        /**
108
         * Gets a JButton
109
         * @return
110
         */
111
        public JButton getButton() {
112
                if(button == null) {
113
                        button = new JButton("...");
114
                        button.setPreferredSize(new Dimension(60, 18));
115
                        button.addActionListener(this);
116
                }
117
                return button;
118
        }
119
        
120
        @Override
121
    public void assignParameters() {
122
        // Nothing to do
123
        }
124

    
125
        @Override
126
        public void setOutputValue(String arg0, String arg1) {
127
                
128
        }
129

    
130
        @Override
131
        public void setParameterValue(String arg0, String arg1) {
132
                
133
        }
134
        
135
        @SuppressWarnings("unchecked")
136
        private void loadProviderList(JComboBox c, ArrayList<DataStoreParameters> paramList) {
137
                try {
138
                DataManager manager = DALLocator.getDataManager();
139
                List list = manager.getStoreProviders();
140
                Iterator it = list.iterator();
141
                c.removeAllItems();
142
                paramList.clear();
143
                while(it.hasNext()) {
144
                        try {
145
                                String provider = it.next().toString();
146
                                DataStoreParameters param = manager.createStoreParameters(provider);
147
                                c.addItem(provider);
148
                                paramList.add(param);
149
                        } catch (InitializeException e1) {
150
                                Sextante.addErrorToLog(e1);
151
                        } catch (ProviderNotRegisteredException e1) {
152
                                Sextante.addErrorToLog(e1);
153
                        }
154
                }
155
                }catch(Exception e){}
156
        }
157

    
158
        public void actionPerformed(ActionEvent e) {
159
                if(e.getSource() == getButton()) {
160
                        int index = getCombo().getSelectedIndex();
161
                        
162
            try {
163
                DynObjectEditor editor = new DynObjectEditor(paramList.get(index));
164
                editor.editObject(true);
165
            } catch (ServiceException ex) {
166
                LOG.error(
167
                    "Error creating a Swing component for the DynObject: "
168
                        + paramList.get(index), ex);
169
                Sextante.addErrorToLog(ex);
170
            }
171

    
172
                }
173
                
174
                if(e.getSource() == getCombo()) {
175
                        
176
                }
177
        }
178
}