Ignore:
Timestamp:
2010-08-31T12:37:51+02:00 (14 years ago)
Author:
bastiK
Message:

see #3278 (redirect shortcuts in the undocked windows to the main window) - also for relation dialog

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r3470 r3502  
    2424import javax.swing.AbstractAction;
    2525import javax.swing.BorderFactory;
    26 import javax.swing.ComponentInputMap;
    2726import javax.swing.ImageIcon;
    28 import javax.swing.InputMap;
    2927import javax.swing.JButton;
    3028import javax.swing.JComponent;
     
    3331import javax.swing.JOptionPane;
    3432import javax.swing.JPanel;
    35 import javax.swing.KeyStroke;
    3633
    3734import org.openstreetmap.josm.Main;
     
    4037import org.openstreetmap.josm.gui.help.HelpUtil;
    4138import org.openstreetmap.josm.gui.help.Helpful;
     39import org.openstreetmap.josm.gui.util.RedirectInputMap;
    4240import org.openstreetmap.josm.tools.GBC;
    4341import org.openstreetmap.josm.tools.ImageProvider;
     
    4947 */
    5048public class ToggleDialog extends JPanel implements Helpful {
    51 
    52     // It's not possible to simply set component input map parent to be Main.contentPane.getInputMap because
    53     // there is check in setParent that InputMap is for the same component
    54     // Yes, this is a hack
    55     // Another possibility would be simply copy InputMap, but that would require to keep copies synchronized when some shortcut is
    56     // later
    57     private static class RedirectInputMap extends ComponentInputMap {
    58 
    59         private final InputMap target;
    60 
    61         public RedirectInputMap(JComponent component, InputMap target) {
    62             super(component);
    63             this.target = target;
    64         }
    65 
    66         @Override
    67         public Object get(KeyStroke keyStroke) {
    68             return target.get(keyStroke);
    69         }
    70 
    71         @Override
    72         public KeyStroke[] keys() {
    73             return target.keys();
    74         }
    75 
    76         @Override
    77         public int size() {
    78             return target.size();
    79         }
    80 
    81         @Override
    82         public KeyStroke[] allKeys() {
    83             return target.allKeys();
    84         }
    85 
    86         @Override
    87         public void put(KeyStroke keyStroke, Object actionMapKey) {
    88             throw new UnsupportedOperationException();
    89         }
    90 
    91         @Override
    92         public void remove(KeyStroke key) {
    93             throw new UnsupportedOperationException();
    94         }
    95 
    96         @Override
    97         public void clear() {
    98             throw new UnsupportedOperationException();
    99         }
    100 
    101     }
    10249
    10350    /** The action to toggle this dialog */
     
    15299     * @param defShow if the dialog should be shown by default, if there is no preference
    153100     */
    154     @SuppressWarnings("deprecation")
    155101    public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight, boolean defShow) {
    156102        super(new BorderLayout());
     
    180126        isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false);
    181127
    182         InputMap lastParent = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    183         while (lastParent.getParent() != null) {
    184             lastParent = lastParent.getParent();
    185         }
    186         lastParent.setParent(new RedirectInputMap(this, Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)));
    187         getActionMap().setParent(Main.contentPane.getActionMap());
     128        RedirectInputMap.redirectToMainContentPane(this);
    188129    }
    189130
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r3440 r3502  
    7272import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    7373import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     74import org.openstreetmap.josm.gui.util.RedirectInputMap;
    7475import org.openstreetmap.josm.tools.ImageProvider;
    7576import org.openstreetmap.josm.tools.Shortcut;
     
    185186        memberTableModel.setSelectedMembers(selectedMembers);
    186187        HelpUtil.setHelpContext(getRootPane(),ht("/Dialog/RelationEditor"));
     188        RedirectInputMap.redirectToMainContentPane(getRootPane());
    187189    }
    188190
Note: See TracChangeset for help on using the changeset viewer.