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