Revision 11004 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramPanelListener.java

View differences:

HistogramPanelListener.java
21 21
import java.awt.event.ActionEvent;
22 22
import java.awt.event.ActionListener;
23 23
import java.awt.event.KeyEvent;
24
import java.awt.event.KeyListener;
25 24
import java.util.ArrayList;
26 25

  
27 26
import javax.swing.JButton;
28 27
import javax.swing.JComboBox;
29 28

  
29
import org.gvsig.gui.beans.graphic.GraphicEvent;
30
import org.gvsig.gui.beans.graphic.GraphicListener;
30 31
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent;
31 32
import org.gvsig.gui.beans.incrementabletask.IncrementableListener;
32 33
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
33 34
import org.gvsig.raster.util.Histogram;
34 35
import org.gvsig.raster.util.IHistogramable;
35 36
import org.gvsig.rastertools.histogram.ui.HistogramPanel;
36

  
37
import com.iver.utiles.swing.threads.Cancellable;
38 37
/**
39 38
 * Listener para eventos del panel de histograma
40 39
 *
......
42 41
 * @author Nacho Brodin (brodin_ign@gva.es)
43 42
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
44 43
 */
45
public class HistogramPanelListener implements ActionListener, KeyListener, IncrementableListener {
44
public class HistogramPanelListener implements IncrementableListener, GraphicListener, ActionListener {
46 45
	private HistogramPanel		histogramPanel = null;
47 46
	private IncrementableTask	incrementableTask = null;
48 47
	private HistogramProcess	histogramProcess = null;
......
50 49
	private int								bandCount = 0;
51 50

  
52 51
	public boolean						comboEventEnable = false;
52
	
53
	private boolean[]					showBands = {true, true, true};
54

  
53 55
		
54 56
	public HistogramPanelListener(HistogramPanel p){
55 57
		histogramPanel = p;
56 58
	}
57 59
	
58 60
	public void setControlListeners(){
59
		histogramPanel.getGraphicContainer().getPlusButtonControlLeft().addActionListener(this);
60
		histogramPanel.getGraphicContainer().getPlusButtonControlRight().addActionListener(this);
61
		histogramPanel.getGraphicContainer().getLessButtonControlLeft().addActionListener(this);
62
		histogramPanel.getGraphicContainer().getLessButtonControlRight().addActionListener(this);
63
		histogramPanel.getGraphicContainer().getTextControlRight().addKeyListener(this);
64
		histogramPanel.getGraphicContainer().getTextControlLeft().addKeyListener(this);
61
		histogramPanel.getGraphicContainer().addValueChangedListener(this);
65 62
	}
66 63

  
67 64
	
68
	public void keyPressed(KeyEvent e) {
69
		if (e.getKeyCode() == 10) {
70
			updateStatistic();
71
			updateGraphic();
72
		}
73
	}
74

  
75 65
	private void updateStatistic() {
76 66
//		TODO Actualizar tabla de los histogramas.
77 67
//		histogramPanel.setStatistic(DatasetStatistics.getBasicStatsFromHistogram(getLastHistogram(), (int)panel.getBoxesValues()[1], (int)panel.getBoxesValues()[0], panel.showBands));
78 68
	}
79 69

  
80

  
81 70
	public void actionPerformed(ActionEvent e) {
82
		//Botones de m?s y menos
83
		if (e.getSource() == histogramPanel.getGraphicContainer().getPlusButtonControlLeft()  ||
84
				e.getSource() == histogramPanel.getGraphicContainer().getLessButtonControlLeft()  ||
85
				e.getSource() == histogramPanel.getGraphicContainer().getPlusButtonControlRight() ||
86
				e.getSource() == histogramPanel.getGraphicContainer().getLessButtonControlRight() ) {
87
			updateStatistic();
88
			updateGraphic();
89
			return;
90
		}
91
		
92 71
		//--------------------------------------
93 72
		//Cambiar las bandas en el combo
94 73
		JComboBox cbb = histogramPanel.getJComboBands();
95 74
		if (comboEventEnable && (e.getSource() == cbb)) {
96 75
			if (cbb.getSelectedItem() == null) return;
97
			updateGraphic();
98
/*			
99
			if(cbb.getSelectedIndex() == 0) {
100
				boolean[] list = histogramPanel.getBandListShowInChart();
101
				for (int i = 0; i < list.length; i++)
102
					list[i] = true;
103
				histogramPanel.setBandListShowInChart(list);
104
				return;
105
			}
106
			if (cbb.getSelectedItem().equals("R")) {
107
				histogramPanel.addOrRemoveGraphicBand(0);
108
				return;
109
			}
110
			if(cbb.getSelectedItem().equals("G")) {
111
				histogramPanel.addOrRemoveGraphicBand(1);
112
				return;
113
			}
114
			if(cbb.getSelectedItem().equals("B")) {
115
				histogramPanel.addOrRemoveGraphicBand(2);
116
				return;
117
			}
118
			for (int i = 0; i < HistogramPanel.MAXBANDS; i++) {
76
			
77
			if (cbb.getSelectedIndex() == 0)
78
				for (int i = 0; i < showBands.length; i++)
79
					showBands[i] = true;
80
			if (cbb.getSelectedItem().equals("R")) addOrRemoveGraphicBand(0);
81
			if (cbb.getSelectedItem().equals("G")) addOrRemoveGraphicBand(1);
82
			if (cbb.getSelectedItem().equals("B")) addOrRemoveGraphicBand(2);
83
			for (int i = 0; i < HistogramPanel.MAXBANDS; i++)
119 84
				if (cbb.getSelectedItem().equals("Band "+i))
120
					histogramPanel.addOrRemoveGraphicBand(i);
121
			}
122
*/
85
					addOrRemoveGraphicBand(i);
86

  
87
			updateStatistic();
88
			updateGraphic();
123 89
			return;
124 90
		}
125 91
		
......
142 108
			
143 109
			//En caso de que el histograma se monte a partir de los datos reales ponemos el n?mero de bandas en el combo
144 110
			if (cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2) {
111
				// TODO: Rellenar BandCount con el valor que toca
145 112
				histogramPanel.setBands(bandCount);
113
				showBands = new boolean[bandCount];
114
				for (int i = 0; i < showBands.length; i++)
115
					showBands[i] = true;
146 116
			}
147 117
			showHistogram();
148 118
			return;
......
170 140
	}
171 141
	
172 142
	/**
143
	 * A?ade o elimina una banda de la visualizaci?n. Si la banda se est? visualizando
144
	 * se elimina y si no entonces se muestra
145
	 * @param band banda a visualizar o borrar del gr?fico
146
	 */
147
	public void addOrRemoveGraphicBand(int band){
148
		if (band > showBands.length)
149
			return;
150
		showBands[band] = !showBands[band];
151
	}
152

  
153
	/**
173 154
	 * Limpia la gr?fica
174 155
	 */
175 156
	public void cleanChart(){
176 157
		histogramPanel.cleanChart();
177
		for(int i = 0; i < histogramPanel.showBands.length; i++)
178
			histogramPanel.showBands[i] = false;
158
		for(int i = 0; i < showBands.length; i++)
159
			showBands[i] = false;
179 160
	}
180 161

  
181
	public void keyReleased(KeyEvent e) {
182
	}
183

  
184
	public void keyTyped(KeyEvent e) {
185
	}
186

  
187 162
	private void updateGraphic() {
188 163
		long[][] auxHistogram = lastHistogram.getHistogramByType(Histogram.getType(histogramPanel.getJComboBoxTipo().getSelectedIndex()));
189 164
		if (auxHistogram == null) return;
......
191 166
		int first = 0;
192 167
		int end = auxHistogram[0].length;
193 168

  
194
		first = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[1]*auxHistogram[0].length)/100);
195
		end = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[0]*auxHistogram[0].length)/100);
