svn-gvsig-desktop / trunk / extensions / extTopology / src / org / gvsig / topology / ui / TopologyErrorPanel.java @ 24091
History | View | Annotate | Download (26.7 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.BorderLayout; |
52 |
import java.awt.Dimension; |
53 |
import java.awt.Frame; |
54 |
import java.awt.Point; |
55 |
import java.awt.Window; |
56 |
import java.awt.event.ActionEvent; |
57 |
import java.awt.event.ActionListener; |
58 |
import java.awt.event.MouseAdapter; |
59 |
import java.awt.event.MouseEvent; |
60 |
import java.awt.geom.Rectangle2D; |
61 |
import java.net.URL; |
62 |
import java.util.HashMap; |
63 |
import java.util.List; |
64 |
import java.util.Map; |
65 |
|
66 |
import javax.swing.JCheckBox; |
67 |
import javax.swing.JComboBox; |
68 |
import javax.swing.JComponent; |
69 |
import javax.swing.JDialog; |
70 |
import javax.swing.JEditorPane; |
71 |
import javax.swing.JLabel; |
72 |
import javax.swing.JMenuItem; |
73 |
import javax.swing.JOptionPane; |
74 |
import javax.swing.JPanel; |
75 |
import javax.swing.JPopupMenu; |
76 |
import javax.swing.JScrollPane; |
77 |
import javax.swing.JTable; |
78 |
import javax.swing.table.AbstractTableModel; |
79 |
import javax.swing.text.html.HTMLEditorKit; |
80 |
|
81 |
import org.gvsig.exceptions.BaseException; |
82 |
import org.gvsig.gui.beans.swing.JButton; |
83 |
import org.gvsig.topology.IOneLyrRule; |
84 |
import org.gvsig.topology.ITopologyErrorContainer; |
85 |
import org.gvsig.topology.ITopologyErrorFix; |
86 |
import org.gvsig.topology.ITopologyRule; |
87 |
import org.gvsig.topology.ITwoLyrRule; |
88 |
import org.gvsig.topology.SimpleTopologyErrorContainer; |
89 |
import org.gvsig.topology.TopologyError; |
90 |
import org.gvsig.topology.errorfixes.ITopologyErrorFixWithParameters; |
91 |
import org.gvsig.topology.ui.util.BoxLayoutPanel; |
92 |
import org.gvsig.topology.ui.util.GUIUtil; |
93 |
import org.gvsig.topology.ui.util.PanelEntriesDialog; |
94 |
import org.gvsig.util.GParameter; |
95 |
|
96 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
97 |
import com.iver.andami.PluginServices; |
98 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
99 |
import com.iver.andami.ui.mdiManager.IWindow; |
100 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
101 |
import com.iver.cit.gvsig.fmap.MapContext; |
102 |
import com.iver.cit.gvsig.fmap.core.FGeometryCollection; |
103 |
import com.iver.cit.gvsig.fmap.core.FShape; |
104 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
105 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
106 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
107 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
108 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
109 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
110 |
import com.iver.utiles.swing.threads.TopologyBatchCorrectionTask; |
111 |
|
112 |
/**
|
113 |
* Panel to show topology errors stored in a ITopologyErrorContainer.
|
114 |
*
|
115 |
* Each topology error in the panel will have associated a popup menu which
|
116 |
* allows to manage the error (view it in a gvSIG view, correct it, etc)
|
117 |
*
|
118 |
* @author Alvaro Zabala
|
119 |
*
|
120 |
*/
|
121 |
public class TopologyErrorPanel extends BoxLayoutPanel { |
122 |
|
123 |
/**
|
124 |
* Table model to show topology errors in a table.
|
125 |
* @author Alvaro Zabala
|
126 |
*
|
127 |
*/
|
128 |
private final class TopologyErrorTableModel extends AbstractTableModel { |
129 |
|
130 |
private static final long serialVersionUID = -5615838036054987191L; |
131 |
|
132 |
private ITopologyErrorContainer errorContainer;
|
133 |
|
134 |
public void setErrorContainer(ITopologyErrorContainer errorContainer) { |
135 |
this.errorContainer = errorContainer;
|
136 |
} |
137 |
|
138 |
public int getColumnCount() { |
139 |
return 7; |
140 |
} |
141 |
|
142 |
public int getRowCount() { |
143 |
return errorContainer.getNumberOfErrors();
|
144 |
} |
145 |
|
146 |
public Object getValueAt(int row, int col) { |
147 |
Object solution = null; |
148 |
TopologyError error = errorContainer.getTopologyError(row); |
149 |
ITopologyRule violatedRule = null;
|
150 |
|
151 |
switch (col) {
|
152 |
case 0: |
153 |
violatedRule = error.getViolatedRule(); |
154 |
solution = violatedRule.getName(); |
155 |
break;
|
156 |
case 1: |
157 |
violatedRule = error.getViolatedRule(); |
158 |
solution = ((IOneLyrRule) violatedRule).getOriginLyr() |
159 |
.getName(); |
160 |
break;
|
161 |
case 2: |
162 |
violatedRule = error.getViolatedRule(); |
163 |
if (violatedRule instanceof ITwoLyrRule) { |
164 |
ITwoLyrRule twoLyrRule = (ITwoLyrRule) violatedRule; |
165 |
solution = twoLyrRule.getDestinationLyr().getName(); |
166 |
} else {
|
167 |
solution = "";
|
168 |
} |
169 |
|
170 |
break;
|
171 |
case 3: |
172 |
int shapeType = error.getShapeType();
|
173 |
switch (shapeType) {
|
174 |
case FShape.POINT:
|
175 |
case FShape.TEXT:
|
176 |
solution = PluginServices.getText(this, "POINT"); |
177 |
break;
|
178 |
case FShape.POLYGON:
|
179 |
solution = PluginServices.getText(this, "POLYGON"); |
180 |
break;
|
181 |
case FShape.LINE:
|
182 |
case FShape.ARC:
|
183 |
case FShape.CIRCLE:
|
184 |
case FShape.ELLIPSE:
|
185 |
//We have found that FGeometryCollection returns FShape.LINE
|
186 |
//Are there any reason for this?
|
187 |
if(error.getGeometry() instanceof FGeometryCollection) |
188 |
solution = PluginServices.getText(this, "MULTIGEOMETRY"); |
189 |
else
|
190 |
solution = PluginServices.getText(this, "LINE"); |
191 |
break;
|
192 |
case FShape.MULTI:
|
193 |
solution = PluginServices.getText(this, "MULTI"); |
194 |
break;
|
195 |
case FShape.MULTIPOINT:
|
196 |
solution = PluginServices.getText(this, "MULTIPOINT"); |
197 |
break;
|
198 |
} |
199 |
break;
|
200 |
|
201 |
case 4: |
202 |
IFeature lyr1Feature = error.getFeature1(); |
203 |
if(lyr1Feature != null) |
204 |
solution = lyr1Feature.getID(); |
205 |
else
|
206 |
solution = "";
|
207 |
break;
|
208 |
|
209 |
case 5: |
210 |
IFeature lyr2Feature = error.getFeature2(); |
211 |
if (lyr2Feature != null) |
212 |
solution = lyr2Feature.getID(); |
213 |
else
|
214 |
solution = "";
|
215 |
break;
|
216 |
|
217 |
case 6: |
218 |
if (error.isException())
|
219 |
solution = PluginServices.getText(this, "SI"); |
220 |
else
|
221 |
solution = PluginServices.getText(this, "NO"); |
222 |
break;
|
223 |
} |
224 |
return solution;
|
225 |
} |
226 |
} |
227 |
|
228 |
private static final long serialVersionUID = 768284651667411053L; |
229 |
|
230 |
/**
|
231 |
* Has topology errors to show in this component (component's model)
|
232 |
*/
|
233 |
private ITopologyErrorContainer errorContainer;
|
234 |
|
235 |
/*
|
236 |
* GUI components
|
237 |
*/
|
238 |
private JTable errorInspectorTable; |
239 |
private TopologyErrorTableModel dataModel;
|
240 |
private JComboBox ruleFilterComboBox; |
241 |
private JCheckBox showErrors; |
242 |
private JCheckBox showExceptions; |
243 |
private JCheckBox showViewExtent; |
244 |
|
245 |
private final static String ALL_RULES_OPTION = PluginServices.getText(null, |
246 |
"ERROR_INSPECTOR_ALL_RULES");
|
247 |
|
248 |
/**
|
249 |
* links the text showed in the combobox with the filter option of the
|
250 |
* topology error table
|
251 |
*/
|
252 |
private Map<String, ITopologyRule> ruleOption_rule; |
253 |
|
254 |
// private List<FGraphic> selectedErrors;
|
255 |
|
256 |
/**
|
257 |
* Code of the symbol used to mark selections
|
258 |
*/
|
259 |
// int symbolSelectionCode;
|
260 |
|
261 |
|
262 |
/**
|
263 |
* Constructor
|
264 |
*
|
265 |
* @param errorContainer
|
266 |
*/
|
267 |
public TopologyErrorPanel(ITopologyErrorContainer errorContainer) {
|
268 |
this.errorContainer = errorContainer;
|
269 |
// this.selectedErrors = new ArrayList<FGraphic>();
|
270 |
|
271 |
// ISymbol selectionSymbol = new SimpleFillSymbol().getSymbolForSelection();
|
272 |
// IWindow f = PluginServices.getMDIManager().getActiveWindow();
|
273 |
// View vista = (View)f;
|
274 |
// symbolSelectionCode = vista.getMapControl().
|
275 |
// getMapContext().
|
276 |
// getGraphicsLayer().
|
277 |
// addSymbol(selectionSymbol);
|
278 |
|
279 |
initialize(); |
280 |
} |
281 |
|
282 |
private void initialize() { |
283 |
this.addRow(new JComponent[] { new JLabel(PluginServices.getText(this, |
284 |
"ERROR_INSPECTOR_TITLE")) });
|
285 |
|
286 |
this.addComponent(PluginServices.getText(this, "MOSTRAR"), |
287 |
getRuleFilterComboBox()); |
288 |
|
289 |
JComponent[] row = new JComponent[] { getShowErrorsCb(), |
290 |
getShowExceptionsCb(), getShowViewExtentCb() }; |
291 |
this.addRow(row, 600, DEFAULT_HEIGHT); |
292 |
|
293 |
this.addRow(new JComponent[] { getUpdateButton(), getBatchFixButton() }, 600, |
294 |
DEFAULT_HEIGHT); |
295 |
|
296 |
this.addRow(new JComponent[] { new JScrollPane(getErrorInspectorTable()) }, |
297 |
600, 300); |
298 |
} |
299 |
|
300 |
private JComboBox getRuleFilterComboBox() { |
301 |
if (ruleFilterComboBox == null) { |
302 |
ruleFilterComboBox = new JComboBox(); |
303 |
ruleOption_rule = new HashMap<String, ITopologyRule>(); |
304 |
ruleFilterComboBox.addItem(ALL_RULES_OPTION); |
305 |
ruleOption_rule.put(ALL_RULES_OPTION, null);
|
306 |
|
307 |
Map<ITopologyRule, ITopologyRule> violatedRules = new HashMap<ITopologyRule, ITopologyRule>(); |
308 |
int errorCount = this.errorContainer.getNumberOfErrors(); |
309 |
for (int i = 0; i < errorCount; i++) { |
310 |
TopologyError topologyError = errorContainer |
311 |
.getTopologyError(i); |
312 |
ITopologyRule violatedRule = topologyError.getViolatedRule(); |
313 |
if (violatedRules.get(violatedRule) != null) |
314 |
continue;
|
315 |
|
316 |
violatedRules.put(violatedRule, violatedRule); |
317 |
String rule_option = ((IOneLyrRule) violatedRule)
|
318 |
.getOriginLyr().getName() |
319 |
+ " - ";
|
320 |
if (violatedRule instanceof ITwoLyrRule) { |
321 |
ITwoLyrRule twoLyrRule = (ITwoLyrRule) violatedRule; |
322 |
rule_option += twoLyrRule.getDestinationLyr().getName() + " - ";
|
323 |
} |
324 |
rule_option += violatedRule.getName(); |
325 |
|
326 |
ruleOption_rule.put(rule_option, violatedRule); |
327 |
ruleFilterComboBox.addItem(rule_option); |
328 |
}// for
|
329 |
}// if
|
330 |
return ruleFilterComboBox;
|
331 |
} |
332 |
|
333 |
private JCheckBox getShowErrorsCb() { |
334 |
if (showErrors == null) { |
335 |
showErrors = new JCheckBox(PluginServices.getText(this, "ERRORS")); |
336 |
showErrors.setSelected(true);
|
337 |
} |
338 |
return showErrors;
|
339 |
} |
340 |
|
341 |
private JCheckBox getShowExceptionsCb() { |
342 |
if (showExceptions == null) { |
343 |
showExceptions = new JCheckBox(PluginServices.getText(this, |
344 |
"EXCEPTIONS"));
|
345 |
showExceptions.setSelected(true);
|
346 |
} |
347 |
return showExceptions;
|
348 |
} |
349 |
|
350 |
private JCheckBox getShowViewExtentCb() { |
351 |
showViewExtent = new JCheckBox(PluginServices.getText(this, |
352 |
"VIEW_EXTENT"));
|
353 |
return showViewExtent;
|
354 |
} |
355 |
|
356 |
private JButton getUpdateButton() { |
357 |
JButton updateButton = new JButton(PluginServices.getText(this, |
358 |
"UPDATE"));
|
359 |
updateButton.addActionListener(new ActionListener() { |
360 |
public void actionPerformed(ActionEvent arg0) { |
361 |
updateErrorTable(); |
362 |
} |
363 |
}); |
364 |
return updateButton;
|
365 |
} |
366 |
|
367 |
private JButton getBatchFixButton(){ |
368 |
JButton batchFixButton = new JButton(PluginServices.getText(this, "BATCH_FIX")); |
369 |
batchFixButton.addActionListener(new ActionListener() { |
370 |
public void actionPerformed(ActionEvent arg0) { |
371 |
batchFix(); |
372 |
} |
373 |
|
374 |
|
375 |
}); |
376 |
return batchFixButton;
|
377 |
} |
378 |
|
379 |
private void batchFix() { |
380 |
ITopologyRule selectedRule = getSelectedRule(); |
381 |
ITopologyErrorFix errorFix = selectedRule.getDefaultFix(); |
382 |
if(errorFix instanceof ITopologyErrorFixWithParameters){ |
383 |
GUIUtil.getInstance().messageBox(PluginServices.getText(this, "correction_needs_user_interaction"), |
384 |
PluginServices.getText(this, "could_not_launch_process")); |
385 |
return;
|
386 |
} |
387 |
|
388 |
TopologyBatchCorrectionTask task = new TopologyBatchCorrectionTask(this.errorContainer, selectedRule); |
389 |
PluginServices.cancelableBackgroundExecution(task); |
390 |
|
391 |
} |
392 |
|
393 |
private JTable getErrorInspectorTable() { |
394 |
if (errorInspectorTable == null) { |
395 |
errorInspectorTable = new JTable(); |
396 |
dataModel = new TopologyErrorTableModel();
|
397 |
dataModel.setErrorContainer(errorContainer); |
398 |
errorInspectorTable.setModel(dataModel); |
399 |
errorInspectorTable.getColumnModel().getColumn(0).setHeaderValue(
|
400 |
PluginServices.getText(this, "Rule_type")); |
401 |
|
402 |
errorInspectorTable.getColumnModel().getColumn(1).setHeaderValue(
|
403 |
PluginServices.getText(this, "Layer_1")); |
404 |
|
405 |
errorInspectorTable.getColumnModel().getColumn(2).setHeaderValue(
|
406 |
PluginServices.getText(this, "Layer_2")); |
407 |
|
408 |
errorInspectorTable.getColumnModel().getColumn(3).setHeaderValue(
|
409 |
PluginServices.getText(this, "Shape_Type")); |
410 |
|
411 |
errorInspectorTable.getColumnModel().getColumn(4).setHeaderValue(
|
412 |
PluginServices.getText(this, "Feature_1")); |
413 |
|
414 |
errorInspectorTable.getColumnModel().getColumn(5).setHeaderValue(
|
415 |
PluginServices.getText(this, "Feature_2")); |
416 |
|
417 |
errorInspectorTable.getColumnModel().getColumn(6).setHeaderValue(
|
418 |
PluginServices.getText(this, "Exception")); |
419 |
} |
420 |
|
421 |
errorInspectorTable.addMouseListener(new MouseAdapter() { |
422 |
|
423 |
private void maybeShowPopup(MouseEvent e) { |
424 |
if (e.isPopupTrigger() && errorInspectorTable.isEnabled()) {
|
425 |
Point p = new Point(e.getX(), e.getY()); |
426 |
int row = errorInspectorTable.rowAtPoint(p);
|
427 |
if (row >= 0 && row < errorInspectorTable.getRowCount()) { |
428 |
JPopupMenu contextMenu = createContextMenu(row);
|
429 |
if (contextMenu != null |
430 |
&& contextMenu.getComponentCount() > 0) {
|
431 |
contextMenu.show(errorInspectorTable, p.x, p.y); |
432 |
}//if
|
433 |
}//if
|
434 |
}//if
|
435 |
} |
436 |
|
437 |
private JPopupMenu createContextMenu(final int row) { |
438 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
439 |
if(! (f instanceof View)) |
440 |
return null; |
441 |
final View vista = (View)f; |
442 |
final TopologyError error = errorContainer.getTopologyError(row);
|
443 |
|
444 |
JPopupMenu contextMenu = new JPopupMenu(); |
445 |
JMenuItem panMenu = new JMenuItem(); |
446 |
panMenu.setText(PluginServices.getText(this, "PAN_TO")); |
447 |
panMenu.addActionListener(new ActionListener() { |
448 |
public void actionPerformed(ActionEvent e) { |
449 |
IProjectView model = vista.getModel(); |
450 |
MapContext mapa = model.getMapContext(); |
451 |
Rectangle2D currentExtent = mapa.getViewPort().getExtent();
|
452 |
double width = currentExtent.getWidth();
|
453 |
double height = currentExtent.getHeight();
|
454 |
|
455 |
Rectangle2D errorBounds = error.getGeometry().getBounds2D();
|
456 |
double centerX = errorBounds.getCenterX();
|
457 |
double centerY = errorBounds.getCenterY();
|
458 |
|
459 |
Rectangle2D newExtent = new Rectangle2D.Double(centerX - (width / 2), |
460 |
centerY - (height / 2),
|
461 |
width, |
462 |
height); |
463 |
mapa.getViewPort().setExtent(newExtent); |
464 |
((ProjectDocument)vista.getModel()).setModified(true);
|
465 |
|
466 |
} |
467 |
|
468 |
}); |
469 |
contextMenu.add(panMenu); |
470 |
|
471 |
|
472 |
JMenuItem zoomMenu = new JMenuItem(); |
473 |
zoomMenu.setText(PluginServices.getText(this, "ZOOM_TO")); |
474 |
zoomMenu.addActionListener(new ActionListener() { |
475 |
public void actionPerformed(ActionEvent e) { |
476 |
IProjectView model = vista.getModel(); |
477 |
MapContext mapa = model.getMapContext(); |
478 |
Rectangle2D errorBounds = null; |
479 |
|
480 |
errorBounds = error.getGeometry().getBounds2D(); |
481 |
// if(error.getGeometry() instanceof FGeometryCollection){
|
482 |
// errorBounds = ((FGeometryCollection) error.getGeometry()).getGeometries()[0].getBounds2D();
|
483 |
// }else
|
484 |
// errorBounds = error.getGeometry().getBounds2D();
|
485 |
//
|
486 |
// double w = 600d;
|
487 |
// double h = 400d;
|
488 |
//
|
489 |
// if(errorBounds.getWidth() > w)
|
490 |
// w = errorBounds.getWidth();
|
491 |
// if(errorBounds.getHeight() > h)
|
492 |
// h = errorBounds.getHeight();
|
493 |
//
|
494 |
// double minx = errorBounds.getMinX();
|
495 |
// double miny = errorBounds.getMinY();
|
496 |
//
|
497 |
// Rectangle2D newExtent = new Rectangle2D.Double(minx,
|
498 |
// miny,
|
499 |
// w / 2,
|
500 |
// h / 2);
|
501 |
// //we select the error to make easy its localization in map
|
502 |
FLyrVect errorLyr = (FLyrVect) error.getTopology().getErrorLayer(); |
503 |
try {
|
504 |
errorLyr.getRecordset().clearSelection(); |
505 |
FBitSet newSelection = new FBitSet();
|
506 |
newSelection.set(row); |
507 |
errorLyr.getRecordset().setSelection(newSelection); |
508 |
} catch (ReadDriverException e1) {
|
509 |
// TODO Auto-generated catch block
|
510 |
e1.printStackTrace(); |
511 |
} |
512 |
|
513 |
Rectangle2D newExtent = errorBounds;
|
514 |
mapa.getViewPort().setExtent(newExtent); |
515 |
((ProjectDocument)vista.getModel()).setModified(true);
|
516 |
} |
517 |
}); |
518 |
contextMenu.add(zoomMenu); |
519 |
contextMenu.addSeparator(); |
520 |
|
521 |
JMenuItem viewDescriptionMenu = new JMenuItem(); |
522 |
viewDescriptionMenu.setText(PluginServices.getText(this, "VIEW_RULE_DESCRIPTION")); |
523 |
viewDescriptionMenu.addActionListener(new ActionListener() { |
524 |
public void actionPerformed(ActionEvent e) { |
525 |
showViolatedRuleDescriptionDialog(error); |
526 |
} |
527 |
|
528 |
private void showViolatedRuleDescriptionDialog( |
529 |
final TopologyError error) {
|
530 |
|
531 |
|
532 |
class DescriptionPanel extends JPanel implements IWindow{ |
533 |
public WindowInfo getWindowInfo() {
|
534 |
WindowInfo solution = new WindowInfo(WindowInfo.MODALDIALOG|
|
535 |
WindowInfo.PALETTE| |
536 |
WindowInfo.ICONIFIABLE| |
537 |
WindowInfo.RESIZABLE|WindowInfo.MAXIMIZABLE); |
538 |
solution.setWidth(300);
|
539 |
solution.setHeight(300);
|
540 |
return solution;
|
541 |
} |
542 |
|
543 |
} |
544 |
|
545 |
final DescriptionPanel descriptionPanel =
|
546 |
new DescriptionPanel();
|
547 |
descriptionPanel.setLayout(new BorderLayout()); |
548 |
|
549 |
JScrollPane rightPanel = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
550 |
JEditorPane htmlViewer = new JEditorPane(){ |
551 |
public URL getPage() { |
552 |
return null; |
553 |
} |
554 |
}; |
555 |
htmlViewer.setEditable(false);
|
556 |
htmlViewer.setEditorKit(new HTMLEditorKit()); |
557 |
rightPanel.setViewportView(htmlViewer); |
558 |
rightPanel.setPreferredSize(new Dimension(250, 140)); |
559 |
try {
|
560 |
ITopologyRule rule = error.getViolatedRule(); |
561 |
URL description = rule.getDescription();
|
562 |
htmlViewer.setPage(description); |
563 |
} catch (Exception ex) { |
564 |
htmlViewer.setText("<p>"+PluginServices.getText(this, "UNAVAILABLE_DESCRIPTION")+"</p>"); |
565 |
} |
566 |
|
567 |
JPanel southPanel = new JPanel(); |
568 |
JButton okButton = new JButton(PluginServices.getText(this, "OK")); |
569 |
okButton.addActionListener(new ActionListener(){ |
570 |
public void actionPerformed(ActionEvent arg0) { |
571 |
Window parentWindow = GUIUtil.getInstance().getParentWindow(descriptionPanel);
|
572 |
parentWindow.setVisible(false);
|
573 |
parentWindow.dispose(); |
574 |
}}); |
575 |
|
576 |
southPanel.setLayout(new BorderLayout()); |
577 |
JPanel aux = new JPanel(); |
578 |
aux.add(okButton, BorderLayout.EAST);
|
579 |
southPanel.add(aux, BorderLayout.EAST);
|
580 |
|
581 |
descriptionPanel.add(rightPanel, BorderLayout.CENTER);
|
582 |
descriptionPanel.add(southPanel, BorderLayout.SOUTH);
|
583 |
descriptionPanel.setSize(new Dimension(300, 300)); |
584 |
PluginServices.getMDIManager().addWindow(descriptionPanel); |
585 |
} |
586 |
}); |
587 |
contextMenu.add(viewDescriptionMenu); |
588 |
contextMenu.addSeparator(); |
589 |
|
590 |
|
591 |
JMenuItem markAsExceptionMenu = new JMenuItem(); |
592 |
markAsExceptionMenu.setText(PluginServices.getText(this, "MARK_AS_EXCEPTION")); |
593 |
markAsExceptionMenu.addActionListener(new ActionListener() { |
594 |
public void actionPerformed(ActionEvent e) { |
595 |
error.getTopology().markAsTopologyException(error); |
596 |
updateErrorTable(); |
597 |
} |
598 |
}); |
599 |
contextMenu.add(markAsExceptionMenu); |
600 |
|
601 |
contextMenu.addSeparator(); |
602 |
|
603 |
ITopologyRule violatedRule = error.getViolatedRule(); |
604 |
List<ITopologyErrorFix> errorFixes =
|
605 |
violatedRule.getAutomaticErrorFixes(); |
606 |
for(int i = 0; i < errorFixes.size(); i++){ |
607 |
final ITopologyErrorFix errorFix = errorFixes.get(i);
|
608 |
JMenuItem fixMenuItem = new JMenuItem(); |
609 |
fixMenuItem.setText(errorFix.getEditionDescription()); |
610 |
fixMenuItem.addActionListener(new ActionListener() { |
611 |
public void actionPerformed(ActionEvent e) { |
612 |
if(errorFix instanceof ITopologyErrorFixWithParameters){ |
613 |
ITopologyErrorFixWithParameters fix = |
614 |
(ITopologyErrorFixWithParameters) errorFix; |
615 |
fix.initialize(error); |
616 |
GParameter[] parameters = fix.getParameters();
|
617 |
|
618 |
Window topologyErrorPanelContainer = (Window)GUIUtil. |
619 |
getInstance(). |
620 |
getParentOfType(TopologyErrorPanel.this, Window.class);
|
621 |
|
622 |
PanelEntriesDialog panelEntriesDialog = new PanelEntriesDialog(PluginServices.getText(this, "Fix_parameters"), |
623 |
400, 130, parameters, topologyErrorPanelContainer); |
624 |
panelEntriesDialog.addOkActionListener(new ActionListener(){ |
625 |
public void actionPerformed(ActionEvent arg0) { |
626 |
try {
|
627 |
errorFix.fix(error); |
628 |
GUIUtil.getInstance().messageBox(PluginServices.getText(this, "ERROR_FIX_SUCCESS"), |
629 |
PluginServices.getText(this, "INFO")); |
630 |
//now we update the error panel and the error layer
|
631 |
updateErrorTable(); |
632 |
vista.getMapControl().repaint(); |
633 |
|
634 |
} catch (BaseException e1) {
|
635 |
GUIUtil.getInstance().messageBox(PluginServices.getText(this, "ERROR_FIX_ERROR")+e1.getFormatString(), |
636 |
PluginServices.getText(this, "ERROR")); |
637 |
} |
638 |
}}); |
639 |
|
640 |
JDialog entriesParent = new JDialog((Frame)PluginServices.getMainFrame(), true); |
641 |
entriesParent.setContentPane(panelEntriesDialog); |
642 |
entriesParent.setTitle(PluginServices.getText(this, "Parametros_De_Entrada_Para_La_Correccion")); |
643 |
entriesParent.setSize(290, 200); |
644 |
GUIUtil.getInstance().centerDialog(entriesParent, (MDIFrame) PluginServices.getMainFrame()); |
645 |
entriesParent.setVisible(true);
|
646 |
}else{
|
647 |
try {
|
648 |
errorFix.fix(error); |
649 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this, "ERROR_FIX_SUCCESS")); |
650 |
} catch (BaseException e1) {
|
651 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this, "ERROR_FIX_ERROR")+e1.getFormatString()); |
652 |
} |
653 |
} |
654 |
} |
655 |
}); |
656 |
contextMenu.add(fixMenuItem); |
657 |
} |
658 |
return contextMenu;
|
659 |
} |
660 |
|
661 |
|
662 |
public void mousePressed(MouseEvent e) { |
663 |
maybeShowPopup(e); |
664 |
} |
665 |
|
666 |
public void mouseReleased(MouseEvent e) { |
667 |
maybeShowPopup(e); |
668 |
} |
669 |
}); |
670 |
/*
|
671 |
errorInspectorTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
|
672 |
public void valueChanged(ListSelectionEvent e) {
|
673 |
if (e.getSource() == errorInspectorTable.getSelectionModel() && errorInspectorTable.getRowSelectionAllowed()) {
|
674 |
IWindow f = PluginServices.getMDIManager().getActiveWindow();
|
675 |
final View vista = (View)f;
|
676 |
MapControl mapControl = vista.getMapControl();
|
677 |
MapContext map = mapControl.getMapContext();
|
678 |
|
679 |
//first of all we delete the graphics of the previous selection
|
680 |
// for(int i = 0; i < selectedErrors.size(); i++){
|
681 |
// FGraphic oldGraphic = selectedErrors.get(i);
|
682 |
// map.getGraphicsLayer().removeGraphic(oldGraphic);
|
683 |
// }
|
684 |
// mapControl.drawGraphics();
|
685 |
// mapControl.repaint();
|
686 |
// selectedErrors.clear();
|
687 |
|
688 |
int first = e.getFirstIndex();
|
689 |
int last = e.getLastIndex();
|
690 |
// for(int i = first; i <= last; i++){
|
691 |
// TopologyError error = errorContainer.getTopologyError(i);
|
692 |
// IGeometry errorGeometry = error.getGeometry();
|
693 |
// FGraphic newGraphic =
|
694 |
// new FGraphic(errorGeometry, symbolSelectionCode);
|
695 |
// map.getGraphicsLayer().addGraphic(newGraphic);
|
696 |
// selectedErrors.add(newGraphic);
|
697 |
// }//for
|
698 |
// mapControl.drawGraphics();
|
699 |
// mapControl.repaint();
|
700 |
}//if
|
701 |
}});
|
702 |
*/
|
703 |
return errorInspectorTable;
|
704 |
} |
705 |
|
706 |
// private JPanel getFixUserEntriesPanel(GParameter[] parameters){
|
707 |
// BoxLayoutPanel solution = new BoxLayoutPanel();
|
708 |
// solution.addRow(new JComponent[] { new JLabel(PluginServices.getText(this,
|
709 |
// "Parametros_De_Entrada_Para_La_Correccion")) });
|
710 |
//
|
711 |
// final List<GParameterChangeListener> paramsListener
|
712 |
// = new ArrayList<GParameterChangeListener>();
|
713 |
//
|
714 |
// for(int i = 0; i < parameters.length; i++){
|
715 |
// GParameter param = parameters[i];
|
716 |
// GParameterChangeListener listener = solution.addComponentForParameter(param);
|
717 |
// paramsListener.add(listener);
|
718 |
// }
|
719 |
//
|
720 |
// JButton bton = new JButton(PluginServices.getText(this, "Aceptar"));
|
721 |
// bton.addActionListener(new ActionListener(){
|
722 |
// public void actionPerformed(ActionEvent arg0) {
|
723 |
// for(int i = 0; i < paramsListener.size(); i++){
|
724 |
// paramsListener.get(i).parameterChange();
|
725 |
// }
|
726 |
// }});
|
727 |
//
|
728 |
// solution.addRow(new JComponent[] { bton }, 600, DEFAULT_HEIGHT);
|
729 |
//
|
730 |
//
|
731 |
// return solution;
|
732 |
//
|
733 |
// }
|
734 |
|
735 |
public void updateErrorTable() { |
736 |
ITopologyRule filterRule = getSelectedRule(); |
737 |
boolean showExceptions = isExceptionsSelected();
|
738 |
boolean showErrors = isErrorsSelected();
|
739 |
// show all topology errors
|
740 |
if (filterRule == null && showExceptions && showErrors) { |
741 |
dataModel.setErrorContainer(errorContainer); |
742 |
getErrorInspectorTable().revalidate(); |
743 |
return;
|
744 |
} |
745 |
boolean filterByViewExtent = isOnlyViewExtentSelected();
|
746 |
SimpleTopologyErrorContainer filteredErrorContainer = new SimpleTopologyErrorContainer();
|
747 |
for (int i = 0; i < errorContainer.getNumberOfErrors(); i++) { |
748 |
TopologyError error = errorContainer.getTopologyError(i); |
749 |
|
750 |
if (filterByViewExtent) {
|
751 |
Rectangle2D errorExtent = error.getGeometry().getBounds2D();
|
752 |
View activeView = (View) PluginServices.getMDIManager() |
753 |
.getActiveWindow(); |
754 |
Rectangle2D viewExtent = null; |
755 |
try {
|
756 |
viewExtent = activeView.getMapControl().getMapContext() |
757 |
.getFullExtent(); |
758 |
|
759 |
if (!errorExtent.intersects(viewExtent))
|
760 |
continue;
|
761 |
} catch (ReadDriverException e) {
|
762 |
e.printStackTrace(); |
763 |
} |
764 |
} |
765 |
if (error.isException() && !showExceptions) {
|
766 |
continue;
|
767 |
} else {
|
768 |
if (!error.isException() && !showErrors) {
|
769 |
continue;
|
770 |
} |
771 |
} |
772 |
if(filterRule != null && error.getViolatedRule() != filterRule) |
773 |
continue;
|
774 |
|
775 |
filteredErrorContainer.addTopologyError(error); |
776 |
}// for
|
777 |
|
778 |
dataModel.setErrorContainer(filteredErrorContainer); |
779 |
getErrorInspectorTable().revalidate(); |
780 |
this.repaint();
|
781 |
|
782 |
} |
783 |
|
784 |
public boolean isErrorsSelected() { |
785 |
return showErrors.isSelected();
|
786 |
} |
787 |
|
788 |
public boolean isExceptionsSelected() { |
789 |
return showExceptions.isSelected();
|
790 |
} |
791 |
|
792 |
public boolean isOnlyViewExtentSelected() { |
793 |
return showViewExtent.isSelected();
|
794 |
} |
795 |
|
796 |
public ITopologyRule getSelectedRule() {
|
797 |
return ruleOption_rule.get(ruleFilterComboBox.getSelectedItem());
|
798 |
} |
799 |
|
800 |
} |