Changeset 19661 in josm


Ignore:
Timestamp:
2026-10-24T13:37:30+02:00 (87 minutes ago)
Author:
stoecker
Message:

fix #24950 - patch by DanProgs - fix sonar issues (patch modifed)

File:
1 edited

Legend:

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

    r19289 r19661  
    33
    44import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.marktr;
    56import static org.openstreetmap.josm.tools.I18n.tr;
    67
    … …  
    5859 */
    5960public class AddImageryLayerAction extends JosmAction implements AdaptableAction {
     61    private static final String WMS_ERROR = marktr("WMS Error");
    6062    private final transient ImageryInfo info;
    6163
    … …  
    8587
    8688        // change toolbar icon from if specified
    87         String icon = info.getIcon();
     89        final String icon = info.getIcon();
    8890        if (icon != null) {
    8991            new ImageProvider(icon).setOptional(true).getResourceAsync(result -> {
    … …  
    127129                // specify which layer to use
    128130                if (Utils.isEmpty(info.getDefaultLayers())) {
    129                     WMTSTileSource tileSource = new WMTSTileSource(info);
    130                     DefaultLayer layerId = tileSource.userSelectLayer();
     131                    final WMTSTileSource tileSource = new WMTSTileSource(info);
     132                    final DefaultLayer layerId = tileSource.userSelectLayer();
    131133                    if (layerId != null) {
    132                         ImageryInfo copy = new ImageryInfo(info);
     134                        final ImageryInfo copy = new ImageryInfo(info);
    133135                        copy.setDefaultLayers(Collections.singletonList(layerId));
    134                         String layerName = tileSource.getLayers().stream()
     136                        final String layerName = tileSource.getLayers().stream()
    135137                                .filter(x -> x.getIdentifier().equals(layerId.getLayerName()))
    136138                                .map(Layer::getUserTitle)
    … …  
    148150            }
    149151        } catch (MalformedURLException ex) {
    150             handleException(ex, tr("Invalid service URL."), tr("WMS Error"), null);
     152            handleException(ex, tr("Invalid service URL."), tr(WMS_ERROR), null);
    151153        } catch (IOException ex) {
    152             handleException(ex, tr("Could not retrieve WMS layer list."), tr("WMS Error"), null);
     154            handleException(ex, tr("Could not retrieve WMS layer list."), tr(WMS_ERROR), null);
    153155        } catch (WMSGetCapabilitiesException ex) {
    154             handleException(ex, tr("Could not parse WMS layer list."), tr("WMS Error"),
     156            handleException(ex, tr("Could not parse WMS layer list."), tr(WMS_ERROR),
    155157                    "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData());
    156158        } catch (WMTSGetCapabilitiesException ex) {
    … …  
    163165    @Override
    164166    public void actionPerformed(ActionEvent e) {
    165         if (!isEnabled()) return;
     167        if (!isEnabled()) {
     168            return;
     169        }
    166170        ImageryLayer layer = null;
    167171        try {
    … …  
    210214        final WMSLayerTree tree = new WMSLayerTree();
    211215
    212         Collection<String> wmsFormats = wms.getFormats();
     216        final Collection<String> wmsFormats = wms.getFormats();
    213217        final JComboBox<String> formats = new JComboBox<>(wmsFormats.toArray(new String[0]));
    214218        formats.setSelectedItem(wms.getPreferredFormat());
    215219        formats.setToolTipText(tr("Select image format for WMS layer"));
    216220
    217         JCheckBox checkBounds = new JCheckBox(tr("Show only layers for current view"), true);
    218         Runnable updateTree = () -> {
    219             LatLon latLon = checkBounds.isSelected() && MainApplication.isDisplayingMapView()
     221        final JCheckBox checkBounds = new JCheckBox(tr("Show only layers for current view"), true);
     222        final Runnable updateTree = () -> {
     223            final LatLon latLon = checkBounds.isSelected() && MainApplication.isDisplayingMapView()
    220224                    ? MainApplication.getMap().mapView.getProjection().eastNorth2latlon(MainApplication.getMap().mapView.getCenter())
    221225                    : null;
    … …  
    228232
    229233        if (!GraphicsEnvironment.isHeadless()) {
    230             ExtendedDialog dialog = new ExtendedDialog(MainApplication.getMainFrame(),
     234            final ExtendedDialog dialog = new ExtendedDialog(MainApplication.getMainFrame(),
    231235                    tr("Select WMS layers"), tr("Add layers"), tr("Cancel"));
    232236            final JScrollPane scrollPane = new JScrollPane(tree.getLayerTree());
    … …  
    260264            return getWMSLayerInfo(info, AddImageryLayerAction::askToSelectLayers);
    261265        } catch (MalformedURLException ex) {
    262             handleException(ex, tr("Invalid service URL."), tr("WMS Error"), null);
     266            handleException(ex, tr("Invalid service URL."), tr(WMS_ERROR), null);
    263267        } catch (IOException ex) {
    264             handleException(ex, tr("Could not retrieve WMS layer list."), tr("WMS Error"), null);
     268            handleException(ex, tr("Could not retrieve WMS layer list."), tr(WMS_ERROR), null);
    265269        } catch (WMSGetCapabilitiesException ex) {
    266             handleException(ex, tr("Could not parse WMS layer list."), tr("WMS Error"),
     270            handleException(ex, tr("Could not parse WMS layer list."), tr(WMS_ERROR),
    267271                    "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData());
    268272        }
    … …  
    286290        final TemplatedWMSTileSource tileSource = new TemplatedWMSTileSource(info, ProjectionRegistry.getProjection());
    287291        final WMSImagery wms = new WMSImagery(tileSource.getBaseUrl(), info.getCustomHttpHeaders());
    288         LayerSelection selection = choice.apply(wms);
     292        final LayerSelection selection = choice.apply(wms);
    289293        if (selection == null) {
    290294            return null;
    … …  
    298302                );
    299303
    300         String selectedLayers = selection.layers.stream()
     304        final String selectedLayers = selection.layers.stream()
    301305                .map(LayerDetails::getName)
    302306                .collect(Collectors.joining(", "));
    303307        // Use full copy of original Imagery info to copy all attributes. Only overwrite what's different
    304         ImageryInfo ret = new ImageryInfo(info);
     308        final ImageryInfo ret = new ImageryInfo(info);
    305309        ret.setUrl(url);
    306310        ret.setImageryType(ImageryType.WMS);
Note: See TracChangeset for help on using the changeset viewer.