Changeset 3252 in josm
- Timestamp:
- 2010-05-15T18:59:10+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r3071 r3252 27 27 import java.util.regex.Pattern; 28 28 29 import javax.swing.Action; 30 import javax.swing.InputMap; 29 31 import javax.swing.JComponent; 30 32 import javax.swing.JFrame; 31 33 import javax.swing.JOptionPane; 32 34 import javax.swing.JPanel; 35 import javax.swing.KeyStroke; 33 36 import javax.swing.UIManager; 34 37 … … 198 201 isOpenjdk = System.getProperty("java.vm.name").toUpperCase().indexOf("OPENJDK") != -1; 199 202 platform.startupHook(); 200 contentPane .add(panel, BorderLayout.CENTER);203 contentPanePrivate.add(panel, BorderLayout.CENTER); 201 204 panel.add(gettingStarted, BorderLayout.CENTER); 202 205 menu = new MainMenu(); … … 205 208 206 209 // creating toolbar 207 contentPane.add(toolbar.control, BorderLayout.NORTH); 208 209 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) 210 .put(Shortcut.registerShortcut("system:help", tr("Help"), 211 KeyEvent.VK_F1, Shortcut.GROUP_DIRECT).getKeyStroke(), "Help"); 212 contentPane.getActionMap().put("Help", menu.help); 210 contentPanePrivate.add(toolbar.control, BorderLayout.NORTH); 211 212 registerActionShortcut(menu.help, Shortcut.registerShortcut("system:help", tr("Help"), 213 KeyEvent.VK_F1, Shortcut.GROUP_DIRECT)); 213 214 214 215 TaggingPresetPreference.initialize(); … … 218 219 219 220 toolbar.control.updateUI(); 220 contentPane .updateUI();221 contentPanePrivate.updateUI(); 221 222 } 222 223 … … 226 227 public final void addLayer(final Layer layer) { 227 228 if (map == null) { 228 final MapFrame mapFrame = new MapFrame( );229 final MapFrame mapFrame = new MapFrame(contentPanePrivate); 229 230 setMapFrame(mapFrame); 230 231 mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction()); … … 281 282 } 282 283 283 /** 284 * Use this to register shortcuts to 285 */ 286 public static final JPanel contentPane = new JPanel(new BorderLayout()); 284 protected static JPanel contentPanePrivate = new JPanel(new BorderLayout()); 285 286 /** 287 * @deprecated If you just need to register shortcut for action, use registerActionShortcut instead of accessing InputMap directly 288 */ 289 @Deprecated 290 public static final JPanel contentPane = contentPanePrivate; 291 292 public static void registerActionShortcut(Action action, Shortcut shortcut) { 293 registerActionShortcut(action, shortcut.getKeyStroke()); 294 } 295 296 public static void registerActionShortcut(Action action, KeyStroke keyStroke) { 297 if (keyStroke == null) 298 return; 299 300 InputMap inputMap = contentPanePrivate.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); 301 Object existing = inputMap.get(keyStroke); 302 if (existing != null && !existing.equals(action)) { 303 System.out.println(String.format("Keystroke is already assigned to %s, will be overridden by %s", existing, action)); 304 } 305 inputMap.put(keyStroke, action); 306 307 contentPanePrivate.getActionMap().put(action, action); 308 } 309 310 public static void unregisterActionShortcut(Shortcut shortcut) { 311 contentPanePrivate.getInputMap().remove(shortcut.getKeyStroke()); 312 } 287 313 288 314 /////////////////////////////////////////////////////////////////////////// … … 324 350 } 325 351 toolbar = new ToolbarPreferences(); 326 contentPane .updateUI();352 contentPanePrivate.updateUI(); 327 353 panel.updateUI(); 328 354 } catch (final Exception e) { -
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r3244 r3252 7 7 8 8 import javax.swing.AbstractAction; 9 import javax.swing.JComponent;10 9 11 10 import org.openstreetmap.josm.Main; … … 72 71 sc = shortcut; 73 72 if (sc != null) { 74 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), name); 75 Main.contentPane.getActionMap().put(name, this); 73 Main.registerActionShortcut(this, sc); 76 74 } 77 75 putValue(SHORT_DESCRIPTION, Main.platform.makeTooltip(tooltip, sc)); … … 90 88 public void destroy() { 91 89 if (sc != null) { 92 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(sc.getKeyStroke()); 93 Main.contentPane.getActionMap().remove(sc.getKeyStroke()); 90 Main.unregisterActionShortcut(sc); 94 91 } 95 92 MapView.removeLayerChangeListener(layerChangeAdapter); -
trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java
r2512 r3252 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;6 6 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 10 import javax.swing.JComponent;11 9 12 10 import org.openstreetmap.josm.Main; … … 22 20 23 21 // Add extra shortcut C-S-a 24 Main. contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(25 Shortcut.registerShortcut("edit:unselectallfocus", tr("Edit: {0}", tr("Unselect All (Focus)")),26 KeyEvent.VK_A, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT).getKeyStroke(), 27 tr("Unselect All")); 22 Main.registerActionShortcut(this, Shortcut.registerShortcut("edit:unselectallfocus", tr("Edit: {0}", tr("Unselect All (Focus)")), 23 KeyEvent.VK_A, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT)); 24 25 28 26 29 27 // Add extra shortcut ESCAPE … … 33 31 * for now this is a reasonable approximation. 34 32 */ 35 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 36 Shortcut.registerShortcut("edit:unselectallescape", tr("Edit: {0}", tr("Unselect All (Escape)")), 37 KeyEvent.VK_ESCAPE, Shortcut.GROUP_DIRECT).getKeyStroke(), 38 tr("Unselect All")); 33 Main.registerActionShortcut(this, Shortcut.registerShortcut("edit:unselectallescape", tr("Edit: {0}", tr("Unselect All (Escape)")), 34 KeyEvent.VK_ESCAPE, Shortcut.GROUP_DIRECT)); 39 35 40 36 putValue("help", ht("/Action/UnselectAll")); -
trunk/src/org/openstreetmap/josm/actions/ZoomInAction.java
r3083 r3252 8 8 import java.awt.event.KeyEvent; 9 9 10 import javax.swing.JComponent;11 10 import javax.swing.KeyStroke; 12 11 … … 25 24 ); 26 25 putValue("help", ht("/Action/ZoomIn")); 27 // make numpad + behave like + (action is already registred)28 Main. contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD,0), tr("Zoom In"));26 // make numpad + behave like + 27 Main.registerActionShortcut(this, KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0)); 29 28 } 30 29 31 30 public void actionPerformed(ActionEvent e) { 32 Object name = Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).get(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0));33 Main.contentPane.getActionMap().put(name, this);34 35 31 if (!Main.isDisplayingMapView()) return; 36 32 Main.map.mapView.zoomToFactor(0.9); -
trunk/src/org/openstreetmap/josm/actions/ZoomOutAction.java
r3083 r3252 8 8 import java.awt.event.KeyEvent; 9 9 10 import javax.swing.JComponent;11 10 import javax.swing.KeyStroke; 12 11 … … 21 20 putValue("help", ht("/Action/ZoomOut")); 22 21 // make numpad - behave like - 23 Main. contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT,0), tr("Zoom Out"));22 Main.registerActionShortcut(this, KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT,0)); 24 23 } 25 24 -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r3177 r3252 30 30 import java.util.Set; 31 31 32 import javax.swing.JComponent;33 32 import javax.swing.JOptionPane; 34 33 … … 95 94 96 95 // Add extra shortcut N 97 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 98 Shortcut.registerShortcut("mapmode:drawfocus", tr("Mode: Draw Focus"), KeyEvent.VK_N, Shortcut.GROUP_EDIT).getKeyStroke(), tr("Draw")); 96 Main.registerActionShortcut(this, Shortcut.registerShortcut("mapmode:drawfocus", tr("Mode: Draw Focus"), KeyEvent.VK_N, Shortcut.GROUP_EDIT)); 99 97 100 98 cursorCrosshair = getCursor(); -
trunk/src/org/openstreetmap/josm/gui/MainApplet.java
r3248 r3252 47 47 private final class MainCaller extends Main { 48 48 private MainCaller() { 49 setContentPane(contentPane );49 setContentPane(contentPanePrivate); 50 50 setJMenuBar(menu); 51 51 setBounds(bounds); -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r3232 r3252 53 53 public MainApplication(JFrame mainFrame) { 54 54 super(); 55 mainFrame.setContentPane(contentPane );55 mainFrame.setContentPane(contentPanePrivate); 56 56 mainFrame.setJMenuBar(menu); 57 57 mainFrame.setBounds(bounds); -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r3189 r3252 91 91 public final int DEF_TOGGLE_DLG_WIDTH = 330; 92 92 93 public MapFrame( ) {93 public MapFrame(JPanel contentPane) { 94 94 setSize(400,400); 95 95 setLayout(new BorderLayout()); 96 96 97 mapView = new MapView( );97 mapView = new MapView(contentPane); 98 98 99 99 new FileDrop(mapView); -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r3229 r3252 29 29 30 30 import javax.swing.AbstractButton; 31 import javax.swing.JComponent;32 31 import javax.swing.JOptionPane; 32 import javax.swing.JPanel; 33 33 34 34 import org.openstreetmap.josm.Main; 35 35 import org.openstreetmap.josm.actions.AutoScaleAction; 36 import org.openstreetmap.josm.actions.JosmAction;37 36 import org.openstreetmap.josm.actions.MoveAction; 38 37 import org.openstreetmap.josm.actions.mapmode.MapMode; … … 189 188 private Rectangle lastClipBounds = new Rectangle(); 190 189 191 public MapView( ) {190 public MapView(final JPanel contentPane) { 192 191 Main.pref.addPreferenceChangeListener(this); 193 192 addComponentListener(new ComponentAdapter(){ … … 213 212 } 214 213 215 new MapMover(MapView.this, Main.contentPane); 216 JosmAction mv; 217 mv = new MoveAction(MoveAction.Direction.UP); 218 if (mv.getShortcut() != null) { 219 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortcut().getKeyStroke(), "UP"); 220 Main.contentPane.getActionMap().put("UP", mv); 221 } 222 mv = new MoveAction(MoveAction.Direction.DOWN); 223 if (mv.getShortcut() != null) { 224 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortcut().getKeyStroke(), "DOWN"); 225 Main.contentPane.getActionMap().put("DOWN", mv); 226 } 227 mv = new MoveAction(MoveAction.Direction.LEFT); 228 if (mv.getShortcut() != null) { 229 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortcut().getKeyStroke(), "LEFT"); 230 Main.contentPane.getActionMap().put("LEFT", mv); 231 } 232 mv = new MoveAction(MoveAction.Direction.RIGHT); 233 if (mv.getShortcut() != null) { 234 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(mv.getShortcut().getKeyStroke(), "RIGHT"); 235 Main.contentPane.getActionMap().put("RIGHT", mv); 236 } 214 new MapMover(MapView.this, contentPane); 215 new MoveAction(MoveAction.Direction.UP); 216 new MoveAction(MoveAction.Direction.DOWN); 217 new MoveAction(MoveAction.Direction.LEFT); 218 new MoveAction(MoveAction.Direction.RIGHT); 237 219 } 238 220 }); -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r3219 r3252 610 610 btnAdd.getActionMap().put("onEnter", addAction); 611 611 612 Shortcut sc = Shortcut.registerShortcut("properties:add", tr("Add Properties"), KeyEvent.VK_B, 613 Shortcut.GROUP_MNEMONIC); 614 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), "properties:add"); 615 Main.contentPane.getActionMap().put("properties:add", addAction); 612 Main.registerActionShortcut(addAction, Shortcut.registerShortcut("properties:add", tr("Add Properties"), KeyEvent.VK_B, 613 Shortcut.GROUP_MNEMONIC)); 616 614 617 615 // -- edit action -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r2969 r3252 17 17 import java.awt.event.WindowEvent; 18 18 19 import javax.swing.AbstractAction; 19 20 import javax.swing.Box; 20 import javax.swing.AbstractAction;21 21 import javax.swing.ImageIcon; 22 22 import javax.swing.JButton; … … 54 54 55 55 public static ImageViewerDialog getInstance() { 56 if (dialog == null) {56 if (dialog == null) 57 57 throw new AssertionError(); // a new instance needs to be created first 58 }59 58 return dialog; 60 59 } … … 83 82 btnPrevious.setPreferredSize(buttonDim); 84 83 Shortcut scPrev = Shortcut.registerShortcut( 85 "geoimage:previous", tr("Geoimage: {0}", tr("Show previous Image")), KeyEvent.VK_PAGE_UP, Shortcut.GROUP_DIRECT);84 "geoimage:previous", tr("Geoimage: {0}", tr("Show previous Image")), KeyEvent.VK_PAGE_UP, Shortcut.GROUP_DIRECT); 86 85 final String APREVIOUS = "Previous Image"; 87 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scPrev.getKeyStroke(), APREVIOUS); 88 Main.contentPane.getActionMap().put(APREVIOUS, prevAction); 86 Main.registerActionShortcut(prevAction, scPrev); 89 87 btnPrevious.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scPrev.getKeyStroke(), APREVIOUS); 90 88 btnPrevious.getActionMap().put(APREVIOUS, prevAction); … … 95 93 btnDelete.setPreferredSize(buttonDim); 96 94 Shortcut scDelete = Shortcut.registerShortcut( 97 "geoimage:deleteimagefromlayer", tr("Geoimage: {0}", DELETE_TEXT), KeyEvent.VK_DELETE, Shortcut.GROUP_DIRECT, Shortcut.SHIFT_DEFAULT); 98 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scDelete.getKeyStroke(), DELETE_TEXT); 99 Main.contentPane.getActionMap().put(DELETE_TEXT, delAction); 95 "geoimage:deleteimagefromlayer", tr("Geoimage: {0}", DELETE_TEXT), KeyEvent.VK_DELETE, Shortcut.GROUP_DIRECT, Shortcut.SHIFT_DEFAULT); 96 Main.registerActionShortcut(delAction, scDelete); 100 97 btnDelete.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scDelete.getKeyStroke(), DELETE_TEXT); 101 98 btnDelete.getActionMap().put(DELETE_TEXT, delAction); … … 105 102 btnDeleteFromDisk.setPreferredSize(buttonDim); 106 103 Shortcut scDeleteFromDisk = Shortcut.registerShortcut( 107 "geoimage:deletefilefromdisk", tr("Geoimage: {0}", tr("Delete File from disk")), KeyEvent.VK_DELETE, Shortcut.GROUP_DIRECT, Shortcut.GROUP_MENU + Shortcut.SHIFT_DEFAULT);104 "geoimage:deletefilefromdisk", tr("Geoimage: {0}", tr("Delete File from disk")), KeyEvent.VK_DELETE, Shortcut.GROUP_DIRECT, Shortcut.GROUP_MENU + Shortcut.SHIFT_DEFAULT); 108 105 final String ADELFROMDISK = "Delete image file from disk"; 109 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scDeleteFromDisk.getKeyStroke(), ADELFROMDISK); 110 Main.contentPane.getActionMap().put(ADELFROMDISK, delFromDiskAction); 106 Main.registerActionShortcut(delFromDiskAction, scDeleteFromDisk); 111 107 btnDeleteFromDisk.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scDeleteFromDisk.getKeyStroke(), ADELFROMDISK); 112 108 btnDeleteFromDisk.getActionMap().put(ADELFROMDISK, delFromDiskAction); … … 116 112 btnNext.setPreferredSize(buttonDim); 117 113 Shortcut scNext = Shortcut.registerShortcut( 118 "geoimage:next", tr("Geoimage: {0}", tr("Show next Image")), KeyEvent.VK_PAGE_DOWN, Shortcut.GROUP_DIRECT);114 "geoimage:next", tr("Geoimage: {0}", tr("Show next Image")), KeyEvent.VK_PAGE_DOWN, Shortcut.GROUP_DIRECT); 119 115 final String ANEXT = "Next Image"; 120 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scNext.getKeyStroke(), ANEXT); 121 Main.contentPane.getActionMap().put(ANEXT, nextAction); 116 Main.registerActionShortcut(nextAction, scNext); 122 117 btnNext.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scNext.getKeyStroke(), ANEXT); 123 118 btnNext.getActionMap().put(ANEXT, nextAction); … … 192 187 } else if (COMMAND_REMOVE.equals(action)) { 193 188 if (currentLayer != null) { 194 currentLayer.removeCurrentPhoto();189 currentLayer.removeCurrentPhoto(); 195 190 } 196 191 } else if (COMMAND_REMOVE_FROM_DISK.equals(action)) { … … 221 216 public void displayImage(GeoImageLayer layer, ImageEntry entry) { 222 217 synchronized(this) { 223 // if (currentLayer == layer && currentEntry == entry) {224 // repaint();225 // return;226 // } TODO: pop up image dialog but don't load image again218 // if (currentLayer == layer && currentEntry == entry) { 219 // repaint(); 220 // return; 221 // } TODO: pop up image dialog but don't load image again 227 222 228 223 if (centerView && Main.map != null && entry != null && entry.getPos() != null) {
Note:
See TracChangeset
for help on using the changeset viewer.