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.Main;
|
---|
11 | import org.openstreetmap.josm.actions.mapmode.DrawAction;
|
---|
12 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * This action toggles automatic moving of the map view to last placed node
|
---|
16 | * @since 3837
|
---|
17 | */
|
---|
18 | public class ViewportFollowToggleAction extends ToggleAction {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Constructs a new {@code ViewportFollowToggleAction}.
|
---|
22 | */
|
---|
23 | public ViewportFollowToggleAction() {
|
---|
24 | super(tr("Viewport Following"),
|
---|
25 | "viewport-follow",
|
---|
26 | tr("Enable/disable automatic moving of the map view to last placed node"),
|
---|
27 | Shortcut.registerShortcut("menu:view:viewportfollow", tr("Toggle Viewport Following"),
|
---|
28 | KeyEvent.VK_F, Shortcut.CTRL_SHIFT),
|
---|
29 | true /* register shortcut */
|
---|
30 | );
|
---|
31 | putValue("help", ht("/Action/ViewportFollowing"));
|
---|
32 | setSelected(false);
|
---|
33 | notifySelectedState();
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void actionPerformed(ActionEvent e) {
|
---|
38 | toggleSelectedState(e);
|
---|
39 | DrawAction.VIEWPORT_FOLLOWING.put(isSelected());
|
---|
40 | notifySelectedState();
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | protected void updateEnabledState() {
|
---|
45 | setEnabled(Main.getLayerManager().getEditDataSet() != null);
|
---|
46 | }
|
---|
47 | }
|
---|