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; 008import java.awt.event.KeyEvent; 009 010import org.openstreetmap.josm.actions.mapmode.DrawAction; 011import org.openstreetmap.josm.tools.Shortcut; 012 013/** 014 * This action toggles automatic moving of the map view to last placed node 015 * @since 3837 016 */ 017public class ViewportFollowToggleAction extends ToggleAction { 018 019 /** 020 * Constructs a new {@code ViewportFollowToggleAction}. 021 */ 022 public ViewportFollowToggleAction() { 023 super(tr("Viewport Following"), 024 "viewport-follow", 025 tr("Enable/disable automatic moving of the map view to last placed node"), 026 Shortcut.registerShortcut("menu:view:viewportfollow", tr("Toggle Viewport Following"), 027 KeyEvent.VK_F, Shortcut.CTRL_SHIFT), 028 true /* register shortcut */ 029 ); 030 setHelpId(ht("/Action/ViewportFollowing")); 031 setSelected(DrawAction.VIEWPORT_FOLLOWING.get()); 032 notifySelectedState(); 033 } 034 035 @Override 036 public void actionPerformed(ActionEvent e) { 037 toggleSelectedState(e); 038 DrawAction.VIEWPORT_FOLLOWING.put(isSelected()); 039 notifySelectedState(); 040 } 041 042 @Override 043 protected void updateEnabledState() { 044 setEnabled(getLayerManager().getEditDataSet() != null); 045 } 046}