Changeset 22779 in osm
- Timestamp:
- 2010-08-26T07:56:39+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/wmsplugin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/.classpath
r22677 r22779 3 3 <classpathentry kind="src" path="src"/> 4 4 <classpathentry including="images/" kind="src" path=""/> 5 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER "/>5 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JDK 6"/> 6 6 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 7 7 <classpathentry combineaccessrules="false" kind="src" path="/remotecontrol"/> -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java
r22712 r22779 13 13 import java.io.ObjectOutputStream; 14 14 import java.io.Serializable; 15 import java.lang.ref.SoftReference; 15 16 16 17 import javax.imageio.ImageIO; … … 28 29 29 30 private BufferedImage image; 30 private BufferedImage reImg = null;31 private SoftReference<BufferedImage> reImg; 31 32 private int xIndex; 32 33 private int yIndex; … … 51 52 this.yIndex = yIndex; 52 53 this.image = null; 53 this.reImg = null;54 flushedResizedCachedInstance(); 54 55 } 55 56 } … … 60 61 61 62 public void changeImage(State state, BufferedImage image) { 63 flushedResizedCachedInstance(); 62 64 this.image = image; 63 this.reImg = null;64 65 this.state = state; 65 66 … … 126 127 return false; 127 128 128 if(reImg != null && reImg.getWidth() == width && reImg.getHeight() == height) { 129 g.drawImage(reImg, x, y, null); 129 BufferedImage img = reImg == null?null:reImg.get(); 130 if(img != null && img.getWidth() == width && img.getHeight() == height) { 131 g.drawImage(img, x, y, null); 130 132 return true; 131 133 } … … 134 136 135 137 try { 136 if( reImg != null) reImg.flush();138 if(img != null) img.flush(); 137 139 long freeMem = Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory(); 138 140 //System.out.println("Free Memory: "+ (freeMem/1024/1024) +" MB"); … … 149 151 } else { 150 152 // We haven't got a saved resized copy, so resize and cache it 151 reImg = new BufferedImage(width, height, alphaChannel?BufferedImage.TYPE_INT_ARGB:BufferedImage.TYPE_3BYTE_BGR);152 reImg.getGraphics().drawImage(getImage(),153 img = new BufferedImage(width, height, alphaChannel?BufferedImage.TYPE_INT_ARGB:BufferedImage.TYPE_3BYTE_BGR); 154 img.getGraphics().drawImage(getImage(), 153 155 0, 0, width, height, // dest 154 156 0, 0, getImage().getWidth(null), getImage().getHeight(null), // src 155 157 null); 156 reImg.getGraphics().dispose(); 157 g.drawImage(reImg, x, y, null); 158 img.getGraphics().dispose(); 159 g.drawImage(img, x, y, null); 160 reImg = new SoftReference<BufferedImage>(img); 158 161 } 159 162 } catch(Exception e) { … … 164 167 165 168 private void fallbackDraw(Graphics g, Image img, int x, int y, int width, int height) { 166 if(reImg != null) { 167 reImg.flush(); 168 reImg = null; 169 } 169 flushedResizedCachedInstance(); 170 170 g.drawImage( 171 171 img, x, y, x + width, y + height, … … 195 195 196 196 public void flushedResizedCachedInstance() { 197 if (reImg != null) { 198 BufferedImage img = reImg.get(); 199 if (img != null) { 200 img.flush(); 201 } 202 } 197 203 reImg = null; 198 204 } -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java
r22720 r22779 61 61 protected MapView mv; 62 62 protected String resolution; 63 protected boolean stopAfterPaint = false;64 63 protected int imageSize = 500; 65 64 protected int dax = 10; 66 65 protected int day = 10; 66 protected int daStep = 5; 67 67 protected int minZoom = 3; 68 69 protected boolean deltaChanged; 68 70 protected double dx = 0.0; 69 71 protected double dy = 0.0; 72 70 73 protected double pixelPerDegree; 71 protected GeorefImage[][] images = new GeorefImage[dax][day];74 protected GeorefImage[][] images; 72 75 protected String baseURL; 73 76 protected String cookies; … … 152 155 153 156 public void initializeImages() { 157 GeorefImage[][] old = images; 154 158 images = new GeorefImage[dax][day]; 159 if (old != null) { 160 for (int i=0; i<old.length; i++) { 161 for (int k=0; k<old[i].length; k++) { 162 GeorefImage o = old[i][k]; 163 images[modulo(o.getXIndex(),dax)][modulo(o.getYIndex(),day)] = old[i][k]; 164 } 165 } 166 } 155 167 for(int x = 0; x<dax; ++x) { 156 168 for(int y = 0; y<day; ++y) { 157 images[x][y]= new GeorefImage(this); 169 if (images[x][y] == null) { 170 images[x][y]= new GeorefImage(this); 171 } 158 172 } 159 173 } … … 188 202 189 203 @Override public void paint(Graphics2D g, final MapView mv, Bounds b) { 204 deltaChanged = false; 190 205 if(baseURL == null) return; 191 206 if (usesInvalidUrl && !isInvalidUrlConfirmed) return; … … 246 261 247 262 public void displace(double dx, double dy) { 263 deltaChanged = true; 248 264 this.dx += dx; 249 265 this.dy += dy; … … 278 294 279 295 protected void downloadAndPaintVisible(Graphics g, final MapView mv, boolean real){ 296 297 int newDax = dax; 298 int newDay = day; 299 300 if (bmaxx - bminx >= dax || bmaxx - bminx < dax - 2 * daStep) { 301 newDax = ((bmaxx - bminx) / daStep + 1) * daStep; 302 } 303 304 if (bmaxy - bminy >= day || bmaxy - bminx < day - 2 * daStep) { 305 newDay = ((bmaxy - bminy) / daStep + 1) * daStep; 306 } 307 308 if (newDax != dax || newDay != day) { 309 dax = newDax; 310 day = newDay; 311 initializeImages(); 312 } 280 313 281 314 for(int x = bminx; x<=bmaxx; ++x) { … … 706 739 } 707 740 741 @Override 742 public boolean isChanged() { 743 requestQueueLock.lock(); 744 try { 745 return !finishedRequests.isEmpty() || deltaChanged; 746 } finally { 747 requestQueueLock.unlock(); 748 } 749 } 750 708 751 public void preferenceChanged(PreferenceChangeEvent event) { 709 752 if (event.getKey().equals(WMSPlugin.PROP_SIMULTANEOUS_CONNECTIONS.getKey())) {
Note:
See TracChangeset
for help on using the changeset viewer.