Changeset 13582 in osm for applications


Ignore:
Timestamp:
2009-02-08T11:21:49+01:00 (15 years ago)
Author:
stoecker
Message:

added patch from 1572

Location:
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/Browser.java

    r13497 r13582  
    2121    static
    2222    {
    23     Logger.getLogger("org.lobobrowser").setLevel(Level.WARNING);
     23        Logger.getLogger("org.lobobrowser").setLevel(Level.WARNING);
    2424    }
    2525
     
    2828    Dimension oldSize = null;
    2929
    30     public Browser(String uri) {
    31     super();
     30    public Browser(String uri, MyHtmlBlockPanel.ViewUpdateListener vul) {
     31        super();
    3232
    33     UserAgentContext ucontext = new CacheableUserAgentContext();
    34     rcontext = new SimpleHtmlRendererContext(this, ucontext);
    35     addNotify();
     33        view_update_listener = vul;
    3634
    37     process( uri );
     35        UserAgentContext ucontext = new CacheableUserAgentContext();
     36        rcontext = new SimpleHtmlRendererContext(this, ucontext);
     37        addNotify();
     38
     39        process( uri );
    3840    }
    3941
    4042    private void process(String uri) {
    41     try {
    42         URL url;
    4343        try {
    44         url = new URL(uri);
    45         } catch (java.net.MalformedURLException mfu) {
    46         int idx = uri.indexOf(':');
    47         if (idx == -1 || idx == 1) {
    48             // try file
    49             url = new URL("file:" + uri);
    50         } else {
    51             throw mfu;
     44            URL url;
     45            try {
     46            url = new URL(uri);
     47            } catch (java.net.MalformedURLException mfu) {
     48            int idx = uri.indexOf(':');
     49            if (idx == -1 || idx == 1) {
     50                // try file
     51                url = new URL("file:" + uri);
     52            } else {
     53                throw mfu;
     54            }
     55            }
     56            // Call SimpleHtmlRendererContext.navigate()
     57            // which implements incremental rendering.
     58            this.rcontext.navigate(url, null);
     59        } catch (Exception err) {
     60            err.printStackTrace();
    5261        }
    53         }
    54         // Call SimpleHtmlRendererContext.navigate()
    55         // which implements incremental rendering.
    56         this.rcontext.navigate(url, null);
    57     } catch (Exception err) {
    58         err.printStackTrace();
    59     }
    6062    }
    6163
     
    6365    public void setSize(final Dimension newSize)
    6466    {
    65     if (!newSize.equals(oldSize)) {
    66         oldSize = newSize;
    67         super.setSize(newSize);
    68         validate();
     67        if (!newSize.equals(oldSize)) {
     68            oldSize = newSize;
     69            super.setSize(newSize);
     70            validate();
    6971
    70         executeAsyncScript("resizeMap(" + newSize.width + "," + newSize.height + ");");
    71     }
     72            executeAsyncScript("resizeMap(" + newSize.width + "," + newSize.height + ");");
     73        }
    7274    }
    7375
    7476    public void executeAsyncScript(final String script)
    7577    {
    76     EventQueue.invokeLater(new Runnable() {
    77         public void run() {
    78         executeScript(script);
    79         }
    80     });
     78        EventQueue.invokeLater(new Runnable() {
     79            public void run() {
     80            executeScript(script);
     81            }
     82        });
    8183    }
    8284
    8385    public Object executeScript(String script)
    8486    {
    85     System.out.println("Executing script " + script);
    86     try {
    87         Window window = Window.getWindow(rcontext);
    88         if( window.getDocumentNode() == null )
    89         return null; // Document not loaded yet
     87        System.out.println("Executing script " + script);
     88        try {
     89            Window window = Window.getWindow(rcontext);
     90            if( window.getDocumentNode() == null )
     91            return null; // Document not loaded yet
    9092
    91         return window.eval(script);
    92     } catch (EcmaError ecmaError) {
    93         logger.log(Level.WARNING, "Javascript error at " + ecmaError.sourceName() + ":" + ecmaError.lineNumber() + ": " + ecmaError.getMessage());
    94     } catch (Throwable err) {
    95         logger.log(Level.WARNING, "Unable to evaluate Javascript code", err);
     93            return window.eval(script);
     94        } catch (EcmaError ecmaError) {
     95            logger.log(Level.WARNING, "Javascript error at " + ecmaError.sourceName() + ":" + ecmaError.lineNumber() + ": " + ecmaError.getMessage());
     96        } catch (Throwable err) {
     97            logger.log(Level.WARNING, "Unable to evaluate Javascript code", err);
     98        }
     99
     100        return null;
    96101    }
    97102
    98     return null;
    99     }
    100 
     103    MyHtmlBlockPanel.ViewUpdateListener view_update_listener;
    101104
    102105    /**
     
    105108    @Override
    106109    protected HtmlBlockPanel createHtmlBlockPanel(UserAgentContext ucontext, HtmlRendererContext rcontext) {
    107     return new MyHtmlBlockPanel(java.awt.Color.WHITE, true, ucontext, rcontext, this);
     110        return new MyHtmlBlockPanel(java.awt.Color.WHITE, true,
     111        ucontext, rcontext, this, view_update_listener);
     112    }
     113
     114    /**
     115     * Get page loading status from the bottom status bar.
     116     */
     117    public String getStatus() {
     118        /* TODO */
     119        return "Tile loaded";
    108120    }
    109121}
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/CacheableHttpRequest.java

    r13497 r13582  
    4444
    4545    public CacheableHttpRequest(UserAgentContext context, Proxy proxy) {
    46     this.context = context;
    47     this.proxy = proxy;
     46        this.context = context;
     47        this.proxy = proxy;
    4848    }
    4949
    5050    public synchronized int getReadyState() {
    51     return this.readyState;
     51        return this.readyState;
    5252    }
    5353
    5454    public synchronized String getResponseText() {
    55     if( response == null ) return null;
    56 
    57     byte[] bytes = this.response.responseBytes;
    58     String encoding = this.response.encoding;
    59 
    60     try {
    61         return bytes == null ? null : new String(bytes, encoding);
    62     } catch (UnsupportedEncodingException uee) {
    63         logger.log(Level.WARNING, "getResponseText(): Charset '" + encoding + "' did not work. Retrying with ISO-8859-1.", uee);
     55        if( response == null ) return null;
     56
     57        byte[] bytes = this.response.responseBytes;
     58        String encoding = this.response.encoding;
     59
    6460        try {
    65         return new String(bytes, "ISO-8859-1");
    66         } catch (UnsupportedEncodingException uee2) {
    67         // Ignore this time
    68         return null;
    69         }
    70     }
     61            return bytes == null ? null : new String(bytes, encoding);
     62        } catch (UnsupportedEncodingException uee) {
     63            logger.log(Level.WARNING, "getResponseText(): Charset '" + encoding + "' did not work. Retrying with ISO-8859-1.", uee);
     64            try {
     65            return new String(bytes, "ISO-8859-1");
     66            } catch (UnsupportedEncodingException uee2) {
     67            // Ignore this time
     68            return null;
     69            }
     70        }
    7171    }
    7272
    7373    public synchronized Document getResponseXML() {
    74     if( response == null ) return null;
    75 
    76     byte[] bytes = this.response.responseBytes;
    77     if (bytes == null) return null;
    78 
    79     InputStream in = new ByteArrayInputStream(bytes);
    80     try {
    81         return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
    82     } catch (Exception err) {
    83         logger.log(Level.WARNING, "Unable to parse response as XML.", err);
    84         return null;
    85     }
     74        if( response == null ) return null;
     75
     76        byte[] bytes = this.response.responseBytes;
     77        if (bytes == null) return null;
     78
     79        InputStream in = new ByteArrayInputStream(bytes);
     80        try {
     81            return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
     82        } catch (Exception err) {
     83            logger.log(Level.WARNING, "Unable to parse response as XML.", err);
     84            return null;
     85        }
    8686    }
    8787
    8888    public synchronized byte[] getResponseBytes() {
    89     if( response == null ) return null;
    90     return this.response.responseBytes;
     89        if( response == null ) return null;
     90        return this.response.responseBytes;
    9191    }
    9292
    9393    public synchronized Image getResponseImage() {
    94     if( response == null ) return null;
    95 
    96     byte[] bytes = this.response.responseBytes;
    97     if (bytes == null) return null;
    98 
    99     return Toolkit.getDefaultToolkit().createImage(bytes);
     94        if( response == null ) return null;
     95
     96        byte[] bytes = this.response.responseBytes;
     97        if (bytes == null) return null;
     98
     99        return Toolkit.getDefaultToolkit().createImage(bytes);
    100100    }
    101101
    102102    public synchronized int getStatus() {
    103     if( response == null ) return 0;
    104     return this.response.status;
     103        if( response == null ) return 0;
     104        return this.response.status;
    105105    }
    106106
    107107    public synchronized String getStatusText() {
    108     if( response == null ) return null;
    109     return this.response.statusText;
     108        if( response == null ) return null;
     109        return this.response.statusText;
    110110    }
    111111
    112112    public synchronized String getAllResponseHeaders() {
    113     if( response == null ) return null;
    114     return this.response.responseHeaders;
     113        if( response == null ) return null;
     114        return this.response.responseHeaders;
    115115    }
    116116
    117117    public synchronized String getResponseHeader(String headerName) {
    118     if( response == null ) return null;
    119     Map headers = this.response.responseHeadersMap;
    120     return headers == null ? null : (String) headers.get(headerName);
     118        if( response == null ) return null;
     119        Map headers = this.response.responseHeadersMap;
     120        return headers == null ? null : (String) headers.get(headerName);
    121121    }
    122122
    123123    public void open(String method, String url) throws IOException {
    124     this.open(method, url, true);
     124        this.open(method, url, true);
    125125    }
    126126
    127127    public void open(String method, URL url) throws IOException {
    128     this.open(method, url, true, null, null);
     128        this.open(method, url, true, null, null);
    129129    }
    130130
    131131    public void open(String method, URL url, boolean asyncFlag) throws IOException {
    132     this.open(method, url, asyncFlag, null, null);
     132        this.open(method, url, asyncFlag, null, null);
    133133    }
    134134
    135135    public void open(String method, String url, boolean asyncFlag) throws IOException {
    136     URL urlObj = Urls.createURL(null, url);
    137     this.open(method, urlObj, asyncFlag, null);
     136        URL urlObj = Urls.createURL(null, url);
     137        this.open(method, urlObj, asyncFlag, null);
    138138    }
    139139
    140140    public void open(String method, URL url, boolean asyncFlag, String userName) throws IOException {
    141     this.open(method, url, asyncFlag, userName, null);
     141        this.open(method, url, asyncFlag, userName, null);
    142142    }
    143143
    144144    public void abort() {
    145     URLConnection c;
    146     synchronized (this) {
    147         c = this.connection;
    148         response = null;
    149     }
    150     if (c instanceof HttpURLConnection) {
    151         ((HttpURLConnection) c).disconnect();
    152     } else if (c != null) {
    153         try {
    154         c.getInputStream().close();
    155         } catch (IOException ioe) {
    156         ioe.printStackTrace();
    157         }
    158     }
     145        URLConnection c;
     146        synchronized (this) {
     147            c = this.connection;
     148            response = null;
     149        }
     150        if (c instanceof HttpURLConnection) {
     151            ((HttpURLConnection) c).disconnect();
     152        } else if (c != null) {
     153            try {
     154            c.getInputStream().close();
     155            } catch (IOException ioe) {
     156            ioe.printStackTrace();
     157            }
     158        }
    159159    }
    160160
     
    170170     */
    171171    public void open(final String method, final URL url, boolean asyncFlag, final String userName, final String password) throws IOException {
    172     this.abort();
    173 
    174     HttpResponse response = HttpResponse.lookup(url);
    175     URLConnection c = null;
    176 
    177     if( response == null )
    178     {
    179         c = proxy == null || proxy == Proxy.NO_PROXY ? url.openConnection() : url.openConnection(proxy);
    180         response = new HttpResponse();
    181     }
    182 
    183     synchronized (this) {
    184         this.connection = c;
    185         this.isAsync = asyncFlag;
    186         this.requestMethod = method;
    187         this.requestUserName = userName;
    188         this.requestPassword = password;
    189         this.requestURL = url;
    190         this.response = response;
    191 
    192         if( response.loaded )
    193         changeState(HttpRequest.STATE_LOADING);
    194         else
    195         changeState(HttpRequest.STATE_LOADING, 0, null, null);
    196     }
     172        this.abort();
     173
     174        HttpResponse response = HttpResponse.lookup(url);
     175        URLConnection c = null;
     176
     177        if( response == null )
     178        {
     179            c = proxy == null || proxy == Proxy.NO_PROXY ? url.openConnection() : url.openConnection(proxy);
     180            response = new HttpResponse();
     181        }
     182
     183        synchronized (this) {
     184            this.connection = c;
     185            this.isAsync = asyncFlag;
     186            this.requestMethod = method;
     187            this.requestUserName = userName;
     188            this.requestPassword = password;
     189            this.requestURL = url;
     190            this.response = response;
     191
     192            if( response.loaded )
     193            changeState(HttpRequest.STATE_LOADING);
     194            else
     195            changeState(HttpRequest.STATE_LOADING, 0, null, null);
     196        }
    197197    }
    198198
     
    206206     */
    207207    public void send(final String content) throws IOException {
    208     final URL url = this.requestURL;
    209     if (url == null) {
    210         throw new IOException("No URL has been provided.");
    211     }
    212     if (this.isAsync) {
    213         // Should use a thread pool instead
    214         new Thread("SimpleHttpRequest-" + url.getHost()) {
    215         @Override
    216         public void run() {
    217             try {
     208        final URL url = this.requestURL;
     209        if (url == null) {
     210            throw new IOException("No URL has been provided.");
     211        }
     212        if (this.isAsync) {
     213            // Should use a thread pool instead
     214            new Thread("SimpleHttpRequest-" + url.getHost()) {
     215                @Override
     216                public void run() {
     217                    try {
     218                    sendSync(content);
     219                    } catch (Throwable thrown) {
     220                    logger.log(Level.WARNING,"send(): Error in asynchronous request on " + url, thrown);
     221                    }
     222                }
     223            }.start();
     224        } else {
    218225            sendSync(content);
    219             } catch (Throwable thrown) {
    220             logger.log(Level.WARNING,"send(): Error in asynchronous request on " + url, thrown);
    221             }
    222         }
    223         }.start();
    224     } else {
    225         sendSync(content);
    226     }
     226        }
    227227    }
    228228
     
    232232     */
    233233    protected String getPostCharset() {
    234     return "UTF-8";
     234        return "UTF-8";
    235235    }
    236236
     
    243243     */
    244244    protected void sendSync(String content) throws IOException {
    245     if( response.loaded )
    246     {
    247         // Response from cache
    248         changeState(HttpRequest.STATE_LOADED);
    249         changeState(HttpRequest.STATE_INTERACTIVE);
    250         changeState(HttpRequest.STATE_COMPLETE);
    251         return;
    252     }
    253 
    254     try {
    255         URLConnection c;
    256         synchronized (this) {
    257         c = this.connection;
    258         }
    259         c.setRequestProperty("User-Agent", this.context.getUserAgent());
    260         int istatus = 0;
    261         String istatusText = "";
    262         InputStream err = null;
    263 
    264         if (c instanceof HttpURLConnection) {
    265         HttpURLConnection hc = (HttpURLConnection) c;
    266         String method = requestMethod.toUpperCase();
    267         hc.setRequestMethod(method);
    268         if ("POST".equals(method) && content != null) {
    269             hc.setDoOutput(true);
    270             byte[] contentBytes = content.getBytes(this.getPostCharset());
    271             hc.setFixedLengthStreamingMode(contentBytes.length);
    272             OutputStream out = hc.getOutputStream();
    273             try {
    274             out.write(contentBytes);
    275             } finally {
    276             out.flush();
    277             }
    278         }
    279         istatus = hc.getResponseCode();
    280         istatusText = hc.getResponseMessage();
    281         err = hc.getErrorStream();
    282         }
    283 
    284         response.setConnectionInfo(c);
    285         changeState(HttpRequest.STATE_LOADED, istatus, istatusText, null);
    286         InputStream in = err == null ? c.getInputStream() : err;
    287         int contentLength = c.getContentLength();
    288         changeState(HttpRequest.STATE_INTERACTIVE, istatus, istatusText, null);
    289         byte[] bytes = IORoutines.load(in, contentLength == -1 ? 4096 : contentLength);
    290         changeState(HttpRequest.STATE_COMPLETE, istatus, istatusText, bytes);
    291         response.store(requestURL);
    292     } finally {
    293         synchronized (this) {
    294         this.connection = null;
    295         }
    296     }
     245        if( response.loaded )
     246        {
     247            // Response from cache
     248            changeState(HttpRequest.STATE_LOADED);
     249            changeState(HttpRequest.STATE_INTERACTIVE);
     250            changeState(HttpRequest.STATE_COMPLETE);
     251            return;
     252        }
     253
     254        try {
     255            URLConnection c;
     256            synchronized (this) {
     257            c = this.connection;
     258            }
     259            c.setRequestProperty("User-Agent", this.context.getUserAgent());
     260            int istatus = 0;
     261            String istatusText = "";
     262            InputStream err = null;
     263
     264            if (c instanceof HttpURLConnection) {
     265            HttpURLConnection hc = (HttpURLConnection) c;
     266            String method = requestMethod.toUpperCase();
     267            hc.setRequestMethod(method);
     268            if ("POST".equals(method) && content != null) {
     269                hc.setDoOutput(true);
     270                byte[] contentBytes = content.getBytes(this.getPostCharset());
     271                hc.setFixedLengthStreamingMode(contentBytes.length);
     272                OutputStream out = hc.getOutputStream();
     273                try {
     274                out.write(contentBytes);
     275                } finally {
     276                out.flush();
     277                }
     278            }
     279            istatus = hc.getResponseCode();
     280            istatusText = hc.getResponseMessage();
     281            err = hc.getErrorStream();
     282            }
     283
     284            response.setConnectionInfo(c);
     285            changeState(HttpRequest.STATE_LOADED, istatus, istatusText, null);
     286            InputStream in = err == null ? c.getInputStream() : err;
     287            int contentLength = c.getContentLength();
     288            changeState(HttpRequest.STATE_INTERACTIVE, istatus, istatusText, null);
     289            byte[] bytes = IORoutines.load(in, contentLength == -1 ? 4096 : contentLength);
     290            changeState(HttpRequest.STATE_COMPLETE, istatus, istatusText, bytes);
     291            response.store(requestURL);
     292        } finally {
     293            synchronized (this) {
     294            this.connection = null;
     295            }
     296        }
    297297    }
    298298
     
    300300
    301301    public void addReadyStateChangeListener( final ReadyStateChangeListener listener) {
    302     readyEvent.addListener(new GenericEventListener() {
    303         public void processEvent(EventObject event) {
    304         listener.readyStateChanged();
    305         }
    306     });
     302        readyEvent.addListener(new GenericEventListener() {
     303            public void processEvent(EventObject event) {
     304            listener.readyStateChanged();
     305            }
     306        });
    307307    }
    308308
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/CacheableUserAgentContext.java

    r13497 r13582  
    1414    @Override
    1515    public HttpRequest createHttpRequest() {
    16     return new CacheableHttpRequest(this, this.getProxy());
     16        return new CacheableHttpRequest(this, this.getProxy());
    1717    }
    1818}
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/HttpResponse.java

    r13497 r13582  
    5656     */
    5757    public synchronized void changeState(int status, String statusMessage, byte[] bytes) {
    58     this.status = status;
     58        this.status = status;
    5959        this.statusText = statusMessage;
    6060        this.responseBytes = bytes;
     
    6868    private String getAllResponseHeaders(URLConnection c) {
    6969        int idx = 0;
    70     String value;
    71     StringBuffer buf = new StringBuffer();
    72     while((value = c.getHeaderField(idx)) != null) {
    73         String key = c.getHeaderFieldKey(idx);
    74         if( key != null )
    75         {
    76         buf.append(key);
    77         buf.append("=");
     70        String value;
     71        StringBuffer buf = new StringBuffer();
     72        while((value = c.getHeaderField(idx)) != null) {
     73            String key = c.getHeaderFieldKey(idx);
     74            if( key != null )
     75            {
     76            buf.append(key);
     77            buf.append("=");
     78            }
     79            buf.append(value);
     80            buf.append("\n");
     81            idx++;
    7882        }
    79         buf.append(value);
    80         buf.append("\n");
    81         idx++;
    82     }
    83     return buf.toString();
     83        return buf.toString();
    8484    }
    8585
     
    8989     */
    9090    public void store(URL requestURL) {
    91     loaded = true;
    92     StorageManager.getInstance().put(requestURL, this);
     91        loaded = true;
     92        StorageManager.getInstance().put(requestURL, this);
    9393    }
    9494
     
    9999     */
    100100    public static HttpResponse lookup(URL requestURL) {
    101     return StorageManager.getInstance().get(requestURL);
     101        return StorageManager.getInstance().get(requestURL);
    102102    }
    103103}
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/MyHtmlBlockPanel.java

    r13497 r13582  
    1818    private static final long serialVersionUID = -4778865358510293592L;
    1919
     20    public interface ViewUpdateListener {
     21        void region_update(int x, int y, int w, int h);
     22    }
     23    ViewUpdateListener view_update_listener;
     24
    2025    /**
    2126     * Constructor
     
    2631     * @param frameContext
    2732     */
    28     public MyHtmlBlockPanel(Color background, boolean opaque, UserAgentContext pcontext, HtmlRendererContext rcontext, FrameContext frameContext) {
     33    public MyHtmlBlockPanel(Color background, boolean opaque, UserAgentContext pcontext, HtmlRendererContext rcontext, FrameContext frameContext,
     34    ViewUpdateListener vul) {
    2935        super(background, opaque, pcontext, rcontext, frameContext);
     36        view_update_listener = vul;
    3037    }
    3138
     
    4855        this.repaint();
    4956    }
     57
     58    public void repaint(int x, int y, int width, int height) {
     59        super.repaint(x, y, width, height);
     60        view_update_listener.region_update(x, y, width, height);
     61    }
    5062}
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/OpenLayersLayer.java

    r13497 r13582  
    2525 *
    2626 */
    27 public class OpenLayersLayer extends Layer implements PreferenceChangedListener, PropertyChangeListener {
     27public class OpenLayersLayer extends Layer implements PreferenceChangedListener,
     28    PropertyChangeListener, MyHtmlBlockPanel.ViewUpdateListener {
    2829
    2930    private Browser browser;
     
    3334     */
    3435    public OpenLayersLayer() {
    35     super("OpenLayers");
     36        super("OpenLayers");
    3637
    37     this.browser = new Browser(OpenLayersPlugin.pluginDir + "yahoo.html");
     38        this.browser = new Browser(OpenLayersPlugin.pluginDir + "yahoo.html", this);
    3839
    39     if( Main.map != null )
    40     {
    41         LatLon bottomLeft = Main.map.mapView.getLatLon(0,Main.map.mapView.getHeight());
    42         LatLon topRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0);
    43         browser.executeAsyncScript("zoomMapToExtent(" + bottomLeft.lon() + "," + bottomLeft.lat() + "," + topRight.lon() + "," + topRight.lat() + ")");
    44     }
     40        if( Main.map != null )
     41        {
     42            LatLon bottomLeft = Main.map.mapView.getLatLon(0,Main.map.mapView.getHeight());
     43            LatLon topRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0);
     44            browser.executeAsyncScript("zoomMapToExtent(" + bottomLeft.lon() + ","
     45            + bottomLeft.lat() + "," + topRight.lon() + "," + topRight.lat() + ")");
     46        }
    4547    }
    4648
     
    5052    @Override
    5153    public void paint(Graphics g, MapView mv) {
    52     setSize(Main.map.mapView.getSize());
    53     browser.paint(g);
     54        setSize(Main.map.mapView.getSize());
     55        browser.paint(g);
    5456    }
    5557
     
    5860     */
    5961    public void setSize(Dimension dim) {
    60     browser.setSize(dim);
     62        browser.setSize(dim);
    6163    }
    6264
    6365    @Override
    6466    public Icon getIcon() {
    65     return ImageProvider.get("OpenLayers.png");
     67        return ImageProvider.get("OpenLayers");
    6668    }
    6769
    6870    @Override
    6971    public Object getInfoComponent() {
    70     return null;
     72        return null;
    7173    }
    7274
    7375    @Override
    7476    public Component[] getMenuEntries() {
    75     return new Component[] {
    76         new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
    77         new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
    78         new JSeparator(),
    79         // color,
    80         new JMenuItem(new RenameLayerAction(associatedFile, this)),
    81         new JSeparator(),
    82         new JMenuItem(new LayerListPopup.InfoAction(this)) };
     77        return new Component[] {
     78            new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
     79            new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
     80            new JSeparator(),
     81            // color,
     82            new JMenuItem(new RenameLayerAction(associatedFile, this)),
     83            new JSeparator(),
     84            new JMenuItem(new LayerListPopup.InfoAction(this)) };
    8385    }
    8486
    8587    @Override
    8688    public String getToolTipText() {
    87     return null;
     89        return null;
    8890    }
    8991
    9092    @Override
    9193    public boolean isMergable(Layer other) {
    92     return false;
     94        return false;
    9395    }
    9496
     
    103105    @Override
    104106    public void destroy() {
    105     Main.pref.listener.remove(this);
     107        Main.pref.listener.remove(this);
    106108
    107     if( Main.map != null )
    108         Main.map.mapView.removePropertyChangeListener(this);
     109        if( Main.map != null )
     110            Main.map.mapView.removePropertyChangeListener(this);
    109111
    110     OpenLayersPlugin.layer = null;
    111     StorageManager.flush();
     112        OpenLayersPlugin.layer = null;
     113        StorageManager.flush();
    112114    }
    113115
     
    116118
    117119    public void propertyChange(PropertyChangeEvent evt) {
    118     if( !visible )
    119         return;
     120        if( !visible )
     121            return;
    120122
    121         String prop = evt.getPropertyName();
    122     if ("center".equals(prop) || "scale".equals(prop)) {
    123         zoomToMapView();
    124     }
     123            String prop = evt.getPropertyName();
     124        if ("center".equals(prop) || "scale".equals(prop)) {
     125            zoomToMapView();
     126        }
    125127    }
    126128
     
    130132        LatLon topRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0);
    131133        Object value = browser.executeScript("zoomMapToExtent(" + bottomLeft.lon() + "," + bottomLeft.lat() + "," + topRight.lon() + "," + topRight.lat() + ")");
    132         if( value != null && false)
    133         {
    134             // TODO wrong calculations
     134        if (value != null && false) {
     135            // TODO: should not be touching Main.map.mapView here as this
     136            // causes endless recurrency - should do the scalling ourselves
    135137
    136138            // Get actual extent from browser
     
    140142            double right  = ((Double)array.get(2, null)).doubleValue();
    141143            double top    = ((Double)array.get(3, null)).doubleValue();
    142         bottomLeft = new LatLon( bottom, left );
    143         topRight   = new LatLon( top, right);
     144            bottomLeft = new LatLon(bottom, left);
     145            topRight   = new LatLon(top, right);
    144146
    145         BoundingXYVisitor v = new BoundingXYVisitor();
    146         v.visit(Main.proj.latlon2eastNorth(bottomLeft));
    147         v.visit(Main.proj.latlon2eastNorth(topRight));
    148         System.out.println("Recalculating position (" + left + "," + bottom + "," + right + "," + top + ")");
    149         Main.map.mapView.recalculateCenterScale(v);
     147            BoundingXYVisitor v = new BoundingXYVisitor();
     148            v.visit(Main.proj.latlon2eastNorth(bottomLeft));
     149            v.visit(Main.proj.latlon2eastNorth(topRight));
     150            System.out.println("Recalculating position (" + left + "," + bottom + "," + right + "," + top + ")");
     151            Main.map.mapView.recalculateCenterScale(v);
    150152        }
    151153    }
     154
     155    public void region_update(int x, int y, int w, int h) {
     156        String status = browser.getStatus();
     157
     158        org.openstreetmap.josm.Main.map.mapView.repaint(x, y, w, h);
     159
     160        org.openstreetmap.josm.Main.map.statusLine.setHelpText(status);
     161    }
    152162}
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/OpenLayersPlugin.java

    r13497 r13582  
    2525
    2626    public OpenLayersPlugin() {
    27     pluginDir = getPluginDir();
    28     try {
    29         copy("/resources/yahoo.html", "yahoo.html");
    30     } catch (FileNotFoundException e) {
    31         // TODO Auto-generated catch block
    32         e.printStackTrace();
    33     } catch (IOException e) {
    34         // TODO Auto-generated catch block
    35         e.printStackTrace();
    36     }
    37     StorageManager.initStorage( pluginDir );
    38     refreshMenu();
     27        pluginDir = getPluginDir();
     28        try {
     29            copy("/resources/yahoo.html", "yahoo.html");
     30        } catch (FileNotFoundException e) {
     31            // TODO Auto-generated catch block
     32            e.printStackTrace();
     33        } catch (IOException e) {
     34            // TODO Auto-generated catch block
     35            e.printStackTrace();
     36        }
     37        StorageManager.initStorage( pluginDir );
     38        refreshMenu();
    3939    }
    4040
    4141    public static void refreshMenu() {
    42     JMenuBar menuBar = Main.main.menu;
    43     if (menu == null) {
    44         menu = new JMenu(tr("OpenLayers"));
    45         menuBar.add(menu, 5);
    46     } else {
    47         menu.removeAll();
    48     }
     42        JMenuBar menuBar = Main.main.menu;
     43        if (menu == null) {
     44            menu = new JMenu(tr("OpenLayers"));
     45            menuBar.add(menu, 5);
     46        } else {
     47            menu.removeAll();
     48        }
    4949
    50     menu.add(new JMenuItem(new ShowOpenLayersAction("Yahoo")));
     50        menu.add(new JMenuItem(new ShowOpenLayersAction("Yahoo")));
    5151    }
    5252
     
    5858    @Override
    5959    public PreferenceSetting getPreferenceSetting() {
    60     return null;
     60        return null;
    6161    }
    62 
    6362}
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/ShowOpenLayersAction.java

    r13497 r13582  
    1010
    1111    public ShowOpenLayersAction(String name) {
    12     super(name, "OpenLayers", "Show layer" + name, 0, 0, false);
     12        super(name, "OpenLayers", "Show layer "+name, null, false);
    1313    }
    1414
    1515    public void actionPerformed(ActionEvent e) {
    16     final OpenLayersLayer layer = OpenLayersPlugin.layer != null ? OpenLayersPlugin.layer : new OpenLayersLayer();
    17     OpenLayersPlugin.layer = layer;
    18     Main.main.addLayer(layer);
     16        final OpenLayersLayer layer = OpenLayersPlugin.layer != null ? OpenLayersPlugin.layer : new OpenLayersLayer();
     17        OpenLayersPlugin.layer = layer;
     18        Main.main.addLayer(layer);
    1919
    20     EventQueue.invokeLater(new Runnable() {
    21         public void run() {
    22         layer.setSize(Main.map.mapView.getSize());
    23         }
    24     });
     20        EventQueue.invokeLater(new Runnable() {
     21            public void run() {
     22                layer.setSize(Main.map.mapView.getSize());
     23            }
     24        });
    2525
    26     // Get notifications of scale and position
    27     Main.map.mapView.addPropertyChangeListener("scale", layer);
    28     Main.map.mapView.addPropertyChangeListener("center", layer);
    29 
     26        // Get notifications of scale and position
     27        Main.map.mapView.addPropertyChangeListener("scale", layer);
     28        Main.map.mapView.addPropertyChangeListener("center", layer);
    3029    }
    3130};
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/StorageManager.java

    r13497 r13582  
    2222    public static void initStorage(String basedir)
    2323    {
    24     if( storage != null ) storage.dispose();
     24        if( storage != null ) storage.dispose();
    2525
    26     storage = new StorageManager(basedir);
     26        storage = new StorageManager(basedir);
    2727    }
    2828
    2929    protected StorageManager(String basedir)
    3030    {
    31     System.setProperty("net.sf.ehcache.enableShutdownHook", "true");
    32     cache = new Cache("OpenLayers", 500, MemoryStoreEvictionPolicy.LRU, true, basedir + "cache", false, 300*24*7, 300, true, 3600*24*7, null);
    33     CacheManager.getInstance().addCache(cache);
     31        System.setProperty("net.sf.ehcache.enableShutdownHook", "true");
     32        cache = new Cache("OpenLayers", 500, MemoryStoreEvictionPolicy.LRU, true, basedir + "cache", false, 300*24*7, 300, true, 3600*24*7, null);
     33        CacheManager.getInstance().addCache(cache);
    3434    }
    3535
    3636    protected void dispose()
    3737    {
    38     if( cache != null )
    39         cache.dispose();
     38        if( cache != null )
     39            cache.dispose();
    4040    }
    4141
    4242    public static StorageManager getInstance()
    4343    {
    44     return storage;
     44        return storage;
    4545    }
    4646
    4747    public HttpResponse get(URL key)
    4848    {
    49     Element element = cache.get(key);
    50     if( element != null )
    51         return (HttpResponse)element.getObjectValue();
     49        Element element = cache.get(key);
     50        if( element != null )
     51            return (HttpResponse)element.getObjectValue();
    5252
    53     return null;
     53        return null;
    5454    }
    5555
    5656    public void put(URL key, HttpResponse value)
    5757    {
    58     Element element = new Element(key, value);
    59     cache.put(element);
     58        Element element = new Element(key, value);
     59        cache.put(element);
    6060    }
    6161
     
    6464     */
    6565    public static void flush() {
    66     if( storage != null )
    67         storage.cache.flush();
     66        if( storage != null )
     67            storage.cache.flush();
    6868    }
    6969}
Note: See TracChangeset for help on using the changeset viewer.