1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 | import java.util.ArrayList;
|
---|
10 | import java.util.List;
|
---|
11 |
|
---|
12 | import javax.swing.ButtonModel;
|
---|
13 | import javax.swing.Icon;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.Main;
|
---|
16 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
17 |
|
---|
18 | /*
|
---|
19 | * Action that hides or shows toggle dialogs panel and other panels
|
---|
20 | * to free more space for drawing (GIMP-like)
|
---|
21 | * @author cmuelle8
|
---|
22 | */
|
---|
23 | public class DialogsToggleAction extends JosmAction {
|
---|
24 | private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>();
|
---|
25 | private boolean selected;
|
---|
26 |
|
---|
27 | public DialogsToggleAction() {
|
---|
28 | super(
|
---|
29 | tr("Toggle dialogs panel"),
|
---|
30 | (Icon) null, /* no icon */
|
---|
31 | tr("Toggle dialogs panel, maximize mapview"),
|
---|
32 | Shortcut.registerShortcut("menu:view:dialogspanel", tr("Toggle dialogs panel"),KeyEvent.VK_TAB, Shortcut.DIRECT),
|
---|
33 | true, "dialogspanel", /* register in toolbar */
|
---|
34 | false
|
---|
35 | );
|
---|
36 | putValue("help", ht("/Action/ToggleDialogsPanel"));
|
---|
37 | selected = Main.pref.getBoolean("draw.dialogspanel", true);
|
---|
38 | notifySelectedState();
|
---|
39 | }
|
---|
40 |
|
---|
41 | public void addButtonModel(ButtonModel model) {
|
---|
42 | if (model != null && !buttonModels.contains(model)) {
|
---|
43 | buttonModels.add(model);
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public void removeButtonModel(ButtonModel model) {
|
---|
48 | if (model != null && buttonModels.contains(model)) {
|
---|
49 | buttonModels.remove(model);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected void notifySelectedState() {
|
---|
54 | for (ButtonModel model: buttonModels) {
|
---|
55 | if (model.isSelected() != selected) {
|
---|
56 | model.setSelected(selected);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected void toggleSelectedState() {
|
---|
62 | selected = !selected;
|
---|
63 | Main.pref.put("draw.dialogspanel", selected);
|
---|
64 | notifySelectedState();
|
---|
65 | setMode();
|
---|
66 | }
|
---|
67 |
|
---|
68 | public void initial() {
|
---|
69 | if(selected) {
|
---|
70 | setMode();
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | protected void setMode() {
|
---|
75 | if (Main.isDisplayingMapView()) {
|
---|
76 | Main.map.setDialogsPanelVisible(selected);
|
---|
77 | Main.map.statusLine.setVisible(selected || Main.pref.getBoolean("statusbar.always-visible", true));
|
---|
78 | Main.toolbar.control.setVisible(selected || Main.pref.getBoolean("toolbar.always-visible", true));
|
---|
79 | Main.main.menu.setVisible(selected || Main.pref.getBoolean("menu.always-visible", true));
|
---|
80 | // sideToolBar listens to preference changes, use it here
|
---|
81 | if (!Main.pref.getBoolean("sidetoolbar.always-visible", true)) {
|
---|
82 | Main.pref.put("sidetoolbar.visible", selected);
|
---|
83 | }
|
---|
84 | Main.map.mapView.rememberLastPositionOnScreen();
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | public void actionPerformed(ActionEvent e) {
|
---|
90 | toggleSelectedState();
|
---|
91 | }
|
---|
92 | }
|
---|