1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.actions.mapmode.DrawAction;
|
---|
11 | import org.openstreetmap.josm.data.preferences.BooleanProperty;
|
---|
12 | import org.openstreetmap.josm.gui.Notification;
|
---|
13 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
14 | import 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 | */
|
---|
20 | public 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 | }
|
---|