Changeset 5958 in josm for trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
- Timestamp:
- 2013-05-13T03:10:05+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r5460 r5958 13 13 14 14 import javax.swing.JOptionPane; 15 import javax.swing.event.ListSelectionEvent; 16 import javax.swing.event.ListSelectionListener; 17 import javax.swing.event.TreeSelectionEvent; 18 import javax.swing.event.TreeSelectionListener; 15 19 16 20 import org.openstreetmap.josm.Main; … … 19 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 24 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 25 import org.openstreetmap.josm.data.validation.TestError; 26 import org.openstreetmap.josm.gui.MapFrame; 27 import org.openstreetmap.josm.gui.MapFrameListener; 21 28 import org.openstreetmap.josm.gui.MapView; 22 29 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 30 import org.openstreetmap.josm.gui.dialogs.ValidatorDialog.ValidatorBoundingXYVisitor; 23 31 import org.openstreetmap.josm.gui.layer.Layer; 24 32 import org.openstreetmap.josm.tools.Shortcut; … … 36 44 marktr("conflict"), 37 45 marktr("download"), 46 marktr("problem"), 38 47 marktr("previous"), 39 48 marktr("next")}; 49 50 private final String mode; 51 52 protected ZoomChangeAdapter zoomChangeAdapter; 53 protected MapFrameAdapter mapFrameAdapter; 40 54 41 55 /** … … 77 91 } 78 92 79 private final String mode;80 81 93 private static int getModeShortcut(String mode) { 82 94 int shortcut = -1; … … 88 100 else if (mode.equals("conflict")) { shortcut = KeyEvent.VK_4; } 89 101 else if (mode.equals("download")) { shortcut = KeyEvent.VK_5; } 102 else if (mode.equals("problem")) { shortcut = KeyEvent.VK_6; } 90 103 else if (mode.equals("previous")) { shortcut = KeyEvent.VK_8; } 91 104 else if (mode.equals("next")) { shortcut = KeyEvent.VK_9; } … … 95 108 96 109 /** 97 * 98 * @param mode 110 * Constructs a new {@code AutoScaleAction}. 111 * @param mode The autoscale mode (one of {@link AutoScaleAction#MODES}) 99 112 * @param marker Used only to differentiate from default constructor 100 113 */ … … 104 117 } 105 118 106 107 public AutoScaleAction(String mode) { 119 /** 120 * Constructs a new {@code AutoScaleAction}. 121 * @param mode The autoscale mode (one of {@link AutoScaleAction#MODES}) 122 */ 123 public AutoScaleAction(final String mode) { 108 124 super(tr("Zoom to {0}", tr(mode)), "dialogs/autoscale/" + mode, tr("Zoom the view to {0}.", tr(mode)), 109 Shortcut.registerShortcut("view:zoom"+mode, tr("View: {0}", tr("Zoom to {0}", tr(mode))), getModeShortcut(mode), Shortcut.DIRECT), true); 125 Shortcut.registerShortcut("view:zoom"+mode, tr("View: {0}", tr("Zoom to {0}", tr(mode))), getModeShortcut(mode), Shortcut.DIRECT), 126 true, null, false); 110 127 String modeHelp = Character.toUpperCase(mode.charAt(0)) + mode.substring(1); 111 128 putValue("help", "Action/AutoScale/" + modeHelp); … … 119 136 } else if (mode.equals("conflict")) { 120 137 putValue("help", ht("/Action/ZoomToConflict")); 138 } else if (mode.equals("problem")) { 139 putValue("help", ht("/Action/ZoomToProblem")); 121 140 } else if (mode.equals("download")) { 122 141 putValue("help", ht("/Action/ZoomToDownload")); … … 125 144 } else if (mode.equals("next")) { 126 145 putValue("help", ht("/Action/ZoomToNext")); 127 } 146 } else { 147 throw new IllegalArgumentException("Unknown mode: "+mode); 148 } 149 installAdapters(); 128 150 } 129 151 … … 171 193 172 194 private BoundingXYVisitor getBoundingBox() { 173 BoundingXYVisitor v = new BoundingXYVisitor(); 174 if (mode.equals("data")) { 195 BoundingXYVisitor v = mode.equals("problem") ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor(); 196 197 if (mode.equals("problem")) { 198 TestError error = Main.map.validatorDialog.getSelectedError(); 199 if (error == null) return null; 200 ((ValidatorBoundingXYVisitor) v).visit(error); 201 if (v.getBounds() == null) return null; 202 v.enlargeBoundingBox(Main.pref.getDouble("validator.zoom-enlarge-bbox", 0.0002)); 203 } else if (mode.equals("data")) { 175 204 for (Layer l : Main.map.mapView.getAllLayers()) { 176 205 l.visitBoundingBox(v); … … 236 265 setEnabled(true); 237 266 } 267 } else if ("conflict".equals(mode)) { 268 setEnabled(Main.map != null && Main.map.conflictDialog.getSelectedConflict() != null); 269 } else if ("problem".equals(mode)) { 270 setEnabled(Main.map != null && Main.map.validatorDialog.getSelectedError() != null); 238 271 } else if ("previous".equals(mode)) { 239 272 setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasZoomUndoEntries()); … … 258 291 protected void installAdapters() { 259 292 super.installAdapters(); 260 // make this action listen to zoom change events293 // make this action listen to zoom and mapframe change events 261 294 // 262 zoomChangeAdapter = new ZoomChangeAdapter();263 Ma pView.addZoomChangeListener(zoomChangeAdapter);295 MapView.addZoomChangeListener(zoomChangeAdapter = new ZoomChangeAdapter()); 296 Main.addMapFrameListener(mapFrameAdapter = new MapFrameAdapter()); 264 297 initEnabledState(); 265 298 } 266 299 267 300 /** 268 * Adapter for selection change events 269 * 301 * Adapter for zoom change events 270 302 */ 271 303 private class ZoomChangeAdapter implements MapView.ZoomChangeListener { … … 275 307 } 276 308 277 private ZoomChangeAdapter zoomChangeAdapter; 309 /** 310 * Adapter for MapFrame change events 311 */ 312 private class MapFrameAdapter implements MapFrameListener { 313 private ListSelectionListener conflictSelectionListener; 314 private TreeSelectionListener validatorSelectionListener; 315 316 public MapFrameAdapter() { 317 if (mode.equals("conflict")) { 318 conflictSelectionListener = new ListSelectionListener() { 319 @Override public void valueChanged(ListSelectionEvent e) { 320 updateEnabledState(); 321 } 322 }; 323 } else if (mode.equals("problem")) { 324 validatorSelectionListener = new TreeSelectionListener() { 325 @Override public void valueChanged(TreeSelectionEvent e) { 326 updateEnabledState(); 327 } 328 }; 329 } 330 } 331 332 @Override public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 333 if (conflictSelectionListener != null) { 334 if (newFrame != null) { 335 newFrame.conflictDialog.addListSelectionListener(conflictSelectionListener); 336 } else if (oldFrame != null) { 337 oldFrame.conflictDialog.removeListSelectionListener(conflictSelectionListener); 338 } 339 } else if (validatorSelectionListener != null) { 340 if (newFrame != null) { 341 newFrame.validatorDialog.addTreeSelectionListener(validatorSelectionListener); 342 } else if (oldFrame != null) { 343 oldFrame.validatorDialog.removeTreeSelectionListener(validatorSelectionListener); 344 } 345 } 346 } 347 } 278 348 }
Note:
See TracChangeset
for help on using the changeset viewer.