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

Last change on this file since 6140 was 6084, checked in by bastiK, 11 years ago

see #8902 - add missing @Override annotations (patch by shinigami)

File size: 2.1 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;
9import java.util.ArrayList;
10import java.util.List;
11
12import javax.swing.ButtonModel;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.tools.Shortcut;
16
17public class ViewportFollowToggleAction extends JosmAction {
18 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>();
19 private boolean selected;
20 public ViewportFollowToggleAction() {
21 super(
22 tr("Viewport Following"),
23 "viewport-follow",
24 tr("Enable/disable automatic moving of the map view to last placed node"),
25 Shortcut.registerShortcut("menu:view:viewportfollow", tr("Toggle Viewport Following"),
26 KeyEvent.VK_F, Shortcut.CTRL_SHIFT),
27 true /* register shortcut */
28 );
29 putValue("help", ht("/Action/ViewportFollowing"));
30 selected = false;
31 notifySelectedState();
32 }
33
34 public void addButtonModel(ButtonModel model) {
35 if (model != null && !buttonModels.contains(model)) {
36 buttonModels.add(model);
37 model.setSelected(selected);
38 }
39 }
40
41 public void removeButtonModel(ButtonModel model) {
42 if (model != null && buttonModels.contains(model)) {
43 buttonModels.remove(model);
44 }
45 }
46
47 protected void notifySelectedState() {
48 for (ButtonModel model: buttonModels) {
49 if (model.isSelected() != selected) {
50 model.setSelected(selected);
51 }
52 }
53 }
54
55 protected void toggleSelectedState() {
56 selected = !selected;
57 Main.map.mapView.viewportFollowing = selected;
58 notifySelectedState();
59 }
60 @Override
61 public void actionPerformed(ActionEvent e) {
62 toggleSelectedState();
63 }
64
65 @Override
66 protected void updateEnabledState() {
67 setEnabled(Main.isDisplayingMapView() && Main.main.getEditLayer() != null);
68 }
69}
Note: See TracBrowser for help on using the repository browser.