Changeset 13582 in osm
- Timestamp:
- 2009-02-08T11:21:49+01:00 (16 years ago)
- 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 21 21 static 22 22 { 23 Logger.getLogger("org.lobobrowser").setLevel(Level.WARNING);23 Logger.getLogger("org.lobobrowser").setLevel(Level.WARNING); 24 24 } 25 25 … … 28 28 Dimension oldSize = null; 29 29 30 public Browser(String uri ) {31 super();30 public Browser(String uri, MyHtmlBlockPanel.ViewUpdateListener vul) { 31 super(); 32 32 33 UserAgentContext ucontext = new CacheableUserAgentContext(); 34 rcontext = new SimpleHtmlRendererContext(this, ucontext); 35 addNotify(); 33 view_update_listener = vul; 36 34 37 process( uri ); 35 UserAgentContext ucontext = new CacheableUserAgentContext(); 36 rcontext = new SimpleHtmlRendererContext(this, ucontext); 37 addNotify(); 38 39 process( uri ); 38 40 } 39 41 40 42 private void process(String uri) { 41 try {42 URL url;43 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; 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(); 52 61 } 53 }54 // Call SimpleHtmlRendererContext.navigate()55 // which implements incremental rendering.56 this.rcontext.navigate(url, null);57 } catch (Exception err) {58 err.printStackTrace();59 }60 62 } 61 63 … … 63 65 public void setSize(final Dimension newSize) 64 66 { 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(); 69 71 70 executeAsyncScript("resizeMap(" + newSize.width + "," + newSize.height + ");");71 }72 executeAsyncScript("resizeMap(" + newSize.width + "," + newSize.height + ");"); 73 } 72 74 } 73 75 74 76 public void executeAsyncScript(final String script) 75 77 { 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 }); 81 83 } 82 84 83 85 public Object executeScript(String script) 84 86 { 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 yet87 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 90 92 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; 96 101 } 97 102 98 return null; 99 } 100 103 MyHtmlBlockPanel.ViewUpdateListener view_update_listener; 101 104 102 105 /** … … 105 108 @Override 106 109 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"; 108 120 } 109 121 } -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/CacheableHttpRequest.java
r13497 r13582 44 44 45 45 public CacheableHttpRequest(UserAgentContext context, Proxy proxy) { 46 this.context = context;47 this.proxy = proxy;46 this.context = context; 47 this.proxy = proxy; 48 48 } 49 49 50 50 public synchronized int getReadyState() { 51 return this.readyState;51 return this.readyState; 52 52 } 53 53 54 54 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 64 60 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 } 71 71 } 72 72 73 73 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 } 86 86 } 87 87 88 88 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; 91 91 } 92 92 93 93 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); 100 100 } 101 101 102 102 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; 105 105 } 106 106 107 107 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; 110 110 } 111 111 112 112 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; 115 115 } 116 116 117 117 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); 121 121 } 122 122 123 123 public void open(String method, String url) throws IOException { 124 this.open(method, url, true);124 this.open(method, url, true); 125 125 } 126 126 127 127 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); 129 129 } 130 130 131 131 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); 133 133 } 134 134 135 135 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); 138 138 } 139 139 140 140 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); 142 142 } 143 143 144 144 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 } 159 159 } 160 160 … … 170 170 */ 171 171 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 else195 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 } 197 197 } 198 198 … … 206 206 */ 207 207 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 { 218 225 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 } 227 227 } 228 228 … … 232 232 */ 233 233 protected String getPostCharset() { 234 return "UTF-8";234 return "UTF-8"; 235 235 } 236 236 … … 243 243 */ 244 244 protected void sendSync(String content) throws IOException { 245 if( response.loaded )246 {247 // Response from cache248 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 } 297 297 } 298 298 … … 300 300 301 301 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 }); 307 307 } 308 308 -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/CacheableUserAgentContext.java
r13497 r13582 14 14 @Override 15 15 public HttpRequest createHttpRequest() { 16 return new CacheableHttpRequest(this, this.getProxy());16 return new CacheableHttpRequest(this, this.getProxy()); 17 17 } 18 18 } -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/HttpResponse.java
r13497 r13582 56 56 */ 57 57 public synchronized void changeState(int status, String statusMessage, byte[] bytes) { 58 this.status = status;58 this.status = status; 59 59 this.statusText = statusMessage; 60 60 this.responseBytes = bytes; … … 68 68 private String getAllResponseHeaders(URLConnection c) { 69 69 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++; 78 82 } 79 buf.append(value); 80 buf.append("\n"); 81 idx++; 82 } 83 return buf.toString(); 83 return buf.toString(); 84 84 } 85 85 … … 89 89 */ 90 90 public void store(URL requestURL) { 91 loaded = true;92 StorageManager.getInstance().put(requestURL, this);91 loaded = true; 92 StorageManager.getInstance().put(requestURL, this); 93 93 } 94 94 … … 99 99 */ 100 100 public static HttpResponse lookup(URL requestURL) { 101 return StorageManager.getInstance().get(requestURL);101 return StorageManager.getInstance().get(requestURL); 102 102 } 103 103 } -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/MyHtmlBlockPanel.java
r13497 r13582 18 18 private static final long serialVersionUID = -4778865358510293592L; 19 19 20 public interface ViewUpdateListener { 21 void region_update(int x, int y, int w, int h); 22 } 23 ViewUpdateListener view_update_listener; 24 20 25 /** 21 26 * Constructor … … 26 31 * @param frameContext 27 32 */ 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) { 29 35 super(background, opaque, pcontext, rcontext, frameContext); 36 view_update_listener = vul; 30 37 } 31 38 … … 48 55 this.repaint(); 49 56 } 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 } 50 62 } -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/OpenLayersLayer.java
r13497 r13582 25 25 * 26 26 */ 27 public class OpenLayersLayer extends Layer implements PreferenceChangedListener, PropertyChangeListener { 27 public class OpenLayersLayer extends Layer implements PreferenceChangedListener, 28 PropertyChangeListener, MyHtmlBlockPanel.ViewUpdateListener { 28 29 29 30 private Browser browser; … … 33 34 */ 34 35 public OpenLayersLayer() { 35 super("OpenLayers");36 super("OpenLayers"); 36 37 37 this.browser = new Browser(OpenLayersPlugin.pluginDir + "yahoo.html");38 this.browser = new Browser(OpenLayersPlugin.pluginDir + "yahoo.html", this); 38 39 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 } 45 47 } 46 48 … … 50 52 @Override 51 53 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); 54 56 } 55 57 … … 58 60 */ 59 61 public void setSize(Dimension dim) { 60 browser.setSize(dim);62 browser.setSize(dim); 61 63 } 62 64 63 65 @Override 64 66 public Icon getIcon() { 65 return ImageProvider.get("OpenLayers.png");67 return ImageProvider.get("OpenLayers"); 66 68 } 67 69 68 70 @Override 69 71 public Object getInfoComponent() { 70 return null;72 return null; 71 73 } 72 74 73 75 @Override 74 76 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)) }; 83 85 } 84 86 85 87 @Override 86 88 public String getToolTipText() { 87 return null;89 return null; 88 90 } 89 91 90 92 @Override 91 93 public boolean isMergable(Layer other) { 92 return false;94 return false; 93 95 } 94 96 … … 103 105 @Override 104 106 public void destroy() { 105 Main.pref.listener.remove(this);107 Main.pref.listener.remove(this); 106 108 107 if( Main.map != null )108 Main.map.mapView.removePropertyChangeListener(this);109 if( Main.map != null ) 110 Main.map.mapView.removePropertyChangeListener(this); 109 111 110 OpenLayersPlugin.layer = null;111 StorageManager.flush();112 OpenLayersPlugin.layer = null; 113 StorageManager.flush(); 112 114 } 113 115 … … 116 118 117 119 public void propertyChange(PropertyChangeEvent evt) { 118 if( !visible )119 return;120 if( !visible ) 121 return; 120 122 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 } 125 127 } 126 128 … … 130 132 LatLon topRight = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0); 131 133 Object value = browser.executeScript("zoomMapToExtent(" + bottomLeft.lon() + "," + bottomLeft.lat() + "," + topRight.lon() + "," + topRight.lat() + ")"); 132 if ( value != null && false)133 {134 // TODO wrong calculations134 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 135 137 136 138 // Get actual extent from browser … … 140 142 double right = ((Double)array.get(2, null)).doubleValue(); 141 143 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); 144 146 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); 150 152 } 151 153 } 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 } 152 162 } -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/OpenLayersPlugin.java
r13497 r13582 25 25 26 26 public OpenLayersPlugin() { 27 pluginDir = getPluginDir();28 try {29 copy("/resources/yahoo.html", "yahoo.html");30 } catch (FileNotFoundException e) {31 // TODO Auto-generated catch block32 e.printStackTrace();33 } catch (IOException e) {34 // TODO Auto-generated catch block35 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(); 39 39 } 40 40 41 41 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 } 49 49 50 menu.add(new JMenuItem(new ShowOpenLayersAction("Yahoo")));50 menu.add(new JMenuItem(new ShowOpenLayersAction("Yahoo"))); 51 51 } 52 52 … … 58 58 @Override 59 59 public PreferenceSetting getPreferenceSetting() { 60 return null;60 return null; 61 61 } 62 63 62 } -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/ShowOpenLayersAction.java
r13497 r13582 10 10 11 11 public ShowOpenLayersAction(String name) { 12 super(name, "OpenLayers", "Show layer" + name, 0, 0, false);12 super(name, "OpenLayers", "Show layer "+name, null, false); 13 13 } 14 14 15 15 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); 19 19 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 }); 25 25 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); 30 29 } 31 30 }; -
applications/editors/josm/plugins/openlayers/src/org/openstreetmap/josm/plugins/openLayers/StorageManager.java
r13497 r13582 22 22 public static void initStorage(String basedir) 23 23 { 24 if( storage != null ) storage.dispose();24 if( storage != null ) storage.dispose(); 25 25 26 storage = new StorageManager(basedir);26 storage = new StorageManager(basedir); 27 27 } 28 28 29 29 protected StorageManager(String basedir) 30 30 { 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); 34 34 } 35 35 36 36 protected void dispose() 37 37 { 38 if( cache != null )39 cache.dispose();38 if( cache != null ) 39 cache.dispose(); 40 40 } 41 41 42 42 public static StorageManager getInstance() 43 43 { 44 return storage;44 return storage; 45 45 } 46 46 47 47 public HttpResponse get(URL key) 48 48 { 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(); 52 52 53 return null;53 return null; 54 54 } 55 55 56 56 public void put(URL key, HttpResponse value) 57 57 { 58 Element element = new Element(key, value);59 cache.put(element);58 Element element = new Element(key, value); 59 cache.put(element); 60 60 } 61 61 … … 64 64 */ 65 65 public static void flush() { 66 if( storage != null )67 storage.cache.flush();66 if( storage != null ) 67 storage.cache.flush(); 68 68 } 69 69 }
Note:
See TracChangeset
for help on using the changeset viewer.