Changeset 3470 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-08-25T20:01:11+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r3421 r3470 24 24 import javax.swing.AbstractAction; 25 25 import javax.swing.BorderFactory; 26 import javax.swing.ComponentInputMap; 26 27 import javax.swing.ImageIcon; 28 import javax.swing.InputMap; 27 29 import javax.swing.JButton; 28 30 import javax.swing.JComponent; … … 31 33 import javax.swing.JOptionPane; 32 34 import javax.swing.JPanel; 35 import javax.swing.KeyStroke; 33 36 34 37 import org.openstreetmap.josm.Main; … … 46 49 */ 47 50 public 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 } 102 48 103 /** The action to toggle this dialog */ 49 104 protected ToggleDialogAction toggleAction; … … 97 152 * @param defShow if the dialog should be shown by default, if there is no preference 98 153 */ 154 @SuppressWarnings("deprecation") 99 155 public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight, boolean defShow) { 100 156 super(new BorderLayout()); … … 123 179 isDocked = Main.pref.getBoolean(preferencePrefix+".docked", true); 124 180 isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false); 181 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()); 125 188 } 126 189
Note:
See TracChangeset
for help on using the changeset viewer.