Changeset 8171 in josm
- Timestamp:
- 2015-04-06T14:59:42+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r7817 r8171 8 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.KeyEvent; 10 import java.util.ArrayList; 10 11 import java.util.Arrays; 11 12 import java.util.Collection; … … 22 23 import org.openstreetmap.josm.Main; 23 24 import org.openstreetmap.josm.data.Bounds; 25 import org.openstreetmap.josm.data.DataSource; 24 26 import org.openstreetmap.josm.data.conflict.Conflict; 25 27 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 31 33 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 32 34 import org.openstreetmap.josm.gui.dialogs.ValidatorDialog.ValidatorBoundingXYVisitor; 33 import org.openstreetmap.josm.gui.download.DownloadDialog;34 35 import org.openstreetmap.josm.gui.layer.Layer; 35 36 import org.openstreetmap.josm.tools.Shortcut; … … 55 56 protected ZoomChangeAdapter zoomChangeAdapter; 56 57 protected MapFrameAdapter mapFrameAdapter; 58 /** Time of last zoom to bounds action */ 59 protected long lastZoomTime = -1; 60 /** Last zommed bounds */ 61 protected int lastZoomArea = -1; 57 62 58 63 /** … … 63 68 */ 64 69 public static void zoomToSelection() { 65 if (Main.main == null || !Main.main.hasEditLayer()) return; 70 if (Main.main == null || !Main.main.hasEditLayer()) 71 return; 66 72 Collection<OsmPrimitive> sel = Main.main.getEditLayer().data.getSelected(); 67 73 if (sel.isEmpty()) { … … 70 76 tr("Nothing selected to zoom to."), 71 77 tr("Information"), 72 JOptionPane.INFORMATION_MESSAGE 73 ); 78 JOptionPane.INFORMATION_MESSAGE); 74 79 return; 75 80 } … … 126 131 public AutoScaleAction(final String mode) { 127 132 super(tr("Zoom to {0}", tr(mode)), "dialogs/autoscale/" + mode, tr("Zoom the view to {0}.", tr(mode)), 128 Shortcut.registerShortcut("view:zoom" +mode, tr("View: {0}", tr("Zoom to {0}", tr(mode))), getModeShortcut(mode), Shortcut.DIRECT),129 true, null, false); 133 Shortcut.registerShortcut("view:zoom" + mode, tr("View: {0}", tr("Zoom to {0}", tr(mode))), 134 getModeShortcut(mode), Shortcut.DIRECT), true, null, false); 130 135 String modeHelp = Character.toUpperCase(mode.charAt(0)) + mode.substring(1); 131 136 putValue("help", "Action/AutoScale/" + modeHelp); … … 157 162 break; 158 163 default: 159 throw new IllegalArgumentException("Unknown mode: " +mode);164 throw new IllegalArgumentException("Unknown mode: " + mode); 160 165 } 161 166 installAdapters(); 162 167 } 163 168 164 public void autoScale() 169 public void autoScale() { 165 170 if (Main.isDisplayingMapView()) { 166 switch(mode) { 171 switch (mode) { 167 172 case "previous": 168 173 Main.map.mapView.zoomPrevious(); … … 195 200 protected Layer getFirstSelectedLayer() { 196 201 List<Layer> layers = LayerListDialog.getInstance().getModel().getSelectedLayers(); 197 if (layers.isEmpty()) return null; 202 if (layers.isEmpty()) 203 return null; 198 204 return layers.get(0); 199 205 } … … 202 208 BoundingXYVisitor v = "problem".equals(mode) ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor(); 203 209 204 switch(mode) { 210 switch (mode) { 205 211 case "problem": 206 212 TestError error = Main.map.validatorDialog.getSelectedError(); 207 if (error == null) return null; 213 if (error == null) 214 return null; 208 215 ((ValidatorBoundingXYVisitor) v).visit(error); 209 if (v.getBounds() == null) return null; 216 if (v.getBounds() == null) 217 return null; 210 218 v.enlargeBoundingBox(Main.pref.getDouble("validator.zoom-enlarge-bbox", 0.0002)); 211 219 break; … … 220 228 // try to zoom to the first selected layer 221 229 Layer l = getFirstSelectedLayer(); 222 if (l == null) return null; 230 if (l == null) 231 return null; 223 232 l.visitBoundingBox(v); 224 233 break; … … 241 250 ("selection".equals(mode) ? tr("Nothing selected to zoom to.") : tr("No conflicts to zoom to")), 242 251 tr("Information"), 243 JOptionPane.INFORMATION_MESSAGE 244 ); 252 JOptionPane.INFORMATION_MESSAGE); 245 253 return null; 246 254 } … … 256 264 break; 257 265 case "download": 258 Bounds bounds = DownloadDialog.getSavedDownloadBounds(); 259 if (bounds != null) { 260 try { 261 v.visit(bounds); 262 } catch (Exception e) { 263 Main.warn(e); 264 } 266 267 if (lastZoomTime > 0 && System.currentTimeMillis() - lastZoomTime > Main.pref.getLong("zoom.bounds.reset.time", 10*1000)) { 268 lastZoomTime = -1; 269 } 270 ArrayList<DataSource> dataSources = new ArrayList<>(Main.main.getCurrentDataSet().getDataSources()); 271 int s = dataSources.size(); 272 if(s > 0) { 273 if(lastZoomTime == -1 || lastZoomArea == -1 || lastZoomArea > s) { 274 lastZoomArea = s-1; 275 v.visit(dataSources.get(lastZoomArea).bounds); 276 } else if(lastZoomArea > 0) { 277 lastZoomArea -= 1; 278 v.visit(dataSources.get(lastZoomArea).bounds); 279 } else { 280 lastZoomArea = -1; 281 v.visit(new Bounds(Main.main.getCurrentDataSet().getDataSourceArea().getBounds2D())); 282 } 283 lastZoomTime = System.currentTimeMillis(); 284 } else { 285 lastZoomTime = -1; 286 lastZoomArea = -1; 265 287 } 266 288 break; … … 271 293 @Override 272 294 protected void updateEnabledState() { 273 switch(mode) { 295 switch (mode) { 274 296 case "selection": 275 setEnabled(getCurrentDataSet() != null && ! 297 setEnabled(getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty()); 276 298 break; 277 299 case "layer": … … 296 318 break; 297 319 default: 298 setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasLayers() 299 ); 320 setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasLayers()); 300 321 } 301 322 } … … 338 359 if ("conflict".equals(mode)) { 339 360 conflictSelectionListener = new ListSelectionListener() { 340 @Override public void valueChanged(ListSelectionEvent e) { 361 @Override 362 public void valueChanged(ListSelectionEvent e) { 341 363 updateEnabledState(); 342 364 } … … 344 366 } else if ("problem".equals(mode)) { 345 367 validatorSelectionListener = new TreeSelectionListener() { 346 @Override public void valueChanged(TreeSelectionEvent e) { 368 @Override 369 public void valueChanged(TreeSelectionEvent e) { 347 370 updateEnabledState(); 348 371 } … … 351 374 } 352 375 353 @Override public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 376 @Override 377 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 354 378 if (conflictSelectionListener != null) { 355 379 if (newFrame != null) {
Note:
See TracChangeset
for help on using the changeset viewer.