1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 | import java.util.ArrayList;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import javax.swing.ButtonModel;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
15 |
|
---|
16 | public 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 | }
|
---|