Ticket #8652: JOSM-toogleDialogsPanel-with-tabulator-key.patch

File JOSM-toogleDialogsPanel-with-tabulator-key.patch, 8.5 KB (added by cmuelle8, 6 years ago)

JOSM-toogleDialogsPanel-with-tabulator-key.patch

  • src/org/openstreetmap/josm/actions/DialogsToggleAction.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.actions;
     3
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.tr;
     6
     7import java.awt.event.ActionEvent;
     8import java.awt.event.KeyEvent;
     9import java.util.ArrayList;
     10import java.util.List;
     11
     12import javax.swing.ButtonModel;
     13
     14import org.openstreetmap.josm.Main;
     15import org.openstreetmap.josm.tools.Shortcut;
     16
     17public class DialogsToggleAction extends JosmAction {
     18    private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>();
     19    private boolean selected;
     20
     21    public DialogsToggleAction() {
     22        super(
     23                tr("Toggle dialogs panel"),
     24                null, /* no icon */
     25                tr("Toggle dialogs panel, maximize mapview"),
     26                Shortcut.registerShortcut("menu:view:dialogspanel", tr("Toggle dialogs panel"),KeyEvent.VK_TAB, Shortcut.DIRECT),
     27                false /* register */
     28        );
     29        putValue("help", ht("/Action/ToggleDialogsPanel"));
     30        //putValue("toolbar", "dialogspanel");
     31        //Main.toolbar.register(this);
     32        selected = Main.pref.getBoolean("draw.dialogspanel", true);
     33        notifySelectedState();
     34    }
     35
     36    public void addButtonModel(ButtonModel model) {
     37        if (model != null && !buttonModels.contains(model)) {
     38            buttonModels.add(model);
     39        }
     40    }
     41
     42    public void removeButtonModel(ButtonModel model) {
     43        if (model != null && buttonModels.contains(model)) {
     44            buttonModels.remove(model);
     45        }
     46    }
     47
     48    protected void notifySelectedState() {
     49        for (ButtonModel model: buttonModels) {
     50            if (model.isSelected() != selected) {
     51                model.setSelected(selected);
     52            }
     53        }
     54    }
     55
     56    protected void toggleSelectedState() {
     57        selected = !selected;
     58        Main.pref.put("draw.dialogspanel", selected);
     59        notifySelectedState();
     60        setMode();
     61    }
     62
     63    public void initial() {
     64        if(selected) {
     65            setMode();
     66        }
     67    }
     68
     69    protected void setMode() {
     70        if (Main.isDisplayingMapView()) {
     71            Main.map.setDialogsPanelVisible(selected);
     72            Main.toolbar.control.setVisible(selected);
     73            Main.main.menu.setVisible(selected);
     74        }
     75    }
     76
     77    public void actionPerformed(ActionEvent e) {
     78        toggleSelectedState();
     79    }
     80}
  • src/org/openstreetmap/josm/gui/MainMenu.java

     
    3333import org.openstreetmap.josm.actions.CreateCircleAction;
    3434import org.openstreetmap.josm.actions.CreateMultipolygonAction;
    3535import org.openstreetmap.josm.actions.DeleteAction;
     36import org.openstreetmap.josm.actions.DialogsToggleAction;
    3637import org.openstreetmap.josm.actions.DistributeAction;
    3738import org.openstreetmap.josm.actions.DownloadAction;
    3839import org.openstreetmap.josm.actions.DownloadPrimitiveAction;
     
    6263import org.openstreetmap.josm.actions.OpenFileAction;
    6364import org.openstreetmap.josm.actions.OpenLocationAction;
    6465import org.openstreetmap.josm.actions.OrthogonalizeAction;
     66import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;
    6567import org.openstreetmap.josm.actions.PasteAction;
    6668import org.openstreetmap.josm.actions.PasteTagsAction;
     69import org.openstreetmap.josm.actions.PreferenceToggleAction;
    6770import org.openstreetmap.josm.actions.PreferencesAction;
    6871import org.openstreetmap.josm.actions.PurgeAction;
    6972import org.openstreetmap.josm.actions.RedoAction;
     
    9093import org.openstreetmap.josm.actions.WireframeToggleAction;
    9194import org.openstreetmap.josm.actions.ZoomInAction;
    9295import org.openstreetmap.josm.actions.ZoomOutAction;
    93 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;
    94 import org.openstreetmap.josm.actions.PreferenceToggleAction;
    9596import org.openstreetmap.josm.actions.audio.AudioBackAction;
    9697import org.openstreetmap.josm.actions.audio.AudioFasterAction;
    9798import org.openstreetmap.josm.actions.audio.AudioFwdAction;
     
    229230    public final JumpToAction jumpToAct = new JumpToAction();
    230231
    231232    public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
     233    public final DialogsToggleAction dialogsToggleAction = new DialogsToggleAction();
    232234    public FullscreenToggleAction fullscreenToggleAction = null;
    233235
    234236    /** this menu listener hides unnecessary JSeparators in a menu list but does not remove them.
     
    514516            fullscreen.setAccelerator(fullscreenToggleAction.getShortcut().getKeyStroke());
    515517            fullscreenToggleAction.addButtonModel(fullscreen.getModel());
    516518        }
     519
     520        // -- dialogs panel toggle action
     521        final JCheckBoxMenuItem dialogspanel = new JCheckBoxMenuItem(dialogsToggleAction);
     522        dialogspanel.setAccelerator(dialogsToggleAction.getShortcut().getKeyStroke());
     523        dialogsToggleAction.addButtonModel(dialogspanel.getModel());
     524        viewMenu.add(dialogspanel);
     525
    517526        viewMenu.addSeparator();
    518527        add(viewMenu, info);
    519528        add(viewMenu, infoweb);
  • src/org/openstreetmap/josm/gui/MapFrame.java

     
    99import java.awt.Dimension;
    1010import java.awt.Font;
    1111import java.awt.GridBagLayout;
     12import java.awt.KeyboardFocusManager;
    1213import java.awt.Rectangle;
    1314import java.awt.event.ActionEvent;
    1415import java.awt.event.KeyEvent;
     
    1718import java.util.ArrayList;
    1819import java.util.Collection;
    1920import java.util.HashMap;
     21import java.util.HashSet;
    2022import java.util.List;
    2123import java.util.Map;
    2224import java.util.concurrent.CopyOnWriteArrayList;
     
    120122     * instead of adding directly to this list.
    121123     */
    122124    private List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>();
     125    private final JSplitPane splitPane;
    123126    private final JPanel leftPanel;
    124127    private final DialogsPanel dialogsPanel;
    125128
     
    177180
    178181        toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
    179182
    180         JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
     183        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    181184        dialogsPanel = new DialogsPanel(splitPane);
    182185        splitPane.setLeftComponent(leftPanel);
    183186        splitPane.setRightComponent(dialogsPanel);
     
    233236        // status line below the map
    234237        statusLine = new MapStatus(this);
    235238        MapView.addLayerChangeListener(this);
     239
     240        // free tabulator key to toggle dialogsPanel
     241        HashSet<KeyStroke> ks = new HashSet<KeyStroke>(1);
     242        ks.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK));
     243        KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
     244        kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, ks);
     245        splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, ks);
    236246    }
    237247
    238248    public boolean selectSelectTool(boolean onlyIfModeless) {
     
    543553        return dialogsPanel.getToggleDialog(type);
    544554    }
    545555
     556    public void setDialogsPanelVisible(boolean visible) {
     557        rememberToggleDialogWidth();
     558        dialogsPanel.setVisible(visible);
     559        splitPane.setDividerLocation(visible?splitPane.getWidth()-Main.pref.getInteger("toggleDialogs.width",DEF_TOGGLE_DLG_WIDTH):0);
     560        splitPane.setDividerSize(visible?5:0);
     561    }
     562
    546563    /**
    547564     * Remember the current width of the (possibly resized) toggle dialog area
    548565     */
    549566    public void rememberToggleDialogWidth() {
    550         Main.pref.putInteger("toggleDialogs.width", dialogsPanel.getWidth());
     567        if (dialogsPanel.isVisible()) {
     568            Main.pref.putInteger("toggleDialogs.width", splitPane.getWidth()-splitPane.getDividerLocation());
    551569    }
     570    }
    552571
    553572    /*
    554573     * Remove panel from top of MapView by class