Revision 4357
org.gvsig.raster.cache/trunk/org.gvsig.raster.cache/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/TileImpl.java | ||
---|---|---|
29 | 29 |
import java.io.IOException; |
30 | 30 |
import java.util.HashMap; |
31 | 31 |
|
32 |
import org.slf4j.Logger; |
|
33 |
import org.slf4j.LoggerFactory; |
|
34 |
|
|
32 | 35 |
import org.gvsig.compat.net.ICancellable; |
33 | 36 |
import org.gvsig.raster.cache.tile.Tile; |
34 | 37 |
import org.gvsig.raster.cache.tile.pool.AtomicTask; |
... | ... | |
53 | 56 |
private Point2D ul = null; |
54 | 57 |
private Point2D lr = null; |
55 | 58 |
private Rectangle2D coordPx = null; |
56 |
|
|
59 |
|
|
57 | 60 |
private File file = null; |
58 | 61 |
private Downloader downloader = null; |
59 |
private HashMap<String, Object>
|
|
62 |
private HashMap<String, Object> |
|
60 | 63 |
downloaderParams = new HashMap<String, Object>(); |
61 | 64 |
private TilePipe sharedPipe = null; |
62 | 65 |
private int priority = 0; |
63 | 66 |
private Object[] data = null; |
64 | 67 |
protected CancelTaskImpl cancelDownloading = null; |
65 |
|
|
68 |
|
|
69 |
private static Logger logger = LoggerFactory.getLogger(TileImpl.class); |
|
70 |
|
|
66 | 71 |
/** |
67 | 72 |
* All tasks which use libRemoteServices need an object that implements ICancellable |
68 | 73 |
* to cancel processes. |
... | ... | |
70 | 75 |
*/ |
71 | 76 |
public class CancelTaskImpl implements ICancellable { |
72 | 77 |
private boolean cancel = false; |
73 |
|
|
78 |
|
|
74 | 79 |
public CancelTaskImpl() { |
75 | 80 |
} |
76 |
|
|
81 |
|
|
77 | 82 |
public Object getID() { |
78 | 83 |
return this; |
79 | 84 |
} |
... | ... | |
81 | 86 |
public boolean isCanceled() { |
82 | 87 |
return cancel; |
83 | 88 |
} |
84 |
|
|
89 |
|
|
85 | 90 |
/** |
86 | 91 |
* Cancel the task |
87 | 92 |
* @param cancel |
88 |
* @throws IOException
|
|
93 |
* @throws IOException |
|
89 | 94 |
*/ |
90 | 95 |
public void setCanceled(boolean cancel) { |
91 | 96 |
this.cancel = cancel; |
92 | 97 |
} |
93 | 98 |
|
94 | 99 |
} |
95 |
|
|
100 |
|
|
96 | 101 |
public TileImpl(int level, int col, int row) { |
97 | 102 |
this.level = level; |
98 | 103 |
this.col = col; |
99 | 104 |
this.row = row; |
100 | 105 |
cancelDownloading = new CancelTaskImpl(); |
101 | 106 |
} |
102 |
|
|
107 |
|
|
103 | 108 |
public TileImpl(int wPx, int hPx, int row, int col, Point2D ul, Point2D lr) { |
104 | 109 |
this.row = row; |
105 | 110 |
this.col = col; |
... | ... | |
109 | 114 |
this.heightPx = hPx; |
110 | 115 |
cancelDownloading = new CancelTaskImpl(); |
111 | 116 |
} |
112 |
|
|
117 |
|
|
113 | 118 |
public Object[] getDownloadingImage() { |
114 | 119 |
return downloader.getDownloadingImage(getWidthPx(), getHeightPx()); |
115 | 120 |
} |
116 |
|
|
121 |
|
|
117 | 122 |
public Object[] getCrashImage() { |
118 | 123 |
return downloader.getCrashImage(getWidthPx(), getHeightPx()); |
119 | 124 |
} |
120 |
|
|
125 |
|
|
121 | 126 |
public Object getDownloadingARGB() { |
122 | 127 |
Object[] result = downloader.getDownloadingImage(getWidthPx(), getHeightPx()); |
123 |
if(result != null && result.length >= 1) |
|
128 |
if(result != null && result.length >= 1) {
|
|
124 | 129 |
return result[0]; |
130 |
} |
|
125 | 131 |
return null; |
126 | 132 |
} |
127 |
|
|
133 |
|
|
128 | 134 |
public Object getCrashARGB() { |
129 | 135 |
Object[] result = downloader.getCrashImage(getWidthPx(), getHeightPx()); |
130 |
if(result != null && result.length >= 1) |
|
136 |
if(result != null && result.length >= 1) {
|
|
131 | 137 |
return result[0]; |
138 |
} |
|
132 | 139 |
return null; |
133 | 140 |
} |
134 |
|
|
141 |
|
|
135 | 142 |
/** |
136 | 143 |
* Convierte un punto desde del mundo a coordenadas pixel. |
137 | 144 |
* @param pt Punto a transformar |
... | ... | |
149 | 156 |
} |
150 | 157 |
return p; |
151 | 158 |
} |
152 |
|
|
159 |
|
|
153 | 160 |
public Tile cloneTile() { |
154 | 161 |
TileImpl newTile = new TileImpl(widthPx, heightPx, row, col, (Point2D)ul.clone(), (Point2D)lr.clone()); |
155 | 162 |
newTile.file = file; |
156 | 163 |
return newTile; |
157 | 164 |
} |
158 |
|
|
165 |
|
|
159 | 166 |
public String getVariable() { |
160 | 167 |
return var; |
161 | 168 |
} |
162 |
|
|
169 |
|
|
163 | 170 |
public String getZ() { |
164 | 171 |
return z; |
165 | 172 |
} |
166 |
|
|
173 |
|
|
167 | 174 |
public String getTimeInstant() { |
168 | 175 |
return time; |
169 | 176 |
} |
170 |
|
|
177 |
|
|
171 | 178 |
public void setVariable(String var) { |
172 | 179 |
this.var = var; |
173 | 180 |
} |
174 |
|
|
181 |
|
|
175 | 182 |
public void setZ(String z) { |
176 | 183 |
this.z = z; |
177 | 184 |
} |
178 |
|
|
185 |
|
|
179 | 186 |
public int getLevel() { |
180 | 187 |
return level; |
181 | 188 |
} |
182 |
|
|
189 |
|
|
183 | 190 |
public void setTimeInstant(String t) { |
184 | 191 |
this.time = t; |
185 | 192 |
} |
... | ... | |
191 | 198 |
public int getRow() { |
192 | 199 |
return row; |
193 | 200 |
} |
194 |
|
|
201 |
|
|
195 | 202 |
public void setCol(int col) { |
196 | 203 |
this.col = col; |
197 | 204 |
} |
198 |
|
|
205 |
|
|
199 | 206 |
public void setRow(int row) { |
200 | 207 |
this.row = row; |
201 | 208 |
} |
202 |
|
|
209 |
|
|
203 | 210 |
public void setLevel(int level) { |
204 | 211 |
this.level = level; |
205 | 212 |
} |
206 |
|
|
213 |
|
|
207 | 214 |
public Rectangle2D getCoordsPx() { |
208 | 215 |
return coordPx; |
209 | 216 |
} |
210 |
|
|
217 |
|
|
211 | 218 |
public void setCoordsPx(Rectangle2D r) { |
212 | 219 |
this.coordPx = r; |
213 | 220 |
} |
... | ... | |
227 | 234 |
public void setHeightPx(int heightPx) { |
228 | 235 |
this.heightPx = heightPx; |
229 | 236 |
} |
230 |
|
|
237 |
|
|
231 | 238 |
public Rectangle2D getExtent() { |
232 |
return new Rectangle2D.Double(ul.getX(), ul.getY(),
|
|
239 |
return new Rectangle2D.Double(ul.getX(), ul.getY(), |
|
233 | 240 |
Math.abs(ul.getX() - lr.getX()), Math.abs(ul.getY() - lr.getY())); |
234 | 241 |
} |
235 | 242 |
|
... | ... | |
276 | 283 |
public void setDownloaderParams(String key, Object value) { |
277 | 284 |
this.downloaderParams.put(key.toUpperCase(), value); |
278 | 285 |
} |
279 |
|
|
286 |
|
|
280 | 287 |
public void setCorrupt(boolean corrupt) { |
281 | 288 |
this.corrupt = corrupt; |
282 | 289 |
} |
283 |
|
|
290 |
|
|
284 | 291 |
public boolean isCorrupt() { |
285 | 292 |
boolean c = corrupt; |
286 | 293 |
corrupt = false; |
287 | 294 |
return c; |
288 | 295 |
} |
289 |
|
|
296 |
|
|
290 | 297 |
/** |
291 | 298 |
* Actions for download a tile |
292 | 299 |
*/ |
... | ... | |
295 | 302 |
downloader.downloadTile(this); |
296 | 303 |
corrupt = false; |
297 | 304 |
} catch (Exception e) { |
298 |
if(getFile().exists()) |
|
305 |
if(getFile().exists()) {
|
|
299 | 306 |
getFile().delete(); |
307 |
} |
|
300 | 308 |
corrupt = true; |
301 |
System.out.println("Exception Cancelando tile....." + getId());
|
|
309 |
logger.warn("Canceling tile....." + getId(), e);
|
|
302 | 310 |
} finally { |
303 | 311 |
if(sharedPipe != null) |
304 | 312 |
sharedPipe.setAtomicTask(this); |
305 | 313 |
} |
306 | 314 |
} |
307 |
|
|
315 |
|
|
308 | 316 |
public void cancelTask() { |
309 | 317 |
((CancelTaskImpl)getCancelled()).setCanceled(true); |
310 | 318 |
sharedPipe = null; |
311 | 319 |
} |
312 |
|
|
320 |
|
|
313 | 321 |
public ICancellable getCancelled() { |
314 | 322 |
return cancelDownloading; |
315 | 323 |
} |
... | ... | |
325 | 333 |
public void setSharedPipe(TilePipe sharedPipe) { |
326 | 334 |
this.sharedPipe = sharedPipe; |
327 | 335 |
} |
328 |
|
|
336 |
|
|
329 | 337 |
public String getId() { |
330 | 338 |
return getLevel() + "_" + getRow() + "_" + getCol(); |
331 | 339 |
} |
... | ... | |
333 | 341 |
public int getPriority() { |
334 | 342 |
return priority; |
335 | 343 |
} |
336 |
|
|
344 |
|
|
337 | 345 |
public void setPriority(int priority) { |
338 | 346 |
this.priority = priority; |
339 | 347 |
} |
340 |
|
|
348 |
|
|
341 | 349 |
public void setData(Object[] data) { |
342 | 350 |
this.data = data; |
343 | 351 |
} |
344 |
|
|
352 |
|
|
345 | 353 |
public Object[] getData() { |
346 | 354 |
return data; |
347 | 355 |
} |
... | ... | |
353 | 361 |
return -1; |
354 | 362 |
return 0; |
355 | 363 |
} |
356 |
|
|
364 |
|
|
357 | 365 |
public boolean dataIsLoaded() { |
358 | 366 |
return (getData() != null && getData().length > 0); |
359 | 367 |
} |
Also available in: Unified diff