| 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.gui.MainApplication;
|
|---|
| 11 | import org.openstreetmap.josm.gui.MapFrame;
|
|---|
| 12 | import org.openstreetmap.josm.spi.preferences.Config;
|
|---|
| 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("Dialogs panel"),
|
|---|
| 31 | new ImageProvider("dialogs/dialogs_panel"),
|
|---|
| 32 | tr("Toggle dialogs panel, maximize mapview"),
|
|---|
| 33 | Shortcut.registerShortcut("menu:view:dialogspanel", tr("View: {0}", tr("Dialogs panel")), KeyEvent.VK_TAB, Shortcut.DIRECT),
|
|---|
| 34 | true, "dialogspanel", /* register in toolbar */
|
|---|
| 35 | false
|
|---|
| 36 | );
|
|---|
| 37 | setHelpId(ht("/ToggleDialogs"));
|
|---|
| 38 | setSelected(Config.getPref().getBoolean("draw.dialogspanel", true));
|
|---|
| 39 | notifySelectedState();
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | @Override
|
|---|
| 43 | public void actionPerformed(ActionEvent e) {
|
|---|
| 44 | toggleSelectedState(e);
|
|---|
| 45 | Config.getPref().putBoolean("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 = MapFrame.TOOLBAR_VISIBLE.get();
|
|---|
| 55 | sideToolbarPreviouslyVisible = MapFrame.SIDE_TOOLBAR_VISIBLE.get();
|
|---|
| 56 | }
|
|---|
| 57 | MapFrame map = MainApplication.getMap();
|
|---|
| 58 | map.setDialogsPanelVisible(selected);
|
|---|
| 59 | map.statusLine.setVisible(selected || Config.getPref().getBoolean("statusbar.always-visible", true));
|
|---|
| 60 | MainApplication.getMenu().setVisible(selected || Config.getPref().getBoolean("menu.always-visible", true));
|
|---|
| 61 | // Toolbars listen to preference changes, use it here
|
|---|
| 62 | if (!Config.getPref().getBoolean("toolbar.always-visible", true) && (!selected || toolbarPreviouslyVisible)) {
|
|---|
| 63 | MapFrame.TOOLBAR_VISIBLE.put(selected);
|
|---|
| 64 | }
|
|---|
| 65 | if (!Config.getPref().getBoolean("sidetoolbar.always-visible", true) && (!selected || sideToolbarPreviouslyVisible)) {
|
|---|
| 66 | MapFrame.SIDE_TOOLBAR_VISIBLE.put(selected);
|
|---|
| 67 | }
|
|---|
| 68 | map.mapView.setMapNavigationComponentVisibility(selected || Config.getPref().getBoolean("navigation.always-visible", true));
|
|---|
| 69 | map.mapView.rememberLastPositionOnScreen();
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|