169
		first = (int) ((histogramPanel.getGraphicContainer().getX1()*auxHistogram[0].length)/100);
170
		end = (int) ((histogramPanel.getGraphicContainer().getX2()*auxHistogram[0].length)/100);
196 171

  
197
		int bands = (histogramPanel.getJComboBands().getSelectedIndex()==0?auxHistogram.length:1);
172
		int bandCount = 0;
173
		for (int i = 0; i < showBands.length; i++) {
174
			if (showBands[i]) bandCount++;
175
		}
198 176

  
199
		int[][] newHistogram = new int[bands][end - first];
200
		String[] bandNames = new String[bands];
177
		int[][] newHistogram = new int[bandCount][end - first];
178
		String[] bandNames = new String[bandCount];
201 179
		
202 180
		bandCount = auxHistogram.length;
203 181

  
204
		for (int iBand=0; iBand<bands; iBand++) {
182
		int numBand = 0;
183
		for (int iBand = 0; iBand < showBands.length; iBand++) {
184
			if (!showBands[iBand]) continue;
185
			
205 186
			for (int j=first; j<end; j++)
206
				newHistogram[iBand][j-first] = (int) auxHistogram[(bands>1?iBand:histogramPanel.getJComboBands().getSelectedIndex()-1)][j];
207
			bandNames[iBand] = iBand + "";
187
				newHistogram[numBand][j-first] = (int) auxHistogram[iBand][j];
188
			bandNames[numBand] = iBand + "";
189

  
190
			numBand++;
208 191
		}
209 192

  
210 193
		histogramPanel.getGraphicContainer().getPGraphic().cleanChart();
......
237 220
		if (histogramProcess == null) return;
238 221
		histogramProcess.suspend();
239 222
	}
223

  
224
	public void actionValueChanged(GraphicEvent e) {
225
		updateStatistic();
226
		updateGraphic();
227
	}
240 228
}

Also available in: Unified diff