Changeset 7012 in josm for trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
- Timestamp:
- 2014-04-27T15:35:47+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r7005 r7012 96 96 int shortcut = -1; 97 97 98 // TODO: convert this to switch/case and make sure the parsing still works 98 99 /* leave as single line for shortcut overview parsing! */ 99 100 if (mode.equals("data")) { shortcut = KeyEvent.VK_1; } … … 130 131 putValue("help", "Action/AutoScale/" + modeHelp); 131 132 this.mode = mode; 132 if (mode.equals("data")) { 133 switch (mode) { 134 case "data": 133 135 putValue("help", ht("/Action/ZoomToData")); 134 } else if (mode.equals("layer")) { 136 break; 137 case "layer": 135 138 putValue("help", ht("/Action/ZoomToLayer")); 136 } else if (mode.equals("selection")) { 139 break; 140 case "selection": 137 141 putValue("help", ht("/Action/ZoomToSelection")); 138 } else if (mode.equals("conflict")) { 142 break; 143 case "conflict": 139 144 putValue("help", ht("/Action/ZoomToConflict")); 140 } else if (mode.equals("problem")) { 145 break; 146 case "problem": 141 147 putValue("help", ht("/Action/ZoomToProblem")); 142 } else if (mode.equals("download")) { 148 break; 149 case "download": 143 150 putValue("help", ht("/Action/ZoomToDownload")); 144 } else if (mode.equals("previous")) { 151 break; 152 case "previous": 145 153 putValue("help", ht("/Action/ZoomToPrevious")); 146 } else if (mode.equals("next")) { 154 break; 155 case "next": 147 156 putValue("help", ht("/Action/ZoomToNext")); 148 } else { 157 break; 158 default: 149 159 throw new IllegalArgumentException("Unknown mode: "+mode); 150 160 } … … 154 164 public void autoScale() { 155 165 if (Main.isDisplayingMapView()) { 156 if (mode.equals("previous")) { 166 switch(mode) { 167 case "previous": 157 168 Main.map.mapView.zoomPrevious(); 158 } else if (mode.equals("next")) { 169 break; 170 case "next": 159 171 Main.map.mapView.zoomNext(); 160 } else { 172 break; 173 default: 161 174 BoundingXYVisitor bbox = getBoundingBox(); 162 175 if (bbox != null && bbox.getBounds() != null) { … … 187 200 188 201 private BoundingXYVisitor getBoundingBox() { 189 BoundingXYVisitor v = mode.equals("problem") ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor(); 190 191 if (mode.equals("problem")) { 202 BoundingXYVisitor v = "problem".equals(mode) ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor(); 203 204 switch(mode) { 205 case "problem": 192 206 TestError error = Main.map.validatorDialog.getSelectedError(); 193 207 if (error == null) return null; … … 195 209 if (v.getBounds() == null) return null; 196 210 v.enlargeBoundingBox(Main.pref.getDouble("validator.zoom-enlarge-bbox", 0.0002)); 197 } else if (mode.equals("data")) { 211 break; 212 case "data": 198 213 for (Layer l : Main.map.mapView.getAllLayers()) { 199 214 l.visitBoundingBox(v); 200 215 } 201 } else if (mode.equals("layer")) { 216 break; 217 case "layer": 202 218 if (Main.main.getActiveLayer() == null) 203 219 return null; … … 206 222 if (l == null) return null; 207 223 l.visitBoundingBox(v); 208 } else if (mode.equals("selection") || mode.equals("conflict")) { 224 break; 225 case "selection": 226 case "conflict": 209 227 Collection<OsmPrimitive> sel = new HashSet<>(); 210 if ( mode.equals("selection")) {228 if ("selection".equals(mode)) { 211 229 sel = getCurrentDataSet().getSelected(); 212 } else if (mode.equals("conflict")){230 } else { 213 231 Conflict<? extends OsmPrimitive> c = Main.map.conflictDialog.getSelectedConflict(); 214 232 if (c != null) { … … 221 239 JOptionPane.showMessageDialog( 222 240 Main.parent, 223 ( mode.equals("selection") ? tr("Nothing selected to zoom to.") : tr("No conflicts to zoom to")),241 ("selection".equals(mode) ? tr("Nothing selected to zoom to.") : tr("No conflicts to zoom to")), 224 242 tr("Information"), 225 243 JOptionPane.INFORMATION_MESSAGE … … 236 254 // ensure reasonable zoom level when zooming onto single nodes. 237 255 v.enlargeToMinDegrees(0.0005); 238 } else if (mode.equals("download")) { 256 break; 257 case "download": 239 258 Bounds bounds = DownloadDialog.getSavedDownloadBounds(); 240 259 if (bounds != null) { … … 245 264 } 246 265 } 266 break; 247 267 } 248 268 return v; … … 251 271 @Override 252 272 protected void updateEnabledState() { 253 if ("selection".equals(mode)) { 273 switch(mode) { 274 case "selection": 254 275 setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty()); 255 } else if ("layer".equals(mode)) { 276 break; 277 case "layer": 256 278 if (!Main.isDisplayingMapView() || Main.map.mapView.getAllLayersAsList().isEmpty()) { 257 279 setEnabled(false); … … 260 282 setEnabled(true); 261 283 } 262 } else if ("conflict".equals(mode)) { 284 break; 285 case "conflict": 263 286 setEnabled(Main.map != null && Main.map.conflictDialog.getSelectedConflict() != null); 264 } else if ("problem".equals(mode)) { 287 break; 288 case "problem": 265 289 setEnabled(Main.map != null && Main.map.validatorDialog.getSelectedError() != null); 266 } else if ("previous".equals(mode)) { 290 break; 291 case "previous": 267 292 setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasZoomUndoEntries()); 268 } else if ("next".equals(mode)) { 293 break; 294 case "next": 269 295 setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasZoomRedoEntries()); 270 } else { 271 setEnabled( 272 Main.isDisplayingMapView() 273 && Main.map.mapView.hasLayers() 296 break; 297 default: 298 setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasLayers() 274 299 ); 275 300 } … … 311 336 312 337 public MapFrameAdapter() { 313 if ( mode.equals("conflict")) {338 if ("conflict".equals(mode)) { 314 339 conflictSelectionListener = new ListSelectionListener() { 315 340 @Override public void valueChanged(ListSelectionEvent e) { … … 317 342 } 318 343 }; 319 } else if ( mode.equals("problem")) {344 } else if ("problem".equals(mode)) { 320 345 validatorSelectionListener = new TreeSelectionListener() { 321 346 @Override public void valueChanged(TreeSelectionEvent e) {
Note:
See TracChangeset
for help on using the changeset viewer.