Ignore:
Timestamp:
2008-09-13T15:56:55+02:00 (16 years ago)
Author:
stotz
Message:

Zooming to the problem is now triggered by a context menu instead of double click; Zooming style is now equal to original JOSM implementation.
Note: This version requires at least JOSM rev 948

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java

    r10541 r10661  
    1616import java.util.Set;
    1717
     18import javax.swing.JMenuItem;
    1819import javax.swing.JOptionPane;
    1920import javax.swing.JPanel;
     21import javax.swing.JPopupMenu;
    2022import javax.swing.JScrollPane;
    2123import javax.swing.event.TreeSelectionEvent;
     
    4749    private static final long serialVersionUID = 2952292777351992696L;
    4850
    49     private static final double MIN_SCALE_ON_SELECT = 0.00001;
    50 
    5151    /** The display tree */
    5252    protected ErrorTreePanel tree;
     
    5959    /** The select button */
    6060
     61    private JPopupMenu popupMenu;
     62    private TestError popupMenuError = null;
     63
    6164    /** Last selected element */
    6265    private DefaultMutableTreeNode lastSelectedNode = null;
     
    6972
    7073        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);
    7183
    7284        tree = new ErrorTreePanel();
     
    226238    }
    227239
     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
    228265    /**
    229266     * Sets the selection of the map to the current selected items.
     
    341378                Main.ds.setSelected(sel);
    342379            }
    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
    361392    }
    362393
Note: See TracChangeset for help on using the changeset viewer.