Changeset 25033 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GrabThread.java
- Timestamp:
- 2011-01-12T23:33:13+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GrabThread.java
r24934 r25033 22 22 private WMSLayer wmsLayer; 23 23 24 private Lock lock = new ReentrantLock(); 24 private Lock lockImagesToGrag = new ReentrantLock(); 25 25 26 26 private ArrayList<EastNorthBound> imagesToGrab = new ArrayList<EastNorthBound>(); … … 30 30 private EastNorthBound currentGrabImage; 31 31 32 private Lock lockCurrentGrabImage = new ReentrantLock(); 33 34 /** 35 * Call directly grabber for raster images or prepare thread for vector images 36 * @param moreImages 37 */ 32 38 public void addImages(ArrayList<EastNorthBound> moreImages) { 33 lock.lock(); 39 lockImagesToGrag.lock(); 34 40 imagesToGrab.addAll(moreImages); 35 lock.unlock(); 41 lockImagesToGrag.unlock(); 36 42 synchronized(this) { 37 43 this.notify(); 38 44 } 39 45 System.out.println("Added " + moreImages.size() + " to the grab thread"); 46 if (wmsLayer.isRaster()) { 47 waitNotification(); 48 } 40 49 } 41 50 42 51 public int getImagesToGrabSize() { 43 lock.lock(); 52 lockImagesToGrag.lock(); 44 53 int size = imagesToGrab.size(); 45 lock.unlock(); 54 lockImagesToGrag.unlock(); 46 55 return size; 47 56 } … … 49 58 public ArrayList<EastNorthBound> getImagesToGrabCopy() { 50 59 ArrayList<EastNorthBound> copyList = new ArrayList<EastNorthBound>(); 51 lock.lock(); 60 lockImagesToGrag.lock(); 52 61 for (EastNorthBound img : imagesToGrab) { 53 62 EastNorthBound imgCpy = new EastNorthBound(img.min, img.max); 54 63 copyList.add(imgCpy); 55 64 } 56 lock.unlock(); 65 lockImagesToGrag.unlock(); 57 66 return copyList; 58 67 } 59 68 60 69 public void clearImagesToGrab() { 61 lock.lock(); 70 lockImagesToGrag.lock(); 62 71 imagesToGrab.clear(); 63 lock.unlock(); 72 lockImagesToGrag.unlock(); 64 73 } 65 74 … … 68 77 for (;;) { 69 78 while (getImagesToGrabSize() > 0) { 70 lock.lock(); 79 lockImagesToGrag.lock(); 80 lockCurrentGrabImage.lock(); 71 81 currentGrabImage = imagesToGrab.get(0); 82 lockCurrentGrabImage.unlock(); 72 83 imagesToGrab.remove(0); 73 lock.unlock(); 84 lockImagesToGrag.unlock(); 74 85 if (cancelled) { 75 86 break; … … 77 88 GeorefImage newImage; 78 89 try { 90 Main.map.repaint(); // paint the current grab box 79 91 newImage = grabber.grab(wmsLayer, currentGrabImage.min, currentGrabImage.max); 80 92 } catch (IOException e) { … … 93 105 break; 94 106 } 107 try { 95 108 if (CadastrePlugin.backgroundTransparent) { 96 109 wmsLayer.imagesLock.lock(); … … 109 122 Main.map.mapView.repaint(); 110 123 saveToCache(newImage); 124 } catch (NullPointerException e) { 125 System.out.println("Layer destroyed. Cancel grab thread"); 126 setCancelled(true); 127 } 111 128 } 112 129 } 113 130 System.out.println("grab thread list empty"); 131 lockCurrentGrabImage.lock(); 114 132 currentGrabImage = null; 133 lockCurrentGrabImage.unlock(); 115 134 if (cancelled) { 116 135 clearImagesToGrab(); 117 136 cancelled = false; 118 137 } 119 synchronized(this) { 120 try { 121 wait(); 122 } catch (InterruptedException e) { 123 e.printStackTrace(System.out); 124 } 125 } 126 } 138 if (wmsLayer.isRaster()) { 139 notifyWaiter(); 140 } 141 waitNotification(); } 127 142 } 128 143 … … 165 180 166 181 public void paintBoxesToGrab(Graphics g, MapView mv) { 167 ArrayList<EastNorthBound> imagesToGrab = getImagesToGrabCopy(); 168 for (EastNorthBound img : imagesToGrab) { 169 paintBox(g, mv, img, Color.red); 170 } 182 if (getImagesToGrabSize() > 0) { 183 ArrayList<EastNorthBound> imagesToGrab = getImagesToGrabCopy(); 184 for (EastNorthBound img : imagesToGrab) { 185 paintBox(g, mv, img, Color.red); 186 } 187 } 188 lockCurrentGrabImage.lock(); 171 189 if (currentGrabImage != null) { 172 190 paintBox(g, mv, currentGrabImage, Color.orange); 173 191 } 192 lockCurrentGrabImage.unlock(); 174 193 } 175 194 … … 203 222 } 204 223 224 private synchronized void notifyWaiter() { 225 this.notify(); 226 } 227 228 private synchronized void waitNotification() { 229 try { 230 wait(); 231 } catch (InterruptedException e) { 232 e.printStackTrace(System.out); 233 } 234 } 235 205 236 }
Note:
See TracChangeset
for help on using the changeset viewer.
