source: josm/trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java@ 2612

Last change on this file since 2612 was 2530, checked in by Gubaer, 14 years ago

fixed #2261: "Wireframe View" should be turned into a JosmAction

File size: 2.2 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 WireframeToggleAction extends JosmAction {
17 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>();
18 //FIXME: replace with property Action.SELECTED_KEY when migrating to
19 // Java 6
20 private boolean selected;
21 public WireframeToggleAction() {
22 super(
23 tr("Wireframe View"),
24 null, /* no icon */
25 tr("Enable/disable rendering the map as wireframe only"),
26 Shortcut.registerShortcut("menu:view:wireframe", tr("Toggle Wireframe view"),KeyEvent.VK_W, Shortcut.GROUP_MENU),
27 true /* register shortcut */
28 );
29 selected = Main.pref.getBoolean("draw.wireframe", false);
30 notifySelectedState();
31 }
32
33 public void addButtonModel(ButtonModel model) {
34 if (model != null && !buttonModels.contains(model)) {
35 buttonModels.add(model);
36 }
37 }
38
39 public void removeButtonModel(ButtonModel model) {
40 if (model != null && buttonModels.contains(model)) {
41 buttonModels.remove(model);
42 }
43 }
44
45 protected void notifySelectedState() {
46 for (ButtonModel model: buttonModels) {
47 if (model.isSelected() != selected) {
48 model.setSelected(selected);
49 }
50 }
51 }
52
53 protected void toggleSelectedState() {
54 selected = !selected;
55 Main.pref.put("draw.wireframe", selected);
56 notifySelectedState();
57 if (Main.map != null) {
58 Main.map.mapView.repaint();
59 }
60 }
61 public void actionPerformed(ActionEvent e) {
62 toggleSelectedState();
63 }
64
65 @Override
66 protected void updateEnabledState() {
67 setEnabled(Main.map != null && Main.main.getEditLayer() != null);
68 }
69}
Note: See TracBrowser for help on using the repository browser.