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 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
12 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
13 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
14 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * This action toggles visibility of dialogs panel and other panels to free more space for drawing (GIMP-like)
|
---|
18 | * @author cmuelle8
|
---|
19 | * @since 5965
|
---|
20 | */
|
---|
21 | public class DialogsToggleAction extends ToggleAction {
|
---|
22 |
|
---|
23 | private boolean toolbarPreviouslyVisible;
|
---|
24 | private boolean sideToolbarPreviouslyVisible;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Constructs a new {@code DialogsToggleAction}.
|
---|
28 | */
|
---|
29 | public DialogsToggleAction() {
|
---|
30 | super(tr("Toggle dialogs panel"),
|
---|
31 | (ImageProvider) null, /* no icon */
|
---|
32 | tr("Toggle dialogs panel, maximize mapview"),
|
---|
33 | Shortcut.registerShortcut("menu:view:dialogspanel", tr("Toggle dialogs panel"), KeyEvent.VK_TAB, Shortcut.DIRECT),
|
---|
34 | true, "dialogspanel", /* register in toolbar */
|
---|
35 | false
|
---|
36 | );
|
---|
37 | putValue("help", ht("/ToggleDialogs"));
|
---|
38 | setSelected(Main.pref.getBoolean("draw.dialogspanel", true));
|
---|
39 | notifySelectedState();
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public void actionPerformed(ActionEvent e) {
|
---|
44 | toggleSelectedState(e);
|
---|
45 | Main.pref.put("draw.dialogspanel", isSelected());
|
---|
46 | notifySelectedState();
|
---|
47 | setMode();
|
---|
48 | }
|
---|
49 |
|
---|
50 | protected void setMode() {
|
---|
51 | if (MainApplication.isDisplayingMapView()) {
|
---|
52 | boolean selected = isSelected();
|
---|
53 | if (!selected) {
|
---|
54 | toolbarPreviouslyVisible = Main.pref.getBoolean("toolbar.visible", true);
|
---|
55 | sideToolbarPreviouslyVisible = Main.pref.getBoolean("sidetoolbar.visible", true);
|
---|
56 | }
|
---|
57 | MapFrame map = MainApplication.getMap();
|
---|
58 | map.setDialogsPanelVisible(selected);
|
---|
59 | map.statusLine.setVisible(selected || Main.pref.getBoolean("statusbar.always-visible", true));
|
---|
60 | MainApplication.getMenu().setVisible(selected || Main.pref.getBoolean("menu.always-visible", true));
|
---|
61 | // Toolbars listen to preference changes, use it here
|
---|
62 | if (!Main.pref.getBoolean("toolbar.always-visible", true) && (!selected || toolbarPreviouslyVisible)) {
|
---|
63 | Main.pref.put("toolbar.visible", selected);
|
---|
64 | }
|
---|
65 | if (!Main.pref.getBoolean("sidetoolbar.always-visible", true) && (!selected || sideToolbarPreviouslyVisible)) {
|
---|
66 | Main.pref.put("sidetoolbar.visible", selected);
|
---|
67 | }
|
---|
68 | map.mapView.rememberLastPositionOnScreen();
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|