Ignore:
Timestamp:
2014-04-27T15:35:47+02:00 (10 years ago)
Author:
Don-vip
Message:

see #8465 - use String switch/case where applicable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r7005 r7012  
    9696        int shortcut = -1;
    9797
     98        // TODO: convert this to switch/case and make sure the parsing still works
    9899        /* leave as single line for shortcut overview parsing! */
    99100        if (mode.equals("data")) { shortcut = KeyEvent.VK_1; }
     
    130131        putValue("help", "Action/AutoScale/" + modeHelp);
    131132        this.mode = mode;
    132         if (mode.equals("data")) {
     133        switch (mode) {
     134        case "data":
    133135            putValue("help", ht("/Action/ZoomToData"));
    134         } else if (mode.equals("layer")) {
     136            break;
     137        case "layer":
    135138            putValue("help", ht("/Action/ZoomToLayer"));
    136         } else if (mode.equals("selection")) {
     139            break;
     140        case "selection":
    137141            putValue("help", ht("/Action/ZoomToSelection"));
    138         } else if (mode.equals("conflict")) {
     142            break;
     143        case "conflict":
    139144            putValue("help", ht("/Action/ZoomToConflict"));
    140         } else if (mode.equals("problem")) {
     145            break;
     146        case "problem":
    141147            putValue("help", ht("/Action/ZoomToProblem"));
    142         } else if (mode.equals("download")) {
     148            break;
     149        case "download":
    143150            putValue("help", ht("/Action/ZoomToDownload"));
    144         } else if (mode.equals("previous")) {
     151            break;
     152        case "previous":
    145153            putValue("help", ht("/Action/ZoomToPrevious"));
    146         } else if (mode.equals("next")) {
     154            break;
     155        case "next":
    147156            putValue("help", ht("/Action/ZoomToNext"));
    148         } else {
     157            break;
     158        default:
    149159            throw new IllegalArgumentException("Unknown mode: "+mode);
    150160        }
     
    154164    public void autoScale()  {
    155165        if (Main.isDisplayingMapView()) {
    156             if (mode.equals("previous")) {
     166            switch(mode) {
     167            case "previous":
    157168                Main.map.mapView.zoomPrevious();
    158             } else if (mode.equals("next")) {
     169                break;
     170            case "next":
    159171                Main.map.mapView.zoomNext();
    160             } else {
     172                break;
     173            default:
    161174                BoundingXYVisitor bbox = getBoundingBox();
    162175                if (bbox != null && bbox.getBounds() != null) {
     
    187200
    188201    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":
    192206            TestError error = Main.map.validatorDialog.getSelectedError();
    193207            if (error == null) return null;
     
    195209            if (v.getBounds() == null) return null;
    196210            v.enlargeBoundingBox(Main.pref.getDouble("validator.zoom-enlarge-bbox", 0.0002));
    197         } else if (mode.equals("data")) {
     211            break;
     212        case "data":
    198213            for (Layer l : Main.map.mapView.getAllLayers()) {
    199214                l.visitBoundingBox(v);
    200215            }
    201         } else if (mode.equals("layer")) {
     216            break;
     217        case "layer":
    202218            if (Main.main.getActiveLayer() == null)
    203219                return null;
     
    206222            if (l == null) return null;
    207223            l.visitBoundingBox(v);
    208         } else if (mode.equals("selection") || mode.equals("conflict")) {
     224            break;
     225        case "selection":
     226        case "conflict":
    209227            Collection<OsmPrimitive> sel = new HashSet<>();
    210             if (mode.equals("selection")) {
     228            if ("selection".equals(mode)) {
    211229                sel = getCurrentDataSet().getSelected();
    212             } else if (mode.equals("conflict")) {
     230            } else {
    213231                Conflict<? extends OsmPrimitive> c = Main.map.conflictDialog.getSelectedConflict();
    214232                if (c != null) {
     
    221239                JOptionPane.showMessageDialog(
    222240                        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")),
    224242                        tr("Information"),
    225243                        JOptionPane.INFORMATION_MESSAGE
     
    236254            // ensure reasonable zoom level when zooming onto single nodes.
    237255            v.enlargeToMinDegrees(0.0005);
    238         } else if (mode.equals("download")) {
     256            break;
     257        case "download":
    239258            Bounds bounds = DownloadDialog.getSavedDownloadBounds();
    240259            if (bounds != null) {
     
    245264                }
    246265            }
     266            break;
    247267        }
    248268        return v;
     
    251271    @Override
    252272    protected void updateEnabledState() {
    253         if ("selection".equals(mode)) {
     273        switch(mode) {
     274        case "selection":
    254275            setEnabled(getCurrentDataSet() != null && ! getCurrentDataSet().getSelected().isEmpty());
    255         }  else if ("layer".equals(mode)) {
     276            break;
     277        case "layer":
    256278            if (!Main.isDisplayingMapView() || Main.map.mapView.getAllLayersAsList().isEmpty()) {
    257279                setEnabled(false);
     
    260282                setEnabled(true);
    261283            }
    262         } else if ("conflict".equals(mode)) {
     284            break;
     285        case "conflict":
    263286            setEnabled(Main.map != null && Main.map.conflictDialog.getSelectedConflict() != null);
    264         } else if ("problem".equals(mode)) {
     287            break;
     288        case "problem":
    265289            setEnabled(Main.map != null && Main.map.validatorDialog.getSelectedError() != null);
    266         } else if ("previous".equals(mode)) {
     290            break;
     291        case "previous":
    267292            setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasZoomUndoEntries());
    268         } else if ("next".equals(mode)) {
     293            break;
     294        case "next":
    269295            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()
    274299            );
    275300        }
     
    311336
    312337        public MapFrameAdapter() {
    313             if (mode.equals("conflict")) {
     338            if ("conflict".equals(mode)) {
    314339                conflictSelectionListener = new ListSelectionListener() {
    315340                    @Override public void valueChanged(ListSelectionEvent e) {
     
    317342                    }
    318343                };
    319             } else if (mode.equals("problem")) {
     344            } else if ("problem".equals(mode)) {
    320345                validatorSelectionListener = new TreeSelectionListener() {
    321346                    @Override public void valueChanged(TreeSelectionEvent e) {
Note: See TracChangeset for help on using the changeset viewer.