Revision 1135 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
TileImpl.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.raster.cache.tile.impl; |
23 | 23 |
|
24 |
import java.awt.event.ActionEvent; |
|
25 |
import java.awt.event.ActionListener; |
|
26 | 24 |
import java.awt.geom.AffineTransform; |
27 | 25 |
import java.awt.geom.NoninvertibleTransformException; |
28 | 26 |
import java.awt.geom.Point2D; |
29 | 27 |
import java.awt.geom.Rectangle2D; |
30 |
import java.io.DataInputStream; |
|
31 | 28 |
import java.io.File; |
32 | 29 |
import java.io.IOException; |
33 | 30 |
import java.util.HashMap; |
34 | 31 |
|
35 |
import javax.swing.Timer; |
|
36 |
|
|
37 | 32 |
import org.gvsig.compat.net.ICancellable; |
38 | 33 |
import org.gvsig.raster.cache.tile.Tile; |
39 | 34 |
import org.gvsig.raster.cache.tile.pool.AtomicTask; |
... | ... | |
45 | 40 |
* |
46 | 41 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
47 | 42 |
*/ |
48 |
public class TileImpl implements Tile, ActionListener { |
|
49 |
private static int msTime = 10000; |
|
43 |
public class TileImpl implements Tile { |
|
50 | 44 |
private boolean corrupt = false; |
51 | 45 |
private int level = 0; |
52 | 46 |
private int col = 0; |
... | ... | |
68 | 62 |
private int priority = 0; |
69 | 63 |
private Object[] data = null; |
70 | 64 |
protected CancelTaskImpl cancelDownloading = null; |
71 |
private Timer timer = null; |
|
72 | 65 |
|
73 | 66 |
/** |
74 | 67 |
* All tasks which use libRemoteServices need an object that implements ICancellable |
... | ... | |
77 | 70 |
*/ |
78 | 71 |
public class CancelTaskImpl implements ICancellable { |
79 | 72 |
private boolean cancel = false; |
80 |
private Object obj = null; |
|
81 | 73 |
|
82 | 74 |
public CancelTaskImpl() { |
83 | 75 |
} |
... | ... | |
103 | 95 |
* @param cancel |
104 | 96 |
* @throws IOException |
105 | 97 |
*/ |
106 |
public void setCanceled(boolean cancel) throws IOException {
|
|
98 |
public void setCanceled(boolean cancel) { |
|
107 | 99 |
this.cancel = cancel; |
108 |
if(cancel && obj != null && obj instanceof DataInputStream) |
|
109 |
((DataInputStream)obj).close(); |
|
110 | 100 |
} |
111 |
|
|
112 |
public boolean equals(Object obj) { |
|
113 |
this.obj = obj; |
|
114 |
return true; |
|
115 |
} |
|
101 |
|
|
116 | 102 |
} |
117 | 103 |
|
118 | 104 |
public TileImpl(int level, int col, int row) { |
... | ... | |
132 | 118 |
cancelDownloading = new CancelTaskImpl(); |
133 | 119 |
} |
134 | 120 |
|
135 |
private Timer getTimer() { |
|
136 |
if(timer == null) |
|
137 |
timer = new Timer(msTime, this); |
|
138 |
return timer; |
|
139 |
} |
|
140 |
|
|
141 | 121 |
/* |
142 | 122 |
* (non-Javadoc) |
143 | 123 |
* @see org.gvsig.raster.cache.tile.Tile#getDownloadingImage() |
... | ... | |
434 | 414 |
*/ |
435 | 415 |
public void run() { |
436 | 416 |
try { |
437 |
cancelDownloading.setCanceled(false); |
|
438 |
//Si en 10 segundos no ha descargado el tile mandar? una se?al de cancelaci?n |
|
439 |
//getTimer().start(); |
|
440 | 417 |
downloader.downloadTile(this); |
441 |
//getTimer().stop(); |
|
442 | 418 |
corrupt = false; |
443 | 419 |
} catch (Exception e) { |
444 | 420 |
if(getFile().exists()) |
... | ... | |
446 | 422 |
corrupt = true; |
447 | 423 |
System.out.println("Exception Cancelando tile....." + getId()); |
448 | 424 |
} finally { |
449 |
//getTimer().stop(); |
|
450 | 425 |
if(sharedPipe != null) |
451 | 426 |
sharedPipe.setAtomicTask(this); |
452 | 427 |
} |
... | ... | |
457 | 432 |
* @see org.gvsig.raster.cache.tile.pool.AtomicTask#cancelTask() |
458 | 433 |
*/ |
459 | 434 |
public void cancelTask() { |
435 |
((CancelTaskImpl)getCancelled()).setCanceled(true); |
|
460 | 436 |
sharedPipe = null; |
461 | 437 |
} |
462 | 438 |
|
463 |
public void actionPerformed(ActionEvent e) { |
|
464 |
System.out.println("+++++Cancelled"); |
|
465 |
try { |
|
466 |
cancelDownloading.setCanceled(true); |
|
467 |
} catch (IOException e1) { |
|
468 |
e1.printStackTrace(); |
|
469 |
} |
|
470 |
getTimer().stop(); |
|
471 |
} |
|
472 | 439 |
|
473 | 440 |
/* |
474 | 441 |
* (non-Javadoc) |
Also available in: Unified diff