Changeset 14221 in josm for trunk/src/org
- Timestamp:
- 2018-09-03T20:15:11+02:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 10 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 } -
trunk/src/org/openstreetmap/josm/actions/ZoomToAction.java
r14143 r14221 10 10 import javax.swing.event.ListSelectionListener; 11 11 12 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode; 12 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 14 import org.openstreetmap.josm.gui.MainApplication; … … 99 100 if (layer != null && primitive != null) { 100 101 layer.data.setSelected(primitive); 101 AutoScaleAction.autoScale( "selection");102 AutoScaleAction.autoScale(AutoScaleMode.SELECTION); 102 103 } 103 104 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r14138 r14221 30 30 import org.openstreetmap.josm.actions.AlignInLineAction; 31 31 import org.openstreetmap.josm.actions.AutoScaleAction; 32 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode; 32 33 import org.openstreetmap.josm.actions.ChangesetManagerToggleAction; 33 34 import org.openstreetmap.josm.actions.CloseChangesetAction; … … 720 721 add(viewMenu, new ZoomOutAction()); 721 722 viewMenu.addSeparator(); 722 for ( String mode : AutoScaleAction.MODES) {723 for (AutoScaleMode mode : AutoScaleMode.values()) { 723 724 AutoScaleAction autoScaleAction = new AutoScaleAction(mode); 724 autoScaleActions.put(mode , autoScaleAction);725 autoScaleActions.put(mode.getEnglishLabel(), autoScaleAction); 725 726 add(viewMenu, autoScaleAction); 726 727 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r14134 r14221 38 38 39 39 import org.openstreetmap.josm.actions.AutoScaleAction; 40 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode; 40 41 import org.openstreetmap.josm.command.Command; 41 42 import org.openstreetmap.josm.command.PseudoCommand; … … 453 454 public void actionPerformed(ActionEvent e) { 454 455 super.actionPerformed(e); 455 AutoScaleAction.autoScale( "selection");456 AutoScaleAction.autoScale(AutoScaleMode.SELECTION); 456 457 } 457 458 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r13926 r14221 39 39 import org.openstreetmap.josm.actions.AbstractSelectAction; 40 40 import org.openstreetmap.josm.actions.AutoScaleAction; 41 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode; 41 42 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction; 42 43 import org.openstreetmap.josm.actions.relation.EditRelationAction; … … 393 394 @Override 394 395 public void actionPerformed(ActionEvent e) { 395 AutoScaleAction.autoScale( "selection");396 AutoScaleAction.autoScale(AutoScaleMode.SELECTION); 396 397 } 397 398 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java
r14214 r14221 22 22 23 23 import org.openstreetmap.josm.actions.AutoScaleAction; 24 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode; 24 25 import org.openstreetmap.josm.actions.ZoomToAction; 25 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 239 240 getLayer().data.setSelected(WayConnectionType.Direction.FORWARD == connectionType.direction 240 241 ? way.firstNode() : way.lastNode()); 241 AutoScaleAction.autoScale( "selection");242 AutoScaleAction.autoScale(AutoScaleMode.SELECTION); 242 243 } else if (!connectionType.linkNext) { 243 244 getLayer().data.setSelected(WayConnectionType.Direction.FORWARD == connectionType.direction 244 245 ? way.lastNode() : way.firstNode()); 245 AutoScaleAction.autoScale( "selection");246 AutoScaleAction.autoScale(AutoScaleMode.SELECTION); 246 247 } 247 248 } -
trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
r13926 r14221 22 22 23 23 import org.openstreetmap.josm.actions.AutoScaleAction; 24 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode; 24 25 import org.openstreetmap.josm.data.osm.IPrimitive; 25 26 import org.openstreetmap.josm.data.osm.OsmData; … … 253 254 if (ds != null) { 254 255 ds.setSelected(p.getPrimitiveId()); 255 AutoScaleAction.autoScale( "selection");256 AutoScaleAction.autoScale(AutoScaleMode.SELECTION); 256 257 } 257 258 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
r14134 r14221 9 9 10 10 import org.openstreetmap.josm.actions.AutoScaleAction; 11 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode; 11 12 import org.openstreetmap.josm.command.AddCommand; 12 13 import org.openstreetmap.josm.data.UndoRedoHandler; … … 107 108 ds.setSelected(node); 108 109 if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { 109 AutoScaleAction.autoScale( "selection");110 AutoScaleAction.autoScale(AutoScaleMode.SELECTION); 110 111 } else { 111 112 MainApplication.getMap().mapView.repaint(); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
r14143 r14221 14 14 15 15 import org.openstreetmap.josm.actions.AutoScaleAction; 16 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode; 16 17 import org.openstreetmap.josm.command.AddCommand; 17 18 import org.openstreetmap.josm.command.Command; … … 174 175 ds.setSelected(way); 175 176 if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { 176 AutoScaleAction.autoScale( "selection");177 AutoScaleAction.autoScale(AutoScaleMode.SELECTION); 177 178 } else { 178 179 MainApplication.getMap().mapView.repaint(); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java
r13973 r14221 17 17 18 18 import org.openstreetmap.josm.actions.AutoScaleAction; 19 import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode; 19 20 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 20 21 import org.openstreetmap.josm.actions.downloadtasks.DownloadParams; … … 264 265 // zoom_mode=(download|selection), defaults to selection 265 266 if (!"download".equals(args.get("zoom_mode")) && !primitives.isEmpty()) { 266 AutoScaleAction.autoScale( "selection");267 AutoScaleAction.autoScale(AutoScaleMode.SELECTION); 267 268 } else if (MainApplication.isDisplayingMapView()) { 268 269 // make sure this isn't called unless there *is* a MapView
Note:
See TracChangeset
for help on using the changeset viewer.