Changeset 10661 in osm for applications/editors/josm/plugins/validator/src/org
- Timestamp:
- 2008-09-13T15:56:55+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java
r10541 r10661 16 16 import java.util.Set; 17 17 18 import javax.swing.JMenuItem; 18 19 import javax.swing.JOptionPane; 19 20 import javax.swing.JPanel; 21 import javax.swing.JPopupMenu; 20 22 import javax.swing.JScrollPane; 21 23 import javax.swing.event.TreeSelectionEvent; … … 47 49 private static final long serialVersionUID = 2952292777351992696L; 48 50 49 private static final double MIN_SCALE_ON_SELECT = 0.00001;50 51 51 /** The display tree */ 52 52 protected ErrorTreePanel tree; … … 59 59 /** The select button */ 60 60 61 private JPopupMenu popupMenu; 62 private TestError popupMenuError = null; 63 61 64 /** Last selected element */ 62 65 private DefaultMutableTreeNode lastSelectedNode = null; … … 69 72 70 73 this.plugin = plugin; 74 popupMenu = new JPopupMenu(); 75 76 JMenuItem zoomTo = new JMenuItem(tr("Zoom to problem")); 77 zoomTo.addActionListener(new ActionListener() { 78 public void actionPerformed(ActionEvent e) { 79 zoomToProblem(); 80 } 81 }); 82 popupMenu.add(zoomTo); 71 83 72 84 tree = new ErrorTreePanel(); … … 226 238 } 227 239 240 private void showPopupMenu(MouseEvent e) { 241 if (!e.isPopupTrigger()) 242 return; 243 popupMenuError = null; 244 TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); 245 if (selPath == null) 246 return; 247 DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getPathComponent(selPath.getPathCount() - 1); 248 if (!(node.getUserObject() instanceof TestError)) 249 return; 250 popupMenuError = (TestError) node.getUserObject(); 251 popupMenu.show(e.getComponent(), e.getX(), e.getY()); 252 } 253 254 private void zoomToProblem() { 255 if (popupMenuError == null) 256 return; 257 ValidatorBoundingXYVisitor bbox = new ValidatorBoundingXYVisitor(); 258 popupMenuError.visitHighlighted(bbox); 259 if (bbox.min == null || bbox.max == null) 260 return; 261 bbox.enlargeBoundingBox(); 262 Main.map.mapView.recalculateCenterScale(bbox); 263 } 264 228 265 /** 229 266 * Sets the selection of the map to the current selected items. … … 341 378 Main.ds.setSelected(sel); 342 379 } 343 TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); 344 if ((selPath != null) && (e.getClickCount() == 2)) { 345 DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath 346 .getPathComponent(selPath.getPathCount() - 1); 347 if (node.getUserObject() instanceof TestError) { 348 TestError testError = (TestError) node.getUserObject(); 349 ValidatorBoundingXYVisitor box = new ValidatorBoundingXYVisitor(); 350 testError.visitHighlighted(box); 351 if (box.max.equals(box.min)) 352 Main.map.mapView.zoomTo(box.max, MIN_SCALE_ON_SELECT); 353 else { 354 Main.map.mapView.recalculateCenterScale(box); 355 if (Main.map.mapView.getScale() < MIN_SCALE_ON_SELECT) 356 Main.map.mapView.zoomTo(Main.map.mapView.getCenter(), MIN_SCALE_ON_SELECT); 357 } 358 } 359 } 360 } 380 } 381 382 @Override 383 public void mousePressed(MouseEvent e) { 384 showPopupMenu(e); 385 } 386 387 @Override 388 public void mouseReleased(MouseEvent e) { 389 showPopupMenu(e); 390 } 391 361 392 } 362 393
Note:
See TracChangeset
for help on using the changeset viewer.