source: josm/trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java@ 8392

Last change on this file since 8392 was 8392, checked in by Don-vip, 9 years ago

remove useless code (Method implemented with an exact copy of its superclass's method)

  • Property svn:eol-style set to native
File size: 5.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Graphics2D;
7import java.util.Enumeration;
8import java.util.List;
9
10import javax.swing.Action;
11import javax.swing.Icon;
12import javax.swing.tree.DefaultMutableTreeNode;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.actions.RenameLayerAction;
16import org.openstreetmap.josm.data.Bounds;
17import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
18import org.openstreetmap.josm.data.validation.OsmValidator;
19import org.openstreetmap.josm.data.validation.PaintVisitor;
20import org.openstreetmap.josm.data.validation.Severity;
21import org.openstreetmap.josm.data.validation.TestError;
22import org.openstreetmap.josm.gui.MapView;
23import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
24import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
25import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
26import org.openstreetmap.josm.tools.ImageProvider;
27import org.openstreetmap.josm.tools.MultiMap;
28
29/**
30 * A layer showing error messages.
31 *
32 * @author frsantos
33 */
34public class ValidatorLayer extends Layer implements LayerChangeListener {
35
36 private int updateCount = -1;
37
38 /**
39 * Constructs a new Validator layer
40 */
41 public ValidatorLayer() {
42 super(tr("Validation errors"));
43 MapView.addLayerChangeListener(this);
44 }
45
46 /**
47 * Return a static icon.
48 */
49 @Override
50 public Icon getIcon() {
51 return ImageProvider.get("layer", "validator_small");
52 }
53
54 /**
55 * Draw all primitives in this layer but do not draw modified ones (they
56 * are drawn by the edit layer).
57 * Draw nodes last to overlap the ways they belong to.
58 */
59 @SuppressWarnings("unchecked")
60 @Override
61 public void paint(final Graphics2D g, final MapView mv, Bounds bounds) {
62 updateCount = Main.map.validatorDialog.tree.getUpdateCount();
63 DefaultMutableTreeNode root = Main.map.validatorDialog.tree.getRoot();
64 if (root == null || root.getChildCount() == 0)
65 return;
66
67 PaintVisitor paintVisitor = new PaintVisitor(g, mv);
68
69 DefaultMutableTreeNode severity = (DefaultMutableTreeNode) root.getLastChild();
70 while (severity != null) {
71 Enumeration<DefaultMutableTreeNode> errorMessages = severity.breadthFirstEnumeration();
72 while (errorMessages.hasMoreElements()) {
73 Object tn = errorMessages.nextElement().getUserObject();
74 if (tn instanceof TestError) {
75 paintVisitor.visit((TestError) tn);
76 }
77 }
78
79 // Severities in inverse order
80 severity = severity.getPreviousSibling();
81 }
82
83 paintVisitor.clearPaintedObjects();
84 }
85
86 @Override
87 public String getToolTipText() {
88 MultiMap<Severity, TestError> errorTree = new MultiMap<>();
89 List<TestError> errors = Main.map.validatorDialog.tree.getErrors();
90 for (TestError e : errors) {
91 errorTree.put(e.getSeverity(), e);
92 }
93
94 StringBuilder b = new StringBuilder();
95 for (Severity s : Severity.values()) {
96 if (errorTree.containsKey(s)) {
97 b.append(tr(s.toString())).append(": ").append(errorTree.get(s).size()).append("<br>");
98 }
99 }
100
101 if (b.length() == 0)
102 return "<html>" + tr("No validation errors") + "</html>";
103 else
104 return "<html>" + tr("Validation errors") + ":<br>" + b + "</html>";
105 }
106
107 @Override
108 public void mergeFrom(Layer from) {
109 }
110
111 @Override
112 public boolean isMergable(Layer other) {
113 return false;
114 }
115
116 @Override
117 public boolean isChanged() {
118 return updateCount != Main.map.validatorDialog.tree.getUpdateCount();
119 }
120
121 @Override
122 public void visitBoundingBox(BoundingXYVisitor v) {
123 }
124
125 @Override
126 public Object getInfoComponent() {
127 return getToolTipText();
128 }
129
130 @Override
131 public Action[] getMenuEntries() {
132 return new Action[] {
133 LayerListDialog.getInstance().createShowHideLayerAction(),
134 LayerListDialog.getInstance().createDeleteLayerAction(),
135 SeparatorLayerAction.INSTANCE,
136 new RenameLayerAction(null, this),
137 SeparatorLayerAction.INSTANCE,
138 new LayerListPopup.InfoAction(this) };
139 }
140
141 @Override
142 public void activeLayerChange(Layer oldLayer, Layer newLayer) {
143 }
144
145 @Override
146 public void layerAdded(Layer newLayer) {
147 }
148
149 /**
150 * If layer is the OSM Data layer, remove all errors
151 */
152 @Override
153 public void layerRemoved(Layer oldLayer) {
154 if (oldLayer instanceof OsmDataLayer && Main.isDisplayingMapView() && !Main.main.hasEditLayer()) {
155 Main.main.removeLayer(this);
156 } else if (oldLayer == this) {
157 MapView.removeLayerChangeListener(this);
158 OsmValidator.errorLayer = null;
159 }
160 }
161}
Note: See TracBrowser for help on using the repository browser.