Ignore:
Timestamp:
2009-08-31T14:40:43+02:00 (15 years ago)
Author:
guggis
Message:

applied #2907: patch by xeen: Add duplicate detection to WMS Plugin Preferences
fixed #3298: WMS -Warn if URL is not correct

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r17397 r17407  
    6565        private ExecutorService executor = null;
    6666
     67        /** set to true if this layer uses an invalid base url */
     68        private boolean usesInvalidUrl = false;
     69        /** set to true if the user confirmed to use an potentially invalid WMS base url */
     70        private boolean isInvalidUrlConfirmed = false;
     71       
    6772        public WMSLayer() {
    6873                this(tr("Blank Layer"), null, null);
     
    8489
    8590                executor = Executors.newFixedThreadPool(3);
     91                if (!baseURL.startsWith("html:") && !WMSGrabber.isUrlWithPatterns(baseURL)) {
     92                        if (!(baseURL.endsWith("&") || baseURL.endsWith("?"))) {
     93                                if (!confirmMalformedUrl(baseURL)) {
     94                                        System.out.println(tr("Warning: WMS layer deactivated because of malformed base url ''{0}''", baseURL));
     95                                        usesInvalidUrl = true;
     96                                        setName(getName() + tr("(deactivated)"));
     97                                        return;
     98                                } else {
     99                                        isInvalidUrlConfirmed = true;
     100                                }
     101                        }
     102                }
    86103        }
    87104
    88105        @Override
    89         public void destroy() {
     106        public void destroy() { 
    90107                try {
    91                         executor.shutdown();
     108                        executor.shutdownNow();
    92109                        // Might not be initalized, so catch NullPointer as well
    93                 } catch(Exception x) {}
     110                } catch(Exception x) {
     111                        x.printStackTrace();
     112                }
    94113        }
    95114
     
    138157        @Override public void paint(Graphics g, final MapView mv) {
    139158                if(baseURL == null) return;
     159                if (usesInvalidUrl && !isInvalidUrlConfirmed) return;
    140160
    141161                if( !startstop.isSelected() || (pixelPerDegree / getPPD() > minZoom) ){ //don't download when it's too outzoomed
     
    155175        }
    156176
     177        protected boolean confirmMalformedUrl(String url) {
     178                if (isInvalidUrlConfirmed)
     179                        return true;
     180                String msg  = tr("<html>The base URL<br>"
     181                                        + "''{0}''<br>"
     182                                        + "for this WML layer does neither end with a ''&'' nor with a ''?''.<br>"
     183                                        + "This is likely to lead to invalid WMS request. You should check your<br>"
     184                                        + "preference settings.<br>"
     185                                        + "Do you want to fetch WMS tiles anyway?",                                     
     186                                        url);
     187                String [] options = new String[] {
     188                        tr("Yes, fetch images"),
     189                        tr("No, abort")
     190                };
     191                int ret = JOptionPane.showOptionDialog(
     192                                Main.parent,
     193                                msg,
     194                                tr("Invalid URL?"),
     195                                JOptionPane.YES_NO_OPTION,
     196                                JOptionPane.WARNING_MESSAGE,
     197                                null,
     198                                options, options[1]
     199                );
     200                switch(ret) {
     201                case JOptionPane.YES_OPTION: return true;
     202                default: return false;
     203                }
     204        }
    157205        protected void downloadAndPaintVisible(Graphics g, final MapView mv){
     206                if (usesInvalidUrl)
     207                        return;
    158208                ProjectionBounds bounds = mv.getProjectionBounds();
    159209                int bminx= (int)Math.floor ((bounds.min.east() * pixelPerDegree ) / ImageSize );
     
    170220                        );
    171221                        return;
    172                 }
    173 
     222                }               
     223               
    174224                for(int x = bminx; x<bmaxx; ++x) {
    175225                        for(int y = bminy; y<bmaxy; ++y){
Note: See TracChangeset for help on using the changeset viewer.