Changeset 9598 in osm for applications/editors/josm/plugins/validator
- Timestamp:
- 2008-08-09T22:06:40+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/validator
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorTreePanel.java
r9269 r9598 4 4 import java.util.Map.Entry; 5 5 6 import java.awt.event.MouseEvent; 7 6 8 import javax.swing.JTree; 9 import javax.swing.ToolTipManager; 7 10 import javax.swing.tree.*; 8 11 9 12 import org.openstreetmap.josm.plugins.validator.util.Bag; 13 import org.openstreetmap.josm.plugins.validator.util.MultipleNameVisitor; 10 14 11 15 /** … … 16 20 * @author frsantos 17 21 */ 22 18 23 public class ErrorTreePanel extends JTree 19 24 { 20 21 22 23 24 25 25 /** Serializable ID */ 26 private static final long serialVersionUID = 2952292777351992696L; 27 28 /** 29 * The validation data. 30 */ 26 31 protected DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode()); 27 32 28 /** The list of errors shown in the tree */ 29 private List<TestError> errors; 30 /** 31 * Constructor 32 * @param errors The list of errors 33 */ 34 public ErrorTreePanel(List<TestError> errors) 35 { 36 this.setModel(treeModel); 33 /** The list of errors shown in the tree */ 34 private List<TestError> errors; 35 /** 36 * Constructor 37 * @param errors The list of errors 38 */ 39 public ErrorTreePanel(List<TestError> errors) 40 { 41 ToolTipManager.sharedInstance().registerComponent(this); 42 this.setModel(treeModel); 37 43 this.setRootVisible(false); 38 44 this.setShowsRootHandles(true); … … 41 47 this.setCellRenderer(new ErrorTreeRenderer()); 42 48 this.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); 43 setErrorList(errors); 44 } 45 46 /** 47 * Constructor 48 */ 49 public ErrorTreePanel() 50 { 51 this(null); 52 } 53 54 @Override 55 public void setVisible(boolean v) 56 { 49 setErrorList(errors); 50 } 51 52 public String getToolTipText(MouseEvent e) { 53 String res = null; 54 TreePath path = getPathForLocation(e.getX(), e.getY()); 55 if (path != null) 56 { 57 DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); 58 Object nodeInfo = node.getUserObject(); 59 60 if (nodeInfo instanceof TestError) 61 { 62 TestError error = (TestError)nodeInfo; 63 MultipleNameVisitor v = new MultipleNameVisitor(); 64 v.visit(error.getPrimitives()); 65 res = "<html>" + v.getText() + "<br>" + error.getMessage(); 66 String d = error.getDescription(); 67 if(d != null) 68 res += "<br>" + d; 69 res += "</html>"; 70 } 71 else 72 res = node.toString(); 73 } 74 return res; 75 } 76 77 /** Constructor */ 78 public ErrorTreePanel() 79 { 80 this(null); 81 } 82 83 @Override 84 public void setVisible(boolean v) 85 { 57 86 if (v) 58 87 buildTree(); … … 61 90 super.setVisible(v); 62 91 } 63 64 92 65 93 /** 66 94 * Builds the errors tree 67 95 */ 68 public void buildTree() 96 public void buildTree() 69 97 { 70 98 DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(); … … 76 104 } 77 105 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 106 // Remember the currently expanded rows 107 Set<Object> oldSelectedRows = new HashSet<Object>(); 108 Enumeration<TreePath> expanded = getExpandedDescendants( new TreePath(getRoot()) ); 109 if( expanded != null ) 110 { 111 while( expanded.hasMoreElements() ) 112 { 113 TreePath path = expanded.nextElement(); 114 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 115 Object userObject = node.getUserObject(); 116 if( userObject instanceof Severity ) 117 oldSelectedRows.add(userObject); 118 else if (userObject instanceof String) 119 { 120 String msg = (String)userObject; 121 msg = msg.substring(0, msg.lastIndexOf(" (")); 122 oldSelectedRows.add(msg); 123 } 124 } 125 } 126 99 127 Map<Severity, Bag<String, TestError>> errorTree = new HashMap<Severity, Bag<String, TestError>>(); 100 128 for(Severity s : Severity.values()) … … 102 130 errorTree.put(s, new Bag<String, TestError>(20)); 103 131 } 104 132 105 133 for(TestError e : errors) 106 134 { 107 135 errorTree.get(e.getSeverity()).add(e.getMessage(), e); 108 136 } 109 110 137 138 List<TreePath> expandedPaths = new ArrayList<TreePath>(); 111 139 for(Severity s : Severity.values()) 112 140 { 113 Bag<String, 141 Bag<String, TestError> severityErrors = errorTree.get(s); 114 142 if( severityErrors.isEmpty() ) 115 143 continue; 116 144 117 145 // Severity node 118 146 DefaultMutableTreeNode severityNode = new DefaultMutableTreeNode(s); 119 147 rootNode.add(severityNode); 120 148 121 149 if( oldSelectedRows.contains(s)) 122 123 150 expandedPaths.add( new TreePath( new Object[] {rootNode, severityNode} ) ); 151 124 152 for(Entry<String, List<TestError>> msgErrors : severityErrors.entrySet() ) 125 153 { … … 130 158 severityNode.add(messageNode); 131 159 132 133 134 160 if( oldSelectedRows.contains(msgErrors.getKey())) 161 expandedPaths.add( new TreePath( new Object[] {rootNode, severityNode, messageNode} ) ); 162 135 163 for (TestError error : errors) 136 164 { … … 142 170 } 143 171 144 145 146 147 148 149 } 150 151 152 153 154 155 156 157 158 159 160 172 treeModel.setRoot(rootNode); 173 for( TreePath path : expandedPaths) 174 { 175 this.expandPath(path); 176 } 177 } 178 179 /** 180 * Sets the errors list used by a data layer 181 * @param errors The error list that is used by a data layer 182 */ 183 public void setErrorList(List<TestError> errors) 184 { 185 this.errors = errors; 186 if( isVisible() ) 187 buildTree(); 188 } 161 189 162 190 /** … … 195 223 } 196 224 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 * Returns the root node model. 216 217 218 219 220 221 225 /** 226 * Expands all tree 227 */ 228 @SuppressWarnings("unchecked") 229 public void expandAll() 230 { 231 DefaultMutableTreeNode root = getRoot(); 232 233 int row = 0; 234 Enumeration<DefaultMutableTreeNode> children = root.breadthFirstEnumeration(); 235 while( children.hasMoreElements() ) 236 { 237 children.nextElement(); 238 expandRow(row++); 239 } 240 } 241 242 /** 243 * Returns the root node model. 244 * @return The root node model 245 */ 246 public DefaultMutableTreeNode getRoot() 247 { 248 return (DefaultMutableTreeNode) treeModel.getRoot(); 249 } 222 250 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorTreeRenderer.java
r2453 r9598 14 14 * @author frsantos 15 15 */ 16 public class ErrorTreeRenderer extends DefaultTreeCellRenderer 16 public class ErrorTreeRenderer extends DefaultTreeCellRenderer 17 17 { 18 19 18 /** Serializable ID */ 19 private static final long serialVersionUID = 5567632718124640198L; 20 20 21 21 @Override 22 22 public Component getTreeCellRendererComponent(JTree tree, Object value, 23 23 boolean selected, boolean expanded, boolean leaf, int row, … … 27 27 28 28 DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; 29 Object nodeInfo = node.getUserObject(); 30 31 if (nodeInfo instanceof Severity) 29 Object nodeInfo = node.getUserObject(); 30 31 if (nodeInfo instanceof Severity) 32 32 { 33 33 Severity s = (Severity)nodeInfo; 34 34 setIcon(ImageProvider.get("data", s.getIcon())); 35 35 } 36 else if (nodeInfo instanceof TestError) 36 else if (nodeInfo instanceof TestError) 37 37 { 38 38 TestError error = (TestError)nodeInfo; -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/TestError.java
r9270 r9598 24 24 /** The error message */ 25 25 private String message; 26 /** Deeper error description */ 27 private String description; 26 28 /** The affected primitives */ 27 29 private List<? extends OsmPrimitive> primitives; … … 35 37 private boolean selected; 36 38 37 public TestError(Test tester, Severity severity, String message, 39 /** 40 * Constructors 41 * @param tester The tester 42 * @param severity The severity of this error 43 * @param message The error message 44 * @param primitive The affected primitive 45 * @param primitives The affected primitives 46 * @param internalCode The internal code 47 */ 48 public TestError(Test tester, Severity severity, String message, String description, 38 49 List<? extends OsmPrimitive> primitives, List<?> highlighted) { 39 50 this.tester = tester; 40 51 this.severity = severity; 41 52 this.message = message; 53 this.description = description; 42 54 this.primitives = primitives; 43 55 this.highlighted = highlighted; 44 56 } 45 46 /**47 * Constructor48 * @param tester The tester49 * @param severity The severity of this error50 * @param message The error message51 * @param primitives The affected primitives52 */57 public TestError(Test tester, Severity severity, String message, List<? extends OsmPrimitive> primitives, List<?> highlighted) 58 { 59 this(tester, severity, message, null, primitives, highlighted); 60 } 61 public TestError(Test tester, Severity severity, String message, String description, List<? extends OsmPrimitive> primitives) 62 { 63 this(tester, severity, message, description, primitives, primitives); 64 } 53 65 public TestError(Test tester, Severity severity, String message, List<? extends OsmPrimitive> primitives) 54 66 { 55 this(tester, severity, message, primitives, primitives); 56 } 57 58 /** 59 * Constructor 60 * @param tester The tester 61 * @param severity The severity of this error 62 * @param message The error message 63 * @param primitive The affected primitive 64 */ 67 this(tester, severity, message, null, primitives, primitives); 68 } 65 69 public TestError(Test tester, Severity severity, String message, OsmPrimitive primitive) 66 70 { 67 this(tester, severity, message, Collections.singletonList(primitive)); 68 } 69 70 /** 71 * Constructor 72 * @param tester The tester 73 * @param severity The severity of this error 74 * @param message The error message 75 * @param primitive The affected primitive 76 * @param internalCode The internal code 77 */ 71 this(tester, severity, message, null, Collections.singletonList(primitive), Collections.singletonList(primitive)); 72 } 73 public TestError(Test tester, Severity severity, String message, String description, OsmPrimitive primitive) 74 { 75 this(tester, severity, message, description, Collections.singletonList(primitive)); 76 } 78 77 public TestError(Test tester, Severity severity, String message, OsmPrimitive primitive, int internalCode) 79 78 { 80 this(tester, severity, message, primitive);79 this(tester, severity, message, null, primitive); 81 80 this.internalCode = internalCode; 82 81 } 83 82 public TestError(Test tester, Severity severity, String message, String description, OsmPrimitive primitive, int internalCode) 83 { 84 this(tester, severity, message, description, primitive); 85 this.internalCode = internalCode; 86 } 87 84 88 /** 85 89 * Gets the error message 86 90 * @return the error message 87 91 */ 88 public String getMessage() 92 public String getMessage() 89 93 { 90 94 return message; 91 95 } 92 96 97 /** 98 * Gets the error message 99 * @return the error description 100 */ 101 public String getDescription() 102 { 103 return description; 104 } 105 93 106 /** 94 107 * Sets the error message -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java
r9561 r9598 261 261 } 262 262 263 public void actionPerformed(ActionEvent e) 263 public void actionPerformed(ActionEvent e) 264 264 { 265 265 String actionCommand = e.getActionCommand(); 266 if( actionCommand.equals(" select"))266 if( actionCommand.equals("Select")) 267 267 setSelectedItems(); 268 else if( actionCommand.equals(" validate"))268 else if( actionCommand.equals("Validate")) 269 269 plugin.validateAction.actionPerformed(e); 270 else if( actionCommand.equals(" fix"))270 else if( actionCommand.equals("Fix")) 271 271 fixErrors(e); 272 else if( actionCommand.equals(" ignore"))272 else if( actionCommand.equals("Ignore")) 273 273 ignoreErrors(e); 274 274 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/OverlappingWays.java
r9561 r9598 70 70 else if (ws.way.get("railway") != null) 71 71 railway++; 72 if (OsmUtils.getOsmBoolean(ws.way.get("area"))) 72 Boolean ar = OsmUtils.getOsmBoolean(ws.way.get("area")); 73 if (ar != null && ar) 73 74 area++; 74 75 if (ws.way.get("landuse") != null || ws.way.get("natural") != null -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java
r9561 r9598 194 194 else if(tagcheckerfile) 195 195 { 196 CheckerData d = new CheckerData(); 197 String err = d.getData(line); 198 199 if(err == null) 200 checkerData.add(d); 201 else 202 System.err.println("Invalid tagchecker line - "+err+":" + line); 196 if(line.length() > 0) 197 { 198 CheckerData d = new CheckerData(); 199 String err = d.getData(line); 200 201 if(err == null) 202 checkerData.add(d); 203 else 204 System.err.println("Invalid tagchecker line - "+err+":" + line); 205 } 203 206 } 204 207 else if( line.charAt(0) == '+' ) … … 286 289 if( checkValues && (value==null || value.trim().length() == 0) && !withErrors.contains(p, "EV")) 287 290 { 288 errors.add( new TestError(this, Severity.WARNING, tr("Tags with empty values"), p, EMPTY_VALUES) );291 errors.add( new TestError(this, Severity.WARNING, tr("Tags with empty values"), tr("Key ''{0}'' invalid.", key), p, EMPTY_VALUES) ); 289 292 withErrors.add(p, "EV"); 290 293 } 291 294 if( checkKeys && spellCheckKeyData.containsKey(key) && !withErrors.contains(p, "IPK")) 292 295 { 293 errors.add( new TestError(this, Severity.WARNING, tr("Invalid property key ''{0}''", key), p, INVALID_KEY) );296 errors.add( new TestError(this, Severity.WARNING, tr("Invalid property key"), tr("Key ''{0}'' invalid.", key), p, INVALID_KEY) ); 294 297 withErrors.add(p, "IPK"); 295 298 } 296 299 if( checkKeys && key.indexOf(" ") >= 0 && !withErrors.contains(p, "IPK")) 297 300 { 298 errors.add( new TestError(this, Severity.WARNING, tr("Invalid white space in property key ''{0}''", key), p, INVALID_KEY) );301 errors.add( new TestError(this, Severity.WARNING, tr("Invalid white space in property key"), tr("Key ''{0}'' invalid.", key), p, INVALID_KEY) ); 299 302 withErrors.add(p, "IPK"); 300 303 } 301 304 if( checkValues && value != null && (value.startsWith(" ") || value.endsWith(" ")) && !withErrors.contains(p, "SPACE")) 302 305 { 303 errors.add( new TestError(this, Severity.OTHER, tr("Property values start or end with white space"), p, INVALID_SPACE) );306 errors.add( new TestError(this, Severity.OTHER, tr("Property values start or end with white space"), tr("Key ''{0}'' invalid.", key), p, INVALID_SPACE) ); 304 307 withErrors.add(p, "SPACE"); 305 308 } … … 309 312 if( values != null && !values.contains(prop.getValue()) && !withErrors.contains(p, "UPV")) 310 313 { 311 errors.add( new TestError(this, Severity.OTHER, tr("Unknown property values"), p, INVALID_VALUE) );314 errors.add( new TestError(this, Severity.OTHER, tr("Unknown property values"), tr("Key ''{0}'' invalid.", key), p, INVALID_VALUE) ); 312 315 withErrors.add(p, "UPV"); 313 316 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java
r9111 r9598 129 129 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 130 130 primitives.add(w); 131 errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way : {0}",type), primitives));131 errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"), type, primitives)); 132 132 _errorWays.add(w,w); 133 133 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/util/MultipleNameVisitor.java
r8691 r9598 34 34 { 35 35 String multipleName = null; 36 String multiplePluralClassname = null; 36 37 String firstName = null; 37 38 boolean initializedname = false; … … 56 57 osm.visit(this); 57 58 if (multipleClassname == null) 59 { 58 60 multipleClassname = className; 61 multiplePluralClassname = classNamePlural; 62 } 59 63 else if (!multipleClassname.equals(className)) 64 { 60 65 multipleClassname = "object"; 66 multiplePluralClassname = trn("object", "objects", 2); 67 } 61 68 } 62 69 63 70 if( size == 1 ) 64 71 displayName = name; 65 72 else if(multipleName != null) 66 displayName = size + " " + trn(multipleClassname, multiple Classname + "s", size) + ": " + multipleName;73 displayName = size + " " + trn(multipleClassname, multiplePluralClassname, size) + ": " + multipleName; 67 74 else if(firstName != null) 68 displayName = size + " " + trn(multipleClassname, multiple Classname + "s", size) + ": " + tr("{0}, ...", firstName);75 displayName = size + " " + trn(multipleClassname, multiplePluralClassname, size) + ": " + tr("{0}, ...", firstName); 69 76 else 70 displayName = size + " " + trn(multipleClassname, multiple Classname + "s", size);77 displayName = size + " " + trn(multipleClassname, multiplePluralClassname, size); 71 78 } 72 79 73 80 @Override 74 public JLabel toLabel() 81 public JLabel toLabel() 75 82 { 76 83 return new JLabel(getText(), getIcon(), JLabel.HORIZONTAL); 77 84 } 78 85 79 86 /** 80 87 * Gets the name of the items -
applications/editors/josm/plugins/validator/tagchecker.cfg
r9269 r9598 22 22 # with and logical and (&&). 23 23 # 24 # The comment at the end of a rule is displayed in validator 25 # 24 26 # Empty lines and space signs are ignored 25 27 26 node : bridge == * 27 node : highway == tertiary 28 node : highway == secondary 29 way : highway == secondary && ref != * 30 way : highway == tertiary && ref != * 28 node : bridge == * # bridge tag on a node 29 node : highway == tertiary # wrong highway tag on a node 30 node : highway == secondary # wrong highway tag on a node 31 way : highway == secondary && ref != * # highway without a reference 32 way : highway == tertiary && ref != * # highway without a reference
Note:
See TracChangeset
for help on using the changeset viewer.