Ticket #24950: 24950.patch

File 24950.patch, 6.9 KB (added by DanProgs <Abenteurer.2901@…>, 31 hours ago)
  • src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    ### Eclipse Workspace Patch 1.0
    #P josm
    diff --git src/org/openstreetmap/josm/actions/AddImageryLayerAction.java src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
    index d6fe8be..18021dc 100644
     
    5757 * @since 3715
    5858 */
    5959public class AddImageryLayerAction extends JosmAction implements AdaptableAction {
     60    private static final String WMS_ERROR = "WMS Error";
    6061    private final transient ImageryInfo info;
    6162
    6263    static class SelectWmsLayersDialog extends ExtendedDialog {
    … …  
    8485        installAdapters();
    8586
    8687        // change toolbar icon from if specified
    87         String icon = info.getIcon();
     88        final String icon = info.getIcon();
    8889        if (icon != null) {
    8990            new ImageProvider(icon).setOptional(true).getResourceAsync(result -> {
    9091                if (result != null) {
    … …  
    126127            case WMTS:
    127128                // specify which layer to use
    128129                if (Utils.isEmpty(info.getDefaultLayers())) {
    129                     WMTSTileSource tileSource = new WMTSTileSource(info);
    130                     DefaultLayer layerId = tileSource.userSelectLayer();
     130                    final WMTSTileSource tileSource = new WMTSTileSource(info);
     131                    final DefaultLayer layerId = tileSource.userSelectLayer();
    131132                    if (layerId != null) {
    132                         ImageryInfo copy = new ImageryInfo(info);
     133                        final ImageryInfo copy = new ImageryInfo(info);
    133134                        copy.setDefaultLayers(Collections.singletonList(layerId));
    134                         String layerName = tileSource.getLayers().stream()
     135                        final String layerName = tileSource.getLayers().stream()
    135136                                .filter(x -> x.getIdentifier().equals(layerId.getLayerName()))
    136137                                .map(Layer::getUserTitle)
    137138                                .findFirst()
    … …  
    147148                return info;
    148149            }
    149150        } catch (MalformedURLException ex) {
    150             handleException(ex, tr("Invalid service URL."), tr("WMS Error"), null);
     151            handleException(ex, tr("Invalid service URL."), tr(WMS_ERROR), null);
    151152        } catch (IOException ex) {
    152             handleException(ex, tr("Could not retrieve WMS layer list."), tr("WMS Error"), null);
     153            handleException(ex, tr("Could not retrieve WMS layer list."), tr(WMS_ERROR), null);
    153154        } catch (WMSGetCapabilitiesException ex) {
    154             handleException(ex, tr("Could not parse WMS layer list."), tr("WMS Error"),
     155            handleException(ex, tr("Could not parse WMS layer list."), tr(WMS_ERROR),
    155156                    "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData());
    156157        } catch (WMTSGetCapabilitiesException ex) {
    157158            handleException(ex, tr("Could not parse WMTS layer list."), tr("WMTS Error"),
    … …  
    162163
    163164    @Override
    164165    public void actionPerformed(ActionEvent e) {
    165         if (!isEnabled()) return;
     166        if (!isEnabled()) {
     167            return;
     168        }
    166169        ImageryLayer layer = null;
    167170        try {
    168171            final ImageryInfo infoToAdd = convertImagery(info);
    … …  
    209212    private static LayerSelection askToSelectLayers(WMSImagery wms) {
    210213        final WMSLayerTree tree = new WMSLayerTree();
    211214
    212         Collection<String> wmsFormats = wms.getFormats();
     215        final Collection<String> wmsFormats = wms.getFormats();
    213216        final JComboBox<String> formats = new JComboBox<>(wmsFormats.toArray(new String[0]));
    214217        formats.setSelectedItem(wms.getPreferredFormat());
    215218        formats.setToolTipText(tr("Select image format for WMS layer"));
    216219
    217         JCheckBox checkBounds = new JCheckBox(tr("Show only layers for current view"), true);
    218         Runnable updateTree = () -> {
    219             LatLon latLon = checkBounds.isSelected() && MainApplication.isDisplayingMapView()
     220        final JCheckBox checkBounds = new JCheckBox(tr("Show only layers for current view"), true);
     221        final Runnable updateTree = () -> {
     222            final LatLon latLon = checkBounds.isSelected() && MainApplication.isDisplayingMapView()
    220223                    ? MainApplication.getMap().mapView.getProjection().eastNorth2latlon(MainApplication.getMap().mapView.getCenter())
    221224                    : null;
    222225            tree.setCheckBounds(latLon);
    … …  
    227230        updateTree.run();
    228231
    229232        if (!GraphicsEnvironment.isHeadless()) {
    230             ExtendedDialog dialog = new ExtendedDialog(MainApplication.getMainFrame(),
     233            final ExtendedDialog dialog = new ExtendedDialog(MainApplication.getMainFrame(),
    231234                    tr("Select WMS layers"), tr("Add layers"), tr("Cancel"));
    232235            final JScrollPane scrollPane = new JScrollPane(tree.getLayerTree());
    233236            scrollPane.setPreferredSize(new Dimension(400, 400));
    … …  
    259262        try {
    260263            return getWMSLayerInfo(info, AddImageryLayerAction::askToSelectLayers);
    261264        } catch (MalformedURLException ex) {
    262             handleException(ex, tr("Invalid service URL."), tr("WMS Error"), null);
     265            handleException(ex, tr("Invalid service URL."), tr(WMS_ERROR), null);
    263266        } catch (IOException ex) {
    264             handleException(ex, tr("Could not retrieve WMS layer list."), tr("WMS Error"), null);
     267            handleException(ex, tr("Could not retrieve WMS layer list."), tr(WMS_ERROR), null);
    265268        } catch (WMSGetCapabilitiesException ex) {
    266             handleException(ex, tr("Could not parse WMS layer list."), tr("WMS Error"),
     269            handleException(ex, tr("Could not parse WMS layer list."), tr(WMS_ERROR),
    267270                    "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData());
    268271        }
    269272        return null;
    … …  
    285288        // We need to get the URL with {apikey} replaced. See #22642.
    286289        final TemplatedWMSTileSource tileSource = new TemplatedWMSTileSource(info, ProjectionRegistry.getProjection());
    287290        final WMSImagery wms = new WMSImagery(tileSource.getBaseUrl(), info.getCustomHttpHeaders());
    288         LayerSelection selection = choice.apply(wms);
     291        final LayerSelection selection = choice.apply(wms);
    289292        if (selection == null) {
    290293            return null;
    291294        }
    … …  
    297300                selection.transparent
    298301                );
    299302
    300         String selectedLayers = selection.layers.stream()
     303        final String selectedLayers = selection.layers.stream()
    301304                .map(LayerDetails::getName)
    302305                .collect(Collectors.joining(", "));
    303306        // Use full copy of original Imagery info to copy all attributes. Only overwrite what's different
    304         ImageryInfo ret = new ImageryInfo(info);
     307        final ImageryInfo ret = new ImageryInfo(info);
    305308        ret.setUrl(url);
    306309        ret.setImageryType(ImageryType.WMS);
    307310        ret.setName(info.getName() + " - " + selectedLayers);