Statistics
| Revision:

root / trunk / extensions / extTopology / src / com / iver / cit / gvsig / geoprocess / impl / referencing / gui / ReferencingGeoprocessPanel.java @ 23163

History | View | Annotate | Download (8.11 KB)

1
/*
2
 * Created on 10-abr-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: 
47
* $Log: 
48
*/
49
package com.iver.cit.gvsig.geoprocess.impl.referencing.gui;
50

    
51
import java.awt.event.ItemEvent;
52
import java.awt.event.ItemListener;
53
import java.util.Collection;
54
import java.util.Iterator;
55

    
56
import javax.swing.JComboBox;
57
import javax.swing.JLabel;
58
import javax.vecmath.MismatchedSizeException;
59

    
60
import org.geotools.referencefork.referencing.operation.builder.RubberSheetBuilder;
61
import org.gvsig.referencing.MappedPositionContainer;
62
import org.gvsig.referencing.ReferencingUtil;
63
import org.gvsig.topology.ui.util.GUIUtil;
64
import org.opengis.referencing.FactoryException;
65
import org.opengis.referencing.operation.MathTransform;
66
import org.opengis.spatialschema.geometry.MismatchedDimensionException;
67
import org.opengis.spatialschema.geometry.MismatchedReferenceSystemException;
68

    
69
import com.iver.andami.PluginServices;
70
import com.iver.andami.ui.mdiManager.IWindow;
71
import com.iver.cit.gvsig.fmap.MapControl;
72
import com.iver.cit.gvsig.fmap.layers.FLayers;
73
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
74
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
75
import com.iver.cit.gvsig.geoprocess.core.gui.AbstractGeoprocessGridbagPanel;
76
import com.iver.cit.gvsig.geoprocess.impl.referencing.IReferencingGeoprocessUserEntries;
77
import com.iver.cit.gvsig.project.documents.view.gui.View;
78
import com.iver.cit.gvsig.referencing.TransformationsRegistry;
79
import com.iver.cit.gvsig.referencing.TransformationsRegistry.TransformationRegistryEntry;
80

    
81
public class ReferencingGeoprocessPanel extends AbstractGeoprocessGridbagPanel implements IReferencingGeoprocessUserEntries{
82

    
83
        private MapControl currentView;
84
        
85
//        private MappedPositionContainer verrorList;
86

    
87
//        private String controlPointsTitle;
88

    
89
        private String transformationTitle;
90

    
91
        private VectorErrorTable vectorErrorTable;
92
        
93
        private JComboBox transformationOptionCb;
94
        
95
        
96
        
97
        public ReferencingGeoprocessPanel(FLayers layers) {
98
                super(layers, PluginServices.getText(null, "SPATIAL_ADJUST"));
99
        }
100

    
101
        private static final long serialVersionUID = 5209039148987326055L;
102

    
103
        @Override
104
        protected void addSpecificDesign() {
105
                IWindow f = PluginServices.getMDIManager().getActiveWindow();
106
                View vista = (View) f;
107
                if (f != null) {
108
                        MapControl mapControl = vista.getMapControl();
109
                        this.currentView = mapControl;
110
                }
111
                
112
                
113
//                controlPointsTitle = PluginServices.getText(null, "Control_points");
114
                transformationTitle = PluginServices.getText(null, "Transform");
115
                
116
        
117
//                JLabel controlPointsLbl = new JLabel(controlPointsTitle);
118
//                addComponent(controlPointsLbl);
119
                
120
                JComboBox cb = getTransformationOptionCb();
121
                addComponent(vectorErrorTable = new VectorErrorTable(currentView, 
122
                                                                                                                 getInputLayer(),
123
                                                                                                                 (TransformationRegistryEntry)cb.getSelectedItem() ));
124
                
125
                
126
                JLabel transformTitleLbl = new JLabel(transformationTitle);
127
                addComponent(transformTitleLbl);
128
                
129
                addComponent(cb);
130
                
131
                initSelectedItemsJCheckBox();
132
                updateNumSelectedFeaturesLabel();
133
        }
134
        
135
        
136

    
137
        private JComboBox getTransformationOptionCb(){
138
                if(transformationOptionCb == null){
139
                        transformationOptionCb = new JComboBox();
140
                        
141
                        Collection<TransformationRegistryEntry> transforms =
142
                                        TransformationsRegistry.getRegisteredTransforms();
143
                        Iterator<TransformationRegistryEntry> it = transforms.iterator();
144
                        while(it.hasNext()){
145
                                transformationOptionCb.addItem(it.next());
146
                        }
147
                        
148
                        transformationOptionCb.addItemListener(new ItemListener() {
149
                                public void itemStateChanged(ItemEvent e) {
150
                                        if (e.getStateChange() == ItemEvent.SELECTED) {
151
                                                TransformationRegistryEntry selectedEntry = 
152
                                                        (TransformationRegistryEntry) e.getItem();
153
                                                try{
154
//                                                        MathTransformBuilder transformBuilder = 
155
//                                                                selectedEntry.createTransformBuilder(verrorList.getAsList());
156
                                                        vectorErrorTable.setTransformBuilderProvider(selectedEntry);
157
                                                }catch(MismatchedSizeException exception){
158
                                                        GUIUtil.getInstance().messageBox(PluginServices.getText(this, "INCORRECT_VERROR_LINKS"), 
159
                                                                        PluginServices.getText(this, "TRANSFORMATION_ERROR"));
160
                                                }catch(MismatchedDimensionException exception){
161
                                                        GUIUtil.getInstance().messageBox(PluginServices.getText(this, "INCORRECT_VERROR_LINKS"), 
162
                                                                        PluginServices.getText(this, "TRANSFORMATION_ERROR"));
163
                                                }catch(MismatchedReferenceSystemException exception){
164
                                                        GUIUtil.getInstance().messageBox(PluginServices.getText(this, "INCORRECT_VERROR_LINKS"), 
165
                                                                        PluginServices.getText(this, "TRANSFORMATION_ERROR"));
166
                                                } catch (FactoryException exception) {
167
                                                        GUIUtil.getInstance().messageBox(PluginServices.getText(this, "FACTORY_EXCEPTION"), 
168
                                                                        PluginServices.getText(this, "TRANSFORMATION_ERROR"));
169
                                                }
170
                                                
171
                                        }
172
                                }// itemStateChange
173
                        });
174
                }//if transformationCb
175
                return transformationOptionCb;
176
        }
177
        
178
        @Override
179
        /**
180
         * This method is called when layer combo box selection changes.
181
         */
182
        protected void processLayerComboBoxStateChange(ItemEvent e) {
183
                vectorErrorTable.setAdjustingLyr(getInputLayer());
184
        }
185

    
186
        public MathTransform getMathTransform() throws GeoprocessException {
187
                try {
188
//                        return  ((TransformationRegistryEntry)getTransformationOptionCb().getSelectedItem()).
189
//                                                        createTransformBuilder(verrorList.getAsList()).getMathTransform();
190
                        MappedPositionContainer mp = this.vectorErrorTable.getVerrorContainer();
191
                        return  ((TransformationRegistryEntry)getTransformationOptionCb().
192
                                                                                                                        getSelectedItem()).
193
                                                                                                                        createTransformBuilder(mp.getAsList()).
194
                                                                                                                        getMathTransform();
195
                } catch (FactoryException e) {
196
                        throw new GeoprocessException(e);
197
                }catch(RuntimeException re){
198
                        re.printStackTrace();
199
                        throw new GeoprocessException(re);
200
                }
201
        }
202

    
203
        public boolean onlyFirstLayerSelected() {
204
                return isFirstOnlySelected();
205
        }
206

    
207

    
208

    
209
        public FLyrVect[] getAuxiliarLyrs() {
210
                if(hasAuxiliarLyrs()){
211
                        MappedPositionContainer mp = this.vectorErrorTable.getVerrorContainer();
212
                        TransformationRegistryEntry transformRegistryEntry = 
213
                                (TransformationRegistryEntry)getTransformationOptionCb().getSelectedItem();
214
                        RubberSheetBuilder transformBuilder = 
215
                                (RubberSheetBuilder) transformRegistryEntry.createTransformBuilder(mp.getAsList());
216
                        FLyrVect tinLyr = ReferencingUtil.getInstance().getTinAsFMapLyr(transformBuilder, currentView.getProjection());
217
                        return new FLyrVect[]{tinLyr};
218
                }else{
219
                        return new FLyrVect[]{};
220
                }
221
        }
222

    
223

    
224

    
225
        public boolean hasAuxiliarLyrs() {
226
                //by now, the only transformation with auxiliar layers is Rubber Sheet Transform,
227
                //being this auxiliar layer TIN formed with mapped positions.
228
                TransformationRegistryEntry transformRegistryEntry = 
229
                        (TransformationRegistryEntry)getTransformationOptionCb().getSelectedItem();
230
                return transformRegistryEntry.getName().
231
                        equals(PluginServices.getText(null, "RUBBER_SHEET_TRANSFORM"));
232
        }
233

    
234
}