Ticket #12034: warning_messages.patch

File warning_messages.patch, 13.6 KB (added by wiktorn, 10 years ago)

preliminary patch

  • data/maps.xsd

    diff --git data/maps.xsd data/maps.xsd
    index 43ca799..f420af8 100644
     
    688688                                                                        <xs:attribute name="metadata-key" type="xs:string" />
    689689                                                                </xs:complexType>
    690690                                                        </xs:element>
     691                                                        <!--  is imagery properly georeferenced (i.e. no need to check offsets). Defaults to false. Affects showing warnings. -->
     692                                                        <xs:element name="valid-georeference" minOccurs="0" maxOccurs="1" type="xs:boolean" />
     693                                                        <!-- does imagery server supports JOSM 4326 to 3857 reprojection and non-square queries. Affects showing warnings. -->
     694                                                        <xs:element name="epsg4326to3857Supported" minOccurs="0" maxOccurs="1" type="xs:boolean" />
    691695                                                </xs:choice>
    692696                                        </xs:sequence>
    693697                                        <xs:attribute name="last-check" type="xs:date" use="optional" />
  • src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    diff --git src/org/openstreetmap/josm/actions/AddImageryLayerAction.java src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
    index 192d9f8..e6ed3b4 100644
    public class AddImageryLayerAction extends JosmAction implements AdaptableAction  
    8282                    ? getWMSLayerInfo() : info;
    8383            if (infoToAdd != null) {
    8484                Main.main.addLayer(ImageryLayer.create(infoToAdd));
    85                 AlignImageryPanel.addNagPanelIfNeeded();
     85                AlignImageryPanel.addNagPanelIfNeeded(infoToAdd);
    8686            }
    8787        } catch (IllegalArgumentException ex) {
    8888            if (ex.getMessage() == null || ex.getMessage().isEmpty()) {
  • src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    diff --git src/org/openstreetmap/josm/data/imagery/ImageryInfo.java src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
    index ff0ed6b..e51325b 100644
    public class ImageryInfo extends TileSourceInfo implements Comparable<ImageryInf  
    199199    private String countryCode = "";
    200200    /** icon used in menu */
    201201    private String icon;
    202     // when adding a field, also adapt the ImageryInfo(ImageryInfo) constructor, equals method, and ImageryPreferenceEntry
     202    private boolean isGeoreferenceValid = false;
     203    private boolean isEpsg4326To3857Supported = false;
     204    // when adding a field, also adapt the ImageryInfo(ImageryInfo) and ImageryInfo(ImageryPreferenceEntry) constructor, equals method, and ImageryPreferenceEntry
    203205
    204206    /**
    205207     * Auxiliary class to save an {@link ImageryInfo} object in the preferences.
    public class ImageryInfo extends TileSourceInfo implements Comparable<ImageryInf  
    229231        @pref Map<String, String> noTileHeaders;
    230232        @pref int tileSize = OsmMercator.DEFAUL_TILE_SIZE;
    231233        @pref Map<String, String> metadataHeaders;
     234        @pref boolean valid_georeference;
     235        @pref boolean supports_epsg_4326_to_3857_conversion;
    232236
    233237        /**
    234238         * Constructs a new empty WMS {@code ImageryPreferenceEntry}.
    public class ImageryInfo extends TileSourceInfo implements Comparable<ImageryInf  
    291295            }
    292296
    293297            tileSize = i.getTileSize();
     298
     299            valid_georeference = i.isGeoreferenceValid();
     300            supports_epsg_4326_to_3857_conversion = i.isEpsg4326To3857Supported();
     301
    294302        }
    295303
    296304        @Override
    public class ImageryInfo extends TileSourceInfo implements Comparable<ImageryInf  
    412420        }
    413421        setTileSize(e.tileSize);
    414422        metadataHeaders = e.metadataHeaders;
     423        isEpsg4326To3857Supported = e.supports_epsg_4326_to_3857_conversion;
     424        isGeoreferenceValid = e.valid_georeference;
    415425    }
    416426
    417427    /**
    public class ImageryInfo extends TileSourceInfo implements Comparable<ImageryInf  
    440450        this.description = i.description;
    441451        this.noTileHeaders = i.noTileHeaders;
    442452        this.metadataHeaders = i.metadataHeaders;
     453        this.isEpsg4326To3857Supported = i.isEpsg4326To3857Supported;
     454        this.isGeoreferenceValid = i.isGeoreferenceValid;
    443455    }
    444456
    445457    @Override
    public class ImageryInfo extends TileSourceInfo implements Comparable<ImageryInf  
    9921004    public void setMetadataHeaders(Map<String, String> metadataHeaders) {
    9931005        this.metadataHeaders = metadataHeaders;
    9941006    }
     1007
     1008    public boolean isEpsg4326To3857Supported() {
     1009        return isEpsg4326To3857Supported;
     1010    }
     1011
     1012    public void setEpsg4326To3857Supported(boolean isEpsg4326To3857Supported) {
     1013        this.isEpsg4326To3857Supported = isEpsg4326To3857Supported;
     1014    }
     1015
     1016    public boolean isGeoreferenceValid() {
     1017        return isGeoreferenceValid;
     1018    }
     1019
     1020    public void setGeoreferenceValid(boolean isGeoreferenceValid) {
     1021        this.isGeoreferenceValid = isGeoreferenceValid;
     1022    }
     1023
    9951024}
  • src/org/openstreetmap/josm/gui/layer/AlignImageryPanel.java

    diff --git src/org/openstreetmap/josm/gui/layer/AlignImageryPanel.java src/org/openstreetmap/josm/gui/layer/AlignImageryPanel.java
    index 2fb1c44..5da7153 100644
    import java.awt.event.ActionEvent;  
    1111import java.awt.event.ActionListener;
    1212
    1313import javax.swing.JButton;
     14import javax.swing.JCheckBox;
    1415import javax.swing.JLabel;
    1516import javax.swing.JPanel;
    1617import javax.swing.border.CompoundBorder;
    import javax.swing.border.EmptyBorder;  
    1819import javax.swing.border.EtchedBorder;
    1920
    2021import org.openstreetmap.josm.Main;
     22import org.openstreetmap.josm.data.imagery.ImageryInfo;
     23import org.openstreetmap.josm.data.preferences.BooleanProperty;
    2124import org.openstreetmap.josm.gui.widgets.UrlLabel;
    2225import org.openstreetmap.josm.tools.GBC;
    2326import org.openstreetmap.josm.tools.ImageProvider;
    import org.openstreetmap.josm.tools.ImageProvider;  
    2831 * @author zverik
    2932 */
    3033public class AlignImageryPanel extends JPanel {
    31     private static final String PREF = "imagery.offsetnagging";
    3234
    33     public AlignImageryPanel(boolean oneLine) {
     35    /**
     36     * @param oneLine if true, show the nagging message in one line, otherwise - in two lines
     37     * @param showAgain show again property
     38     * @param infoToAdd imagery info for which the nagging message is shown
     39     */
     40    public AlignImageryPanel(boolean oneLine, final BooleanProperty showAgain, ImageryInfo infoToAdd) {
    3441        Font font = getFont().deriveFont(Font.PLAIN, 14.0f);
    35         JLabel nagLabel = new JLabel(tr("Aerial imagery might be misaligned. Please check its offset using GPS tracks!"));
     42        JLabel nagLabel = new JLabel(tr("Aerial imagery \"{0}\" might be misaligned. Please check its offset using GPS tracks!", infoToAdd.getName()));
    3643        UrlLabel detailsList = new UrlLabel(tr("http://wiki.openstreetmap.org/wiki/Using_Imagery"), tr("Details..."));
    3744        nagLabel.setLabelFor(detailsList);
    3845        nagLabel.setFont(font);
    3946        detailsList.setFont(font);
     47        final JCheckBox doNotShowAgain = new JCheckBox(tr("Do not show this message again"));
     48        doNotShowAgain.setOpaque(false);
    4049
    4150        JButton closeButton = new JButton(ImageProvider.get("misc", "black_x"));
    4251        closeButton.setContentAreaFilled(false);
    public class AlignImageryPanel extends JPanel {  
    4857            public void actionPerformed(ActionEvent e) {
    4958                if (Main.isDisplayingMapView()) {
    5059                    Main.map.removeTopPanel(AlignImageryPanel.class);
    51                     Main.pref.put(PREF, false);
     60                    if (doNotShowAgain.isSelected()) {
     61                        showAgain.put(false);
     62                    }
    5263                }
    5364            }
    5465        });
    public class AlignImageryPanel extends JPanel {  
    5768        if (!oneLine) { // tune for small screens
    5869            add(nagLabel, GBC.std(1, 1).fill());
    5970            add(detailsList, GBC.std(1, 2).fill());
     71            add(doNotShowAgain, GBC.std(1, 3).fill());
    6072            add(closeButton, GBC.std(2, 1).span(1, 2).anchor(GBC.EAST));
    6173        } else {
    6274            add(nagLabel, GBC.std(1, 1).fill());
    6375            add(detailsList, GBC.std(2, 1).fill());
     76            add(doNotShowAgain, GBC.std(1, 2).fill());
    6477            add(closeButton, GBC.std(3, 1).anchor(GBC.EAST));
    6578        }
    6679        setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.LOWERED), new EmptyBorder(12, 12, 12, 12)));
    6780        setBackground(new Color(224, 236, 249));
    6881    }
    6982
    70     public static void addNagPanelIfNeeded() {
    71         if (Main.isDisplayingMapView() && !Main.pref.getBoolean("expert") && Main.pref.getBoolean(PREF, true)) {
     83    /**
     84     * @param infoToAdd ImageryInfo for which the nag panel should be created
     85     */
     86    public static void addNagPanelIfNeeded(ImageryInfo infoToAdd) {
     87        BooleanProperty showAgain = new BooleanProperty("message.imagery.nagPanel." + infoToAdd.getUrl(), true);
     88        if (Main.isDisplayingMapView() && showAgain.get() && !infoToAdd.isGeoreferenceValid() ) {
    7289            if (Main.map.getTopPanel(AlignImageryPanel.class) == null) {
    7390                double w = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
    74                 AlignImageryPanel p = new AlignImageryPanel(w > 1300);
     91                AlignImageryPanel p = new AlignImageryPanel(w > 1300, showAgain, infoToAdd);
    7592                Main.map.addTopPanel(p);
    7693            }
    7794        }
  • src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    diff --git src/org/openstreetmap/josm/gui/layer/WMSLayer.java src/org/openstreetmap/josm/gui/layer/WMSLayer.java
    index 96268ed..17d1e2d 100644
    import org.openstreetmap.josm.data.imagery.WMSCachedTileLoader;  
    2828import org.openstreetmap.josm.data.preferences.BooleanProperty;
    2929import org.openstreetmap.josm.data.preferences.IntegerProperty;
    3030import org.openstreetmap.josm.data.projection.Projection;
     31import org.openstreetmap.josm.gui.ExtendedDialog;
    3132
    3233/**
    3334 * This is a layer that grabs the current screen from an WMS server. The data
    public class WMSLayer extends AbstractCachedTileSourceLayer {  
    112113
    113114    @Override
    114115    public boolean isProjectionSupported(Projection proj) {
    115         return supportedProjections == null || supportedProjections.isEmpty() || supportedProjections.contains(proj.toCode());
     116        return supportedProjections == null || supportedProjections.isEmpty() || supportedProjections.contains(proj.toCode()) ||
     117                (info.isEpsg4326To3857Supported() && supportedProjections.contains("EPSG:4326") &&  "EPSG:3857".equals(Main.getProjection().toCode()));
    116118    }
    117119
    118120    @Override
    public class WMSLayer extends AbstractCachedTileSourceLayer {  
    123125        }
    124126        String appendix = "";
    125127
    126         if (supportedProjections.contains("EPSG:4326") &&  "EPSG:3857".equals(Main.getProjection().toCode())) {
     128        if (isReprojectionPossible()) {
    127129            appendix = ". " + tr("JOSM will use EPSG:4326 to query the server, but results may vary "
    128130                    + "depending on the WMS server");
    129131        }
    public class WMSLayer extends AbstractCachedTileSourceLayer {  
    132134
    133135    @Override
    134136    public void projectionChanged(Projection oldValue, Projection newValue) {
    135         super.projectionChanged(oldValue, newValue);
     137        // do not call super - we need custom warning dialog
     138
     139        if (!isProjectionSupported(newValue)) {
     140            String message = tr("The layer {0} does not support the new projection {1}.\n"
     141                    + " Supported projections are: {2}\n"
     142                    + "Change the projection again or remove the layer.",
     143                    getName(), newValue.toCode(), nameSupportedProjections());
     144
     145            ExtendedDialog warningDialog = new ExtendedDialog(Main.parent, tr("Warning"), new String[]{tr("OK")}).setContent(message);
     146
     147            if (isReprojectionPossible()) {
     148                warningDialog.toggleEnable("imagery.wms.projectionSupportWarnings." + tileSource.getBaseUrl());
     149            }
     150            warningDialog.showDialog();
     151        }
    136152
    137153        if (!newValue.equals(oldValue) && tileSource instanceof TemplatedWMSTileSource) {
    138154            ((TemplatedWMSTileSource) tileSource).initProjection(newValue);
    public class WMSLayer extends AbstractCachedTileSourceLayer {  
    155171    public static CacheAccess<String, BufferedImageCacheEntry> getCache() {
    156172        return AbstractCachedTileSourceLayer.getCache(CACHE_REGION_NAME);
    157173    }
     174
     175    private boolean isReprojectionPossible() {
     176        return supportedProjections.contains("EPSG:4326") &&  "EPSG:3857".equals(Main.getProjection().toCode());
     177    }
    158178}
  • src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    diff --git src/org/openstreetmap/josm/io/imagery/ImageryReader.java src/org/openstreetmap/josm/io/imagery/ImageryReader.java
    index d88380e..5bee3ae 100644
    public class ImageryReader {  
    142142                        "country-code",
    143143                        "icon",
    144144                        "tile-size",
     145                        "validGeoreference",
     146                        "epsg4326to3857Supported",
    145147                }).contains(qName)) {
    146148                    newState = State.ENTRY_ATTRIBUTE;
    147149                    lang = atts.getValue("lang");
    public class ImageryReader {  
    323325                        entry.setTileSize(tileSize.intValue());
    324326                    }
    325327                    break;
     328                case "valid-georeference":
     329                    entry.setGeoreferenceValid(new Boolean(accumulator.toString()));
     330                    break;
     331                case "epsg4326to3857Supported":
     332                    entry.setEpsg4326To3857Supported(new Boolean(accumulator.toString()));
     333                    break;
    326334                }
    327335                break;
    328336            case BOUNDS: