source: josm/trunk/src/org/openstreetmap/josm/actions/ViewportFollowToggleAction.java@ 17379

Last change on this file since 17379 was 17188, checked in by Klumbumbus, 4 years ago

fix #19851 - Fix shortcut names

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9
10import org.openstreetmap.josm.actions.mapmode.DrawAction;
11import org.openstreetmap.josm.data.preferences.BooleanProperty;
12import org.openstreetmap.josm.gui.Notification;
13import org.openstreetmap.josm.gui.util.GuiHelper;
14import org.openstreetmap.josm.tools.Shortcut;
15
16/**
17 * This action toggles automatic moving of the map view to last placed node
18 * @since 3837
19 */
20public class ViewportFollowToggleAction extends ToggleAction {
21
22 /**
23 * Defines if a notification should be displayed after enabling and disabling
24 */
25 public static final BooleanProperty PROP_NOTIFICATION = new BooleanProperty("viewportfollow.notification", true);
26
27 /**
28 * Constructs a new {@code ViewportFollowToggleAction}.
29 */
30 public ViewportFollowToggleAction() {
31 super(tr("Viewport Following"),
32 "viewport-follow",
33 tr("Enable/disable automatic moving of the map view to last placed node"),
34 Shortcut.registerShortcut("menu:view:viewportfollow", tr("View: {0}", tr("Viewport Following")),
35 KeyEvent.VK_F, Shortcut.CTRL_SHIFT),
36 true /* register shortcut */
37 );
38 setHelpId(ht("/Action/ViewportFollowing"));
39 setSelected(DrawAction.VIEWPORT_FOLLOWING.get());
40 notifySelectedState();
41 }
42
43 @Override
44 public void actionPerformed(ActionEvent e) {
45 toggleSelectedState(e);
46 DrawAction.VIEWPORT_FOLLOWING.put(isSelected());
47 if (!getShortcut().getKeyText().isEmpty() && PROP_NOTIFICATION.get()) {
48 String msg = isSelected()
49 ? tr("Viewport following is enabled, press {0} to disable it", getShortcut().getKeyText())
50 : tr("Viewport following is disabled");
51 GuiHelper.runInEDT(() -> new Notification(msg).show());
52 }
53 notifySelectedState();
54 }
55
56 @Override
57 protected boolean listenToSelectionChange() {
58 return false;
59 }
60
61 @Override
62 protected void updateEnabledState() {
63 setEnabled(getLayerManager().getEditDataSet() != null);
64 }
65}
Note: See TracBrowser for help on using the repository browser.