Revision 10997

View differences:

trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramProcess.java
25 25

  
26 26
public class HistogramProcess extends Thread implements IIncrementable {
27 27
	IHistogramable iHistogramable = null;
28
	long[][] histogram = null;
29
	int type = 0;
28
	Histogram histogram = null;
30 29
	
31
	public HistogramProcess(IHistogramable iHistogramable, int type) {
30
	public HistogramProcess(IHistogramable iHistogramable) {
32 31
		this.iHistogramable = iHistogramable;
33
		this.type = type;
34 32
		this.start();
35 33
	}
36 34
	
37 35
	public void run() {
38 36
		try {
39
			histogram = iHistogramable.getHistogram().getHistogramByType(Histogram.getType(type));
37
			histogram = iHistogramable.getHistogram();
40 38
		} catch (HistogramException e) {
41 39
			e.printStackTrace();
42 40
		}
43 41
	}
44 42
	
45
	public long[][] getLastHistogram() {
43
	public Histogram getLastHistogram() {
46 44
		return histogram;
47 45
	}
48 46
	/*
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramTocMenuEntry.java
57 57
	}
58 58
	
59 59
	public void execute(ITocItem item, FLayer[] selectedItems) {
60

  
61 60
		
62 61
		if (selectedItems.length == 1 )
63 62
			lyr = selectedItems[0];
......
67 66
		lyr = getNodeLayer(item);
68 67
		
69 68
		histogramDialog = new HistogramDialog(width, height);
70
		histogramDialog.setSize(width, height);
69
//		histogramDialog.setSize(width, height);
71 70

  
72 71
		histogramDialog.clearSources();
73 72
		histogramDialog.setHistogramableSource(((FLyrRasterSE)lyr).getSource().getRender().getLastRenderBuffer(), PluginServices.getText(this, "datos_visualizados"));
74
		histogramDialog.setHistogramableSource(((FLyrRasterSE)lyr).getSource().getDatasource().getGeoRasterMultiFile(), PluginServices.getText(this, "vista_datasource"));
73
		histogramDialog.setHistogramableSource(((FLyrRasterSE)lyr).getSource().getDatasource().getGeoRasterMultiFile(), PluginServices.getText(this, "imagen_completa"));
75 74

  
76 75
		//Par?metros de inicializaci?n del histograma
77 76

  
......
80 79
		histogramDialog.getHistogramPanel().setRGBInBandList(); //Asignaci?n R,G,B en el combo
81 80

  
82 81
		histogramDialog.getHistogramPanel().firstRun(); // Mostar por primera vez el histograma
82
		histogramDialog.setVisible(true);
83 83
 		       					
84 84
		PluginServices.getMDIManager().addWindow(histogramDialog);
85 85
	}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramPanel.java
396 396
	 * @param band banda a visualizar o borrar del gr?fico
397 397
	 */
398 398
	public void addOrRemoveGraphicBand(int band){
399
		if(band > showBands.length)
399
		if (band > showBands.length)
400 400
			return;
401 401
		showBands[band] = !showBands[band];
402 402
	}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramPanelListener.java
33 33
import org.gvsig.raster.util.Histogram;
34 34
import org.gvsig.raster.util.IHistogramable;
35 35
import org.gvsig.rastertools.histogram.ui.HistogramPanel;
36

  
37
import com.iver.utiles.swing.threads.Cancellable;
36 38
/**
37 39
 * Listener para eventos del panel de histograma
38 40
 *
......
44 46
	private HistogramPanel		histogramPanel = null;
45 47
	private IncrementableTask	incrementableTask = null;
46 48
	private HistogramProcess	histogramProcess = null;
47
	private long[][]					lastHistogram = null; 
49
	private Histogram					lastHistogram = null;
50
	private int								bandCount = 0;
48 51

  
49 52
	public boolean						comboEventEnable = false;
50 53
		
......
91 94
		JComboBox cbb = histogramPanel.getJComboBands();
92 95
		if (comboEventEnable && (e.getSource() == cbb)) {
93 96
			if (cbb.getSelectedItem() == null) return;
97
			updateGraphic();
98
/*			
94 99
			if(cbb.getSelectedIndex() == 0) {
95 100
				boolean[] list = histogramPanel.getBandListShowInChart();
96 101
				for (int i = 0; i < list.length; i++)
......
114 119
				if (cbb.getSelectedItem().equals("Band "+i))
115 120
					histogramPanel.addOrRemoveGraphicBand(i);
116 121
			}
122
*/
117 123
			return;
118 124
		}
119 125
		
......
129 135
		//Selecci?n de fuente de datos del histograma
130 136
		JComboBox cbo = histogramPanel.getJComboBoxOrigen();
131 137
		if (comboEventEnable && e.getSource() == cbo) {
132
			showHistogram();
133
//			panel.setHistogramDataSource(cbo.getSelectedIndex());
134
			
135 138
			//En caso de que el histograma se monte a partir de los datos de la vista ponemos RGB en el combo
136
//			if(cbo.getSelectedIndex() == 0)
137
//				panel.setRGBInBandList();
139
			if(cbo.getSelectedIndex() == 0) {
140
				histogramPanel.setRGBInBandList();
141
			}
138 142
			
139 143
			//En caso de que el histograma se monte a partir de los datos reales ponemos el n?mero de bandas en el combo
140
//			if (cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2)
141
//				panel.setBands(getHistogram().getGrid().getGrid().getBandCount());			
144
			if (cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2) {
145
				histogramPanel.setBands(bandCount);
146
			}
147
			showHistogram();
142 148
			return;
143 149
		}
144 150
				
......
147 153
		JComboBox cbt = histogramPanel.getJComboBoxTipo();
148 154
		if (comboEventEnable && e.getSource() == cbt) {
149 155
			histogramPanel.setType(cbt.getSelectedIndex());
150
			showHistogram();
156
			updateStatistic();
157
			updateGraphic();
151 158
			return;
152 159
		}
153 160
	}
154 161

  
155 162
	public void showHistogram() {
156 163
		if (histogramPanel.getJComboBoxOrigen().getSelectedIndex() < 0) return;
164
		closeHistogramProcess();
157 165
		IHistogramable iaux = (IHistogramable) ((ArrayList) histogramPanel.getComboSource().get(histogramPanel.getJComboBoxOrigen().getSelectedIndex())).get(0);
158
		histogramProcess = new HistogramProcess(iaux, histogramPanel.getJComboBoxTipo().getSelectedIndex());
166
		histogramProcess = new HistogramProcess(iaux);
159 167
		incrementableTask = new IncrementableTask(histogramProcess);
160 168
		incrementableTask.addIncrementableListener(this);
161 169
		incrementableTask.showWindow();
......
176 184
	public void keyTyped(KeyEvent e) {
177 185
	}
178 186

  
179
	private void closeHistogramProcess() {
180
		histogramProcess = null;
181
		incrementableTask = null;
182
	}
183
	public void actionCanceled(IncrementableEvent e) {
184
		closeHistogramProcess();
185
	}
186

  
187 187
	private void updateGraphic() {
188
		if (lastHistogram == null) return;
188
		long[][] auxHistogram = lastHistogram.getHistogramByType(Histogram.getType(histogramPanel.getJComboBoxTipo().getSelectedIndex()));
189
		if (auxHistogram == null) return;
189 190

  
190 191
		int first = 0;
191
		int end = lastHistogram[0].length;
192
		int end = auxHistogram[0].length;
192 193

  
193
		first = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[1]*lastHistogram[0].length)/100);
194
		end = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[0]*lastHistogram[0].length)/100);
