Changeset 14221 in josm for trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
- Timestamp:
- 2018-09-03T20:15:11+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r14153 r14221 15 15 import java.util.HashSet; 16 16 import java.util.List; 17 import java.util.Objects; 17 18 import java.util.concurrent.TimeUnit; 18 19 … … 45 46 * Toggles the autoScale feature of the mapView 46 47 * @author imi 48 * @since 17 47 49 */ 48 50 public class AutoScaleAction extends JosmAction { … … 50 52 /** 51 53 * A list of things we can zoom to. The zoom target is given depending on the mode. 52 */ 54 * @since 14221 55 */ 56 public enum AutoScaleMode { 57 /** Zoom the window so that all the data fills the window area */ 58 DATA(marktr(/* ICON(dialogs/autoscale/) */ "data")), 59 /** Zoom the window so that all the data on the currently selected layer fills the window area */ 60 LAYER(marktr(/* ICON(dialogs/autoscale/) */ "layer")), 61 /** Zoom the window so that only data which is currently selected fills the window area */ 62 SELECTION(marktr(/* ICON(dialogs/autoscale/) */ "selection")), 63 /** Zoom to the first selected conflict */ 64 CONFLICT(marktr(/* ICON(dialogs/autoscale/) */ "conflict")), 65 /** Zoom the view to last downloaded data */ 66 DOWNLOAD(marktr(/* ICON(dialogs/autoscale/) */ "download")), 67 /** Zoom the view to problem */ 68 PROBLEM(marktr(/* ICON(dialogs/autoscale/) */ "problem")), 69 /** Zoom to the previous zoomed to scale and location (zoom undo) */ 70 PREVIOUS(marktr(/* ICON(dialogs/autoscale/) */ "previous")), 71 /** Zoom to the next zoomed to scale and location (zoom redo) */ 72 NEXT(marktr(/* ICON(dialogs/autoscale/) */ "next")); 73 74 private final String label; 75 76 AutoScaleMode(String label) { 77 this.label = label; 78 } 79 80 /** 81 * Returns the English label. Used for retrieving icons. 82 * @return the English label 83 */ 84 public String getEnglishLabel() { 85 return label; 86 } 87 88 /** 89 * Returns the localized label. Used for display 90 * @return the localized label 91 */ 92 public String getLocalizedLabel() { 93 return tr(label); 94 } 95 96 /** 97 * Returns {@code AutoScaleMode} for a given English label 98 * @param englishLabel English label 99 * @return {@code AutoScaleMode} for given English label 100 * @throws IllegalArgumentException if Engligh label is unknown 101 */ 102 public static AutoScaleMode of(String englishLabel) { 103 for (AutoScaleMode v : values()) { 104 if (Objects.equals(v.label, englishLabel)) { 105 return v; 106 } 107 } 108 throw new IllegalArgumentException(englishLabel); 109 } 110 } 111 112 /** 113 * A list of things we can zoom to. The zoom target is given depending on the mode. 114 * @deprecated Use {@link AutoScaleMode} enum instead 115 */ 116 @Deprecated 53 117 public static final Collection<String> MODES = Collections.unmodifiableList(Arrays.asList( 54 118 marktr(/* ICON(dialogs/autoscale/) */ "data"), … … 62 126 63 127 /** 64 * One of {@link #MODES}. Defines what we are zooming to.65 */ 66 private final Stringmode;128 * One of {@link AutoScaleMode}. Defines what we are zooming to. 129 */ 130 private final AutoScaleMode mode; 67 131 68 132 /** Time of last zoom to bounds action */ … … 112 176 * Performs the auto scale operation of the given mode without the need to create a new action. 113 177 * @param mode One of {@link #MODES}. 114 */ 178 * @since 14221 179 */ 180 public static void autoScale(AutoScaleMode mode) { 181 new AutoScaleAction(mode, false).autoScale(); 182 } 183 184 /** 185 * Performs the auto scale operation of the given mode without the need to create a new action. 186 * @param mode One of {@link #MODES}. 187 * @deprecated Use {@link #autoScale(AutoScaleMode)} instead 188 */ 189 @Deprecated 115 190 public static void autoScale(String mode) { 116 new AutoScaleAction(mode, false).autoScale();191 autoScale(AutoScaleMode.of(mode)); 117 192 } 118 193 … … 140 215 /** 141 216 * Constructs a new {@code AutoScaleAction}. 142 * @param mode The autoscale mode (one of {@link AutoScale Action#MODES})217 * @param mode The autoscale mode (one of {@link AutoScaleMode}) 143 218 * @param marker Must be set to false. Used only to differentiate from default constructor 144 219 */ 145 private AutoScaleAction( Stringmode, boolean marker) {220 private AutoScaleAction(AutoScaleMode mode, boolean marker) { 146 221 super(marker); 147 222 this.mode = mode; … … 151 226 * Constructs a new {@code AutoScaleAction}. 152 227 * @param mode The autoscale mode (one of {@link AutoScaleAction#MODES}) 153 */ 228 * @deprecated Use {@link #AutoScaleAction(AutoScaleMode)} instead 229 */ 230 @Deprecated 154 231 public AutoScaleAction(final String mode) { 155 super(tr("Zoom to {0}", tr(mode)), "dialogs/autoscale/" + mode, tr("Zoom the view to {0}.", tr(mode)), 156 Shortcut.registerShortcut("view:zoom" + mode, tr("View: {0}", tr("Zoom to {0}", tr(mode))), 157 getModeShortcut(mode), Shortcut.DIRECT), true, null, false); 158 String modeHelp = Character.toUpperCase(mode.charAt(0)) + mode.substring(1); 232 this(AutoScaleMode.of(mode)); 233 } 234 235 /** 236 * Constructs a new {@code AutoScaleAction}. 237 * @param mode The autoscale mode (one of {@link AutoScaleAction#MODES}) 238 * @since 14221 239 */ 240 public AutoScaleAction(final AutoScaleMode mode) { 241 super(tr("Zoom to {0}", mode.getLocalizedLabel()), "dialogs/autoscale/" + mode.getEnglishLabel(), 242 tr("Zoom the view to {0}.", mode.getLocalizedLabel()), 243 Shortcut.registerShortcut("view:zoom" + mode.getEnglishLabel(), 244 tr("View: {0}", tr("Zoom to {0}", mode.getLocalizedLabel())), 245 getModeShortcut(mode.getEnglishLabel()), Shortcut.DIRECT), true, null, false); 246 String label = mode.getEnglishLabel(); 247 String modeHelp = Character.toUpperCase(label.charAt(0)) + label.substring(1); 159 248 putValue("help", "Action/AutoScale/" + modeHelp); 160 249 this.mode = mode; 161 250 switch (mode) { 162 case "data":251 case DATA: 163 252 putValue("help", ht("/Action/ZoomToData")); 164 253 break; 165 case "layer":254 case LAYER: 166 255 putValue("help", ht("/Action/ZoomToLayer")); 167 256 break; 168 case "selection":257 case SELECTION: 169 258 putValue("help", ht("/Action/ZoomToSelection")); 170 259 break; 171 case "conflict":260 case CONFLICT: 172 261 putValue("help", ht("/Action/ZoomToConflict")); 173 262 break; 174 case "problem":263 case PROBLEM: 175 264 putValue("help", ht("/Action/ZoomToProblem")); 176 265 break; 177 case "download":266 case DOWNLOAD: 178 267 putValue("help", ht("/Action/ZoomToDownload")); 179 268 break; 180 case "previous":269 case PREVIOUS: 181 270 putValue("help", ht("/Action/ZoomToPrevious")); 182 271 break; 183 case "next":272 case NEXT: 184 273 putValue("help", ht("/Action/ZoomToNext")); 185 274 break; … … 197 286 MapView mapView = MainApplication.getMap().mapView; 198 287 switch (mode) { 199 case "previous":288 case PREVIOUS: 200 289 mapView.zoomPrevious(); 201 290 break; 202 case "next":291 case NEXT: 203 292 mapView.zoomNext(); 204 293 break; … … 241 330 private BoundingXYVisitor getBoundingBox() { 242 331 switch (mode) { 243 case "problem":332 case PROBLEM: 244 333 return modeProblem(new ValidatorBoundingXYVisitor()); 245 case "data":334 case DATA: 246 335 return modeData(new BoundingXYVisitor()); 247 case "layer":336 case LAYER: 248 337 return modeLayer(new BoundingXYVisitor()); 249 case "selection":250 case "conflict":338 case SELECTION: 339 case CONFLICT: 251 340 return modeSelectionOrConflict(new BoundingXYVisitor()); 252 case "download":341 case DOWNLOAD: 253 342 return modeDownload(new BoundingXYVisitor()); 254 343 default: … … 286 375 private BoundingXYVisitor modeSelectionOrConflict(BoundingXYVisitor v) { 287 376 Collection<IPrimitive> sel = new HashSet<>(); 288 if ( "selection".equals(mode)) {377 if (AutoScaleMode.SELECTION == mode) { 289 378 OsmData<?, ?, ?, ?> dataSet = getLayerManager().getActiveData(); 290 379 if (dataSet != null) { … … 303 392 JOptionPane.showMessageDialog( 304 393 MainApplication.getMainFrame(), 305 "selection".equals(mode)? tr("Nothing selected to zoom to.") : tr("No conflicts to zoom to"),394 AutoScaleMode.SELECTION == mode ? tr("Nothing selected to zoom to.") : tr("No conflicts to zoom to"), 306 395 tr("Information"), 307 396 JOptionPane.INFORMATION_MESSAGE); … … 357 446 MapFrame map = MainApplication.getMap(); 358 447 switch (mode) { 359 case "selection":448 case SELECTION: 360 449 setEnabled(ds != null && !ds.selectionEmpty()); 361 450 break; 362 case "layer":451 case LAYER: 363 452 setEnabled(getFirstSelectedLayer() != null); 364 453 break; 365 case "conflict":454 case CONFLICT: 366 455 setEnabled(map != null && map.conflictDialog.getSelectedConflict() != null); 367 456 break; 368 case "download":457 case DOWNLOAD: 369 458 setEnabled(ds != null && !ds.getDataSources().isEmpty()); 370 459 break; 371 case "problem":460 case PROBLEM: 372 461 setEnabled(map != null && map.validatorDialog.getSelectedError() != null); 373 462 break; 374 case "previous":463 case PREVIOUS: 375 464 setEnabled(MainApplication.isDisplayingMapView() && map.mapView.hasZoomUndoEntries()); 376 465 break; 377 case "next":466 case NEXT: 378 467 setEnabled(MainApplication.isDisplayingMapView() && map.mapView.hasZoomRedoEntries()); 379 468 break; … … 385 474 @Override 386 475 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 387 if ( "selection".equals(mode)) {476 if (AutoScaleMode.SELECTION == mode) { 388 477 setEnabled(selection != null && !selection.isEmpty()); 389 478 } … … 418 507 419 508 MapFrameAdapter() { 420 if ( "conflict".equals(mode)) {509 if (AutoScaleMode.CONFLICT == mode) { 421 510 conflictSelectionListener = e -> updateEnabledState(); 422 } else if ( "problem".equals(mode)) {511 } else if (AutoScaleMode.PROBLEM == mode) { 423 512 validatorSelectionListener = e -> updateEnabledState(); 424 513 }
Note:
See TracChangeset
for help on using the changeset viewer.