Statistics
| Revision:

root / trunk / extensions / extTopology / src / org / gvsig / topology / ui / TopologyErrorPanel.java @ 18063

History | View | Annotate | Download (11.5 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 org.gvsig.topology.ui;
50

    
51
import java.awt.event.ActionEvent;
52
import java.awt.event.ActionListener;
53
import java.awt.geom.Rectangle2D;
54
import java.util.HashMap;
55
import java.util.Map;
56

    
57
import javax.swing.JCheckBox;
58
import javax.swing.JComboBox;
59
import javax.swing.JComponent;
60
import javax.swing.JLabel;
61
import javax.swing.JScrollPane;
62
import javax.swing.JTable;
63
import javax.swing.table.AbstractTableModel;
64

    
65
import org.gvsig.gui.beans.swing.JButton;
66
import org.gvsig.topology.IOneLyrRule;
67
import org.gvsig.topology.ITopologyErrorContainer;
68
import org.gvsig.topology.ITopologyRule;
69
import org.gvsig.topology.ITwoLyrRule;
70
import org.gvsig.topology.SimpleTopologyErrorContainer;
71
import org.gvsig.topology.TopologyError;
72
import org.gvsig.topology.ui.util.BoxLayoutPanel;
73

    
74
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
75
import com.iver.andami.PluginServices;
76
import com.iver.cit.gvsig.fmap.core.FShape;
77
import com.iver.cit.gvsig.fmap.core.IFeature;
78
import com.iver.cit.gvsig.project.documents.view.gui.View;
79

    
80
/**
81
 * Panel to show topology errors in a ITopologyErrorContainer.
82
 * 
83
 * Each topology error in the panel will have associated a popup menu
84
 * which allows to manage the error (view it in a gvSIG view, correct it, etc)
85
 * 
86
 * @author Alvaro Zabala
87
 *
88
 */
89
public class TopologyErrorPanel extends BoxLayoutPanel {
90

    
91
        private final class TopologyErrorTableModel extends AbstractTableModel {
92
                
93
                private static final long serialVersionUID = -5615838036054987191L;
94
                
95
                private ITopologyErrorContainer errorContainer;
96
                
97
                public void setErrorContainer(ITopologyErrorContainer errorContainer){
98
                        this.errorContainer = errorContainer;
99
                }
100
                
101
                
102
                public int getColumnCount() {
103
                        return 7;
104
                }
105

    
106
                public int getRowCount() {
107
                        return errorContainer.getNumberOfErrors();
108
                }
109

    
110
                public Object getValueAt(int row, int col) {
111
                        Object solution = null;
112
                        TopologyError error = errorContainer.getTopologyError(row);
113
                        ITopologyRule violatedRule = null;
114
                        
115
                        switch(col){
116
                        case 0:
117
                                violatedRule = error.getViolatedRule();
118
                                solution = violatedRule.getName();
119
                        break;
120
                        case 1:
121
                                violatedRule = error.getViolatedRule();
122
                                solution = ((IOneLyrRule)violatedRule).getOriginLyr().getName();
123
                        break;
124
                        case 2:
125
                                violatedRule = error.getViolatedRule();
126
                                if(violatedRule instanceof ITwoLyrRule){
127
                                        ITwoLyrRule twoLyrRule = (ITwoLyrRule) violatedRule;
128
                                        solution = twoLyrRule.getDestinationLyr().getName();
129
                                }else{
130
                                        solution = "";
131
                                }
132
                                
133
                        break;
134
                        case 3:
135
                                int shapeType = error.getShapeType();
136
                                switch(shapeType){
137
                                case FShape.POINT:
138
                                case FShape.TEXT:
139
                                        solution = PluginServices.getText(this, "POINT");
140
                                        break;
141
                                case FShape.POLYGON:
142
                                        solution = PluginServices.getText(this, "POLYGON");
143
                                        break;
144
                                case FShape.LINE:
145
                                case FShape.ARC:
146
                                case FShape.CIRCLE:
147
                                case FShape.ELLIPSE:
148
                                        solution = PluginServices.getText(this, "LINE");
149
                                        break;
150
                                case FShape.MULTI:
151
                                        solution = PluginServices.getText(this, "MULTI");
152
                                        break;
153
                                case FShape.MULTIPOINT:
154
                                        solution = PluginServices.getText(this, "MULTIPOINT");
155
                                        break;
156
                                }
157
                        break;
158
                        
159
                        case 4:
160
                                IFeature lyr1Feature = error.getFeature1();
161
                                solution = lyr1Feature.getID();
162
                        break;
163
                        
164
                        case 5:
165
                                IFeature lyr2Feature = error.getFeature2();
166
                                if(lyr2Feature != null)
167
                                        solution = lyr2Feature.getID();
168
                                else
169
                                        solution = "";
170
                        break;
171
                        
172
                        case 6:
173
                                if(error.isException())
174
                                        solution = PluginServices.getText(this, "SI");
175
                                else
176
                                        solution = PluginServices.getText(this, "NO");
177
                        break;
178
                        }
179
                        return solution;
180
                }
181
        }
182

    
183

    
184
        private static final long serialVersionUID = 768284651667411053L;
185
        
186
        /**
187
         * Has topology errors to show in this component (component's model)
188
         */
189
        private ITopologyErrorContainer errorContainer;
190
        
191
        /*
192
         * GUI components
193
         * */
194
        private JTable errorInspectorTable;
195
        private TopologyErrorTableModel dataModel;
196
        private JComboBox ruleFilterComboBox;
197
        private JCheckBox showErrors;
198
        private JCheckBox showExceptions;
199
        private JCheckBox showViewExtent;
200
        
201
        
202
        private final static String ALL_RULES_OPTION = 
203
                        PluginServices.getText(null, "ERROR_INSPECTOR_ALL_RULES");
204
        
205
        /**
206
         * links the text showed in the combobox with the filter option of the
207
         * topology error table
208
         */
209
        private Map<String, ITopologyRule> ruleOption_rule;
210
        
211
        
212
        /**
213
         * Constructor
214
         * @param errorContainer
215
         */
216
        public TopologyErrorPanel(ITopologyErrorContainer errorContainer){
217
                this.errorContainer = errorContainer;
218
                initialize();
219
        }
220
        
221
        
222
        private void initialize(){
223
                this.addRow(new JComponent[]{
224
                                new JLabel(PluginServices.getText(this, "ERROR_INSPECTOR_TITLE"))});
225
                
226
        
227
                this.addComponent(PluginServices.getText(this, "MOSTRAR"), 
228
                                                                                getRuleFilterComboBox());
229
                
230
                JComponent[] row = new JComponent[]{getShowErrorsCb(), getShowExceptionsCb(), getShowViewExtentCb()};
231
                this.addRow(row);
232
                
233
                this.addRow(new JComponent[]{getUpdateButton()});        
234
                
235
                this.addRow(new JComponent[]{new JScrollPane(getErrorInspectorTable())}, DEFAULT_WIDTH, 300);
236
        }
237
        
238
        private JComboBox getRuleFilterComboBox(){
239
                if(ruleFilterComboBox == null){
240
                        ruleFilterComboBox = new JComboBox();
241
                        ruleOption_rule = new HashMap<String, ITopologyRule>();
242
                        ruleFilterComboBox.addItem(ALL_RULES_OPTION);
243
                        ruleOption_rule.put(ALL_RULES_OPTION, null);
244
                        
245
                        Map<ITopologyRule,ITopologyRule> violatedRules = new HashMap<ITopologyRule, ITopologyRule>();
246
                        int errorCount = this.errorContainer.getNumberOfErrors();
247
                        for(int i = 0; i < errorCount; i++){
248
                                TopologyError topologyError = errorContainer.getTopologyError(i);
249
                                ITopologyRule violatedRule = topologyError.getViolatedRule();
250
                                if(violatedRules.get(violatedRule) != null)
251
                                        continue;
252
                                        
253
                                violatedRules.put(violatedRule, violatedRule);
254
                                String rule_option = ((IOneLyrRule)violatedRule).getOriginLyr().getName() 
255
                                        + " - ";
256
                                if(violatedRule instanceof ITwoLyrRule){
257
                                        ITwoLyrRule twoLyrRule = (ITwoLyrRule) violatedRule;
258
                                        rule_option += twoLyrRule.getName() + " - ";
259
                                }
260
                                rule_option += violatedRule.getDescription();
261
                                
262
                                ruleOption_rule.put(rule_option, violatedRule);
263
                                ruleFilterComboBox.addItem(rule_option);
264
                        }//for
265
                }//if
266
                return ruleFilterComboBox;
267
        }
268
        
269
        private JCheckBox getShowErrorsCb(){
270
                if(showErrors == null){
271
                        showErrors = new JCheckBox(PluginServices.getText(this, "ERRORS"));
272
                        showErrors.setSelected(true);
273
                }
274
                return showErrors;
275
        }
276
        
277
        private JCheckBox getShowExceptionsCb(){
278
                if(showExceptions == null){
279
                        showExceptions = new JCheckBox(PluginServices.getText(this, "EXCEPTIONS"));
280
                        showExceptions.setSelected(true);
281
                }
282
                return showExceptions;
283
        }
284
        
285
        private JCheckBox getShowViewExtentCb(){
286
                showViewExtent = new JCheckBox(PluginServices.getText(this, "VIEW_EXTENT"));
287
                return showViewExtent;
288
        }
289
        
290
        private JButton getUpdateButton(){
291
                JButton updateButton = new JButton(PluginServices.getText(this, "UPDATE"));
292
                updateButton.addActionListener(new ActionListener(){
293
                        public void actionPerformed(ActionEvent arg0) {
294
                                updateErrorTable();
295
                        }});
296
                return updateButton;
297
        }
298
        
299
        private JTable getErrorInspectorTable(){
300
                if(errorInspectorTable == null){
301
                        errorInspectorTable = new JTable();
302
                        dataModel = new TopologyErrorTableModel();
303
                        dataModel.setErrorContainer(errorContainer);
304
                        errorInspectorTable.setModel(dataModel);
305
                        errorInspectorTable.getColumnModel().
306
                                                                        getColumn(0).
307
                                                                        setHeaderValue(PluginServices.getText(this, "Rule_type"));
308
                        
309
                        errorInspectorTable.getColumnModel().
310
                                                                        getColumn(1).
311
                                                                        setHeaderValue(PluginServices.getText(this, "Layer_1"));
312
                        
313
                        errorInspectorTable.getColumnModel().
314
                                                                        getColumn(2).
315
                                                                        setHeaderValue(PluginServices.getText(this, "Layer_2"));
316
                        
317
                        errorInspectorTable.getColumnModel().
318
                                                                        getColumn(3).
319
                                                                        setHeaderValue(PluginServices.getText(this, "Shape_Type"));
320
                        
321
                        errorInspectorTable.getColumnModel().
322
                                                                        getColumn(4).
323
                                                                        setHeaderValue(PluginServices.getText(this, "Feature_1"));
324
                        
325
                        errorInspectorTable.getColumnModel().
326
                                                                        getColumn(5).
327
                                                                        setHeaderValue(PluginServices.getText(this, "Feature_2"));
328
                        
329
                        errorInspectorTable.getColumnModel().
330
                                                                        getColumn(6).
331
                                                                        setHeaderValue(PluginServices.getText(this, "Exception"));        
332
                }
333
                return errorInspectorTable;
334
        }
335
        
336
        
337
        public void updateErrorTable(){
338
                ITopologyRule filterRule = getSelectedRule();
339
                boolean showExceptions = isExceptionsSelected();
340
                boolean showErrors = isErrorsSelected();
341
                //show all topology errors
342
                if(filterRule == null && showExceptions && showErrors){
343
                        dataModel.setErrorContainer(errorContainer);
344
                        getErrorInspectorTable().revalidate();
345
                        return;
346
                }
347
                boolean filterByViewExtent = isOnlyViewExtentSelected();
348
                SimpleTopologyErrorContainer filteredErrorContainer = 
349
                        new SimpleTopologyErrorContainer();
350
                for(int i = 0; i < errorContainer.getNumberOfErrors(); i++){
351
                        TopologyError error = errorContainer.getTopologyError(i);
352
                        
353
                        if(filterByViewExtent){
354
                                Rectangle2D errorExtent = error.getGeometry().getBounds2D();
355
                                View activeView = (View) PluginServices.getMDIManager().getActiveWindow();
356
                                Rectangle2D viewExtent = null;
357
                                try {
358
                                        viewExtent = activeView.getMapControl().
359
                                                                                        getMapContext().
360
                                                                                        getFullExtent();
361
                                        
362
                                        if(! errorExtent.intersects(viewExtent))
363
                                                continue;
364
                                } catch (ReadDriverException e) {
365
                                        e.printStackTrace();
366
                                }
367
                        }
368
                        if(error.isException() && !showExceptions){
369
                                continue;
370
                        }else{
371
                                if(!error.isException()&& !showErrors){
372
                                        continue;
373
                                }
374
                        }
375
                        filteredErrorContainer.addTopologyError(error);
376
                }//for        
377
                
378
                dataModel.setErrorContainer(filteredErrorContainer);
379
                getErrorInspectorTable().revalidate();
380
                
381
        }
382
        
383
        
384
        public boolean isErrorsSelected(){
385
                return showErrors.isSelected();
386
        }
387
        
388
        
389
        public boolean isExceptionsSelected(){
390
                return showExceptions.isSelected();
391
        }
392
        
393
        
394
        public boolean isOnlyViewExtentSelected(){
395
                return showViewExtent.isSelected();
396
        }
397
        
398
        
399
        public ITopologyRule getSelectedRule(){
400
                return ruleOption_rule.get(ruleFilterComboBox.getSelectedItem());
401
        }
402
        
403
}