194
		first = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[1]*auxHistogram[0].length)/100);
195
		end = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[0]*auxHistogram[0].length)/100);
195 196

  
196
		int[][] newHistogram = new int[lastHistogram.length][end - first];
197
		String[] bandNames = new String[lastHistogram.length];
197
		int bands = (histogramPanel.getJComboBands().getSelectedIndex()==0?auxHistogram.length:1);
198

  
199
		int[][] newHistogram = new int[bands][end - first];
200
		String[] bandNames = new String[bands];
198 201
		
199
		for (int iBand=0; iBand<lastHistogram.length; iBand++) {
202
		bandCount = auxHistogram.length;
203

  
204
		for (int iBand=0; iBand<bands; iBand++) {
200 205
			for (int j=first; j<end; j++)
201
				newHistogram[iBand][j-first] = (int) lastHistogram[iBand][j];
206
				newHistogram[iBand][j-first] = (int) auxHistogram[(bands>1?iBand:histogramPanel.getJComboBands().getSelectedIndex()-1)][j];
202 207
			bandNames[iBand] = iBand + "";
203 208
		}
204 209

  
205 210
		histogramPanel.getGraphicContainer().getPGraphic().cleanChart();
206 211
		histogramPanel.getGraphicContainer().getPGraphic().setNewChart(newHistogram, bandNames);
207 212
	}
213

  
214
	private void closeHistogramProcess() {
215
		histogramProcess = null;
216
		incrementableTask = null;
217
	}
218

  
219
	public void actionCanceled(IncrementableEvent e) {
220
//		if (histogramProcess != null) histogramProcess.suspend();		
221
		closeHistogramProcess();
222
	}
208 223
	
209 224
	public void actionClosed(IncrementableEvent e) {
225
		if (histogramProcess == null) return;
210 226
		lastHistogram = histogramProcess.getLastHistogram();
211 227
		updateGraphic();
212 228
		closeHistogramProcess();
213 229
	}
214 230

  
215 231
	public void actionResumed(IncrementableEvent e) {
232
		if (histogramProcess == null) return;
216 233
		histogramProcess.resume();
217 234
	}
218 235

  
219 236
	public void actionSuspended(IncrementableEvent e) {
237
		if (histogramProcess == null) return;
220 238
		histogramProcess.suspend();
221 239
	}
222 240
}

Also available in: Unified diff