Changeset 2672 in osm for applications/editors
- Timestamp:
- 2007-04-26T22:20:17+02:00 (18 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
r2453 r2672 68 68 if (newFrame != null) 69 69 { 70 errors = new ArrayList<TestError>(50); 70 71 validationDialog = new ValidatorDialog(); 71 72 newFrame.addToggleDialog(validationDialog); 73 Main.main.addLayer(new ErrorLayer(tr("Validation errors"))); 72 74 } 73 75 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/Severity.java
r2453 r2672 1 1 package org.openstreetmap.josm.plugins.validator; 2 3 import java.awt.Color; 4 5 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor; 2 6 3 7 /** The error severity */ 4 8 public enum Severity { 5 9 /** Error messages */ 6 ERROR("Errors", "error.gif" ),10 ERROR("Errors", "error.gif", SimplePaintVisitor.getPreferencesColor("validation error", Color.RED)), 7 11 /** Warning messages */ 8 WARNING("Warnings", "warning.gif" ),12 WARNING("Warnings", "warning.gif", SimplePaintVisitor.getPreferencesColor("validation warning", Color.YELLOW)), 9 13 /** Other messages */ 10 OTHER("Other", "other.gif" );14 OTHER("Other", "other.gif", SimplePaintVisitor.getPreferencesColor("validation other", Color.CYAN)); 11 15 12 16 /** Description of the severity code */ 13 17 private final String message; 14 18 15 /** Associated icon */ 16 private final String icon; 19 /** Associated icon */ 20 private final String icon; 21 22 /** Associated color */ 23 private final Color color; 17 24 18 25 /** … … 22 29 * @param icon Associated icon 23 30 */ 24 Severity(String message, String icon )31 Severity(String message, String icon, Color color) 25 32 { 26 33 this.message = message; 27 34 this.icon = icon; 35 this.color = color; 28 36 } 29 37 … … 42 50 return icon; 43 51 } 52 53 /** 54 * Gets the associated color 55 * @return The associated color 56 */ 57 public Color getColor() 58 { 59 return color; 60 } 44 61 45 62 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/Test.java
r2591 r2672 139 139 * @return The command to fix the error 140 140 */ 141 public Command fixError( TestError testError)141 public Command fixError(@SuppressWarnings("unused") TestError testError) 142 142 { 143 143 return null; … … 150 150 * @return true if the error can be fixed 151 151 */ 152 public boolean isFixable( TestError testError)152 public boolean isFixable(@SuppressWarnings("unused") TestError testError) 153 153 { 154 154 return false; -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/TestError.java
r2591 r2672 1 1 package org.openstreetmap.josm.plugins.validator; 2 2 3 import java.awt.*; 3 4 import java.util.ArrayList; 4 5 import java.util.List; 5 6 6 7 import org.openstreetmap.josm.command.Command; 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 import org.openstreetmap.josm.data.osm.*; 9 import org.openstreetmap.josm.data.osm.visitor.Visitor; 10 import org.openstreetmap.josm.gui.MapView; 8 11 9 12 /** … … 23 26 /** Internal code used by testers to classify errors */ 24 27 private int internalCode; 28 /** If this error is selected */ 29 private boolean selected; 25 30 26 31 /** … … 183 188 184 189 return tester.fixError(this); 185 } 190 } 191 192 /** 193 * Paints the error on affected primitives 194 * 195 * @param g The graphics 196 * @param mv The MapView 197 */ 198 public void paint(Graphics g, MapView mv) 199 { 200 PaintVisitor v = new PaintVisitor(g, mv); 201 for( OsmPrimitive p : primitives) 202 { 203 if( !p.deleted ) 204 p.visit(v); 205 } 206 } 207 208 class PaintVisitor implements Visitor 209 { 210 /** The graphics */ 211 private final Graphics g; 212 /** The MapView */ 213 private final MapView mv; 214 215 /** 216 * Constructor 217 * @param g The graphics 218 * @param mv The Mapview 219 */ 220 public PaintVisitor(Graphics g, MapView mv) 221 { 222 this.g = g; 223 this.mv = mv; 224 } 225 226 /** 227 * Draws a circle around the node 228 * @param n The node 229 * @param color The circle color 230 */ 231 public void drawNode(Node n, Color color) 232 { 233 Point p = mv.getPoint(n.eastNorth); 234 g.setColor(color); 235 if( selected ) 236 { 237 g.fillOval(p.x-5, p.y-5, 10, 10); 238 } 239 else 240 g.drawOval(p.x-5, p.y-5, 10, 10); 241 } 242 243 /** 244 * Draws a line around the segment 245 * 246 * @param s The segment 247 * @param color The color 248 */ 249 public void drawSegment(Segment s, Color color) 250 { 251 Point p1 = mv.getPoint(s.from.eastNorth); 252 Point p2 = mv.getPoint(s.to.eastNorth); 253 g.setColor(color); 254 255 double t = Math.atan2(p2.x-p1.x, p2.y-p1.y); 256 double cosT = Math.cos(t); 257 double sinT = Math.sin(t); 258 int deg = (int)Math.toDegrees(t); 259 if( selected ) 260 { 261 int[] x = new int[] {(int)(p1.x + 5*cosT), (int)(p2.x + 5*cosT), (int)(p2.x - 5*cosT), (int)(p1.x - 5*cosT)}; 262 int[] y = new int[] {(int)(p1.y - 5*sinT), (int)(p2.y - 5*sinT), (int)(p2.y + 5*sinT), (int)(p1.y + 5*sinT)}; 263 g.fillPolygon(x, y, 4); 264 g.fillArc(p1.x-5, p1.y-5, 10, 10, deg, 180 ); 265 g.fillArc(p2.x-5, p2.y-5, 10, 10, deg, -180); 266 } 267 else 268 { 269 g.drawLine((int)(p1.x + 5*cosT), (int)(p1.y - 5*sinT), (int)(p2.x + 5*cosT), (int)(p2.y - 5*sinT)); 270 g.drawLine((int)(p1.x - 5*cosT), (int)(p1.y + 5*sinT), (int)(p2.x - 5*cosT), (int)(p2.y + 5*sinT)); 271 g.drawArc(p1.x-5, p1.y-5, 10, 10, deg, 180 ); 272 g.drawArc(p2.x-5, p2.y-5, 10, 10, deg, -180); 273 } 274 } 275 276 277 278 /** 279 * Draw a small rectangle. 280 * White if selected (as always) or red otherwise. 281 * 282 * @param n The node to draw. 283 */ 284 public void visit(Node n) 285 { 286 if( isNodeVisible(n) ) 287 drawNode(n, severity.getColor()); 288 } 289 290 /** 291 * Draw just a line between the points. 292 * White if selected (as always) or green otherwise. 293 */ 294 public void visit(Segment ls) 295 { 296 if( isSegmentVisible(ls) ) 297 drawSegment(ls, severity.getColor()); 298 } 299 300 public void visit(Way w) 301 { 302 for (Segment ls : w.segments) 303 { 304 if (isSegmentVisible(ls)) 305 { 306 drawSegment(ls, severity.getColor()); 307 } 308 } 309 } 310 311 /** 312 * Checks if the given node is in the visible area. 313 */ 314 protected boolean isNodeVisible(Node n) { 315 Point p = mv.getPoint(n.eastNorth); 316 return !((p.x < 0) || (p.y < 0) || (p.x > mv.getWidth()) || (p.y > mv.getHeight())); 317 } 318 319 /** 320 * Checks if the given segment is in the visible area. 321 * NOTE: This will return true for a small number of non-visible 322 * segments. 323 */ 324 protected boolean isSegmentVisible(Segment ls) { 325 if (ls.incomplete) return false; 326 Point p1 = mv.getPoint(ls.from.eastNorth); 327 Point p2 = mv.getPoint(ls.to.eastNorth); 328 if ((p1.x < 0) && (p2.x < 0)) return false; 329 if ((p1.y < 0) && (p2.y < 0)) return false; 330 if ((p1.x > mv.getWidth()) && (p2.x > mv.getWidth())) return false; 331 if ((p1.y > mv.getHeight()) && (p2.y > mv.getHeight())) return false; 332 return true; 333 } 334 } 335 336 /** 337 * Sets the selection flag of this error 338 * @param selected if this error is selected 339 */ 340 public void setSelected(boolean selected) 341 { 342 this.selected = selected; 343 } 186 344 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java
r2591 r2672 50 50 * @param getSelectedItems If selected or last selected items must be validated 51 51 */ 52 public void doValidate( ActionEvent ev, boolean getSelectedItems)52 public void doValidate(@SuppressWarnings("unused") ActionEvent ev, boolean getSelectedItems) 53 53 { 54 54 OSMValidatorPlugin plugin = OSMValidatorPlugin.getPlugin(); … … 95 95 96 96 plugin.validationDialog.refresh(); 97 Main.map.repaint(); 98 Main.ds.fireSelectionChanged(Main.ds.getSelected()); 99 97 100 } 98 101 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java
r2591 r2672 37 37 * The validation data. 38 38 */ 39 pr ivateDefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());39 protected DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode()); 40 40 41 41 /** … … 47 47 * The fix button 48 48 */ 49 private JButton fixButton; 50 49 private JButton fixButton; 50 51 /** 52 * The select button 53 */ 54 private JButton selectButton; 55 56 /** Last selected truee element */ 57 private DefaultMutableTreeNode lastSelectedNode = null; 51 58 52 59 /** … … 70 77 JPanel buttonPanel = new JPanel(new GridLayout(1,2)); 71 78 72 buttonPanel.add(Util.createButton("Select", "mapmode/selection/select", "Set the selected elements on the map to the selected items in the list above.", this)); 73 add(buttonPanel, BorderLayout.SOUTH); 79 selectButton = Util.createButton("Select", "mapmode/selection/select", "Set the selected elements on the map to the selected items in the list above.", this); 80 selectButton.setEnabled(false); 81 buttonPanel.add(selectButton); 82 //add(buttonPanel, BorderLayout.SOUTH); 74 83 buttonPanel.add(Util.createButton("Validate", "dialogs/refresh", "Validate the data.", this)); 75 add(buttonPanel, BorderLayout.SOUTH);84 // add(buttonPanel, BorderLayout.SOUTH); 76 85 fixButton = Util.createButton("Fix", "dialogs/fix", "Fix the selected errors.", this); 77 86 fixButton.setEnabled(false); … … 215 224 private void setSelectedItems() 216 225 { 226 if( tree == null ) 227 return; 228 217 229 Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(40); 218 230 219 231 TreePath[] selectedPaths = tree.getSelectionPaths(); 232 if( selectedPaths == null) 233 return; 234 220 235 for( TreePath path : selectedPaths) 221 236 { … … 267 282 boolean hasFixes = false; 268 283 269 DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); 284 DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); 285 if( lastSelectedNode != null && !lastSelectedNode.equals(node) ) 286 { 287 Enumeration<DefaultMutableTreeNode> children = lastSelectedNode.breadthFirstEnumeration(); 288 while( children.hasMoreElements() ) 289 { 290 DefaultMutableTreeNode childNode = children.nextElement(); 291 Object nodeInfo = childNode.getUserObject(); 292 if( nodeInfo instanceof TestError) 293 { 294 TestError error = (TestError)nodeInfo; 295 error.setSelected(false); 296 } 297 } 298 } 299 300 lastSelectedNode = node; 270 301 if( node == null ) 271 302 return hasFixes; … … 279 310 { 280 311 TestError error = (TestError)nodeInfo; 312 error.setSelected(true); 313 281 314 hasFixes = hasFixes || error.isFixable(); 282 315 if( addSelected ) … … 286 319 } 287 320 } 321 selectButton.setEnabled(true); 288 322 289 323 return hasFixes; … … 298 332 public void mouseClicked(MouseEvent e) 299 333 { 300 fixButton.setEnabled(false); 301 302 if(e.getSource() instanceof JScrollPane) 303 return; 304 305 DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); 306 if( node == null ) 307 return; 308 309 Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(40); 334 System.out.println("mouseClicked " + e.getClickCount() + " " + e.getSource()); 335 fixButton.setEnabled(false); 336 selectButton.setEnabled(false); 337 310 338 boolean isDblClick = e.getClickCount() > 1; 339 Collection<OsmPrimitive> sel = isDblClick ? new HashSet<OsmPrimitive>(40) : null; 311 340 312 341 boolean hasFixes = setSelection(sel, isDblClick); … … 328 357 public void valueChanged(TreeSelectionEvent e) 329 358 { 359 System.out.println("valueChanged"); 330 360 fixButton.setEnabled(false); 361 selectButton.setEnabled(false); 331 362 332 363 if(e.getSource() instanceof JScrollPane) 333 return; 364 { 365 System.out.println(e.getSource()); 366 return; 367 } 334 368 335 DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();336 if( node == null )337 return;338 339 369 boolean hasFixes = setSelection(null, false); 340 370 fixButton.setEnabled(hasFixes); 371 Main.map.repaint(); 341 372 } 342 373 }
Note:
See TracChangeset
for help on using the changeset viewer.