Revision 17719 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramProcess.java
HistogramProcess.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.rastertools.histogram; |
20 | 20 |
|
21 |
import org.gvsig.gui.beans.incrementabletask.IIncrementable; |
|
22 |
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent; |
|
23 |
import org.gvsig.gui.beans.incrementabletask.IncrementableListener; |
|
24 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
|
25 | 21 |
import org.gvsig.raster.datastruct.Histogram; |
26 | 22 |
import org.gvsig.raster.datastruct.HistogramException; |
27 | 23 |
import org.gvsig.raster.hierarchy.IHistogramable; |
28 |
import org.gvsig.raster.process.CancelEvent; |
|
29 |
import org.gvsig.raster.process.RasterTask; |
|
30 |
import org.gvsig.raster.process.RasterTaskQueue; |
|
24 |
import org.gvsig.rastertools.RasterProcess; |
|
31 | 25 |
|
32 | 26 |
import com.iver.andami.PluginServices; |
33 | 27 |
import com.iver.andami.messages.NotificationManager; |
... | ... | |
38 | 32 |
* @version 23/04/2007 |
39 | 33 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
40 | 34 |
*/ |
41 |
public class HistogramProcess implements Runnable, IIncrementable, IncrementableListener { |
|
42 |
IHistogramable iHistogramable = null; |
|
43 |
HistogramPanelListener hpl = null; |
|
35 |
public class HistogramProcess extends RasterProcess { |
|
36 |
IHistogramable iHistogramable = null; |
|
44 | 37 |
|
45 |
IncrementableTask incrementableTask = null; |
|
46 |
private volatile Thread blinker; |
|
47 |
private RasterTask rasterTask = new RasterTask(this); |
|
48 |
|
|
49 |
/** |
|
50 |
* Constructor del Proceso de calculo de histogramas. |
|
51 |
* @param iHistogramable |
|
52 |
* @param hpl |
|
38 |
/* |
|
39 |
* (non-Javadoc) |
|
40 |
* @see org.gvsig.rastertools.RasterProcess#init() |
|
53 | 41 |
*/ |
54 |
public HistogramProcess(IHistogramable iHistogramable, HistogramPanelListener hpl) { |
|
55 |
this.iHistogramable = iHistogramable; |
|
56 |
this.hpl = hpl; |
|
42 |
public void init() { |
|
43 |
iHistogramable = (IHistogramable) getParam("histogramable"); |
|
57 | 44 |
} |
58 | 45 |
|
59 |
/** |
|
60 |
* Lanzar el Thread del proceso de calculo de histograma. |
|
61 |
*/ |
|
62 |
public void start() { |
|
63 |
blinker = new Thread(this); |
|
64 |
blinker.start(); |
|
65 |
} |
|
66 |
|
|
67 | 46 |
/* |
68 | 47 |
* (non-Javadoc) |
69 |
* @see java.lang.Runnable#run()
|
|
48 |
* @see org.gvsig.rastertools.RasterProcess#process()
|
|
70 | 49 |
*/ |
71 |
public void run() { |
|
72 |
RasterTaskQueue.register(rasterTask); |
|
73 |
|
|
50 |
public void process() throws InterruptedException { |
|
74 | 51 |
try { |
75 | 52 |
// Proceso duro de obtener un histograma. Puede durar bastante tiempo. |
76 | 53 |
Histogram histogram = iHistogramable.getHistogram(); |
77 | 54 |
// Ya tenemos el histograma y lo representamos en la ventana |
78 | 55 |
if (histogram != null) |
79 |
hpl.setNewHistogram(histogram);
|
|
56 |
externalActions.end(histogram);
|
|
80 | 57 |
} catch (HistogramException e) { |
81 | 58 |
NotificationManager.addError("Error calculando el histograma.", e); |
82 |
} catch (InterruptedException e) { |
|
83 |
//No hacemos nada en la cancelaci?n. Se ejecuta el finally |
|
84 |
} finally { |
|
85 |
RasterTaskQueue.remove(rasterTask); |
|
86 |
//Cerramos la ventana de incremento de manera correcta. |
|
87 |
incrementableTask.processFinalize(); |
|
88 | 59 |
} |
89 | 60 |
} |
90 | 61 |
|
91 |
/** |
|
92 |
* Definir el IncrementableTask |
|
93 |
* @param value |
|
94 |
*/ |
|
95 |
public void setIncrementableTask(IncrementableTask value) { |
|
96 |
incrementableTask = value; |
|
97 |
incrementableTask.addIncrementableListener(this); |
|
98 |
} |
|
99 |
|
|
100 | 62 |
/* |
101 | 63 |
* (non-Javadoc) |
102 |
* @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getLabel()
|
|
64 |
* @see org.gvsig.rastertools.RasterProcess#getLog()
|
|
103 | 65 |
*/ |
104 |
public String getLabel() { |
|
105 |
return PluginServices.getText(this, "generando_histograma") + "..."; |
|
106 |
} |
|
107 |
|
|
108 |
/* |
|
109 |
* (non-Javadoc) |
|
110 |
* @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getLog() |
|
111 |
*/ |
|
112 | 66 |
public String getLog() { |
113 |
if (iHistogramable.getPercent() == 0) { |
|
114 |
return PluginServices.getText(this, "calculando_estadisticas") + "...\n"; |
|
115 |
} |
|
116 |
return PluginServices.getText(this, "estadisticas_calculadas") + "\n" + PluginServices.getText(this, "calculando_histograma") + "...\n"; |
|
67 |
return PluginServices.getText(this, "calculando_histograma") + "...\n"; |
|
117 | 68 |
} |
118 | 69 |
|
119 | 70 |
/* |
120 | 71 |
* (non-Javadoc) |
121 |
* @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getPercent()
|
|
72 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent()
|
|
122 | 73 |
*/ |
123 | 74 |
public int getPercent() { |
124 |
return iHistogramable.getPercent(); |
|
75 |
if (iHistogramable != null) |
|
76 |
return iHistogramable.getPercent(); |
|
77 |
return 0; |
|
125 | 78 |
} |
126 | 79 |
|
127 | 80 |
/* |
128 | 81 |
* (non-Javadoc) |
129 |
* @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getTitle()
|
|
82 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle()
|
|
130 | 83 |
*/ |
131 | 84 |
public String getTitle() { |
132 | 85 |
return PluginServices.getText(this, "calculando_histograma"); |
133 | 86 |
} |
134 |
|
|
135 |
/* |
|
136 |
* (non-Javadoc) |
|
137 |
* @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionCanceled(org.gvsig.gui.beans.incrementabletask.IncrementableEvent) |
|
138 |
*/ |
|
139 |
public void actionCanceled(IncrementableEvent e) { |
|
140 |
rasterTask.setEvent(new CancelEvent(this)); |
|
141 |
} |
|
142 |
|
|
143 |
/* |
|
144 |
* (non-Javadoc) |
|
145 |
* @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionResumed(org.gvsig.gui.beans.incrementabletask.IncrementableEvent) |
|
146 |
*/ |
|
147 |
public void actionResumed(IncrementableEvent e) { |
|
148 |
} |
|
149 |
|
|
150 |
/* |
|
151 |
* (non-Javadoc) |
|
152 |
* @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionSuspended(org.gvsig.gui.beans.incrementabletask.IncrementableEvent) |
|
153 |
*/ |
|
154 |
public void actionSuspended(IncrementableEvent e) { |
|
155 |
} |
|
156 | 87 |
} |
Also available in: Unified diff