Changeset 10382 in osm for applications


Ignore:
Timestamp:
2008-09-02T11:23:39+02:00 (16 years ago)
Author:
petrdlouhy
Message:

Added automatic tiles downloading and Yahoo support.

Location:
applications/editors/josm/plugins/wmsplugin
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/README

    r7270 r10382  
    1515some code from Jonathan Stott <jonathan@jstott.me.uk>, Gabriel Ebner
    1616<ge@gabrielebner.at> and Ulf Lamping <ulf.lamping@web.de>.
     17The automatic tiles downloading and Yahoo downloader made by Petr Dlouhý <petr.dlouhy@email.cz>
    1718
    1819This plugin is licensed under the GNU GPL v2 or later.
  • applications/editors/josm/plugins/wmsplugin/build.xml

    r8666 r10382  
    3333
    3434  <target name="dist" depends="compile">
     35    <copy todir="${plugin.build.dir}/resources">
     36      <fileset dir="resources"/>
     37    </copy>
    3538    <copy todir="build/images" >
    3639      <fileset dir="images" />
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java

    r6984 r10382  
    1515
    1616public class GeorefImage implements Serializable {
    17         public BufferedImage image;
     17        public BufferedImage image = null;
    1818        public EastNorth min, max;
     19        public boolean downloadingStarted;
    1920
    20         public GeorefImage(BufferedImage img, EastNorth min, EastNorth max) {
    21                 image = img;
    22                 this.min = min;
    23                 this.max = max;
     21        public GeorefImage(boolean downloadingStarted) {
     22                this.downloadingStarted = downloadingStarted;
    2423        }
    2524
     
    3433        }
    3534
    36         public void paint(Graphics g, NavigatableComponent nc) {
    37                 if (image == null || min == null || max == null) return;
     35        public boolean isVisible(NavigatableComponent nc) {
     36                Point minPt = nc.getPoint(min), maxPt = nc.getPoint(max);
     37                Graphics g = nc.getGraphics();
     38
     39                return (g.hitClip(minPt.x, maxPt.y,
     40                                maxPt.x - minPt.x, minPt.y - maxPt.y));
     41        }
     42
     43        public boolean paint(Graphics g, NavigatableComponent nc) {
     44                if (image == null || min == null || max == null) return false;
    3845
    3946                Point minPt = nc.getPoint(min), maxPt = nc.getPoint(max);
    4047
    41                 if (!g.hitClip(minPt.x, maxPt.y,
    42                                 maxPt.x - minPt.x, minPt.y - maxPt.y))
    43                         return;
     48                if(!isVisible(nc))
     49                        return false;
    4450
    4551                g.drawImage(image,
     
    4753                        0, 0, image.getWidth(), image.getHeight(), // src
    4854                        null);
     55
     56                return true;
    4957        }
    5058
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Grabber.java

    r6777 r10382  
    33import org.openstreetmap.josm.data.Bounds;
    44import org.openstreetmap.josm.data.projection.Projection;
     5import java.util.ArrayList;
     6import org.openstreetmap.josm.gui.MapView;
    57
    68public interface Grabber {
    7         public GeorefImage grab(Bounds bounds,
    8                 Projection proj, double pixelPerDegree)
    9                 throws IOException;
     9        public void start();
    1010}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/OSGBGrabber.java

    r6777 r10382  
     1/*
    12package wmsplugin;
    23
     
    6162        }
    6263}
     64*/
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSDownloadAction.java

    r8721 r10382  
    99import org.openstreetmap.josm.gui.MapView;
    1010import org.openstreetmap.josm.gui.layer.Layer;
     11import org.openstreetmap.josm.data.Bounds;
    1112
    1213public class WMSDownloadAction extends JosmAction {
     
    2223                System.out.println(info.url);
    2324               
    24                 DownloadWMSTask.download(getLayer(info));
     25                WMSLayer wmsLayer = getLayer(info);
     26                MapView mv = Main.map.mapView;
     27
     28                Bounds b = new Bounds(
     29                        mv.getLatLon(0, mv.getHeight()),
     30                        mv.getLatLon(mv.getWidth(), 0));
     31                double pixelPerDegree = mv.getWidth() / (b.max.lon() - b.min.lon());
     32
     33                wmsLayer.grab(b, pixelPerDegree);
    2534        }
    2635
     
    3443
    3544                // FIXME: move this to WMSPlugin/WMSInfo/preferences.
    36                 WMSLayer wmsLayer = new WMSLayer(info.name, info.grabber);
     45                WMSLayer wmsLayer = new WMSLayer(info.name, info.url);
    3746                Main.main.addLayer(wmsLayer);
    3847                return wmsLayer;
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java

    r8721 r10382  
    1212import java.text.NumberFormat;
    1313import java.util.Locale;
     14import java.util.ArrayList;
    1415
    1516import javax.imageio.ImageIO;
     17import javax.swing.JOptionPane;
    1618
    1719import org.openstreetmap.josm.Main;
     
    1921import org.openstreetmap.josm.data.projection.Projection;
    2022import org.openstreetmap.josm.io.ProgressInputStream;
     23import org.openstreetmap.josm.gui.MapView;
    2124
    22 public class WMSGrabber implements Grabber {
    23         public String baseURL;
    2425
    25         public WMSGrabber(String baseURL) {
    26                 this.baseURL = baseURL;
     26public class WMSGrabber extends Thread implements Grabber{
     27        protected String baseURL;
     28
     29        protected Bounds b;
     30        protected Projection proj;
     31        protected double pixelPerDegree;
     32        protected GeorefImage image;
     33        protected MapView mv;
     34        protected WMSLayer layer;
     35
     36        WMSGrabber(String _baseURL, Bounds _b, Projection _proj,
     37                        double _pixelPerDegree, GeorefImage _image, MapView _mv, WMSLayer _layer) {
     38                this.baseURL = _baseURL;
     39                b = _b;
     40                proj = _proj;
     41                pixelPerDegree = _pixelPerDegree;
     42                image = _image;
     43                mv = _mv;
     44                layer = _layer;
     45                this.setDaemon(true);
     46                this.setPriority(Thread.MIN_PRIORITY);
    2747        }
    2848
    29         public GeorefImage grab(Bounds b, Projection proj,
    30                         double pixelPerDegree) throws IOException {
    31                 int w = (int) ((b.max.lon() - b.min.lon()) * pixelPerDegree);
    32                 int h = (int) ((b.max.lat() - b.min.lat()) * pixelPerDegree);
     49        public void run() {
     50                       
     51                        int w = (int) ((b.max.lon() - b.min.lon()) * pixelPerDegree);
     52                        int h = (int) ((b.max.lat() - b.min.lat()) * pixelPerDegree);
    3353
    34                 try {
    35                         URL url = getURL(
    36                                 b.min.lon(), b.min.lat(),
    37                                 b.max.lon(), b.max.lat(),
    38                                 w, h);
     54                        try {
     55                                URL url = getURL(
     56                                        b.min.lon(), b.min.lat(),
     57                                        b.max.lon(), b.max.lat(),
     58                                        w, h);
    3959
    40                         BufferedImage img = grab(url);
     60                                image.min = proj.latlon2eastNorth(b.min);
     61                                image.max = proj.latlon2eastNorth(b.max);
    4162
    42                         return new GeorefImage(img,
    43                                 proj.latlon2eastNorth(b.min),
    44                                 proj.latlon2eastNorth(b.max));
    45                 } catch (MalformedURLException e) {
    46                         throw (IOException) new IOException(
    47                                 tr("WMSGrabber: Illegal url.")).initCause(e);
    48                 }
     63                                image.image = grab(url);
     64                                image.downloadingStarted = false;
     65
     66                                mv.repaint();
     67                        }
     68                        catch (MalformedURLException e) {
     69                                if(layer.messageNum-- > 0)
     70                                        JOptionPane.showMessageDialog(Main.parent,tr("WMSPlugin: Illegal url.\n{0}",e.getMessage()));
     71                        }
     72                        catch (IOException e) {
     73                                if(layer.messageNum-- > 0)
     74                                        JOptionPane.showMessageDialog(Main.parent,tr("WMSPlugin: IO exception.\n{0}",e.getMessage()));
     75                        }
    4976        }
    5077
     
    6592
    6693        protected BufferedImage grab(URL url) throws IOException {
    67                 InputStream is = new ProgressInputStream(
    68                         url.openConnection(), Main.pleaseWaitDlg);
    69                 BufferedImage img = ImageIO.read(is);
    70                 is.close();
    71                 return img;
     94                        InputStream is = new ProgressInputStream(
     95                                url.openConnection(), null);
     96                        BufferedImage img;
     97                synchronized (layer){ //download only one tile in one moment
     98                        if(!image.isVisible(mv)){
     99                                return null;
     100                        }
     101                        img = ImageIO.read(is);
     102                }
     103                        is.close();
     104                        return img;
    72105        }
    73106}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSInfo.java

    r6780 r10382  
    1212        String name;
    1313        String url;
    14         Grabber grabber;
    1514        int prefid;
    1615       
    17         public WMSInfo(String name, String url, Grabber grabber, int prefid) {
     16        public WMSInfo(String name, String url, int prefid) {
    1817                this.name=name; this.url=url; this.prefid=prefid;
    19                 this.grabber = grabber;
    2018        }
    2119
    22         public WMSInfo(String name, String url, int prefid) {
    23                 this(name, url, WMSPlugin.getGrabber(url), prefid);
    24         }
    2520       
    2621        public void save() {
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r8721 r10382  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.lang.Math;
    56import java.awt.Component;
    67import java.awt.Graphics;
     8import java.awt.Point;
    79import java.awt.Toolkit;
    810import java.awt.event.ActionEvent;
     
    3032import org.openstreetmap.josm.data.projection.Projection;
    3133import org.openstreetmap.josm.data.Bounds;
     34import org.openstreetmap.josm.data.coor.LatLon;
    3235import org.openstreetmap.josm.gui.MapView;
     36import java.util.ArrayList;
    3337import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    3438import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     
    4650                new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png")));
    4751
    48         protected ArrayList<GeorefImage> images = new ArrayList<GeorefImage>();
    49         protected Grabber grabber;
    50         protected final int serializeFormatVersion = 2;
     52        public int messageNum = 5; //limit for messages per layer
     53        protected boolean started = true;
     54        protected boolean stopAfterPaint = false;
     55        protected int ImageSize = 500;
     56        protected int dax = 10;
     57        protected int day = 10;
     58        protected int minZoom = 3;
     59        protected double pixelPerDegree;
     60        protected GeorefImage[][] images = new GeorefImage[dax][day];
     61
     62        protected String baseURL;
     63        protected final int serializeFormatVersion = 3;
    5164
    5265        public WMSLayer() {
    5366                this(tr("Blank Layer"), null);
    54         }
    55 
    56         public WMSLayer(String name, Grabber grabber) {
     67                initializeImages();
     68        }
     69
     70        public WMSLayer(String name, String baseURL) {
    5771                super(name);
    58                 this.grabber = grabber;
    59         }
    60 
    61         public void grab(Bounds b, double pixelPerDegree) throws IOException {
    62                 if (grabber == null) return;
    63                 images.add(grabber.grab(b, Main.main.proj, pixelPerDegree));
    64                 Main.map.mapView.repaint();
     72                initializeImages();
     73                this.baseURL = baseURL;
     74        }
     75
     76        public void initializeImages() {
     77                images = new GeorefImage[dax][day];
     78                for(int x = 0; x<dax; ++x)
     79                        for(int y = 0; y<day; ++y)
     80                                images[x][y]= new GeorefImage(false);
     81        }
     82
     83        public void grab(Bounds b, double _pixelPerDegree) {
     84                if (baseURL == null) return;
     85                //set resolution
     86                if(started || Math.round(pixelPerDegree/10000) != Math.round(_pixelPerDegree/10000))
     87                        initializeImages();
     88                pixelPerDegree = _pixelPerDegree;
     89                if(!started)stopAfterPaint = true;
     90                started = true;
    6591        }
    6692
     
    7096
    7197        @Override public String getToolTipText() {
    72                 return tr("WMS layer ({0}), {1} tile(s) loaded", name, images.size());
     98                if(started)
     99                        return tr("WMS layer ({0}), automaticaly downloading in zoom {1}", name, Math.round(pixelPerDegree/10000));
     100                else
     101                        return tr("WMS layer ({0}), downloading in zoom {1}", name, Math.round(pixelPerDegree/10000));
    73102        }
    74103
     
    80109        }
    81110
     111        private Bounds XYtoBounds (int x, int y) {
     112                return new Bounds(
     113                        new LatLon( x * ImageSize / pixelPerDegree,
     114                                         y * ImageSize / pixelPerDegree),
     115                        new LatLon((x + 1) *  ImageSize / pixelPerDegree,
     116                                   (y + 1) * ImageSize / pixelPerDegree));
     117        }
     118
     119        private int modulo (int a, int b) {
     120          if(a%b>=0)return a%b;
     121          else return a%b+b;
     122        }         
     123
    82124        @Override public void paint(Graphics g, final MapView mv) {
    83                 for (GeorefImage img : images) img.paint(g, mv);
     125                Bounds b = new Bounds(
     126                        mv.getLatLon(0, mv.getHeight()),
     127                        mv.getLatLon(mv.getWidth(), 0));
     128                int bminx= (int)Math.floor ((b.min.lat() * pixelPerDegree ) / ImageSize );
     129                int bminy= (int)Math.floor ((b.min.lon() * pixelPerDegree ) / ImageSize );
     130                int bmaxx= (int)Math.ceil  ((b.max.lat() * pixelPerDegree ) / ImageSize );
     131                int bmaxy= (int)Math.ceil  ((b.max.lon() * pixelPerDegree ) / ImageSize );
     132
     133
     134                if( !started || (pixelPerDegree / (mv.getWidth() / (b.max.lon() - b.min.lon())) > minZoom) ){ //don't download when it's too outzoomed
     135                        for(int x = 0; x<dax; ++x)
     136                                for(int y = 0; y<day; ++y){
     137                                                images[modulo(x,dax)][modulo(y,day)].paint(g, mv);
     138                                }
     139                } else {
     140                        for(int x = bminx; x<bmaxx; ++x)
     141                                for(int y = bminy; y<bmaxy; ++y){
     142                                        GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
     143                                        if(!img.paint(g, mv) && !img.downloadingStarted){
     144                                                //System.out.println(tr("------{0}|{1}|{2}|{3}", modulo(x,dax), modulo(y,day), img.downloadingStarted, img.isVisible(mv)));
     145                                                img.downloadingStarted = true;
     146                                                img.image = null;
     147                                                Grabber gr = WMSPlugin.getGrabber(baseURL, XYtoBounds(x,y), Main.main.proj, pixelPerDegree, img, mv, this);
     148                                                gr.start();
     149                                }
     150                        }
     151                }
     152                if(stopAfterPaint){
     153                        started = false;
     154                        stopAfterPaint = false;
     155                }
    84156        }
    85157
    86158        @Override public void visitBoundingBox(BoundingXYVisitor v) {
    87                 for (GeorefImage img : images) {
    88                         v.visit(img.min);
    89                         v.visit(img.max);
    90                 }
     159                for(int x = 0; x<dax; ++x)
     160                        for(int y = 0; y<day; ++y)
     161                                        if(images[x][y]!=null){
     162                                                v.visit(images[x][y].min);
     163                                                v.visit(images[x][y].max);
     164                                        }
    91165        }
    92166
     
    99173                                new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
    100174                                new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),                             
     175                                new JSeparator(),
    101176                                new JMenuItem(new LoadWmsAction()),
    102177                                new JMenuItem(new SaveWmsAction()),
    103178                                new JSeparator(),
     179                                new JMenuItem(new StartWmsAction()),
     180                                new JMenuItem(new StopWmsAction()),
     181                                new JSeparator(),
    104182                                new JMenuItem(new LayerListPopup.InfoAction(this))};
     183
    105184        }
    106185
    107186        public GeorefImage findImage(EastNorth eastNorth) {
    108                 // Iterate in reverse, so we return the image which is painted last.
    109                 // (i.e. the topmost one)
    110                 for (int i = images.size() - 1; i >= 0; i--) {
    111                         if (images.get(i).contains(eastNorth)) {
    112                                 return images.get(i);
    113                         }
    114                 }
     187                for(int x = 0; x<dax; ++x)
     188                        for(int y = 0; y<day; ++y)
     189                                        if(images[x][y]!=null && images[x][y].image!=null && images[x][y].min!=null && images[x][y].max!=null){
     190                                                if (images[x][y].contains(eastNorth)) {
     191                                                        return images[x][y];
     192                                                }
     193                                        }
    115194                return null;
    116195        }
     196
    117197
    118198        public class SaveWmsAction extends AbstractAction {
     
    122202                public void actionPerformed(ActionEvent ev) {
    123203                        File f = openFileDialog(false);
    124                         try {
     204                        try
     205                        {
    125206                                FileOutputStream fos = new FileOutputStream(f);
    126207                                ObjectOutputStream oos = new ObjectOutputStream(fos);
    127208                                oos.writeInt(serializeFormatVersion);
    128                                 oos.writeInt(images.size());
    129                                 for (GeorefImage img : images) {
    130                                         oos.writeObject(img);
    131                                 }
     209                                oos.writeInt(dax);
     210                                oos.writeInt(day);
     211                                oos.writeInt(ImageSize);
     212                                oos.writeDouble(pixelPerDegree);
     213                                oos.writeObject(baseURL);
     214                                oos.writeObject(images);
    132215                                oos.close();
    133216                                fos.close();
    134                         } catch (Exception ex) {
     217                        }
     218                        catch (Exception ex) {
    135219                                ex.printStackTrace(System.out);
    136220                        }
    137221                }
    138222        }
    139        
     223
    140224        public class LoadWmsAction extends AbstractAction {
    141225                public LoadWmsAction() {
     
    145229                        File f = openFileDialog(true);
    146230                        if (f == null) return;
    147                         try {
     231                        try
     232                        {
    148233                                FileInputStream fis = new FileInputStream(f);
    149234                                ObjectInputStream ois = new ObjectInputStream(fis);
    150235                                int sfv = ois.readInt();
    151236                                if (sfv != serializeFormatVersion) {
    152                                         JOptionPane.showMessageDialog(Main.parent, 
     237                                        JOptionPane.showMessageDialog(Main.parent,
    153238                                                tr("Unsupported WMS file version; found {0}, expected {1}", sfv, serializeFormatVersion),
    154                                                 tr("File Format Error"), 
     239                                                tr("File Format Error"),
    155240                                                JOptionPane.ERROR_MESSAGE);
    156241                                        return;
    157242                                }
    158                                 int numImg = ois.readInt();
    159                                 for (int i=0; i< numImg; i++) {
    160                                         GeorefImage img = (GeorefImage) ois.readObject();
    161                                         images.add(img);
    162                                 }
     243                                dax = ois.readInt();
     244                                day = ois.readInt();
     245                                ImageSize = ois.readInt();
     246                                pixelPerDegree = ois.readDouble();
     247                                baseURL = (String) ois.readObject();
     248                                images = (GeorefImage[][])ois.readObject();
     249
    163250                                ois.close();
    164251                                fis.close();
    165                         } catch (Exception ex) {
     252                                started = false;
     253                        }
     254                        catch (Exception ex) {
    166255                                // FIXME be more specific
    167256                                ex.printStackTrace(System.out);
    168                                 JOptionPane.showMessageDialog(Main.parent,
    169                                                 tr("Error loading file"),
    170                                                 tr("Error"),
    171                                                 JOptionPane.ERROR_MESSAGE);
    172                                         return;
    173                         }
    174                 }
    175         }
    176        
     257                                JOptionPane.showMessageDialog(Main.parent,
     258                                        tr("Error loading file"),
     259                                        tr("Error"),
     260                                        JOptionPane.ERROR_MESSAGE);
     261                                return;
     262                        }
     263                }
     264        }
     265
     266        public class StartWmsAction extends AbstractAction {
     267                public StartWmsAction() {
     268                        super(tr("Start automatic downloading"), null);
     269                }
     270                public void actionPerformed(ActionEvent ev) {
     271                        started = true;
     272                }
     273        }
     274
     275        public class StopWmsAction extends AbstractAction {
     276                public StopWmsAction() {
     277                        super(tr("Stop automatic downloading"), null);
     278                }
     279                public void actionPerformed(ActionEvent ev) {
     280                        started = false;
     281                }
     282        }
     283
    177284        protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple) {
    178285                String curDir = Main.pref.get("lastDirectory");
     
    184291                        fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]);
    185292                fc.setAcceptAllFileFilterUsed(true);
    186        
     293
    187294                int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
    188295                if (answer != JFileChooser.APPROVE_OPTION)
    189296                        return null;
    190                
     297
    191298                if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
    192299                        Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
     
    194301                if (!open) {
    195302                        File file = fc.getSelectedFile();
    196                         if (file == null || (file.exists() && JOptionPane.YES_OPTION != 
    197                                         JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION)))
     303                        if (file == null || (file.exists() && JOptionPane.YES_OPTION !=
     304                                JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION)))
    198305                                return null;
    199306                }
    200                
     307
    201308                return fc;
    202309        }
    203        
     310
    204311        public static File openFileDialog(boolean open) {
    205312                JFileChooser fc = createAndOpenFileChooser(open, false);
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java

    r8721 r10382  
    99import java.util.Map;
    1010import java.util.TreeSet;
     11import java.io.*;
    1112
    1213import javax.swing.AbstractAction;
     
    2122import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    2223import org.openstreetmap.josm.actions.JosmAction;
     24import org.openstreetmap.josm.data.Bounds;
     25import org.openstreetmap.josm.data.projection.Projection;
     26import org.openstreetmap.josm.gui.MapView;
    2327
    2428
     
    2630// data.
    2731
     32
     33
    2834public class WMSPlugin extends Plugin {
    2935
     
    3743       
    3844        public WMSPlugin() {
     45                try
     46                {
     47                        copy("/resources/ymap.html", "ymap.html");
     48                }
     49                catch(IOException e) {
     50                        e.printStackTrace();
     51                }
    3952                refreshMenu();
    4053        }
     
    4457        // wmsplugin.1.name=Landsat
    4558        // wmsplugin.1.url=http://and.so.on/
     59       
     60        public void copy(String from, String to) throws FileNotFoundException, IOException
     61        {
     62                File pluginDir = new File(Main.pref.getPreferencesDir() + "plugins/wmsplugin/");
     63                if (!pluginDir.exists())
     64                        pluginDir.mkdirs();
     65                FileOutputStream out = new FileOutputStream(Main.pref.getPreferencesDir() + "plugins/wmsplugin/" + to);
     66                InputStream in = WMSPlugin.class.getResourceAsStream(from);
     67                byte[] buffer = new byte[8192];
     68                for(int len = in.read(buffer); len > 0; len = in.read(buffer))
     69                        out.write(buffer, 0, len);
     70                in.close();
     71                out.close();
     72        }
     73
    4674       
    4775        public static void refreshMenu() {
     
    5482                String url = null;
    5583                int lastid = -1;
     84                boolean isYahoo = false;
    5685                for (String key : keys) {
    5786                        String[] elements = key.split("\\.");
     
    6594                                if ((name != null) && (url != null)) {
    6695                                        wmsList.add(new WMSInfo(name, url, prefid));
     96                                        if(name.equals("YAHOO"))isYahoo = true;
    6797                                }
    6898                                name = null; url = null; lastid = prefid;
     
    76106                if ((name != null) && (url != null)) {
    77107                        wmsList.add(new WMSInfo(name, url, prefid));
    78                 }
    79                
     108                        if(name.equals("YAHOO"))isYahoo = true;
     109                }
     110
    80111                // if no (valid) prefs are set, initialize to a sensible default.
    81112                if (wmsList.isEmpty()) {
     
    92123                        wmsList.add(npeInfo);
    93124                }
     125                if(!isYahoo){ //add Yahoo to the list, if there isn't
     126                        int maxKey = 0;
     127                        for(WMSInfo in : wmsList)
     128                                if(maxKey < in.prefid)maxKey = in.prefid;
     129                        WMSInfo yahooInfo = new WMSInfo(tr("YAHOO"),
     130                                        "yahoo://gnome-web-photo --mode=photo --format=png {0} /dev/stdout", maxKey+1);
     131                        yahooInfo.save();
     132                        wmsList.add(yahooInfo);
     133                }
    94134               
    95135                JMenuBar menu = Main.main.menu;
     
    122162        }
    123163
    124         public static Grabber getGrabber(String wmsurl) {
    125                 if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){
    126                         return new OSGBGrabber(wmsurl);
    127                 } else {
    128                         return new WMSGrabber(wmsurl);
    129                 }
     164        public static Grabber getGrabber(String _baseURL, Bounds _b, Projection _proj,
     165                                 double _pixelPerDegree, GeorefImage _image, MapView _mv, WMSLayer _layer){
     166                if(_baseURL.startsWith("yahoo://"))
     167                        return new YAHOOGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer);
     168                else
     169                        return new WMSGrabber(_baseURL, _b, _proj, _pixelPerDegree, _image, _mv, _layer);
     170                // OSBGrabber should be rewrite for thread support first
     171                //if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){
     172                //      return new OSGBGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
     173                //} else {
     174                //      return new WMSGrabber(_b, _proj, _pixelPerDegree,  _images, _mv, _layer);
     175                //}
    130176        }
    131177       
Note: See TracChangeset for help on using the changeset viewer.