Changeset 24934 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
- Timestamp:
- 2011-01-02T00:36:28+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r24913 r24934 20 20 import java.util.HashSet; 21 21 import java.util.Vector; 22 import java.util.concurrent.locks.Lock; 23 import java.util.concurrent.locks.ReentrantLock; 22 24 23 25 import javax.swing.Action; … … 34 36 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 35 37 import org.openstreetmap.josm.gui.layer.Layer; 36 import org.openstreetmap.josm.io.OsmTransferException;37 38 38 39 /** … … 48 49 CadastrePlugin.class.getResource("/images/cadastre_small.png"))); 49 50 50 protected Vector<GeorefImage> images = new Vector<GeorefImage>(); 51 private Vector<GeorefImage> images = new Vector<GeorefImage>(); 52 53 public Lock imagesLock = new ReentrantLock(); 51 54 52 55 /** … … 61 64 private ArrayList<EastNorthBound> dividedBbox = new ArrayList<EastNorthBound>(); 62 65 63 private CacheControl cacheControl = null;64 65 66 private String location = ""; 66 67 … … 70 71 71 72 public EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0,0), new EastNorth(0,0)); 72 73 public boolean cancelled;74 73 75 74 private boolean isRaster = false; … … 84 83 private Action saveAsPng; 85 84 85 private Action cancelGrab; 86 86 87 public boolean adjustModeEnabled; 87 88 88 89 public GrabThread grabThread; 90 89 91 public WMSLayer() { 90 92 this(tr("Blank Layer"), "", -1); … … 96 98 this.codeCommune = codeCommune; 97 99 this.lambertZone = lambertZone; 100 grabThread = new GrabThread(this); 101 grabThread.start(); 98 102 // enable auto-sourcing option 99 103 CadastrePlugin.pluginUsed = true; … … 103 107 public void destroy() { 104 108 // if the layer is currently saving the images in the cache, wait until it's finished 105 if (cacheControl != null) { 106 while (!cacheControl.isCachePipeEmpty()) { 107 System.out.println("Try to close a WMSLayer which is currently saving in cache : wait 1 sec."); 108 CadastrePlugin.safeSleep(1000); 109 } 110 } 109 grabThread.cancel(); 111 110 super.destroy(); 112 111 images = null; … … 127 126 128 127 public void grab(CadastreGrabber grabber, Bounds b) throws IOException { 129 cancelled = false; 128 grabThread.setCancelled(false); 129 grabThread.setGrabber(grabber); 130 130 // if it is the first layer, use the communeBBox as grab bbox (and not divided) 131 131 if (Main.map.mapView.getAllLayers().size() == 1 ) { … … 142 142 } 143 143 144 int lastSavedImage = images.size(); 145 for (EastNorthBound n : dividedBbox) { 146 if (cancelled) 147 return; 148 GeorefImage newImage; 149 try { 150 newImage = grabber.grab(this, n.min, n.max); 151 } catch (IOException e) { 152 System.out.println("Download action cancelled by user or server did not respond"); 153 break; 154 } catch (OsmTransferException e) { 155 System.out.println("OSM transfer failed"); 156 break; 157 } 158 if (grabber.getWmsInterface().downloadCancelled) { 159 System.out.println("Download action cancelled by user"); 160 break; 161 } 162 if (CadastrePlugin.backgroundTransparent) { 163 for (GeorefImage img : images) { 164 if (img.overlap(newImage)) 165 // mask overlapping zone in already grabbed image 166 img.withdraw(newImage); 167 else 168 // mask overlapping zone in new image only when new 169 // image covers completely the existing image 170 newImage.withdraw(img); 171 } 172 } 173 images.add(newImage); 174 Main.map.mapView.repaint(); 175 } 176 if (!cancelled) { 177 for (int i=lastSavedImage; i < images.size(); i++) 178 saveToCache(images.get(i)); 179 } 144 grabThread.addImages(dividedBbox); 145 Main.map.repaint(); 180 146 } 181 147 … … 255 221 else 256 222 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); 257 synchronized(this){258 259 260 261 }223 imagesLock.lock(); 224 for (GeorefImage img : images) 225 img.paint(g, mv, CadastrePlugin.backgroundTransparent, 226 CadastrePlugin.transparency, CadastrePlugin.drawBoundaries); 227 imagesLock.unlock(); 262 228 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, savedInterpolation); 263 229 } 264 230 if (this.isRaster) { 265 231 paintCrosspieces(g, mv); 232 } 233 if (grabThread.getImagesToGrabSize() > 0) { 234 grabThread.paintBoxesToGrab(g, mv); 266 235 } 267 236 if (this.adjustModeEnabled) { … … 287 256 saveAsPng = new MenuActionSaveRasterAs(this); 288 257 saveAsPng.setEnabled(isRaster); 258 cancelGrab = new MenuActionCancelGrab(this); 259 cancelGrab.setEnabled(!isRaster && grabThread.getImagesToGrabSize() > 0); 289 260 return new Action[] { 290 261 LayerListDialog.getInstance().createShowHideLayerAction(), … … 292 263 new MenuActionLoadFromCache(), 293 264 saveAsPng, 265 cancelGrab, 294 266 new LayerListPopup.InfoAction(this), 295 267 … … 318 290 } 319 291 return false; 320 }321 322 public void saveToCache(GeorefImage image) {323 if (CacheControl.cacheEnabled && !isRaster()) {324 getCacheControl().saveCache(image);325 }326 }327 328 public void saveNewCache() {329 if (CacheControl.cacheEnabled) {330 getCacheControl().deleteCacheFile();331 for (GeorefImage image : images)332 getCacheControl().saveCache(image);333 }334 }335 336 public CacheControl getCacheControl() {337 if (cacheControl == null)338 cacheControl = new CacheControl(this);339 return cacheControl;340 292 } 341 293 … … 642 594 } 643 595 596 public GeorefImage getImage(int index) { 597 imagesLock.lock(); 598 GeorefImage img = null; 599 try { 600 img = this.images.get(index); 601 } catch (ArrayIndexOutOfBoundsException e) { 602 e.printStackTrace(System.out); 603 } 604 imagesLock.unlock(); 605 return img; 606 } 607 608 public Vector<GeorefImage> getImages() { 609 return this.images; 610 } 611 612 public void addImage(GeorefImage img) { 613 imagesLock.lock(); 614 this.images.add(img); 615 imagesLock.unlock(); 616 } 617 618 public void setImages(Vector<GeorefImage> images) { 619 imagesLock.lock(); 620 this.images = images; 621 imagesLock.unlock(); 622 } 623 624 public void clearImages() { 625 imagesLock.lock(); 626 this.images.clear(); 627 imagesLock.unlock(); 628 } 629 644 630 }
Note:
See TracChangeset
for help on using the changeset viewer.