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

Last change on this file was 19122, checked in by stoecker, 13 months ago

fix #23745 - add more icons, patch by gaben

  • Property svn:eol-style set to native
File size: 2.5 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 javax.swing.JOptionPane;
11import org.openstreetmap.josm.actions.mapmode.DrawAction;
12import org.openstreetmap.josm.data.preferences.BooleanProperty;
13import org.openstreetmap.josm.gui.Notification;
14import org.openstreetmap.josm.gui.util.GuiHelper;
15import org.openstreetmap.josm.tools.Shortcut;
16
17/**
18 * This action toggles automatic moving of the map view to last placed node
19 * @since 3837
20 */
21public class ViewportFollowToggleAction extends ToggleAction {
22
23 /**
24 * Defines if a notification should be displayed after enabling and disabling
25 */
26 public static final BooleanProperty PROP_NOTIFICATION = new BooleanProperty("viewportfollow.notification", true);
27
28 /**
29 * Constructs a new {@code ViewportFollowToggleAction}.
30 */
31 public ViewportFollowToggleAction() {
32 super(tr("Viewport Following"),
33 "viewport-follow",
34 tr("Enable/disable automatic moving of the map view to last placed node"),
35 Shortcut.registerShortcut("menu:view:viewportfollow", tr("View: {0}", tr("Viewport Following")),
36 KeyEvent.VK_F, Shortcut.CTRL_SHIFT),
37 true /* register shortcut */
38 );
39 setHelpId(ht("/Action/ViewportFollowing"));
40 setSelected(DrawAction.VIEWPORT_FOLLOWING.get());
41 notifySelectedState();
42 }
43
44 @Override
45 public void actionPerformed(ActionEvent e) {
46 if (!ExpertToggleAction.isExpert()) {
47 // #16848 (Possible to activate "Viewport following" mode when not in "Expert mode" through keyboard shortcut)
48 return;
49 }
50 toggleSelectedState(e);
51 DrawAction.VIEWPORT_FOLLOWING.put(isSelected());
52 if (!getShortcut().getKeyText().isEmpty() && PROP_NOTIFICATION.get()) {
53 String msg = isSelected()
54 ? tr("Viewport following is enabled, press {0} to disable it", getShortcut().getKeyText())
55 : tr("Viewport following is disabled");
56 GuiHelper.runInEDT(() -> new Notification(msg).setIcon(JOptionPane.INFORMATION_MESSAGE).show());
57 }
58 notifySelectedState();
59 }
60
61 @Override
62 protected boolean listenToSelectionChange() {
63 return false;
64 }
65
66 @Override
67 protected void updateEnabledState() {
68 setEnabled(getLayerManager().getEditDataSet() != null);
69 }
70}
Note: See TracBrowser for help on using the repository browser.