Ignore:
Timestamp:
2009-07-04T20:28:12+02:00 (15 years ago)
Author:
stoecker
Message:

modernized WMS plugin, many settings of older WMS will need some adjustment

Location:
applications/editors/josm/plugins/wmsplugin/src/wmsplugin
Files:
4 edited
1 moved

Legend:

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

    r16302 r16308  
    1010import javax.imageio.ImageIO;
    1111
     12import org.openstreetmap.josm.Main;
    1213import org.openstreetmap.josm.data.ProjectionBounds;
    1314import org.openstreetmap.josm.gui.MapView;
    1415import org.openstreetmap.josm.io.CacheFiles;
    1516
    16 
    17 public class YAHOOGrabber extends WMSGrabber {
    18     protected String browserCmd;
    19 
    20     YAHOOGrabber(ProjectionBounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
     17public class HTMLGrabber extends WMSGrabber {
     18    HTMLGrabber(ProjectionBounds b, GeorefImage image, MapView mv, WMSLayer layer, CacheFiles cache) {
    2119        super(b, image, mv, layer, cache);
    22         this.baseURL = "file:///" + WMSPlugin.getPrefsPath() + "ymap.html?";
    23         this.browserCmd = layer.baseURL.replaceFirst("yahoo://", "");
     20        this.baseURL = layer.baseURL.replaceFirst("html:", "");
    2421    }
    2522
     
    2724    protected BufferedImage grab(URL url) throws IOException {
    2825        String urlstring = url.toExternalForm();
    29         // work around a problem in URL removing 2 slashes
    30         if(!urlstring.startsWith("file:///"))
    31             urlstring = urlstring.replaceFirst("file:", "file://");
    3226
    3327        BufferedImage cached = cache.getImg(urlstring);
     
    3529
    3630        ArrayList<String> cmdParams = new ArrayList<String>();
    37         StringTokenizer st = new StringTokenizer(MessageFormat.format(browserCmd, urlstring));
     31        StringTokenizer st = new StringTokenizer(MessageFormat.format(
     32        Main.pref.get("wmsplugin.browser", "webkit-image {0}"), urlstring));
    3833        while( st.hasMoreTokens() )
    3934            cmdParams.add(st.nextToken());
    4035
    41         System.out.println("WMS::Browsing YAHOO: " + cmdParams);
    4236        ProcessBuilder builder = new ProcessBuilder( cmdParams);
    4337
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSDownloadAction.java

    r15858 r16308  
    1919
    2020    public void actionPerformed(ActionEvent e) {
    21         System.out.println(info.url);
     21        //System.out.println(info.url);
    2222
    2323        WMSLayer wmsLayer = new WMSLayer(info.name, info.url, info.cookies);
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java

    r16290 r16308  
    4343        this.baseURL = layer.baseURL;
    4444        /* URL containing placeholders? */
    45         urlWithPatterns = baseURL != null && baseURL.contains("{1}");
     45        urlWithPatterns = baseURL != null && baseURL.contains("{") && baseURL.contains("}");
    4646    }
    4747
     
    6262            image.max = b.max;
    6363
    64 System.out.println(url + " " + b + " " + image.min + " " + image.max);
    6564            if(image.isVisible(mv)) { //don't download, if the image isn't visible already
    6665                image.image = grab(url);
     
    8180        if(Main.proj instanceof Mercator) // don't use mercator code directly
    8281        {
    83             LatLon sw = Main.proj.eastNorth2latlon(new EastNorth(s, w));
    84             LatLon ne = Main.proj.eastNorth2latlon(new EastNorth(n, e));
     82            LatLon sw = Main.proj.eastNorth2latlon(new EastNorth(w, s));
     83            LatLon ne = Main.proj.eastNorth2latlon(new EastNorth(e, n));
    8584            proj = "EPSG:4326";
    8685            s = sw.lat();
     
    8988            e = ne.lon();
    9089        }
    91 /*        else if(!(Main.proj instanceof Epsg4326))
    92         {
    93             EastNorth sw = Main.proj.latlon2eastNorth(new LatLon(s, w));
    94             EastNorth ne = Main.proj.latlon2eastNorth(new LatLon(n, e));
    95             s = sw.north();
    96             w = sw.east();
    97             n = ne.north();
    98             e = ne.east();
    99         }
    100 */
     90
    10191        String str = baseURL;
    10292        String bbox = latLonFormat.format(w) + ","
     
    10696
    10797        if (urlWithPatterns) {
    108             str = MessageFormat.format(str, proj, bbox, wi, ht);
     98            str = str.replaceAll("{proj}", proj)
     99            .replaceAll("{bbox}", bbox)
     100            .replaceAll("{width}", String.valueOf(wi))
     101            .replaceAll("{height}", String.valueOf(ht));
    109102        } else {
    110             if(!str.endsWith("?"))
     103            if(!str.contains("?"))
     104                str += "?";
     105            else if(!str.endsWith("?"))
    111106                str += "&";
    112107            str += "bbox="
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java

    r16290 r16308  
    4848
    4949    public WMSPlugin() {
    50         try
    51         {
    52             copy("/resources/ymap.html", "ymap.html");
    53         }
    54         catch(IOException e) {
    55             e.printStackTrace();
    56         }
    5750        refreshMenu();
    5851        cache.setExpire(cache.EXPIRE_MONTHLY, false);
     
    190183
    191184    public static Grabber getGrabber(ProjectionBounds bounds, GeorefImage img, MapView mv, WMSLayer layer){
    192         if(layer.baseURL.startsWith("yahoo://"))
    193             return new YAHOOGrabber(bounds, img, mv, layer, cache);
     185        if(layer.baseURL.startsWith("html:"))
     186            return new HTMLGrabber(bounds, img, mv, layer, cache);
    194187        else
    195188            return new WMSGrabber(bounds, img, mv, layer, cache);
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java

    r16290 r16308  
    1717import javax.swing.Box;
    1818import javax.swing.JButton;
     19import javax.swing.JComboBox;
    1920import javax.swing.JLabel;
    2021import javax.swing.JOptionPane;
     
    3233    private Map<String,String> orig;
    3334    private DefaultTableModel model;
     35    private JComboBox browser;
    3436    private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>();
    3537
     
    6971                JPanel p = new JPanel(new GridBagLayout());
    7072                p.add(new JLabel(tr("Menu Name")), GBC.std().insets(0,0,5,0));
    71                 JTextField key = new JTextField(10);
    72                 JTextField value = new JTextField(10);
     73                JTextField key = new JTextField(40);
     74                JTextField value = new JTextField(40);
    7375                p.add(key, GBC.eop().insets(5,0,0,0).fill(GBC.HORIZONTAL));
    7476                p.add(new JLabel(tr("WMS URL")), GBC.std().insets(0,0,5,0));
     
    113115        p.add(buttonPanel);
    114116        p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL));
     117        browser = new JComboBox(new String[]{
     118        "webkit-image {0}",
     119        "gnome-web-photo --mode=photo --format=png {0} /dev/stdout",
     120        "gnome-web-photo-fixed {0}",
     121        "webkit-image-gtk {0}"});
     122        browser.setEditable(true);
     123        browser.setSelectedItem(Main.pref.get("wmsplugin.browser", "webkit-image {0}"));
     124        p.add(new JLabel(tr("Downloader:")), GBC.eol().fill(GBC.HORIZONTAL));
     125        p.add(browser, GBC.eol().fill(GBC.HORIZONTAL));
    115126    }
    116127
     
    152163        if (change) WMSPlugin.refreshMenu();
    153164
     165        Main.pref.put("wmsplugin.browser", browser.getEditor().getItem().toString());
    154166        return false;
    155167    }
Note: See TracChangeset for help on using the changeset viewer.