001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.actions; 003 004import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 005import static org.openstreetmap.josm.tools.I18n.tr; 006 007import java.awt.event.ActionEvent; 008 009import org.openstreetmap.josm.gui.MainApplication; 010import org.openstreetmap.josm.gui.layer.MapGridPaintable; 011import org.openstreetmap.josm.tools.ImageProvider; 012 013/** 014 * This action toggles the display of the grid over the map view. 015 * @see MapGridPaintable 016 * @since 19640 017 */ 018public class ShowGridAction extends PreferenceToggleAction { 019 020 /** 021 * Constructs a new {@link ShowGridAction}. 022 */ 023 public ShowGridAction() { 024 super(tr("Show"), 025 new ImageProvider("grid"), 026 tr("Enable/disable the grid drawn over the map. Its spacing and orientation are set in the display preferences."), 027 MapGridPaintable.ENABLED 028 ); 029 setHelpId(ht("/MapView#Grid")); 030 } 031 032 @Override 033 protected boolean listenToSelectionChange() { 034 return false; 035 } 036 037 @Override 038 protected void updateEnabledState() { 039 setEnabled(MainApplication.isDisplayingMapView()); 040 } 041 042 @Override 043 public void actionPerformed(ActionEvent e) { 044 super.actionPerformed(e); 045 if (MainApplication.isDisplayingMapView()) { 046 MainApplication.getMap().mapView.repaint(); 047 } 048 } 049}