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

Last change on this file since 3872 was 3837, checked in by framm, 13 years ago

new viewport following function; moves the viewport so that the last placed
node is in the center. the idea is to greatly improve tracing of long, linear
features from imagery or tracks (no need to right-click and pan all the time),
however the execution still leaves to be desired; problem is that after you
have placed a node you have to wait for the movement to finish before you can
place the next node. possible enhancements: only scroll if placed node is on
the outer rim of viewport?

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