Ignore:
Timestamp:
2009-01-01T18:28:53+01:00 (16 years ago)
Author:
stoecker
Message:

removed tab stop usage

Location:
applications/editors/josm/plugins/wmsplugin/src
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/uk/me/jstott/jcoord/LatLng.java

    r6775 r12778  
    33/**
    44 * Class to represent a latitude/longitude pair.
    5  * 
     5 *
    66 * (c) 2006 Jonathan Stott
    7  * 
     7 *
    88 * Created on 11-02-2006
    9  * 
     9 *
    1010 * @author Jonathan Stott
    1111 * @version 1.0
     
    2727  /**
    2828   * Create a new LatLng object to represent a latitude/longitude pair.
    29    * 
     29   *
    3030   * @param lat
    3131   *          the latitude in degrees
     
    4242  /**
    4343   * Get a String representation of this LatLng object.
    44    * 
     44   *
    4545   * @return a String representation of this LatLng object.
    4646   * @since 1.0
     
    5454   * Convert this latitude and longitude into an OSGB (Ordnance Survey of Great
    5555   * Britain) grid reference.
    56    * 
     56   *
    5757   * @return the converted OSGB grid reference
    5858   * @since 1.0
     
    124124  /**
    125125   * Convert this latitude and longitude to a UTM reference.
    126    * 
     126   *
    127127   * @return the converted UTM reference
    128128   * @since 1.0
     
    212212   * Convert this LatLng from the OSGB36 datum to the WGS84 datum using an
    213213   * approximate Helmert transformation.
    214    * 
     214   *
    215215   * @since 1.0
    216216   */
     
    260260   * Convert this LatLng from the WGS84 datum to the OSGB36 datum using an
    261261   * approximate Helmert transformation.
    262    * 
     262   *
    263263   * @since 1.0
    264264   */
     
    310310   * Calculate the surface distance in kilometres from the this LatLng to the
    311311   * given LatLng.
    312    * 
     312   *
    313313   * @param ll
    314314   * @return the surface distance in km
     
    334334  /**
    335335   * Return the latitude in degrees.
    336    * 
     336   *
    337337   * @return the latitude in degrees
    338338   * @since 1.0
     
    345345  /**
    346346   * Return the longitude in degrees.
    347    * 
     347   *
    348348   * @return the longitude in degrees
    349349   * @since 1.0
  • applications/editors/josm/plugins/wmsplugin/src/uk/me/jstott/jcoord/OSRef.java

    r6775 r12778  
    33/**
    44 * Class to represent an Ordnance Survey grid reference
    5  * 
     5 *
    66 * (c) 2006 Jonathan Stott
    7  * 
     7 *
    88 * Created on 11-02-2006
    9  * 
     9 *
    1010 * @author Jonathan Stott
    1111 * @version 1.0
     
    2727  /**
    2828   * Create a new Ordnance Survey grid reference.
    29    * 
     29   *
    3030   * @param easting
    3131   *          the easting in metres
     
    4545   * first character must be H, N, S, O or T. The second character can be any
    4646   * uppercase character from A through Z excluding I.
    47    * 
     47   *
    4848   * @param ref
    4949   *          a String representing a six-figure Ordnance Survey grid reference
     
    8383   * Return a String representation of this OSGB grid reference showing the
    8484   * easting and northing.
    85    * 
     85   *
    8686   * @return a String represenation of this OSGB grid reference
    8787   * @since 1.0
     
    9595   * Return a String representation of this OSGB grid reference using the
    9696   * six-figure notation in the form XY123456
    97    * 
     97   *
    9898   * @return a String representing this OSGB grid reference in six-figure
    9999   *         notation
     
    147147   * OSGB36 datum. Note that, the LatLng object may need to be converted to the
    148148   * WGS84 datum depending on the application.
    149    * 
     149   *
    150150   * @return a LatLng object representing this OSGB grid reference using the
    151151   *         OSGB36 datum
     
    225225  /**
    226226   * Get the easting.
    227    * 
     227   *
    228228   * @return the easting in metres
    229229   * @since 1.0
     
    236236  /**
    237237   * Get the northing.
    238    * 
     238   *
    239239   * @return the northing in metres
    240240   * @since 1.0
  • applications/editors/josm/plugins/wmsplugin/src/uk/me/jstott/jcoord/RefEll.java

    r6775 r12778  
    44 * Class to represent a reference ellipsoid. Also provides a number of
    55 * pre-determined reference ellipsoids as constants.
    6  * 
     6 *
    77 * (c) 2006 Jonathan Stott
    8  * 
     8 *
    99 * Created on 11-Feb-2006
    10  * 
     10 *
    1111 * @author Jonathan Stott
    1212 * @version 1.0
     
    4343  /**
    4444   * Create a new reference ellipsoid
    45    * 
     45   *
    4646   * @param maj
    4747   *          semi-major axis
     
    5959  /**
    6060   * Return the semi-major axis.
    61    * 
     61   *
    6262   * @return the semi-major axis
    6363   * @since 1.0
     
    7070  /**
    7171   * Return the semi-minor axis
    72    * 
     72   *
    7373   * @return the semi-minor axis
    7474   * @since 1.0
     
    8181  /**
    8282   * Return the eccentricity.
    83    * 
     83   *
    8484   * @return the eccentricity
    8585   * @since 1.0
  • applications/editors/josm/plugins/wmsplugin/src/uk/me/jstott/jcoord/Test.java

    r6775 r12778  
    44 * Class to illustrate the use of the various functions of the classes in the
    55 * Jcoord package.
    6  * 
     6 *
    77 * (c) 2006 Jonathan Stott
    8  * 
     8 *
    99 * Created on 11-Feb-2006
    10  * 
     10 *
    1111 * @author Jonathan Stott
    1212 * @version 1.0
     
    1717  /**
    1818   * Main method
    19    * 
     19   *
    2020   * @param args
    2121   *          not used
     
    2626    /*
    2727     * Calculate Surface Distance between two Latitudes/Longitudes
    28      * 
     28     *
    2929     * The distance() function takes a reference to a LatLng object as a
    3030     * parameter and calculates the surface distance between the the given
     
    4545    /*
    4646     * Convert OS Grid Reference to Latitude/Longitude
    47      * 
     47     *
    4848     * Note that the OSGB-Latitude/Longitude conversions use the OSGB36 datum by
    4949     * default. The majority of applications use the WGS84 datum, for which the
     
    7676    /*
    7777     * Convert Latitude/Longitude to OS Grid Reference
    78      * 
     78     *
    7979     * Note that the OSGB-Latitude/Longitude conversions use the OSGB36 datum by
    8080     * default. The majority of applications use the WGS84 datum, for which the
     
    107107    /*
    108108     * Convert Six-Figure OS Grid Reference String to an OSRef Object
    109      * 
     109     *
    110110     * To convert a string representing a six-figure OSGB grid reference:
    111111     */
  • applications/editors/josm/plugins/wmsplugin/src/uk/me/jstott/jcoord/UTMRef.java

    r6775 r12778  
    33/**
    44 * Class to represent a UTM reference
    5  * 
     5 *
    66 * (c) 2006 Jonathan Stott
    7  * 
     7 *
    88 * Created on 11-Feb-2006
    9  * 
     9 *
    1010 * @author Jonathan Stott
    1111 * @version 1.0
     
    3737  /**
    3838   * Create a new UTM reference object.
    39    * 
     39   *
    4040   * @param easting
    4141   *          the easting
     
    5858  /**
    5959   * Convert this UTM reference to a latitude and longitude.
    60    * 
     60   *
    6161   * @return the converted latitude and longitude
    6262   * @since 1.0
     
    130130  /**
    131131   * Work out the UTM latitude zone from the latitude.
    132    * 
     132   *
    133133   * @param latitude
    134134   *          the latitude to find the UTM latitude zone for
     
    184184  /**
    185185   * Convert this UTM reference to a String representation for printing out.
    186    * 
     186   *
    187187   * @return a String representation of this UTM reference
    188188   * @since 1.0
     
    196196  /**
    197197   * Get the easting.
    198    * 
     198   *
    199199   * @return the easting
    200200   * @since 1.0
     
    207207  /**
    208208   * Get the northing.
    209    * 
     209   *
    210210   * @return the northing
    211211   * @since 1.0
     
    218218  /**
    219219   * Get the latitude zone character.
    220    * 
     220   *
    221221   * @return the latitude zone character
    222222   * @since 1.0
     
    229229  /**
    230230   * Get the longitude zone number.
    231    * 
     231   *
    232232   * @return the longitude zone number
    233233   * @since 1.0
  • applications/editors/josm/plugins/wmsplugin/src/uk/me/jstott/jcoord/Util.java

    r6775 r12778  
    33/**
    44 * Some utility functions used by classes in the uk.me.jstott.jcoord package.
    5  * 
     5 *
    66 * (c) 2006 Jonathan Stott
    7  * 
     7 *
    88 * Created on 11-Feb-2006
    9  * 
     9 *
    1010 * @author Jonathan Stott
    1111 * @version 1.0
     
    1616  /**
    1717   * Calculate sin^2(x).
    18    * 
     18   *
    1919   * @param x
    2020   *          x
     
    2929  /**
    3030   * Calculate cos^2(x).
    31    * 
     31   *
    3232   * @param x
    3333   *          x
     
    4242  /**
    4343   * Calculate tan^2(x).
    44    * 
     44   *
    4545   * @param x
    4646   *          x
     
    5555  /**
    5656   * Calculate sec(x).
    57    * 
     57   *
    5858   * @param x
    5959   *          x
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java

    r12438 r12778  
    1515
    1616public class GeorefImage implements Serializable {
    17         public BufferedImage image = null;
    18         public EastNorth min, max;
    19         public boolean downloadingStarted;
     17    public BufferedImage image = null;
     18    public EastNorth min, max;
     19    public boolean downloadingStarted;
    2020
    21         public GeorefImage(boolean downloadingStarted) {
    22                 this.downloadingStarted = downloadingStarted;
    23         }
     21    public GeorefImage(boolean downloadingStarted) {
     22        this.downloadingStarted = downloadingStarted;
     23    }
    2424
    25         public boolean contains(EastNorth en, double dx, double dy) {
    26                 return min.east()+dx <= en.east() && en.east() <= max.east()+dx
    27                         && min.north()+dy <= en.north() && en.north() <= max.north()+dy;
    28         }
     25    public boolean contains(EastNorth en, double dx, double dy) {
     26        return min.east()+dx <= en.east() && en.east() <= max.east()+dx
     27            && min.north()+dy <= en.north() && en.north() <= max.north()+dy;
     28    }
    2929
    30         /* this does not take dx and dy offset into account! */
    31         public boolean isVisible(NavigatableComponent nc) {
    32                 Point minPt = nc.getPoint(min), maxPt = nc.getPoint(max);
    33                 Graphics g = nc.getGraphics();
     30    /* this does not take dx and dy offset into account! */
     31    public boolean isVisible(NavigatableComponent nc) {
     32        Point minPt = nc.getPoint(min), maxPt = nc.getPoint(max);
     33        Graphics g = nc.getGraphics();
    3434
    35                 return (g.hitClip(minPt.x, maxPt.y,
    36                                 maxPt.x - minPt.x, minPt.y - maxPt.y));
    37         }
     35        return (g.hitClip(minPt.x, maxPt.y,
     36                maxPt.x - minPt.x, minPt.y - maxPt.y));
     37    }
    3838
    39         public boolean paint(Graphics g, NavigatableComponent nc, double dx, double dy) {
    40                 if (image == null || min == null || max == null) return false;
     39    public boolean paint(Graphics g, NavigatableComponent nc, double dx, double dy) {
     40        if (image == null || min == null || max == null) return false;
    4141
    42                 EastNorth mi = new EastNorth(min.east()+dx, min.north()+dy);
    43                 EastNorth ma = new EastNorth(max.east()+dx, max.north()+dy);
    44                 Point minPt = nc.getPoint(mi), maxPt = nc.getPoint(ma);
     42        EastNorth mi = new EastNorth(min.east()+dx, min.north()+dy);
     43        EastNorth ma = new EastNorth(max.east()+dx, max.north()+dy);
     44        Point minPt = nc.getPoint(mi), maxPt = nc.getPoint(ma);
    4545
    46                 /* this is isVisible() but taking dx, dy into account */
    47                 if(!(g.hitClip(minPt.x, maxPt.y,
    48                                 maxPt.x - minPt.x, minPt.y - maxPt.y)))
    49                         return false;
     46        /* this is isVisible() but taking dx, dy into account */
     47        if(!(g.hitClip(minPt.x, maxPt.y,
     48                maxPt.x - minPt.x, minPt.y - maxPt.y)))
     49            return false;
    5050
    51                 g.drawImage(image,
    52                         minPt.x, maxPt.y, maxPt.x, minPt.y, // dest
    53                         0, 0, image.getWidth(), image.getHeight(), // src
    54                         null);
     51        g.drawImage(image,
     52            minPt.x, maxPt.y, maxPt.x, minPt.y, // dest
     53            0, 0, image.getWidth(), image.getHeight(), // src
     54            null);
    5555
    56                 return true;
    57         }
     56        return true;
     57    }
    5858
    59         private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    60                 max = (EastNorth) in.readObject();
    61                 min = (EastNorth) in.readObject();
    62                 image = (BufferedImage) ImageIO.read(ImageIO.createImageInputStream(in));
    63         }
    64        
    65         private void writeObject(ObjectOutputStream out) throws IOException {
    66                 out.writeObject(max);
    67                 out.writeObject(min);
    68                 if(image == null)
    69                         out.writeObject(null);
    70                 else
    71                         ImageIO.write(image, "png", ImageIO.createImageOutputStream(out));
    72         }
     59    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
     60        max = (EastNorth) in.readObject();
     61        min = (EastNorth) in.readObject();
     62        image = (BufferedImage) ImageIO.read(ImageIO.createImageInputStream(in));
     63    }
     64
     65    private void writeObject(ObjectOutputStream out) throws IOException {
     66        out.writeObject(max);
     67        out.writeObject(min);
     68        if(image == null)
     69            out.writeObject(null);
     70        else
     71            ImageIO.write(image, "png", ImageIO.createImageOutputStream(out));
     72    }
    7373}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Grabber.java

    r11301 r12778  
    1414
    1515abstract public class Grabber implements Runnable {
    16         protected Bounds b;
    17         protected Projection proj;
    18         protected double pixelPerDegree;
    19         protected MapView mv;
    20         protected WMSLayer layer;
    21         protected GeorefImage image;
     16    protected Bounds b;
     17    protected Projection proj;
     18    protected double pixelPerDegree;
     19    protected MapView mv;
     20    protected WMSLayer layer;
     21    protected GeorefImage image;
    2222
    23         Grabber(Bounds b, Projection proj,
    24                         double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
    25                 this.b = b;
    26                 this.proj = proj;
    27                 this.pixelPerDegree = pixelPerDegree;
    28                 this.image = image;
    29                 this.mv = mv;
    30                 this.layer = layer;
    31         }
     23    Grabber(Bounds b, Projection proj,
     24            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
     25        this.b = b;
     26        this.proj = proj;
     27        this.pixelPerDegree = pixelPerDegree;
     28        this.image = image;
     29        this.mv = mv;
     30        this.layer = layer;
     31    }
    3232
    33         abstract void fetch() throws Exception; // the image fetch code
     33    abstract void fetch() throws Exception; // the image fetch code
    3434
    35         int width(){
    36                 return (int) ((b.max.lon() - b.min.lon()) * pixelPerDegree);
    37         }
    38         int height(){
    39                 return (int) ((b.max.lat() - b.min.lat()) * pixelPerDegree);
    40         }
     35    int width(){
     36        return (int) ((b.max.lon() - b.min.lon()) * pixelPerDegree);
     37    }
     38    int height(){
     39        return (int) ((b.max.lat() - b.min.lat()) * pixelPerDegree);
     40    }
    4141
    42         protected void grabError(Exception e){ // report error when grabing image
    43                 e.printStackTrace();
    44                
    45                 BufferedImage img = new BufferedImage(width(), height(), BufferedImage.TYPE_INT_ARGB);
    46                 Graphics g = img.getGraphics();
    47                 g.setColor(Color.RED);
    48                 g.fillRect(0, 0, width(), height());
    49                 Font font = g.getFont();
    50                 Font tempFont = font.deriveFont(Font.PLAIN).deriveFont(36.0f);
    51                 g.setFont(tempFont);
    52                 g.setColor(Color.BLACK);
    53                 g.drawString(tr("Exception occurred"), 10, height()/2);
    54                 image.image = img;
    55                 g.setFont(font);
    56         }
     42    protected void grabError(Exception e){ // report error when grabing image
     43        e.printStackTrace();
    5744
    58         protected void attempt(){ // try to fetch the image
    59                 int maxTries = 5; // n tries for every image
    60                 for (int i = 1; i <= maxTries; i++) {
    61                         try {
    62                                 fetch();
    63                                 break; // break out of the retry loop
    64                         } catch (Exception e) {
    65                                 try { // sleep some time and then ask the server again
    66                                         Thread.sleep(random(1000, 2000));
    67                                 } catch (InterruptedException e1) {}
     45        BufferedImage img = new BufferedImage(width(), height(), BufferedImage.TYPE_INT_ARGB);
     46        Graphics g = img.getGraphics();
     47        g.setColor(Color.RED);
     48        g.fillRect(0, 0, width(), height());
     49        Font font = g.getFont();
     50        Font tempFont = font.deriveFont(Font.PLAIN).deriveFont(36.0f);
     51        g.setFont(tempFont);
     52        g.setColor(Color.BLACK);
     53        g.drawString(tr("Exception occurred"), 10, height()/2);
     54        image.image = img;
     55        g.setFont(font);
     56    }
    6857
    69                                 if(i == maxTries) grabError(e);
    70                         }
    71                 }
    72         }
     58    protected void attempt(){ // try to fetch the image
     59        int maxTries = 5; // n tries for every image
     60        for (int i = 1; i <= maxTries; i++) {
     61            try {
     62                fetch();
     63                break; // break out of the retry loop
     64            } catch (Exception e) {
     65                try { // sleep some time and then ask the server again
     66                    Thread.sleep(random(1000, 2000));
     67                } catch (InterruptedException e1) {}
    7368
    74         public static int random(int min, int max) {
    75             return (int)(Math.random() * ((max+1)-min) ) + min;
    76         }
     69                if(i == maxTries) grabError(e);
     70            }
     71        }
     72    }
     73
     74    public static int random(int min, int max) {
     75        return (int)(Math.random() * ((max+1)-min) ) + min;
     76    }
    7777}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Help_WMSmenuAction.java

    r12707 r12778  
    1111public class Help_WMSmenuAction extends JosmAction {
    1212
    13         /**
    14         *
    15         */
    16        
     13    /**
     14    *
     15    */
     16   
    1717
    18         public Help_WMSmenuAction() {
    19                 //super("Help / About");
    20                 super(tr("help"), "help", tr("Help / About"), null, false);
    21                
    22         }
    23        
    24         public void actionPerformed(ActionEvent e) {
    25                 //todo - put this into a txt file?
    26                   String helptext =
    27                         tr("You can add, edit and delete WMS entries in the WMSplugin Preference Tab - "  +
    28                         "these will then show up in the WMS menu.\n\n"+
    29                        
    30                         "You can also do this manually in the Advanced Preferences, using the following schema:\n"+
    31                         "wmsplugin.url.1.name=Landsat\n"+
    32                         "wmsplugin.url.1.url=http://onearth.jpl.nasa.gov....\n"+
    33                         "wmsplugin.url.2.name=NPE Maps... etc\n\n"+
    34                                        
    35                         "Full WMS URL input format example (landsat)\n"+
    36                         "http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&\n"+
    37                         "layers=global_mosaic&styles=&srs=EPSG:4326&\n"+
    38                         "format=image/jpeg \n\n"+
    39                        
    40                         "For Metacarta's Map Rectifier http://labs.metacarta.com/rectifier/ , you only need to input the relevant 'id'.\n" +
    41                         "To add a Metacarta Map Rectifier menu item, manually create the URL like in this example," +
    42                         "replacing 73 with your image id: \n" +
    43                         "http://labs.metacarta.com/rectifier/wms.cgi?id=73\n" +
    44                         "&srs=EPSG:4326&Service=WMS&Version=1.1.0&Request=GetMap&format=image/png\n" +
    45                         " \n" +
    46                         "Note: Make sure the image is suitable, copyright-wise, if in doubt, don't use.");
    47                
    48                 JTextPane tp = new JTextPane();
    49                   JScrollPane js = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
    50                                   JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    51                
    52                  
    53                   js.getViewport().add(tp);
    54                   JFrame jf = new JFrame(tr("WMS Plugin Help"));
    55                   jf.getContentPane().add(js);
    56                   jf.pack();
    57                   jf.setSize(400,500);
    58                   jf.setVisible(true);
    59                   tp.setText(helptext);
    60         }
     18    public Help_WMSmenuAction() {
     19        //super("Help / About");
     20        super(tr("help"), "help", tr("Help / About"), null, false);
     21       
     22    }
     23   
     24    public void actionPerformed(ActionEvent e) {
     25        //todo - put this into a txt file?
     26          String helptext =
     27            tr("You can add, edit and delete WMS entries in the WMSplugin Preference Tab - "  +
     28            "these will then show up in the WMS menu.\n\n"+
     29           
     30            "You can also do this manually in the Advanced Preferences, using the following schema:\n"+
     31            "wmsplugin.url.1.name=Landsat\n"+
     32            "wmsplugin.url.1.url=http://onearth.jpl.nasa.gov....\n"+
     33            "wmsplugin.url.2.name=NPE Maps... etc\n\n"+
     34                   
     35            "Full WMS URL input format example (landsat)\n"+
     36            "http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&\n"+
     37            "layers=global_mosaic&styles=&srs=EPSG:4326&\n"+
     38            "format=image/jpeg \n\n"+
     39           
     40            "For Metacarta's Map Rectifier http://labs.metacarta.com/rectifier/ , you only need to input the relevant 'id'.\n" +
     41            "To add a Metacarta Map Rectifier menu item, manually create the URL like in this example," +
     42            "replacing 73 with your image id: \n" +
     43            "http://labs.metacarta.com/rectifier/wms.cgi?id=73\n" +
     44            "&srs=EPSG:4326&Service=WMS&Version=1.1.0&Request=GetMap&format=image/png\n" +
     45            " \n" +
     46            "Note: Make sure the image is suitable, copyright-wise, if in doubt, don't use.");
     47       
     48        JTextPane tp = new JTextPane();
     49          JScrollPane js = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
     50                  JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
     51       
     52         
     53          js.getViewport().add(tp);
     54          JFrame jf = new JFrame(tr("WMS Plugin Help"));
     55          jf.getContentPane().add(js);
     56          jf.pack();
     57          jf.setSize(400,500);
     58          jf.setVisible(true);
     59          tp.setText(helptext);
     60    }
    6161}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Map_Rectifier_WMSmenuAction.java

    r12707 r12778  
    1212public class Map_Rectifier_WMSmenuAction extends JosmAction {
    1313
    14         /**
    15         * tim waters "chippy"
    16         */
    17         private static final long serialVersionUID = 1L;
     14    /**
     15    * tim waters "chippy"
     16    */
     17    private static final long serialVersionUID = 1L;
    1818
    19         public Map_Rectifier_WMSmenuAction() {
    20                 super(tr("Rectified Image ..."), "OLmarker", tr("Download Rectified Image from Metacarta's Map Rectifier WMS"), null, false);
    21         }
     19    public Map_Rectifier_WMSmenuAction() {
     20        super(tr("Rectified Image ..."), "OLmarker", tr("Download Rectified Image from Metacarta's Map Rectifier WMS"), null, false);
     21    }
    2222
    23         public void actionPerformed(ActionEvent e) {
    24                 String newid = JOptionPane.showInputDialog(Main.parent, tr("Metacarta Map Rectifier image id"),
    25                 Main.pref.get("wmsplugin.rectifier_id"));
     23    public void actionPerformed(ActionEvent e) {
     24        String newid = JOptionPane.showInputDialog(Main.parent, tr("Metacarta Map Rectifier image id"),
     25        Main.pref.get("wmsplugin.rectifier_id"));
    2626
    27                 if (newid != null && !newid.equals("")) {
    28                         String newURL = "http://labs.metacarta.com/rectifier/wms.cgi?id="+newid+
    29                         "&srs=EPSG:4326&Service=WMS&Version=1.1.0&Request=GetMap&format=image/png";
     27        if (newid != null && !newid.equals("")) {
     28            String newURL = "http://labs.metacarta.com/rectifier/wms.cgi?id="+newid+
     29            "&srs=EPSG:4326&Service=WMS&Version=1.1.0&Request=GetMap&format=image/png";
    3030
    31                         Main.pref.put("wmsplugin.rectifier_id", newid);
    32                         WMSLayer wmsLayer = new WMSLayer(tr("rectifier id={0}",newid), newURL);
    33                         Main.main.addLayer(wmsLayer);
    34                 }
    35         }
     31            Main.pref.put("wmsplugin.rectifier_id", newid);
     32            WMSLayer wmsLayer = new WMSLayer(tr("rectifier id={0}",newid), newURL);
     33            Main.main.addLayer(wmsLayer);
     34        }
     35    }
    3636}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/OSGBGrabber.java

    r10382 r12778  
    1515// FIXME: Remove this hack when we have proper projection support.
    1616public class OSGBGrabber extends WMSGrabber {
    17         public OSGBGrabber(String baseURL) {
    18                 super(baseURL);
    19         }
     17    public OSGBGrabber(String baseURL) {
     18        super(baseURL);
     19    }
    2020
    21         private Epsg4326 latlonProj = new Epsg4326();
     21    private Epsg4326 latlonProj = new Epsg4326();
    2222
    23         @Override public GeorefImage grab(Bounds b, Projection proj,
    24                         double pixelPerDegree) throws IOException {
    25                 Bounds bnew = toOSGB(b);
    26                 double pixelPerDegreeNew =
    27                         pixelPerDegree / (bnew.max.lon() - bnew.min.lon())
    28                                 * (b.max.lon() - b.min.lon());
     23    @Override public GeorefImage grab(Bounds b, Projection proj,
     24            double pixelPerDegree) throws IOException {
     25        Bounds bnew = toOSGB(b);
     26        double pixelPerDegreeNew =
     27            pixelPerDegree / (bnew.max.lon() - bnew.min.lon())
     28                * (b.max.lon() - b.min.lon());
    2929
    30                 GeorefImage img = super.grab(bnew, latlonProj, pixelPerDegreeNew);
     30        GeorefImage img = super.grab(bnew, latlonProj, pixelPerDegreeNew);
    3131
    32                 img.min = proj.latlon2eastNorth(fromOSGB(img.min));
    33                 img.max = proj.latlon2eastNorth(fromOSGB(img.max));
     32        img.min = proj.latlon2eastNorth(fromOSGB(img.min));
     33        img.max = proj.latlon2eastNorth(fromOSGB(img.max));
    3434
    35                 return img;
    36         }
     35        return img;
     36    }
    3737
    38         protected static Bounds toOSGB(Bounds b) {
    39                 LatLng[] lls = new LatLng[] {
    40                         new LatLng(b.min.lat(), b.min.lon()),
    41                         new LatLng(b.min.lat(), b.max.lon()),
    42                         new LatLng(b.max.lat(), b.min.lon()),
    43                         new LatLng(b.max.lat(), b.max.lon()) };
     38    protected static Bounds toOSGB(Bounds b) {
     39        LatLng[] lls = new LatLng[] {
     40            new LatLng(b.min.lat(), b.min.lon()),
     41            new LatLng(b.min.lat(), b.max.lon()),
     42            new LatLng(b.max.lat(), b.min.lon()),
     43            new LatLng(b.max.lat(), b.max.lon()) };
    4444
    45                 for (LatLng ll : lls) ll.toOSGB36();
     45        for (LatLng ll : lls) ll.toOSGB36();
    4646
    47                 OSRef[] grs = new OSRef[lls.length];
    48                 for (int i = 0; i < lls.length; i++) grs[i] = lls[i].toOSRef();
     47        OSRef[] grs = new OSRef[lls.length];
     48        for (int i = 0; i < lls.length; i++) grs[i] = lls[i].toOSRef();
    4949
    50                 LatLon latlon = new LatLon(grs[0].getNorthing(), grs[0].getEasting());
    51                 Bounds bnew = new Bounds(latlon, latlon);
    52                 for (int i = 1; i < grs.length; i++)
    53                         bnew.extend(new LatLon(grs[i].getNorthing(), grs[i].getEasting()));
     50        LatLon latlon = new LatLon(grs[0].getNorthing(), grs[0].getEasting());
     51        Bounds bnew = new Bounds(latlon, latlon);
     52        for (int i = 1; i < grs.length; i++)
     53            bnew.extend(new LatLon(grs[i].getNorthing(), grs[i].getEasting()));
    5454
    55                 return bnew;
    56         }
     55        return bnew;
     56    }
    5757
    58         protected static LatLon fromOSGB(EastNorth en) {
    59                 LatLng ll = new OSRef(en.east(), en.north()).toLatLng();
    60                 ll.toWGS84();
    61                 return new LatLon(ll.getLat(), ll.getLng());
    62         }
     58    protected static LatLon fromOSGB(EastNorth en) {
     59        LatLng ll = new OSRef(en.east(), en.north()).toLatLng();
     60        ll.toWGS84();
     61        return new LatLon(ll.getLat(), ll.getLng());
     62    }
    6363}
    6464*/
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSAdjustAction.java

    r12438 r12778  
    1717
    1818public class WMSAdjustAction extends MapMode implements
    19                 MouseListener, MouseMotionListener{
     19        MouseListener, MouseMotionListener{
    2020
    21         GeorefImage selectedImage;
    22         WMSLayer selectedLayer;
    23         boolean mouseDown;
    24         EastNorth prevEastNorth;
     21    GeorefImage selectedImage;
     22    WMSLayer selectedLayer;
     23    boolean mouseDown;
     24    EastNorth prevEastNorth;
    2525
    26         public WMSAdjustAction(MapFrame mapFrame) {
    27                 super(tr("Adjust WMS"), "adjustwms",
    28                                                 tr("Adjust the position of the WMS layer"), mapFrame,
    29                                                 ImageProvider.getCursor("normal", "move"));
    30         }
     26    public WMSAdjustAction(MapFrame mapFrame) {
     27        super(tr("Adjust WMS"), "adjustwms",
     28                        tr("Adjust the position of the WMS layer"), mapFrame,
     29                        ImageProvider.getCursor("normal", "move"));
     30    }
    3131
    32         @Override public void enterMode() {
    33                 super.enterMode();
    34                 Main.map.mapView.addMouseListener(this);
    35                 Main.map.mapView.addMouseMotionListener(this);
    36         }
     32    @Override public void enterMode() {
     33        super.enterMode();
     34        Main.map.mapView.addMouseListener(this);
     35        Main.map.mapView.addMouseMotionListener(this);
     36    }
    3737
    38         @Override public void exitMode() {
    39                 super.exitMode();
    40                 Main.map.mapView.removeMouseListener(this);
    41                 Main.map.mapView.removeMouseMotionListener(this);
    42         }
     38    @Override public void exitMode() {
     39        super.exitMode();
     40        Main.map.mapView.removeMouseListener(this);
     41        Main.map.mapView.removeMouseMotionListener(this);
     42    }
    4343
    44         @Override public void mousePressed(MouseEvent e) {
    45                 if (e.getButton() != MouseEvent.BUTTON1)
    46                         return;
     44    @Override public void mousePressed(MouseEvent e) {
     45        if (e.getButton() != MouseEvent.BUTTON1)
     46            return;
    4747
    48                 for(Layer layer:Main.map.mapView.getAllLayers()) {
    49                         if (layer.visible && layer instanceof WMSLayer) {
    50                                 prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY());
    51                                 selectedLayer = ((WMSLayer)layer);
    52                                 selectedImage = selectedLayer.findImage(prevEastNorth);
    53                                 if(selectedImage!=null){
    54                                         Main.map.mapView.setCursor
    55                                                 (Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    56                                 }
    57                         }
    58                 }
    59         }
     48        for(Layer layer:Main.map.mapView.getAllLayers()) {
     49            if (layer.visible && layer instanceof WMSLayer) {
     50                prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY());
     51                selectedLayer = ((WMSLayer)layer);
     52                selectedImage = selectedLayer.findImage(prevEastNorth);
     53                if(selectedImage!=null){
     54                    Main.map.mapView.setCursor
     55                        (Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
     56                }
     57            }
     58        }
     59    }
    6060
    61         @Override public void mouseDragged(MouseEvent e) {
    62                         /*
    63                 if (e.getButton() != MouseEvent.BUTTON1)
    64                         return;
    65                         */
     61    @Override public void mouseDragged(MouseEvent e) {
     62            /*
     63        if (e.getButton() != MouseEvent.BUTTON1)
     64            return;
     65            */
    6666
    67                 if(selectedImage!=null) {
    68                         EastNorth eastNorth=
    69                                         Main.map.mapView.getEastNorth(e.getX(),e.getY());
    70                         selectedLayer.displace(eastNorth.east()-prevEastNorth.east(),
    71                                 eastNorth.north()-prevEastNorth.north());
    72                         prevEastNorth = eastNorth;
    73                         Main.map.mapView.repaint();
    74                 }
    75         }
     67        if(selectedImage!=null) {
     68            EastNorth eastNorth=
     69                    Main.map.mapView.getEastNorth(e.getX(),e.getY());
     70                selectedLayer.displace(eastNorth.east()-prevEastNorth.east(),
     71                eastNorth.north()-prevEastNorth.north());
     72            prevEastNorth = eastNorth;
     73            Main.map.mapView.repaint();
     74        }
     75    }
    7676
    77         @Override public void mouseReleased(MouseEvent e) {
    78                 Main.map.mapView.repaint();
    79                 Main.map.mapView.setCursor(Cursor.getDefaultCursor());
    80                 selectedImage = null;   
    81                 prevEastNorth = null;
    82                 selectedLayer = null;
    83         }
     77    @Override public void mouseReleased(MouseEvent e) {
     78        Main.map.mapView.repaint();
     79        Main.map.mapView.setCursor(Cursor.getDefaultCursor());
     80        selectedImage = null;   
     81        prevEastNorth = null;
     82        selectedLayer = null;
     83    }
    8484
    85         public void mouseEntered(MouseEvent e) {
    86         }
    87         public void mouseExited(MouseEvent e) {
    88         }
    89         public void mouseMoved(MouseEvent e) {
    90         }
     85    public void mouseEntered(MouseEvent e) {
     86    }
     87    public void mouseExited(MouseEvent e) {
     88    }
     89    public void mouseMoved(MouseEvent e) {
     90    }
    9191
    92         @Override public void mouseClicked(MouseEvent e) {
    93         }
     92    @Override public void mouseClicked(MouseEvent e) {
     93    }
    9494}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSDownloadAction.java

    r12187 r12778  
    1313public class WMSDownloadAction extends JosmAction {
    1414
    15         private WMSInfo info;
    16        
    17         public WMSDownloadAction(WMSInfo info) {
    18                 super(info.name, "wmsmenu", tr("Download WMS tile from {0}",info.name), null, false);
    19                 this.info = info;
    20         }
    21        
    22         public void actionPerformed(ActionEvent e) {
    23                 System.out.println(info.url);
    24                
    25                 WMSLayer wmsLayer = new WMSLayer(info.name, info.url);
    26                 Main.main.addLayer(wmsLayer);
    27         }
     15    private WMSInfo info;
    2816
    29         public static WMSLayer getLayer(WMSInfo info) {
    30                 // FIXME: move this to WMSPlugin/WMSInfo/preferences.
    31                 WMSLayer wmsLayer = new WMSLayer(info.name, info.url);
    32                 Main.main.addLayer(wmsLayer);
    33                 return wmsLayer;
    34         }
     17    public WMSDownloadAction(WMSInfo info) {
     18        super(info.name, "wmsmenu", tr("Download WMS tile from {0}",info.name), null, false);
     19        this.info = info;
     20    }
     21
     22    public void actionPerformed(ActionEvent e) {
     23        System.out.println(info.url);
     24
     25        WMSLayer wmsLayer = new WMSLayer(info.name, info.url);
     26        Main.main.addLayer(wmsLayer);
     27    }
     28
     29    public static WMSLayer getLayer(WMSInfo info) {
     30        // FIXME: move this to WMSPlugin/WMSInfo/preferences.
     31        WMSLayer wmsLayer = new WMSLayer(info.name, info.url);
     32        Main.main.addLayer(wmsLayer);
     33        return wmsLayer;
     34    }
    3535};
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java

    r11400 r12778  
    2525
    2626public class WMSGrabber extends Grabber {
    27         protected String baseURL;
     27    protected String baseURL;
    2828
    29         WMSGrabber(String baseURL, Bounds b, Projection proj,
    30                         double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
    31                 super(b, proj, pixelPerDegree, image, mv, layer);
    32                 this.baseURL = baseURL;
    33         }
     29    WMSGrabber(String baseURL, Bounds b, Projection proj,
     30            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
     31        super(b, proj, pixelPerDegree, image, mv, layer);
     32        this.baseURL = baseURL;
     33    }
    3434
    35         public void run() {
    36                 attempt();
    37                 mv.repaint();
    38         }
     35    public void run() {
     36        attempt();
     37        mv.repaint();
     38    }
    3939
    40         void fetch() throws Exception{
    41                 URL url = null;
    42                 try {
    43                         url = getURL(
    44                                 b.min.lon(), b.min.lat(),
    45                                 b.max.lon(), b.max.lat(),
    46                                 width(), height());
    47                        
    48                         image.min = proj.latlon2eastNorth(b.min);
    49                         image.max = proj.latlon2eastNorth(b.max);
     40    void fetch() throws Exception{
     41        URL url = null;
     42        try {
     43            url = getURL(
     44                b.min.lon(), b.min.lat(),
     45                b.max.lon(), b.max.lat(),
     46                width(), height());
    5047
    51                         if(image.isVisible(mv)) //don't download, if the image isn't visible already
    52                                 image.image = grab(url);
    53                         image.downloadingStarted = false;
    54                 } catch(Exception e) {
    55                         throw new Exception(e.getMessage() + "\nImage couldn't be fetched: " + (url != null ? url.toString() : ""));
    56                 }
    57         }
     48            image.min = proj.latlon2eastNorth(b.min);
     49            image.max = proj.latlon2eastNorth(b.max);
    5850
    59         public static final NumberFormat
    60                 latLonFormat = new DecimalFormat("###0.0000000",
    61                         new DecimalFormatSymbols(Locale.US));
     51            if(image.isVisible(mv)) //don't download, if the image isn't visible already
     52                image.image = grab(url);
     53            image.downloadingStarted = false;
     54        } catch(Exception e) {
     55            throw new Exception(e.getMessage() + "\nImage couldn't be fetched: " + (url != null ? url.toString() : ""));
     56        }
     57    }
    6258
    63         protected URL getURL(double w, double s,double e,double n,
    64                         int wi, int ht) throws MalformedURLException {
    65                 String str = baseURL;
    66                 if(!str.endsWith("?"))
    67                         str += "&";
    68                 str += "bbox="
    69                         + latLonFormat.format(w) + ","
    70                         + latLonFormat.format(s) + ","
    71                         + latLonFormat.format(e) + ","
    72                         + latLonFormat.format(n)
    73                         + "&width=" + wi + "&height=" + ht;
    74                 return new URL(str.replace(" ", "%20"));
    75         }
     59    public static final NumberFormat
     60        latLonFormat = new DecimalFormat("###0.0000000",
     61            new DecimalFormatSymbols(Locale.US));
    7662
    77         protected BufferedImage grab(URL url) throws IOException {
    78                 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    79                
    80                 String contentType = conn.getHeaderField("Content-Type");
    81                 if( conn.getResponseCode() != 200
    82                                 || contentType != null && !contentType.startsWith("image") ) {
    83                         throw new IOException(readException(conn));
    84                 }
    85                
    86                 InputStream is = new ProgressInputStream(conn, null);
    87                 BufferedImage img = ImageIO.read(is);
    88                 is.close();
    89                 return img;
    90         }
     63    protected URL getURL(double w, double s,double e,double n,
     64            int wi, int ht) throws MalformedURLException {
     65        String str = baseURL;
     66        if(!str.endsWith("?"))
     67            str += "&";
     68        str += "bbox="
     69            + latLonFormat.format(w) + ","
     70            + latLonFormat.format(s) + ","
     71            + latLonFormat.format(e) + ","
     72            + latLonFormat.format(n)
     73            + "&width=" + wi + "&height=" + ht;
     74        return new URL(str.replace(" ", "%20"));
     75    }
    9176
    92         protected String readException(URLConnection conn) throws IOException {
    93                 StringBuilder exception = new StringBuilder();
    94                 InputStream in = conn.getInputStream();
    95                 BufferedReader br = new BufferedReader(new InputStreamReader(in));
    96                
    97                 String line = null;
    98                 while( (line = br.readLine()) != null) {
    99                         exception.append(line);
    100                         exception.append('\n');
    101                 }
    102                 return exception.toString();
    103         }
     77    protected BufferedImage grab(URL url) throws IOException {
     78        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
     79
     80        String contentType = conn.getHeaderField("Content-Type");
     81        if( conn.getResponseCode() != 200
     82                || contentType != null && !contentType.startsWith("image") ) {
     83            throw new IOException(readException(conn));
     84        }
     85
     86        InputStream is = new ProgressInputStream(conn, null);
     87        BufferedImage img = ImageIO.read(is);
     88        is.close();
     89        return img;
     90    }
     91
     92    protected String readException(URLConnection conn) throws IOException {
     93        StringBuilder exception = new StringBuilder();
     94        InputStream in = conn.getInputStream();
     95        BufferedReader br = new BufferedReader(new InputStreamReader(in));
     96
     97        String line = null;
     98        while( (line = br.readLine()) != null) {
     99            exception.append(line);
     100            exception.append('\n');
     101        }
     102        return exception.toString();
     103    }
    104104}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSInfo.java

    r10767 r12778  
    55/**
    66 * Class that stores info about a WMS server.
    7  * 
     7 *
    88 * @author Frederik Ramm <frederik@remote.org>
    99 */
    1010public class WMSInfo implements Comparable {
    11        
    12         String name;
    13         String url;
    14         int prefid;
    15        
    16         public WMSInfo(String name, String url, int prefid) {
    17                 this.name=name; this.url=url; this.prefid=prefid;
    18         }
    1911
    20        
    21         public void save() {
    22                 Main.pref.put("wmsplugin.url." + prefid + ".name", name);
    23                 Main.pref.put("wmsplugin.url." + prefid + ".url", url);
    24         }
    25         public int compareTo(Object c)
    26         {
    27                 Integer i = 0;
    28                 if(c instanceof WMSInfo)
    29                 {
    30                         WMSInfo in = (WMSInfo)c;
    31                         i = name.compareTo(in.name);
    32                         if(i == 0)
    33                                 i = url.compareTo(in.url);
    34                         if(i == 0)
    35                                 i = prefid-in.prefid;
    36                 }
    37                 return i;
    38         }
     12    String name;
     13    String url;
     14    int prefid;
     15
     16    public WMSInfo(String name, String url, int prefid) {
     17        this.name=name; this.url=url; this.prefid=prefid;
     18    }
     19
     20
     21    public void save() {
     22        Main.pref.put("wmsplugin.url." + prefid + ".name", name);
     23        Main.pref.put("wmsplugin.url." + prefid + ".url", url);
     24    }
     25    public int compareTo(Object c)
     26    {
     27        Integer i = 0;
     28        if(c instanceof WMSInfo)
     29        {
     30            WMSInfo in = (WMSInfo)c;
     31            i = name.compareTo(in.name);
     32            if(i == 0)
     33                i = url.compareTo(in.url);
     34            if(i == 0)
     35                i = prefid-in.prefid;
     36        }
     37        return i;
     38    }
    3939}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r12707 r12778  
    4545public class WMSLayer extends Layer {
    4646
    47         protected static final Icon icon =
    48                 new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png")));
    49 
    50         public int messageNum = 5; //limit for messages per layer
    51         protected MapView mv;
    52         protected String resolution;
    53         protected boolean stopAfterPaint = false;
    54         protected int ImageSize = 500;
    55         protected int dax = 10;
    56         protected int day = 10;
    57         protected int minZoom = 3;
    58         protected double dx = 0.0;
    59         protected double dy = 0.0;
    60         protected double pixelPerDegree;
    61         protected GeorefImage[][] images = new GeorefImage[dax][day];
    62         JCheckBoxMenuItem startstop = new JCheckBoxMenuItem(tr("Automatic downloading"), true);
    63 
    64         protected String baseURL;
    65         protected final int serializeFormatVersion = 4;
    66        
    67         private ExecutorService executor;
    68 
    69         public WMSLayer() {
    70                 this(tr("Blank Layer"), null);
    71                 initializeImages();
    72                 mv = Main.map.mapView;
    73         }
    74 
    75         public WMSLayer(String name, String baseURL) {
    76                 super(name);
    77                 background = true; /* set global background variable */
    78                 initializeImages();
    79                 this.baseURL = baseURL;
    80                 mv = Main.map.mapView;
    81                 getPPD();
    82                
    83                 executor = Executors.newFixedThreadPool(3);
    84         }
    85 
    86         public void getPPD(){
    87                 pixelPerDegree = mv.getWidth() / (bounds().max.lon() - bounds().min.lon());
    88         }
    89 
    90         public void initializeImages() {
    91                 images = new GeorefImage[dax][day];
    92                 for(int x = 0; x<dax; ++x)
    93                         for(int y = 0; y<day; ++y)
    94                                 images[x][y]= new GeorefImage(false);
    95         }
    96 
    97         @Override public Icon getIcon() {
    98                 return icon;
    99         }
    100 
    101         public String scale(){
    102                 LatLon ll1 = mv.getLatLon(0,0);
    103                 LatLon ll2 = mv.getLatLon(100,0);
    104                 double dist = ll1.greatCircleDistance(ll2);
    105                 return dist > 1000 ? (Math.round(dist/100)/10.0)+" km" : Math.round(dist*10)/10+" m";
    106         }
    107 
    108         @Override public String getToolTipText() {
    109                 if(startstop.isSelected())
    110                         return tr("WMS layer ({0}), automatically downloading in zoom {1}", name, resolution);
    111                 else
    112                         return tr("WMS layer ({0}), downloading in zoom {1}", name, resolution);
    113         }
    114 
    115         @Override public boolean isMergable(Layer other) {
    116                 return false;
    117         }
    118 
    119         @Override public void mergeFrom(Layer from) {
    120         }
    121 
    122         private Bounds XYtoBounds (int x, int y) {
    123                 return new Bounds( 
    124                         new LatLon( x * ImageSize / pixelPerDegree,
    125                                          y * ImageSize / pixelPerDegree),
    126                         new LatLon((x + 1) *  ImageSize / pixelPerDegree,
    127                                    (y + 1) * ImageSize / pixelPerDegree));
    128         }
    129 
    130         private int modulo (int a, int b) {
    131           if(a%b>=0)return a%b;
    132           else return a%b+b;
    133         }         
    134 
    135         protected Bounds bounds(){
    136                 return new Bounds(
    137                         mv.getLatLon(0, mv.getHeight()),
    138                         mv.getLatLon(mv.getWidth(), 0));
    139         }
    140 
    141         @Override public void paint(Graphics g, final MapView mv) {
    142                 if(baseURL == null) return;
    143 
    144                 if( !startstop.isSelected() || (pixelPerDegree / (mv.getWidth() / (bounds().max.lon() - bounds().min.lon())) > minZoom) ){ //don't download when it's too outzoomed
    145                         for(int x = 0; x<dax; ++x)
    146                                 for(int y = 0; y<day; ++y)
    147                                         images[modulo(x,dax)][modulo(y,day)].paint(g, mv, dx, dy);
    148                 } else
    149                         downloadAndPaintVisible(g, mv);
    150         }
    151 
    152         public void displace(double dx, double dy) {
    153                 this.dx += dx;
    154                 this.dy += dy;
    155         }
    156 
    157         protected void downloadAndPaintVisible(Graphics g, final MapView mv){
    158                 int bminx= (int)Math.floor ((bounds().min.lat() * pixelPerDegree ) / ImageSize );
    159                 int bminy= (int)Math.floor ((bounds().min.lon() * pixelPerDegree ) / ImageSize );
    160                 int bmaxx= (int)Math.ceil  ((bounds().max.lat() * pixelPerDegree ) / ImageSize );
    161                 int bmaxy= (int)Math.ceil  ((bounds().max.lon() * pixelPerDegree ) / ImageSize );
    162 
    163                 if((bmaxx - bminx > dax) || (bmaxy - bminy > day)){
    164                         JOptionPane.showMessageDialog(Main.parent, tr("The requested area is too big. Please zoom in a little, or change resolution"));
    165                         return;
    166                 }
    167 
    168                 for(int x = bminx; x<bmaxx; ++x)
    169                         for(int y = bminy; y<bmaxy; ++y){
    170                                 GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
    171                                 if(!img.paint(g, mv, dx, dy) && !img.downloadingStarted){
    172                                         img.downloadingStarted = true;
    173                                         img.image = null;
    174                                         Grabber gr = WMSPlugin.getGrabber(baseURL, XYtoBounds(x,y), Main.main.proj, pixelPerDegree, img, mv, this);
    175                                         executor.submit(gr);
    176                         }
    177                 }
    178         }
    179 
    180         @Override public void visitBoundingBox(BoundingXYVisitor v) {
    181                 for(int x = 0; x<dax; ++x)
    182                         for(int y = 0; y<day; ++y)
    183                                 if(images[x][y].image!=null){
    184                                         v.visit(images[x][y].min);
    185                                         v.visit(images[x][y].max);
    186                                 }
    187         }
    188 
    189         @Override public Object getInfoComponent() {
    190                 return getToolTipText();
    191         }
    192 
    193         @Override public Component[] getMenuEntries() {
    194                 return new Component[]{
    195                                 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
    196                                 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),                             
    197                                 new JSeparator(),
    198                                 new JMenuItem(new LoadWmsAction()),
    199                                 new JMenuItem(new SaveWmsAction()),
    200                                 new JSeparator(),
    201                                 startstop,
    202                                 new JMenuItem(new changeResolutionAction()),
    203                                 new JMenuItem(new downloadAction()),
    204                                 new JSeparator(),
    205                                 new JMenuItem(new LayerListPopup.InfoAction(this))
    206                 };
    207         }
    208 
    209         public GeorefImage findImage(EastNorth eastNorth) {
    210                 for(int x = 0; x<dax; ++x)
    211                         for(int y = 0; y<day; ++y)
    212                                         if(images[x][y].image!=null && images[x][y].min!=null && images[x][y].max!=null)
    213                                                 if(images[x][y].contains(eastNorth, dx, dy))
    214                                                         return images[x][y];
    215                 return null;
    216         }
    217 
    218         public class downloadAction extends AbstractAction {
    219                 public downloadAction() {
    220                         super(tr("Download visible tiles"));
    221                 }
    222                 public void actionPerformed(ActionEvent ev) {
    223                         downloadAndPaintVisible(mv.getGraphics(), mv);
    224                 }
    225         }
    226 
    227         public class changeResolutionAction extends AbstractAction {
    228                 public changeResolutionAction() {
    229                         super(tr("Change resolution"));
    230                 }
    231                 public void actionPerformed(ActionEvent ev) {
    232                         initializeImages();
    233                         resolution = scale();
    234                         getPPD();
    235                         mv.repaint();
    236                 }
    237         }
    238 
    239         public class SaveWmsAction extends AbstractAction {
    240                 public SaveWmsAction() {
    241                         super(tr("Save WMS layer to file"), ImageProvider.get("save"));
    242                 }
    243                 public void actionPerformed(ActionEvent ev) {
    244                         File f = openFileDialog(false);
    245                         try
    246                         {
    247                                 FileOutputStream fos = new FileOutputStream(f);
    248                                 ObjectOutputStream oos = new ObjectOutputStream(fos);
    249                                 oos.writeInt(serializeFormatVersion);
    250                                 oos.writeInt(dax);
    251                                 oos.writeInt(day);
    252                                 oos.writeInt(ImageSize);
    253                                 oos.writeDouble(pixelPerDegree);
    254                                 oos.writeObject(name);
    255                                 oos.writeObject(baseURL);
    256                                 oos.writeObject(images);
    257                                 oos.close();
    258                                 fos.close();
    259                         }
    260                         catch (Exception ex) {
    261                                 ex.printStackTrace(System.out);
    262                         }
    263                 }
    264         }
    265 
    266         public class LoadWmsAction extends AbstractAction {
    267                 public LoadWmsAction() {
    268                         super(tr("Load WMS layer from file"), ImageProvider.get("load"));
    269                 }
    270                 public void actionPerformed(ActionEvent ev) {
    271                         File f = openFileDialog(true);
    272                         if (f == null) return;
    273                         try
    274                         {
    275                                 FileInputStream fis = new FileInputStream(f);
    276                                 ObjectInputStream ois = new ObjectInputStream(fis);
    277                                 int sfv = ois.readInt();
    278                                 if (sfv != serializeFormatVersion) {
    279                                         JOptionPane.showMessageDialog(Main.parent,
    280                                                 tr("Unsupported WMS file version; found {0}, expected {1}", sfv, serializeFormatVersion),
    281                                                 tr("File Format Error"),
    282                                                 JOptionPane.ERROR_MESSAGE);
    283                                         return;
    284                                 }
    285                                 startstop.setSelected(false);
    286                                 dax = ois.readInt();
    287                                 day = ois.readInt();
    288                                 ImageSize = ois.readInt();
    289                                 pixelPerDegree = ois.readDouble();
    290                                 name = (String) ois.readObject();
    291                                 baseURL = (String) ois.readObject();
    292                                 images = (GeorefImage[][])ois.readObject();
    293                                 ois.close();
    294                                 fis.close();
    295                                 mv.repaint();
    296                         }
    297                         catch (Exception ex) {
    298                                 // FIXME be more specific
    299                                 ex.printStackTrace(System.out);
    300                                 JOptionPane.showMessageDialog(Main.parent,
    301                                         tr("Error loading file"),
    302                                         tr("Error"),
    303                                         JOptionPane.ERROR_MESSAGE);
    304                                 return;
    305                         }
    306                 }
    307         }
    308 
    309         protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple) {
    310                 String curDir = Main.pref.get("lastDirectory");
    311                 if (curDir.equals(""))
    312                         curDir = ".";
    313                 JFileChooser fc = new JFileChooser(new File(curDir));
    314                 fc.setMultiSelectionEnabled(multiple);
    315                 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i)
    316                         fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]);
    317                 fc.setAcceptAllFileFilterUsed(true);
    318 
    319                 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
    320                 if (answer != JFileChooser.APPROVE_OPTION)
    321                         return null;
    322 
    323                 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
    324                         Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
    325 
    326                 if (!open) {
    327                         File file = fc.getSelectedFile();
    328                         if (file == null || (file.exists() && JOptionPane.YES_OPTION !=
    329                                 JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION)))
    330                                 return null;
    331                 }
    332 
    333                 return fc;
    334         }
    335 
    336         public static File openFileDialog(boolean open) {
    337                 JFileChooser fc = createAndOpenFileChooser(open, false);
    338                 if (fc == null)
    339                         return null;
    340 
    341                 File file = fc.getSelectedFile();
    342 
    343                 String fn = file.getPath();
    344                 if (fn.indexOf('.') == -1) {
    345                         FileFilter ff = fc.getFileFilter();
    346                         if (ff instanceof ExtensionFileFilter)
    347                                 fn = "." + ((ExtensionFileFilter)ff).defaultExtension;
    348                         else
    349                                 fn += ".osm";
    350                         file = new File(fn);
    351                 }
    352                 return file;
    353         }
     47    protected static final Icon icon =
     48        new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png")));
     49
     50    public int messageNum = 5; //limit for messages per layer
     51    protected MapView mv;
     52    protected String resolution;
     53    protected boolean stopAfterPaint = false;
     54    protected int ImageSize = 500;
     55    protected int dax = 10;
     56    protected int day = 10;
     57    protected int minZoom = 3;
     58    protected double dx = 0.0;
     59    protected double dy = 0.0;
     60    protected double pixelPerDegree;
     61    protected GeorefImage[][] images = new GeorefImage[dax][day];
     62    JCheckBoxMenuItem startstop = new JCheckBoxMenuItem(tr("Automatic downloading"), true);
     63
     64    protected String baseURL;
     65    protected final int serializeFormatVersion = 4;
     66
     67    private ExecutorService executor;
     68
     69    public WMSLayer() {
     70        this(tr("Blank Layer"), null);
     71        initializeImages();
     72        mv = Main.map.mapView;
     73    }
     74
     75    public WMSLayer(String name, String baseURL) {
     76        super(name);
     77        background = true; /* set global background variable */
     78        initializeImages();
     79        this.baseURL = baseURL;
     80        mv = Main.map.mapView;
     81        getPPD();
     82
     83        executor = Executors.newFixedThreadPool(3);
     84    }
     85
     86    public void getPPD(){
     87        pixelPerDegree = mv.getWidth() / (bounds().max.lon() - bounds().min.lon());
     88    }
     89
     90    public void initializeImages() {
     91        images = new GeorefImage[dax][day];
     92        for(int x = 0; x<dax; ++x)
     93            for(int y = 0; y<day; ++y)
     94                images[x][y]= new GeorefImage(false);
     95    }
     96
     97    @Override public Icon getIcon() {
     98        return icon;
     99    }
     100
     101    public String scale(){
     102        LatLon ll1 = mv.getLatLon(0,0);
     103        LatLon ll2 = mv.getLatLon(100,0);
     104        double dist = ll1.greatCircleDistance(ll2);
     105        return dist > 1000 ? (Math.round(dist/100)/10.0)+" km" : Math.round(dist*10)/10+" m";
     106    }
     107
     108    @Override public String getToolTipText() {
     109        if(startstop.isSelected())
     110            return tr("WMS layer ({0}), automatically downloading in zoom {1}", name, resolution);
     111        else
     112            return tr("WMS layer ({0}), downloading in zoom {1}", name, resolution);
     113    }
     114
     115    @Override public boolean isMergable(Layer other) {
     116        return false;
     117    }
     118
     119    @Override public void mergeFrom(Layer from) {
     120    }
     121
     122    private Bounds XYtoBounds (int x, int y) {
     123        return new Bounds(
     124            new LatLon( x * ImageSize / pixelPerDegree,
     125                         y * ImageSize / pixelPerDegree),
     126            new LatLon((x + 1) *  ImageSize / pixelPerDegree,
     127                       (y + 1) * ImageSize / pixelPerDegree));
     128    }
     129
     130    private int modulo (int a, int b) {
     131      if(a%b>=0)return a%b;
     132      else return a%b+b;
     133    }
     134
     135    protected Bounds bounds(){
     136        return new Bounds(
     137            mv.getLatLon(0, mv.getHeight()),
     138            mv.getLatLon(mv.getWidth(), 0));
     139    }
     140
     141    @Override public void paint(Graphics g, final MapView mv) {
     142        if(baseURL == null) return;
     143
     144        if( !startstop.isSelected() || (pixelPerDegree / (mv.getWidth() / (bounds().max.lon() - bounds().min.lon())) > minZoom) ){ //don't download when it's too outzoomed
     145            for(int x = 0; x<dax; ++x)
     146                for(int y = 0; y<day; ++y)
     147                    images[modulo(x,dax)][modulo(y,day)].paint(g, mv, dx, dy);
     148        } else
     149            downloadAndPaintVisible(g, mv);
     150    }
     151
     152    public void displace(double dx, double dy) {
     153        this.dx += dx;
     154        this.dy += dy;
     155    }
     156
     157    protected void downloadAndPaintVisible(Graphics g, final MapView mv){
     158        int bminx= (int)Math.floor ((bounds().min.lat() * pixelPerDegree ) / ImageSize );
     159        int bminy= (int)Math.floor ((bounds().min.lon() * pixelPerDegree ) / ImageSize );
     160        int bmaxx= (int)Math.ceil  ((bounds().max.lat() * pixelPerDegree ) / ImageSize );
     161        int bmaxy= (int)Math.ceil  ((bounds().max.lon() * pixelPerDegree ) / ImageSize );
     162
     163        if((bmaxx - bminx > dax) || (bmaxy - bminy > day)){
     164            JOptionPane.showMessageDialog(Main.parent, tr("The requested area is too big. Please zoom in a little, or change resolution"));
     165            return;
     166        }
     167
     168        for(int x = bminx; x<bmaxx; ++x)
     169            for(int y = bminy; y<bmaxy; ++y){
     170                GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
     171                if(!img.paint(g, mv, dx, dy) && !img.downloadingStarted){
     172                    img.downloadingStarted = true;
     173                    img.image = null;
     174                    Grabber gr = WMSPlugin.getGrabber(baseURL, XYtoBounds(x,y), Main.main.proj, pixelPerDegree, img, mv, this);
     175                    executor.submit(gr);
     176            }
     177        }
     178    }
     179
     180    @Override public void visitBoundingBox(BoundingXYVisitor v) {
     181        for(int x = 0; x<dax; ++x)
     182            for(int y = 0; y<day; ++y)
     183                if(images[x][y].image!=null){
     184                    v.visit(images[x][y].min);
     185                    v.visit(images[x][y].max);
     186                }
     187    }
     188
     189    @Override public Object getInfoComponent() {
     190        return getToolTipText();
     191    }
     192
     193    @Override public Component[] getMenuEntries() {
     194        return new Component[]{
     195                new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
     196                new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
     197                new JSeparator(),
     198                new JMenuItem(new LoadWmsAction()),
     199                new JMenuItem(new SaveWmsAction()),
     200                new JSeparator(),
     201                startstop,
     202                new JMenuItem(new changeResolutionAction()),
     203                new JMenuItem(new downloadAction()),
     204                new JSeparator(),
     205                new JMenuItem(new LayerListPopup.InfoAction(this))
     206        };
     207    }
     208
     209    public GeorefImage findImage(EastNorth eastNorth) {
     210        for(int x = 0; x<dax; ++x)
     211            for(int y = 0; y<day; ++y)
     212                    if(images[x][y].image!=null && images[x][y].min!=null && images[x][y].max!=null)
     213                        if(images[x][y].contains(eastNorth, dx, dy))
     214                            return images[x][y];
     215        return null;
     216    }
     217
     218    public class downloadAction extends AbstractAction {
     219        public downloadAction() {
     220            super(tr("Download visible tiles"));
     221        }
     222        public void actionPerformed(ActionEvent ev) {
     223            downloadAndPaintVisible(mv.getGraphics(), mv);
     224        }
     225    }
     226
     227    public class changeResolutionAction extends AbstractAction {
     228        public changeResolutionAction() {
     229            super(tr("Change resolution"));
     230        }
     231        public void actionPerformed(ActionEvent ev) {
     232            initializeImages();
     233            resolution = scale();
     234            getPPD();
     235            mv.repaint();
     236        }
     237    }
     238
     239    public class SaveWmsAction extends AbstractAction {
     240        public SaveWmsAction() {
     241            super(tr("Save WMS layer to file"), ImageProvider.get("save"));
     242        }
     243        public void actionPerformed(ActionEvent ev) {
     244            File f = openFileDialog(false);
     245            try
     246            {
     247                FileOutputStream fos = new FileOutputStream(f);
     248                ObjectOutputStream oos = new ObjectOutputStream(fos);
     249                oos.writeInt(serializeFormatVersion);
     250                oos.writeInt(dax);
     251                oos.writeInt(day);
     252                oos.writeInt(ImageSize);
     253                oos.writeDouble(pixelPerDegree);
     254                oos.writeObject(name);
     255                oos.writeObject(baseURL);
     256                oos.writeObject(images);
     257                oos.close();
     258                fos.close();
     259            }
     260            catch (Exception ex) {
     261                ex.printStackTrace(System.out);
     262            }
     263        }
     264    }
     265
     266    public class LoadWmsAction extends AbstractAction {
     267        public LoadWmsAction() {
     268            super(tr("Load WMS layer from file"), ImageProvider.get("load"));
     269        }
     270        public void actionPerformed(ActionEvent ev) {
     271            File f = openFileDialog(true);
     272            if (f == null) return;
     273            try
     274            {
     275                FileInputStream fis = new FileInputStream(f);
     276                ObjectInputStream ois = new ObjectInputStream(fis);
     277                int sfv = ois.readInt();
     278                if (sfv != serializeFormatVersion) {
     279                    JOptionPane.showMessageDialog(Main.parent,
     280                        tr("Unsupported WMS file version; found {0}, expected {1}", sfv, serializeFormatVersion),
     281                        tr("File Format Error"),
     282                        JOptionPane.ERROR_MESSAGE);
     283                    return;
     284                }
     285                startstop.setSelected(false);
     286                dax = ois.readInt();
     287                day = ois.readInt();
     288                ImageSize = ois.readInt();
     289                pixelPerDegree = ois.readDouble();
     290                name = (String) ois.readObject();
     291                baseURL = (String) ois.readObject();
     292                images = (GeorefImage[][])ois.readObject();
     293                ois.close();
     294                fis.close();
     295                mv.repaint();
     296            }
     297            catch (Exception ex) {
     298                // FIXME be more specific
     299                ex.printStackTrace(System.out);
     300                JOptionPane.showMessageDialog(Main.parent,
     301                    tr("Error loading file"),
     302                    tr("Error"),
     303                    JOptionPane.ERROR_MESSAGE);
     304                return;
     305            }
     306        }
     307    }
     308
     309    protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple) {
     310        String curDir = Main.pref.get("lastDirectory");
     311        if (curDir.equals(""))
     312            curDir = ".";
     313        JFileChooser fc = new JFileChooser(new File(curDir));
     314        fc.setMultiSelectionEnabled(multiple);
     315        for (int i = 0; i < ExtensionFileFilter.filters.length; ++i)
     316            fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]);
     317        fc.setAcceptAllFileFilterUsed(true);
     318
     319        int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
     320        if (answer != JFileChooser.APPROVE_OPTION)
     321            return null;
     322
     323        if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
     324            Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
     325
     326        if (!open) {
     327            File file = fc.getSelectedFile();
     328            if (file == null || (file.exists() && JOptionPane.YES_OPTION !=
     329                JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION)))
     330                return null;
     331        }
     332
     333        return fc;
     334    }
     335
     336    public static File openFileDialog(boolean open) {
     337        JFileChooser fc = createAndOpenFileChooser(open, false);
     338        if (fc == null)
     339            return null;
     340
     341        File file = fc.getSelectedFile();
     342
     343        String fn = file.getPath();
     344        if (fn.indexOf('.') == -1) {
     345            FileFilter ff = fc.getFileFilter();
     346            if (ff instanceof ExtensionFileFilter)
     347                fn = "." + ((ExtensionFileFilter)ff).defaultExtension;
     348            else
     349                fn += ".osm";
     350            file = new File(fn);
     351        }
     352        return file;
     353    }
    354354}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java

    r12472 r12778  
    3939public class WMSPlugin extends Plugin {
    4040
    41         WMSLayer wmsLayer;
    42         static JMenu wmsJMenu;
    43 
    44         static ArrayList<WMSInfo> wmsList = new ArrayList<WMSInfo>();
    45         static TreeMap<String,String> wmsListDefault = new TreeMap<String,String>();
    46 
    47         // remember state of menu item to restore on changed preferences
    48         static private boolean menuEnabled = false;
    49        
    50         public WMSPlugin() {
    51                 try
    52                 {
    53                         copy("/resources/ymap.html", "ymap.html");
    54                 }
    55                 catch(IOException e) {
    56                         e.printStackTrace();
    57                 }
    58                 refreshMenu();
    59         }
    60 
    61         // this parses the preferences settings. preferences for the wms plugin have to
    62         // look like this:
    63         // wmsplugin.1.name=Landsat
    64         // wmsplugin.1.url=http://and.so.on/
    65        
    66         public void copy(String from, String to) throws FileNotFoundException, IOException
    67         {
    68                 File pluginDir = new File(Main.pref.getPreferencesDir() + "plugins/wmsplugin/");
    69                 if (!pluginDir.exists())
    70                         pluginDir.mkdirs();
    71                 FileOutputStream out = new FileOutputStream(Main.pref.getPreferencesDir() + "plugins/wmsplugin/" + to);
    72                 InputStream in = WMSPlugin.class.getResourceAsStream(from);
    73                 byte[] buffer = new byte[8192];
    74                 for(int len = in.read(buffer); len > 0; len = in.read(buffer))
    75                         out.write(buffer, 0, len);
    76                 in.close();
    77                 out.close();
    78         }
    79 
    80        
    81         public static void refreshMenu() {
    82                 wmsList.clear();
    83                 Map<String,String> prefs = Main.pref.getAllPrefix("wmsplugin.url.");
    84                
    85                 TreeSet<String> keys = new TreeSet<String>(prefs.keySet());
    86                 int prefid = 0;
    87                 String name = null;
    88                 String url = null;
    89                 int lastid = -1;
    90                 for (String key : keys) {
    91                         String[] elements = key.split("\\.");
    92                         if (elements.length != 4) continue;
    93                         try {
    94                                 prefid = Integer.parseInt(elements[2]);
    95                         } catch(NumberFormatException e) {
    96                                 continue;
    97                         }
    98                         if (prefid != lastid) {
    99                                 name = url = null; lastid = prefid;
    100                         }
    101                         if (elements[3].equals("name"))
    102                                 name = prefs.get(key);
    103                         else if (elements[3].equals("url"))
    104                                 url = prefs.get(key);
    105                         if (name != null && url != null)
    106                                 wmsList.add(new WMSInfo(name, url, prefid));
    107                 }
    108                 String source = "http://svn.openstreetmap.org/applications/editors/josm/plugins/wmsplugin/sources.cfg";
    109                 try
    110                 {
    111                         MirroredInputStream s = new MirroredInputStream(source,
    112                         Main.pref.getPreferencesDir() + "plugins/wmsplugin/", -1);
    113                         InputStreamReader r;
    114                         try
    115                         {
    116                                 r = new InputStreamReader(s, "UTF-8");
    117                         }
    118                         catch (UnsupportedEncodingException e)
    119                         {
    120                                 r = new InputStreamReader(s);
    121                         }
    122                         BufferedReader reader = new BufferedReader(r);
    123                         String line;
    124                         while((line = reader.readLine()) != null)
    125                         {
    126                                 String val[] = line.split(";");
    127                                 if(!line.startsWith("#") && val.length == 3)
    128                                         setDefault("true".equals(val[0]), tr(val[1]), val[2]);
    129                         }
    130                 }
    131                 catch (IOException e)
    132                 {
    133                 }
    134 
    135                 Collections.sort(wmsList);
    136                 MainMenu menu = Main.main.menu;
    137 
    138                 if (wmsJMenu == null) {
    139                         wmsJMenu = new JMenu(tr("WMS"));
    140                         menu.add(wmsJMenu, KeyEvent.VK_W, "wms");
    141                         menu.add(wmsJMenu, 5);
    142                 } else {
    143                         wmsJMenu.removeAll();
    144                 }
    145                
    146                 // for each configured WMSInfo, add a menu entry.
    147                 for (final WMSInfo u : wmsList) {
    148                         wmsJMenu.add(new JMenuItem(new WMSDownloadAction(u)));
    149                 }
    150                 wmsJMenu.addSeparator();
    151                 wmsJMenu.add(new JMenuItem(new Map_Rectifier_WMSmenuAction()));
    152                
    153                 wmsJMenu.addSeparator();
    154                 wmsJMenu.add(new JMenuItem(new 
    155                                 JosmAction(tr("Blank Layer"), "blankmenu", tr("Open a blank WMS layer to load data from a file"), null, false) {
    156                         public void actionPerformed(ActionEvent ev) {
    157                                 Main.main.addLayer(new WMSLayer());
    158                         }
    159                 }));
    160                 wmsJMenu.addSeparator();
    161                 wmsJMenu.add(new JMenuItem(new Help_WMSmenuAction()));
    162                 setEnabledAll(menuEnabled);
    163         }
    164 
    165         /* add a default entry in case the URL does not yet exist */
    166         private static void setDefault(Boolean force, String name, String url)
    167         {
    168                 String testurl = url.replaceAll("=", "_");
    169                 wmsListDefault.put(name, url);
    170 
    171                 if(force && !Main.pref.getBoolean("wmsplugin.default."+testurl))
    172                 {
    173                         Main.pref.put("wmsplugin.default."+testurl, true);
    174                         int id = -1;
    175                         for(WMSInfo i : wmsList)
    176                         {
    177                                 if(url.equals(i.url))
    178                                         return;
    179                                 if(i.prefid > id)
    180                                         id = i.prefid;
    181                         }
    182                         WMSInfo newinfo = new WMSInfo(name, url, id+1);
    183                         newinfo.save();
    184                         wmsList.add(newinfo);
    185                 }
    186         }
    187 
    188         public static Grabber getGrabber(String _baseURL, Bounds _b, Projection _proj,
    189                                  double _pixelPerDegree, GeorefImage _image, MapView _mv, WMSLayer _layer){
    190                 if(_baseURL.startsWith("yahoo://"))
    191                         return new YAHOOGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer);
    192                 else
    193                         return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer);
    194                 // OSBGrabber should be rewrite for thread support first
    195                 //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){
    196                 //      return new OSGBGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
    197                 //} else {
    198                 //      return new WMSGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
    199                 //}
    200         }
    201        
    202         private static void setEnabledAll(boolean isEnabled) {
    203                 for(int i=0; i < wmsJMenu.getItemCount(); i++) {
    204                         JMenuItem item = wmsJMenu.getItem(i);
    205                        
    206                         if(item != null) item.setEnabled(isEnabled);
    207                 }
     41    WMSLayer wmsLayer;
     42    static JMenu wmsJMenu;
     43
     44    static ArrayList<WMSInfo> wmsList = new ArrayList<WMSInfo>();
     45    static TreeMap<String,String> wmsListDefault = new TreeMap<String,String>();
     46
     47    // remember state of menu item to restore on changed preferences
     48    static private boolean menuEnabled = false;
     49
     50    public WMSPlugin() {
     51        try
     52        {
     53            copy("/resources/ymap.html", "ymap.html");
     54        }
     55        catch(IOException e) {
     56            e.printStackTrace();
     57        }
     58        refreshMenu();
     59    }
     60
     61    // this parses the preferences settings. preferences for the wms plugin have to
     62    // look like this:
     63    // wmsplugin.1.name=Landsat
     64    // wmsplugin.1.url=http://and.so.on/
     65
     66    public void copy(String from, String to) throws FileNotFoundException, IOException
     67    {
     68        File pluginDir = new File(Main.pref.getPreferencesDir() + "plugins/wmsplugin/");
     69        if (!pluginDir.exists())
     70            pluginDir.mkdirs();
     71        FileOutputStream out = new FileOutputStream(Main.pref.getPreferencesDir() + "plugins/wmsplugin/" + to);
     72        InputStream in = WMSPlugin.class.getResourceAsStream(from);
     73        byte[] buffer = new byte[8192];
     74        for(int len = in.read(buffer); len > 0; len = in.read(buffer))
     75            out.write(buffer, 0, len);
     76        in.close();
     77        out.close();
     78    }
     79
     80
     81    public static void refreshMenu() {
     82        wmsList.clear();
     83        Map<String,String> prefs = Main.pref.getAllPrefix("wmsplugin.url.");
     84
     85        TreeSet<String> keys = new TreeSet<String>(prefs.keySet());
     86        int prefid = 0;
     87        String name = null;
     88        String url = null;
     89        int lastid = -1;
     90        for (String key : keys) {
     91            String[] elements = key.split("\\.");
     92            if (elements.length != 4) continue;
     93            try {
     94                prefid = Integer.parseInt(elements[2]);
     95            } catch(NumberFormatException e) {
     96                continue;
     97            }
     98            if (prefid != lastid) {
     99                name = url = null; lastid = prefid;
     100            }
     101            if (elements[3].equals("name"))
     102                name = prefs.get(key);
     103            else if (elements[3].equals("url"))
     104                url = prefs.get(key);
     105            if (name != null && url != null)
     106                wmsList.add(new WMSInfo(name, url, prefid));
     107        }
     108        String source = "http://svn.openstreetmap.org/applications/editors/josm/plugins/wmsplugin/sources.cfg";
     109        try
     110        {
     111            MirroredInputStream s = new MirroredInputStream(source,
     112            Main.pref.getPreferencesDir() + "plugins/wmsplugin/", -1);
     113            InputStreamReader r;
     114            try
     115            {
     116                r = new InputStreamReader(s, "UTF-8");
     117            }
     118            catch (UnsupportedEncodingException e)
     119            {
     120                r = new InputStreamReader(s);
     121            }
     122            BufferedReader reader = new BufferedReader(r);
     123            String line;
     124            while((line = reader.readLine()) != null)
     125            {
     126                String val[] = line.split(";");
     127                if(!line.startsWith("#") && val.length == 3)
     128                    setDefault("true".equals(val[0]), tr(val[1]), val[2]);
     129            }
     130        }
     131        catch (IOException e)
     132        {
     133        }
     134
     135        Collections.sort(wmsList);
     136        MainMenu menu = Main.main.menu;
     137
     138        if (wmsJMenu == null) {
     139            wmsJMenu = new JMenu(tr("WMS"));
     140            menu.add(wmsJMenu, KeyEvent.VK_W, "wms");
     141            menu.add(wmsJMenu, 5);
     142        } else {
     143            wmsJMenu.removeAll();
     144        }
     145
     146        // for each configured WMSInfo, add a menu entry.
     147        for (final WMSInfo u : wmsList) {
     148            wmsJMenu.add(new JMenuItem(new WMSDownloadAction(u)));
     149        }
     150        wmsJMenu.addSeparator();
     151        wmsJMenu.add(new JMenuItem(new Map_Rectifier_WMSmenuAction()));
     152
     153        wmsJMenu.addSeparator();
     154        wmsJMenu.add(new JMenuItem(new
     155                JosmAction(tr("Blank Layer"), "blankmenu", tr("Open a blank WMS layer to load data from a file"), null, false) {
     156            public void actionPerformed(ActionEvent ev) {
     157                Main.main.addLayer(new WMSLayer());
     158            }
     159        }));
     160        wmsJMenu.addSeparator();
     161        wmsJMenu.add(new JMenuItem(new Help_WMSmenuAction()));
     162        setEnabledAll(menuEnabled);
     163    }
     164
     165    /* add a default entry in case the URL does not yet exist */
     166    private static void setDefault(Boolean force, String name, String url)
     167    {
     168        String testurl = url.replaceAll("=", "_");
     169        wmsListDefault.put(name, url);
     170
     171        if(force && !Main.pref.getBoolean("wmsplugin.default."+testurl))
     172        {
     173            Main.pref.put("wmsplugin.default."+testurl, true);
     174            int id = -1;
     175            for(WMSInfo i : wmsList)
     176            {
     177                if(url.equals(i.url))
     178                    return;
     179                if(i.prefid > id)
     180                    id = i.prefid;
     181            }
     182            WMSInfo newinfo = new WMSInfo(name, url, id+1);
     183            newinfo.save();
     184            wmsList.add(newinfo);
     185        }
     186    }
     187
     188    public static Grabber getGrabber(String _baseURL, Bounds _b, Projection _proj,
     189                     double _pixelPerDegree, GeorefImage _image, MapView _mv, WMSLayer _layer){
     190        if(_baseURL.startsWith("yahoo://"))
     191            return new YAHOOGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer);
     192        else
     193            return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer);
     194        // OSBGrabber should be rewrite for thread support first
     195        //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){
     196        //  return new OSGBGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
     197        //} else {
     198        //  return new WMSGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
     199        //}
     200    }
     201
     202    private static void setEnabledAll(boolean isEnabled) {
     203        for(int i=0; i < wmsJMenu.getItemCount(); i++) {
     204            JMenuItem item = wmsJMenu.getItem(i);
     205
     206            if(item != null) item.setEnabled(isEnabled);
     207        }
    208208               menuEnabled = isEnabled;
    209         }
    210        
    211         public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    212                 if (oldFrame==null && newFrame!=null) { 
    213                         setEnabledAll(true);
    214                         Main.map.addMapMode(new IconToggleButton
    215                                                 (new WMSAdjustAction(Main.map)));
    216                 } else if (oldFrame!=null && newFrame==null ) {
    217                         setEnabledAll(false);
    218                 }
    219         }
    220        
    221         public PreferenceSetting getPreferenceSetting() {
    222                 return new WMSPreferenceEditor();
    223         }
     209    }
     210
     211    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
     212        if (oldFrame==null && newFrame!=null) {
     213            setEnabledAll(true);
     214            Main.map.addMapMode(new IconToggleButton
     215                        (new WMSAdjustAction(Main.map)));
     216        } else if (oldFrame!=null && newFrame==null ) {
     217            setEnabledAll(false);
     218        }
     219    }
     220
     221    public PreferenceSetting getPreferenceSetting() {
     222        return new WMSPreferenceEditor();
     223    }
    224224}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java

    r12588 r12778  
    2727
    2828public class WMSPreferenceEditor implements PreferenceSetting {
    29        
    30         private Map<String,String> orig;
    31         private DefaultTableModel model;
    32         private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>();
    3329
    34         public void addGui(final PreferenceDialog gui) {
    35                 JPanel p = gui.createPreferenceTab("wms", tr("WMS Plugin Preferences"), tr("Modify list of WMS servers displayed in the WMS plugin menu"));
    36                
    37                 model = new DefaultTableModel(new String[]{tr("Menu Name"), tr("WMS URL")}, 0);
    38                 final JTable list = new JTable(model);
    39                 JScrollPane scroll = new JScrollPane(list);
    40                 p.add(scroll, GBC.eol().fill(GBC.BOTH));
    41                 scroll.setPreferredSize(new Dimension(200,200));
    42                
    43                 for (WMSInfo i : WMSPlugin.wmsList) {
    44                         oldValues.put(i.prefid, i);
    45                         model.addRow(new String[]{i.name, i.url});
    46                 }
     30    private Map<String,String> orig;
     31    private DefaultTableModel model;
     32    private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>();
    4733
    48                 final DefaultTableModel modeldef = new DefaultTableModel(
    49                 new String[]{tr("Menu Name (Default)"), tr("WMS URL (Default)")}, 0);
    50                 final JTable listdef = new JTable(modeldef){
    51                         public boolean isCellEditable(int row,int column){return false;}
    52                 };;
    53                 JScrollPane scrolldef = new JScrollPane(listdef);
    54                 p.add(scrolldef, GBC.eol().insets(0,5,0,0).fill(GBC.BOTH));
    55                 scrolldef.setPreferredSize(new Dimension(200,200));
     34    public void addGui(final PreferenceDialog gui) {
     35        JPanel p = gui.createPreferenceTab("wms", tr("WMS Plugin Preferences"), tr("Modify list of WMS servers displayed in the WMS plugin menu"));
    5636
    57                 for (Map.Entry<String,String> i : WMSPlugin.wmsListDefault.entrySet()) {
    58                         modeldef.addRow(new String[]{i.getKey(), i.getValue()});
    59                 }
     37        model = new DefaultTableModel(new String[]{tr("Menu Name"), tr("WMS URL")}, 0);
     38        final JTable list = new JTable(model);
     39        JScrollPane scroll = new JScrollPane(list);
     40        p.add(scroll, GBC.eol().fill(GBC.BOTH));
     41        scroll.setPreferredSize(new Dimension(200,200));
    6042
    61                 JButton add = new JButton(tr("Add"));
    62                 p.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
    63                 p.add(add, GBC.std().insets(0,5,0,0));
    64                 add.addActionListener(new ActionListener(){
    65                         public void actionPerformed(ActionEvent e) {
    66                                 JPanel p = new JPanel(new GridBagLayout());
    67                                 p.add(new JLabel(tr("Menu Name")), GBC.std().insets(0,0,5,0));
    68                                 JTextField key = new JTextField(10);
    69                                 JTextField value = new JTextField(10);
    70                                 p.add(key, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL));
    71                                 p.add(new JLabel(tr("WMS URL")), GBC.std().insets(0,0,5,0));
    72                                 p.add(value, GBC.eol().insets(5,0,0,0).fill(GBC.HORIZONTAL));
    73                                 int answer = JOptionPane.showConfirmDialog(gui, p, tr("Enter a menu name and WMS URL"), JOptionPane.OK_CANCEL_OPTION);
    74                                 if (answer == JOptionPane.OK_OPTION) {
    75                                         model.addRow(new String[]{key.getText(), value.getText()});
    76                                 }
    77                         }
    78                 });
     43        for (WMSInfo i : WMSPlugin.wmsList) {
     44            oldValues.put(i.prefid, i);
     45            model.addRow(new String[]{i.name, i.url});
     46        }
    7947
    80                 JButton delete = new JButton(tr("Delete"));
    81                 p.add(delete, GBC.std().insets(0,5,0,0));
    82                 delete.addActionListener(new ActionListener(){
    83                         public void actionPerformed(ActionEvent e) {
    84                                 if (list.getSelectedRow() == -1)
    85                                         JOptionPane.showMessageDialog(gui, tr("Please select the row to delete."));
    86                                 else
    87                                 {
    88                                         Integer i;
    89                                         while ((i = list.getSelectedRow()) != -1)
    90                                                 model.removeRow(i);
    91                                 }
    92                         }
    93                 });
    94                
    95                 JButton copy = new JButton(tr("Copy Default"));
    96                 p.add(copy, GBC.std().insets(0,5,0,0));
    97                 copy.addActionListener(new ActionListener(){
    98                         public void actionPerformed(ActionEvent e) {
    99                                 Integer line = listdef.getSelectedRow();
    100                                 if (line == -1)
    101                                         JOptionPane.showMessageDialog(gui, tr("Please select the row to copy."));
    102                                 else
    103                                 {
    104                                         model.addRow(new String[]{modeldef.getValueAt(line, 0).toString(),
    105                                         modeldef.getValueAt(line, 1).toString()});
    106                                 }
    107                         }
    108                 });
    109         }
    110        
    111         public boolean ok() {
    112                 boolean change = false;
    113                 for (int i = 0; i < model.getRowCount(); ++i) {
    114                         String name = model.getValueAt(i,0).toString();
    115                         String url = model.getValueAt(i,1).toString();
     48        final DefaultTableModel modeldef = new DefaultTableModel(
     49        new String[]{tr("Menu Name (Default)"), tr("WMS URL (Default)")}, 0);
     50        final JTable listdef = new JTable(modeldef){
     51            public boolean isCellEditable(int row,int column){return false;}
     52        };;
     53        JScrollPane scrolldef = new JScrollPane(listdef);
     54        p.add(scrolldef, GBC.eol().insets(0,5,0,0).fill(GBC.BOTH));
     55        scrolldef.setPreferredSize(new Dimension(200,200));
    11656
    117                         WMSInfo origValue = oldValues.get(i);
    118                         if (origValue == null)
    119                         {
    120                                 new WMSInfo(name, url, i).save();
    121                                 change = true;
    122                         }
    123                         else
    124                         {
    125                                 if (!origValue.name.equals(name) || !origValue.url.equals(url))
    126                                 {
    127                                         origValue.name = name;
    128                                         origValue.url = url;
    129                                         origValue.save();
    130                                         change = true;
    131                                 }
    132                                 oldValues.remove(i);
    133                         }
    134                 }
    135                
    136                 // using null values instead of empty string really deletes
    137                 // the preferences entry
    138                 for (WMSInfo i : oldValues.values())
    139                 {
    140                         i.url = null;
    141                         i.name = null;
    142                         i.save();
    143                         change = true;
    144                 }
     57        for (Map.Entry<String,String> i : WMSPlugin.wmsListDefault.entrySet()) {
     58            modeldef.addRow(new String[]{i.getKey(), i.getValue()});
     59        }
    14560
    146                 if (change) WMSPlugin.refreshMenu();
    147                 return false;
    148         }
    149        
     61        JButton add = new JButton(tr("Add"));
     62        p.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
     63        p.add(add, GBC.std().insets(0,5,0,0));
     64        add.addActionListener(new ActionListener(){
     65            public void actionPerformed(ActionEvent e) {
     66                JPanel p = new JPanel(new GridBagLayout());
     67                p.add(new JLabel(tr("Menu Name")), GBC.std().insets(0,0,5,0));
     68                JTextField key = new JTextField(10);
     69                JTextField value = new JTextField(10);
     70                p.add(key, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL));
     71                p.add(new JLabel(tr("WMS URL")), GBC.std().insets(0,0,5,0));
     72                p.add(value, GBC.eol().insets(5,0,0,0).fill(GBC.HORIZONTAL));
     73                int answer = JOptionPane.showConfirmDialog(gui, p, tr("Enter a menu name and WMS URL"), JOptionPane.OK_CANCEL_OPTION);
     74                if (answer == JOptionPane.OK_OPTION) {
     75                    model.addRow(new String[]{key.getText(), value.getText()});
     76                }
     77            }
     78        });
     79
     80        JButton delete = new JButton(tr("Delete"));
     81        p.add(delete, GBC.std().insets(0,5,0,0));
     82        delete.addActionListener(new ActionListener(){
     83            public void actionPerformed(ActionEvent e) {
     84                if (list.getSelectedRow() == -1)
     85                    JOptionPane.showMessageDialog(gui, tr("Please select the row to delete."));
     86                else
     87                {
     88                    Integer i;
     89                    while ((i = list.getSelectedRow()) != -1)
     90                        model.removeRow(i);
     91                }
     92            }
     93        });
     94
     95        JButton copy = new JButton(tr("Copy Default"));
     96        p.add(copy, GBC.std().insets(0,5,0,0));
     97        copy.addActionListener(new ActionListener(){
     98            public void actionPerformed(ActionEvent e) {
     99                Integer line = listdef.getSelectedRow();
     100                if (line == -1)
     101                    JOptionPane.showMessageDialog(gui, tr("Please select the row to copy."));
     102                else
     103                {
     104                    model.addRow(new String[]{modeldef.getValueAt(line, 0).toString(),
     105                    modeldef.getValueAt(line, 1).toString()});
     106                }
     107            }
     108        });
     109    }
     110
     111    public boolean ok() {
     112        boolean change = false;
     113        for (int i = 0; i < model.getRowCount(); ++i) {
     114            String name = model.getValueAt(i,0).toString();
     115            String url = model.getValueAt(i,1).toString();
     116
     117            WMSInfo origValue = oldValues.get(i);
     118            if (origValue == null)
     119            {
     120                new WMSInfo(name, url, i).save();
     121                change = true;
     122            }
     123            else
     124            {
     125                if (!origValue.name.equals(name) || !origValue.url.equals(url))
     126                {
     127                    origValue.name = name;
     128                    origValue.url = url;
     129                    origValue.save();
     130                    change = true;
     131                }
     132                oldValues.remove(i);
     133            }
     134        }
     135
     136        // using null values instead of empty string really deletes
     137        // the preferences entry
     138        for (WMSInfo i : oldValues.values())
     139        {
     140            i.url = null;
     141            i.name = null;
     142            i.save();
     143            change = true;
     144        }
     145
     146        if (change) WMSPlugin.refreshMenu();
     147        return false;
     148    }
     149
    150150    /**
    151151     * Updates a server URL in the preferences dialog. Used by other plugins.
    152      * 
     152     *
    153153     * @param server The server name
    154154     * @param url The server URL
     
    156156    public void setServerUrl(String server, String url)
    157157    {
    158         for (int i = 0; i < model.getRowCount(); i++) 
     158        for (int i = 0; i < model.getRowCount(); i++)
    159159        {
    160160            if( server.equals(model.getValueAt(i,0).toString()) )
     
    175175    public String getServerUrl(String server)
    176176    {
    177         for (int i = 0; i < model.getRowCount(); i++) 
     177        for (int i = 0; i < model.getRowCount(); i++)
    178178        {
    179179            if( server.equals(model.getValueAt(i,0).toString()) )
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/YAHOOGrabber.java

    r11400 r12778  
    2020
    2121public class YAHOOGrabber extends WMSGrabber{
    22         protected String browserCmd;
     22    protected String browserCmd;
    2323
    24         YAHOOGrabber(String baseURL, Bounds b, Projection proj,
    25                         double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
    26                 super("file:///" + Main.pref.getPreferencesDir() + "plugins/wmsplugin/ymap.html?"
     24    YAHOOGrabber(String baseURL, Bounds b, Projection proj,
     25            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
     26        super("file:///" + Main.pref.getPreferencesDir() + "plugins/wmsplugin/ymap.html?"
    2727//                + "request=getmap&format=image/jpeg"
    28                 , b, proj, pixelPerDegree, image, mv, layer);
    29                 this.browserCmd = baseURL.replaceFirst("yahoo://", "");
    30         }
     28        , b, proj, pixelPerDegree, image, mv, layer);
     29        this.browserCmd = baseURL.replaceFirst("yahoo://", "");
     30    }
    3131
    32         protected BufferedImage grab(URL url) throws IOException {
    33                 ArrayList<String> cmdParams = new ArrayList<String>();
    34                 String urlstring = url.toExternalForm();
    35                 // work around a problem in URL removing 2 slashes
    36                 if(!urlstring.startsWith("file:///"))
    37                         urlstring = urlstring.replaceFirst("file:", "file://");
    38                 StringTokenizer st = new StringTokenizer(MessageFormat.format(browserCmd, urlstring));
    39                 while( st.hasMoreTokens() )
    40                         cmdParams.add(st.nextToken());
     32    protected BufferedImage grab(URL url) throws IOException {
     33        ArrayList<String> cmdParams = new ArrayList<String>();
     34        String urlstring = url.toExternalForm();
     35        // work around a problem in URL removing 2 slashes
     36        if(!urlstring.startsWith("file:///"))
     37            urlstring = urlstring.replaceFirst("file:", "file://");
     38        StringTokenizer st = new StringTokenizer(MessageFormat.format(browserCmd, urlstring));
     39        while( st.hasMoreTokens() )
     40            cmdParams.add(st.nextToken());
    4141
    42                 System.out.println("WMS::Browsing YAHOO: " + cmdParams);
    43                 ProcessBuilder builder = new ProcessBuilder( cmdParams);
     42        System.out.println("WMS::Browsing YAHOO: " + cmdParams);
     43        ProcessBuilder builder = new ProcessBuilder( cmdParams);
    4444
    45                 Process browser;
    46                 try {
    47                         browser = builder.start();
    48                 } catch(IOException ioe) {
    49                         throw new IOException( "Could not start browser. Please check that the executable path is correct.\n" + ioe.getMessage() );
    50                 }
     45        Process browser;
     46        try {
     47            browser = builder.start();
     48        } catch(IOException ioe) {
     49            throw new IOException( "Could not start browser. Please check that the executable path is correct.\n" + ioe.getMessage() );
     50        }
    5151
    52                 return ImageIO.read(browser.getInputStream());
    53         }
     52        return ImageIO.read(browser.getInputStream());
     53    }
    5454}
Note: See TracChangeset for help on using the changeset viewer.