Ticket #8652: JOSM-toogleDialogsPanel-with-tabulator-key.patch
File JOSM-toogleDialogsPanel-with-tabulator-key.patch, 8.5 KB (added by , 12 years ago) |
---|
-
src/org/openstreetmap/josm/actions/DialogsToggleAction.java
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 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.tools.Shortcut; 16 17 public 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
33 33 import org.openstreetmap.josm.actions.CreateCircleAction; 34 34 import org.openstreetmap.josm.actions.CreateMultipolygonAction; 35 35 import org.openstreetmap.josm.actions.DeleteAction; 36 import org.openstreetmap.josm.actions.DialogsToggleAction; 36 37 import org.openstreetmap.josm.actions.DistributeAction; 37 38 import org.openstreetmap.josm.actions.DownloadAction; 38 39 import org.openstreetmap.josm.actions.DownloadPrimitiveAction; … … 62 63 import org.openstreetmap.josm.actions.OpenFileAction; 63 64 import org.openstreetmap.josm.actions.OpenLocationAction; 64 65 import org.openstreetmap.josm.actions.OrthogonalizeAction; 66 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo; 65 67 import org.openstreetmap.josm.actions.PasteAction; 66 68 import org.openstreetmap.josm.actions.PasteTagsAction; 69 import org.openstreetmap.josm.actions.PreferenceToggleAction; 67 70 import org.openstreetmap.josm.actions.PreferencesAction; 68 71 import org.openstreetmap.josm.actions.PurgeAction; 69 72 import org.openstreetmap.josm.actions.RedoAction; … … 90 93 import org.openstreetmap.josm.actions.WireframeToggleAction; 91 94 import org.openstreetmap.josm.actions.ZoomInAction; 92 95 import org.openstreetmap.josm.actions.ZoomOutAction; 93 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;94 import org.openstreetmap.josm.actions.PreferenceToggleAction;95 96 import org.openstreetmap.josm.actions.audio.AudioBackAction; 96 97 import org.openstreetmap.josm.actions.audio.AudioFasterAction; 97 98 import org.openstreetmap.josm.actions.audio.AudioFwdAction; … … 229 230 public final JumpToAction jumpToAct = new JumpToAction(); 230 231 231 232 public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction(); 233 public final DialogsToggleAction dialogsToggleAction = new DialogsToggleAction(); 232 234 public FullscreenToggleAction fullscreenToggleAction = null; 233 235 234 236 /** this menu listener hides unnecessary JSeparators in a menu list but does not remove them. … … 514 516 fullscreen.setAccelerator(fullscreenToggleAction.getShortcut().getKeyStroke()); 515 517 fullscreenToggleAction.addButtonModel(fullscreen.getModel()); 516 518 } 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 517 526 viewMenu.addSeparator(); 518 527 add(viewMenu, info); 519 528 add(viewMenu, infoweb); -
src/org/openstreetmap/josm/gui/MapFrame.java
9 9 import java.awt.Dimension; 10 10 import java.awt.Font; 11 11 import java.awt.GridBagLayout; 12 import java.awt.KeyboardFocusManager; 12 13 import java.awt.Rectangle; 13 14 import java.awt.event.ActionEvent; 14 15 import java.awt.event.KeyEvent; … … 17 18 import java.util.ArrayList; 18 19 import java.util.Collection; 19 20 import java.util.HashMap; 21 import java.util.HashSet; 20 22 import java.util.List; 21 23 import java.util.Map; 22 24 import java.util.concurrent.CopyOnWriteArrayList; … … 120 122 * instead of adding directly to this list. 121 123 */ 122 124 private List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>(); 125 private final JSplitPane splitPane; 123 126 private final JPanel leftPanel; 124 127 private final DialogsPanel dialogsPanel; 125 128 … … 177 180 178 181 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true); 179 182 180 JSplitPanesplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);183 splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); 181 184 dialogsPanel = new DialogsPanel(splitPane); 182 185 splitPane.setLeftComponent(leftPanel); 183 186 splitPane.setRightComponent(dialogsPanel); … … 233 236 // status line below the map 234 237 statusLine = new MapStatus(this); 235 238 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); 236 246 } 237 247 238 248 public boolean selectSelectTool(boolean onlyIfModeless) { … … 543 553 return dialogsPanel.getToggleDialog(type); 544 554 } 545 555 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 546 563 /** 547 564 * Remember the current width of the (possibly resized) toggle dialog area 548 565 */ 549 566 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()); 551 569 } 570 } 552 571 553 572 /* 554 573 * Remove panel from top of MapView by class