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

removed tab stop usage

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

    r8748 r12778  
    2121    static
    2222    {
    23         Logger.getLogger("org.lobobrowser").setLevel(Level.WARNING);
     23    Logger.getLogger("org.lobobrowser").setLevel(Level.WARNING);
    2424    }
    2525
     
    2929
    3030    public Browser(String uri) {
    31         super();
     31    super();
    3232
    33         UserAgentContext ucontext = new CacheableUserAgentContext();
    34         rcontext = new SimpleHtmlRendererContext(this, ucontext);
    35         addNotify();
     33    UserAgentContext ucontext = new CacheableUserAgentContext();
     34    rcontext = new SimpleHtmlRendererContext(this, ucontext);
     35    addNotify();
    3636
    37         process( uri );
     37    process( uri );
    3838    }
    3939
    4040    private void process(String uri) {
    41         try {
    42             URL url;
    43             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;
    52                 }
    53             }
    54             // Call SimpleHtmlRendererContext.navigate()
    55             // which implements incremental rendering.
    56             this.rcontext.navigate(url, null);
    57         } catch (Exception err) {
    58             err.printStackTrace();
    59         }
     41    try {
     42        URL url;
     43        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;
     52        }
     53        }
     54        // Call SimpleHtmlRendererContext.navigate()
     55        // which implements incremental rendering.
     56        this.rcontext.navigate(url, null);
     57    } catch (Exception err) {
     58        err.printStackTrace();
    6059    }
    61    
     60    }
     61
    6262    @Override
    6363    public void setSize(final Dimension newSize)
    6464    {
    65         if (!newSize.equals(oldSize)) {
    66             oldSize = newSize;
    67             super.setSize(newSize);
    68             validate();
     65    if (!newSize.equals(oldSize)) {
     66        oldSize = newSize;
     67        super.setSize(newSize);
     68        validate();
    6969
    70             executeAsyncScript("resizeMap(" + newSize.width + "," + newSize.height + ");");
    71         }
     70        executeAsyncScript("resizeMap(" + newSize.width + "," + newSize.height + ");");
     71    }
    7272    }
    7373
    7474    public void executeAsyncScript(final String script)
    7575    {
    76         EventQueue.invokeLater(new Runnable() {
    77             public void run() {
    78                 executeScript(script);
    79             }
    80         });
     76    EventQueue.invokeLater(new Runnable() {
     77        public void run() {
     78        executeScript(script);
     79        }
     80    });
    8181    }
    82    
     82
    8383    public Object executeScript(String script)
    8484    {
    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
     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
    9090
    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);
    96         }
    97        
    98         return null;
     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);
    9996    }
    100    
    101    
     97
     98    return null;
     99    }
     100
     101
    102102    /**
    103103     * Overrided to hide hardcoded scrollbars and insets
     
    105105    @Override
    106106    protected HtmlBlockPanel createHtmlBlockPanel(UserAgentContext ucontext, HtmlRendererContext rcontext) {
    107         return new MyHtmlBlockPanel(java.awt.Color.WHITE, true, ucontext, rcontext, this);
     107    return new MyHtmlBlockPanel(java.awt.Color.WHITE, true, ucontext, rcontext, this);
    108108    }
    109109}
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/CacheableHttpRequest.java

    r8748 r12778  
    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);
    64             try {
    65                 return new String(bytes, "ISO-8859-1");
    66             } catch (UnsupportedEncodingException uee2) {
    67                 // Ignore this time
    68                 return null;
    69             }
    70         }
     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);
     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
    161161    /**
    162162     * Opens the request. Call {@link #send(String)} to complete it.
    163      * 
     163     *
    164164     * @param method The request method.
    165165     * @param url The request URL.
     
    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
     
    201201     * <p>
    202202     * In the case of asynchronous requests, a new thread is created.
    203      * 
     203     *
    204204     * @param content POST content or <code>null</code> if there's no such
    205205     *        content.
    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
     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
    216216        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 {
    225             sendSync(content);
    226         }
     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 {
     225        sendSync(content);
     226    }
    227227    }
    228228
     
    232232     */
    233233    protected String getPostCharset() {
    234         return "UTF-8";
     234    return "UTF-8";
    235235    }
    236236
     
    238238     * This is a synchronous implementation of {@link #send(String)} method
    239239     * functionality. It may be overridden to change the behavior of the class.
    240      * 
     240     *
    241241     * @param content POST content if any. It may be <code>null</code>.
    242242     * @throws IOException
    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         });
    307     }
    308    
     302    readyEvent.addListener(new GenericEventListener() {
     303        public void processEvent(EventObject event) {
     304        listener.readyStateChanged();
     305        }
     306    });
     307    }
     308
    309309    protected void changeState(int readyState, int status, String statusMessage, byte[] bytes) {
    310310        synchronized (this) {
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/CacheableUserAgentContext.java

    r8748 r12778  
    99public class CacheableUserAgentContext extends SimpleUserAgentContext {
    1010
    11     /** 
     11    /**
    1212     * Returns a cache aware HttpRequest
    1313     */
    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

    r8748 r12778  
    11/**
    2  * 
     2 *
    33 */
    44package org.openstreetmap.josm.plugins.openLayers;
     
    1616public class HttpResponse implements Serializable {
    1717    private static final long serialVersionUID = -8605486951415515445L;
    18    
     18
    1919    /** The status of the response */
    2020    protected int status;
     
    2727    /** Whether this response has been already loaded */
    2828    protected boolean loaded = false;
    29    
     29
    3030    /** Response headers are set in this map after a response is received. */
    3131    protected Map<String, List<String>> responseHeadersMap;
     
    3333    /** Response headers are set in this string after a response is received. */
    3434    protected String responseHeaders;
    35    
     35
    3636    /**
    3737     * Sets the information about this response: headers and encoding
     
    4343        if (encoding == null)
    4444            encoding = "ISO-8859-1";
    45        
     45
    4646        responseHeaders = getAllResponseHeaders(c);
    4747        responseHeadersMap = c.getHeaderFields();
     
    5050    /**
    5151     * Sets the state of this response
    52      * 
     52     *
    5353     * @param status The response status
    5454     * @param statusMessage The status message
     
    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;
    6161    }
    62        
     62
    6363    /**
    6464     * Returns the headers of the connection as a String
     
    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("=");
    78             }
    79             buf.append(value);
    80             buf.append("\n");
    81             idx++;
    82         }
    83         return buf.toString();
     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++;
     82    }
     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    }
    94    
     94
    9595    /**
    9696     * Looks up the requested URL in the cache
    97      * @param requestURL The requested URL 
     97     * @param requestURL The requested URL
    9898     * @return The response, if available
    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

    r8748 r12778  
    4343            this.rblock = null;
    4444        }
    45        
     45
    4646        this.invalidate();
    4747        this.validateAll();
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/OpenLayersLayer.java

    r8748 r12778  
    2121/**
    2222 * Class that displays a OpenLayers layer.
    23  * 
     23 *
    2424 * @author Francisco R. Santos <frsantos@gmail.com>
    25  * 
     25 *
    2626 */
    2727public class OpenLayersLayer extends Layer implements PreferenceChangedListener, PropertyChangeListener {
     
    3333     */
    3434    public OpenLayersLayer() {
    35         super("OpenLayers");
    36        
    37         this.browser = new Browser(OpenLayersPlugin.pluginDir + "yahoo.html");
    38        
    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         }
     35    super("OpenLayers");
     36
     37    this.browser = new Browser(OpenLayersPlugin.pluginDir + "yahoo.html");
     38
     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    }
    4545    }
    4646
     
    5050    @Override
    5151    public void paint(Graphics g, MapView mv) {
    52         setSize(Main.map.mapView.getSize());
    53         browser.paint(g);
     52    setSize(Main.map.mapView.getSize());
     53    browser.paint(g);
    5454    }
    5555
     
    5858     */
    5959    public void setSize(Dimension dim) {
    60         browser.setSize(dim);
     60    browser.setSize(dim);
    6161    }
    62    
     62
    6363    @Override
    6464    public Icon getIcon() {
    65         return ImageProvider.get("OpenLayers.png");
     65    return ImageProvider.get("OpenLayers.png");
    6666    }
    6767
    6868    @Override
    6969    public Object getInfoComponent() {
    70         return null;
     70    return null;
    7171    }
    7272
    7373    @Override
    7474    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)) };
     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)) };
    8383    }
    8484
    8585    @Override
    8686    public String getToolTipText() {
    87         return null;
     87    return null;
    8888    }
    8989
    9090    @Override
    9191    public boolean isMergable(Layer other) {
    92         return false;
     92    return false;
    9393    }
    9494
     
    103103    @Override
    104104    public void destroy() {
    105         Main.pref.listener.remove(this);
     105    Main.pref.listener.remove(this);
    106106
    107         if( Main.map != null )
    108             Main.map.mapView.removePropertyChangeListener(this);
    109        
    110         OpenLayersPlugin.layer = null;
    111         StorageManager.flush();
     107    if( Main.map != null )
     108        Main.map.mapView.removePropertyChangeListener(this);
     109
     110    OpenLayersPlugin.layer = null;
     111    StorageManager.flush();
    112112    }
    113113
     
    116116
    117117    public void propertyChange(PropertyChangeEvent evt) {
    118         if( !visible )
    119             return;
    120        
     118    if( !visible )
     119        return;
     120
    121121        String prop = evt.getPropertyName();
    122         if ("center".equals(prop) || "scale".equals(prop)) {
    123             zoomToMapView();
    124         }
     122    if ("center".equals(prop) || "scale".equals(prop)) {
     123        zoomToMapView();
    125124    }
    126    
     125    }
     126
    127127    public void zoomToMapView()
    128128    {
     
    133133        {
    134134            // TODO wrong calculations
    135            
     135
    136136            // Get actual extent from browser
    137137            NativeArray array = (NativeArray)value;
     
    140140            double right  = ((Double)array.get(2, null)).doubleValue();
    141141            double top    = ((Double)array.get(3, null)).doubleValue();
    142             bottomLeft = new LatLon( bottom, left );
    143             topRight   = new LatLon( top, right);
    144            
    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);
     142        bottomLeft = new LatLon( bottom, left );
     143        topRight   = new LatLon( top, right);
     144
     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);
    150150        }
    151151    }
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/OpenLayersPlugin.java

    r8748 r12778  
    1414/**
    1515 * Main class for the OpenLayers plugin.
    16  * 
     16 *
    1717 * @author Francisco R. Santos <frsantos@gmail.com>
    18  * 
     18 *
    1919 */
    2020public class OpenLayersPlugin extends Plugin {
     
    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();
    3936    }
    40    
     37    StorageManager.initStorage( pluginDir );
     38    refreshMenu();
     39    }
     40
    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         }
    49        
    50         menu.add(new JMenuItem(new ShowOpenLayersAction("Yahoo")));
     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    }
     49
     50    menu.add(new JMenuItem(new ShowOpenLayersAction("Yahoo")));
    5151    }
    5252
    5353    /*
    5454     * (non-Javadoc)
    55      * 
     55     *
    5656     * @see org.openstreetmap.josm.plugins.Plugin#getPreferenceSetting()
    5757     */
    5858    @Override
    5959    public PreferenceSetting getPreferenceSetting() {
    60         return null;
     60    return null;
    6161    }
    6262
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/ShowOpenLayersAction.java

    r8748 r12778  
    1010
    1111    public ShowOpenLayersAction(String name) {
    12         super(name, "OpenLayers", "Show layer" + name, 0, 0, false);
     12    super(name, "OpenLayers", "Show layer" + name, 0, 0, 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);
    19        
    20         EventQueue.invokeLater(new Runnable() {
    21             public void run() {
    22                 layer.setSize(Main.map.mapView.getSize());
    23             }
    24         });
    25            
    26         // Get notifications of scale and position
    27         Main.map.mapView.addPropertyChangeListener("scale", layer);
    28         Main.map.mapView.addPropertyChangeListener("center", layer);
    29        
     16    final OpenLayersLayer layer = OpenLayersPlugin.layer != null ? OpenLayersPlugin.layer : new OpenLayersLayer();
     17    OpenLayersPlugin.layer = layer;
     18    Main.main.addLayer(layer);
     19
     20    EventQueue.invokeLater(new Runnable() {
     21        public void run() {
     22        layer.setSize(Main.map.mapView.getSize());
     23        }
     24    });
     25
     26    // Get notifications of scale and position
     27    Main.map.mapView.addPropertyChangeListener("scale", layer);
     28    Main.map.mapView.addPropertyChangeListener("center", layer);
     29
    3030    }
    3131};
  • applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/StorageManager.java

    r8748 r12778  
    1010 * too big, with many jars, it should be replaced for a hand-made storage to
    1111 * disk.
    12  * 
     12 *
    1313 * @author frsantos
    14  * 
     14 *
    1515 */
    1616public class StorageManager {
    1717
    1818    private Cache cache;
    19    
     19
    2020    private static StorageManager storage;
    21    
     21
    2222    public static void initStorage(String basedir)
    2323    {
    24         if( storage != null ) storage.dispose();
    25        
    26         storage = new StorageManager(basedir);
     24    if( storage != null ) storage.dispose();
     25
     26    storage = new StorageManager(basedir);
    2727    }
    28    
     28
    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    }
    35    
     35
    3636    protected void dispose()
    3737    {
    38         if( cache != null )
    39             cache.dispose();
     38    if( cache != null )
     39        cache.dispose();
    4040    }
    41    
     41
    4242    public static StorageManager getInstance()
    4343    {
    44         return storage;
     44    return storage;
    4545    }
    46    
     46
    4747    public HttpResponse get(URL key)
    4848    {
    49         Element element = cache.get(key);
    50         if( element != null )
    51             return (HttpResponse)element.getObjectValue();
    52        
    53         return null;
     49    Element element = cache.get(key);
     50    if( element != null )
     51        return (HttpResponse)element.getObjectValue();
     52
     53    return null;
    5454    }
    55    
     55
    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.