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

Last change on this file since 3965 was 3894, checked in by bastiK, 13 years ago

integrate wireframe into mappaint dialog; rename 'shortdescription' to 'title' (xml header key is unchanged)

  • Property svn:eol-style set to native
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 model.setSelected(selected);
37 }
38 }
39
40 public void removeButtonModel(ButtonModel model) {
41 if (model != null && buttonModels.contains(model)) {
42 buttonModels.remove(model);
43 }
44 }
45
46 protected void notifySelectedState() {
47 for (ButtonModel model: buttonModels) {
48 if (model.isSelected() != selected) {
49 model.setSelected(selected);
50 }
51 }
52 }
53
54 protected void toggleSelectedState() {
55 selected = !selected;
56 Main.pref.put("draw.wireframe", selected);
57 notifySelectedState();
58 if (Main.map != null) {
59 Main.map.mapView.repaint();
60 }
61 }
62 public void actionPerformed(ActionEvent e) {
63 toggleSelectedState();
64 }
65
66 @Override
67 protected void updateEnabledState() {
68 setEnabled(Main.map != null && Main.main.getEditLayer() != null);
69 }
70
71 public boolean isSelected() {
72 return selected;
73 }
74}
Note: See TracBrowser for help on using the repository browser.