Revision 19852

View differences:

trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/profiles/listener/LineProfileOptionsListener.java
52 52
import java.awt.event.ActionEvent;
53 53
import java.awt.event.ActionListener;
54 54
import java.util.ArrayList;
55
import java.util.Iterator;
56 55

  
57 56
import javax.swing.event.ListSelectionEvent;
58 57
import javax.swing.event.ListSelectionListener;
......
85 84
	
86 85
	
87 86
	public void actionPerformed(ActionEvent e) {
87
		
88 88
		if (e.getSource() == optionsPanel.getNewButton()){
89 89
			try {
90 90
				String roiName= "";
......
107 107
			optionsPanel.getDeleteButton().setSelected(false);
108 108
		}
109 109
		
110
		if (e.getSource() == optionsPanel.getComboBands()){
111
			try {
112
				if(optionsPanel.getTable().getRowCount()>0){
113
					ROI lineRoi =(VectorialROI)optionsPanel.getROIs().get(optionsPanel.getTable().getSelectedRow());
114
					int band = optionsPanel.getComboBands().getSelectedIndex();
115
					drawChartRoi((VectorialROI)lineRoi,band);
116
				}
117
			} catch (NotInitializeException e1) {
118
				e1.printStackTrace();
119
			}
120
			optionsPanel.selectDrawRoiTool();
121
			optionsPanel.getNewButton().setSelected(true);
122
			optionsPanel.getDeleteButton().setSelected(false);
123
		}
124
			
110 125
		
111 126
//		 Cada vez que se elimina una roi 
112 127
		if (e.getSource() == optionsPanel.getDeleteButton()){
......
117 132
					String className = (String)optionsPanel.getTable().getModel().getValueAt(optionsPanel.getTable().getSelectedRow(),0);
118 133
					optionsPanel.removeROI(className);
119 134
					((DefaultTableModel)optionsPanel.getTable().getModel()).removeRow(optionsPanel.getTable().getSelectedRow());
120
					
121
					for (Iterator iter = optionsPanel.getROIs().iterator(); iter.hasNext();) {	
122
						ROI roi =(VectorialROI) iter.next();
123
						int nSeries = optionsPanel.getROIs().size();
124
						int[][] series = new int[nSeries][roi.getValues()];
125
						String[] names = new String[nSeries];
126
			
127
//						 Se establecen los colores de las graficas segun color de las rois
128
						for(int iSerie = 0; iSerie < nSeries; iSerie++){
129
							names[iSerie] = "Band " + (iSerie+1);
130
							roi.setBandToOperate(optionsPanel.getComboBands().getSelectedIndex());
131
							roi=(VectorialROI) optionsPanel.getROIs().get(iSerie);
132
							series = new int[nSeries][roi.getValues()];
133
							int k=0;
134
							int z=0;
135
							if(roi.getGrid().getDataType() == RasterBuffer.TYPE_BYTE){
136
								for (int i = 0; i < roi.getNX(); i++){
137
									for (int j = 0; j < roi.getNY(); j++){	
138
										z= (int) roi.getCellValueAsByte(i,j);
139
										if(!roi.isNoDataValue(z)){
140
											series[iSerie][k] =z;
141
											k++;
142
										}
143
									}
144
								}
145
							}
146
							else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_SHORT){
147
								for (int i = 0; i < roi.getNX(); i++){
148
									for (int j = 0; j < roi.getNY(); j++){	
149
										z= (int) roi.getCellValueAsShort(i,j);
150
										if(!roi.isNoDataValue(z)){
151
											series[iSerie][k] =z;
152
											k++;
153
										}
154
									}
155
								}
156
							}
157
							else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_INT){
158
								for (int i = 0; i < roi.getNX(); i++){
159
									for (int j = 0; j < roi.getNY(); j++){	
160
										z= (int) roi.getCellValueAsInt(i,j);
161
										if(!roi.isNoDataValue(z)){
162
											series[iSerie][k] =z;
163
											k++;
164
										}
165
									}
166
								}
167
							}
168
						}
169
					// Actualizacion del grafico
170
					optionsPanel.UpdateChart();
171
					optionsPanel.getJPanelChart().setNewChart(series, names);
172
					optionsPanel.updateUI();
173
					}
135
					ROI lineRoi =(VectorialROI)optionsPanel.getROIs().get(optionsPanel.getTable().getSelectedRow());
136
					int band = optionsPanel.getComboBands().getSelectedIndex();
137
					drawChartRoi((VectorialROI)lineRoi,band);
138
						
174 139
				}
175 140
			} catch (NotInitializeException e2) {
176 141
				e2.printStackTrace();
177
			} catch (GridException e2) {
178
				e2.printStackTrace();
179
			}
142
			} 
180 143
		}			
181 144
	}
182 145

  
183 146
	public void tableChanged(TableModelEvent e) {
184
		// Corregir segun cualsea definitivamente  la columna asociada al color
147
		// Corregir segun cual sea definitivamente  la columna asociada al color
185 148
		if(e.getColumn()==4){
186 149
			String roiName = (String)optionsPanel.getTable().getTable().getJTable().getValueAt(e.getFirstRow(),0);
187 150
			ArrayList graphics = optionsPanel.getRoiGraphics(roiName);
......
203 166
	
204 167
	public void valueChanged(ListSelectionEvent e) {
205 168
		
206
		
207 169
		try {
208
			if(optionsPanel.getTable().getSelectedRow()!=-1){
209
				
170
			if(optionsPanel.getTable().getSelectedRow()!=-1){		
210 171
				ROI lineRoi =(VectorialROI)optionsPanel.getROIs().get(optionsPanel.getTable().getSelectedRow());
211
				String[] names = new String[1];
212
				names[0]="Serie0";
213
				lineRoi.setBandToOperate(optionsPanel.getComboBands().getSelectedIndex());
214
				int[][] series = new int[1][lineRoi.getValues()];
215
				int k=0; int z=0;
172
				int band = optionsPanel.getComboBands().getSelectedIndex();
173
				drawChartRoi((VectorialROI)lineRoi,band);
174
			}
175
		
176
		} catch (NotInitializeException e3) {
177
		
178
				e3.printStackTrace();
179
		}
180
		
181
	}
182

  
183
	public void actionButtonPressed(ButtonsPanelEvent e) {
184
		// TODO Auto-generated method stub
185
		
186
	}
187

  
188
	
189
	/** 
190
	 * 	Metodo que se encarga de pintar la roi que se pasa como parametro sobre el grafico.
191
	 * 	La vanda de la que se tomar?n los valores es la que se pasa como par?metro.
192
	 * */
193
	private  void drawChartRoi(VectorialROI roi, int band){
194
		
195
		try {
216 196
			
217
				if(lineRoi.getGrid().getDataType() == RasterBuffer.TYPE_BYTE){
218
					for (int i = 0; i < lineRoi.getNX(); i++){
219
						for (int j = 0; j < lineRoi.getNY(); j++){	
220
							z= (int) lineRoi.getCellValueAsByte(i,j);
221
							if(!lineRoi.isNoDataValue(z)){
222
								series[0][k] =z;
223
								k++;
224
							}
197
			int[][] series;
198
			series = new int[1][roi.getValues()];
199
			String[] names = new String[1];
200
			names[0] = "Grafico";
201
			roi.setBandToOperate(band);
202
			series = new int[1][roi.getValues()];
203
			int k=0;
204
			int z=0;
205
			if(roi.getGrid().getDataType() == RasterBuffer.TYPE_BYTE){
206
				for (int i = 0; i < roi.getNX(); i++){
207
					for (int j = 0; j < roi.getNY(); j++){	
208
						z= (int) roi.getCellValueAsByte(i,j);
209
						if(!roi.isNoDataValue(z)){
210
							series[0][k] =z;
211
							k++;
225 212
						}
226 213
					}
227 214
				}
228
				else if(lineRoi.getGrid().getDataType() == RasterBuffer.TYPE_SHORT){
229
					for (int i = 0; i < lineRoi.getNX(); i++){
230
						for (int j = 0; j < lineRoi.getNY(); j++){	
231
							z= (int) lineRoi.getCellValueAsShort(i,j);
232
							if(!lineRoi.isNoDataValue(z)){
233
								series[0][k] =z;
234
								k++;
235
							}
215
			}
216
			else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_SHORT){
217
				for (int i = 0; i < roi.getNX(); i++){
218
					for (int j = 0; j < roi.getNY(); j++){	
219
						z= (int) roi.getCellValueAsShort(i,j);
220
						if(!roi.isNoDataValue(z)){
221
							series[0][k] =z;
222
							k++;
236 223
						}
237 224
					}
238 225
				}
239
				else if(lineRoi.getGrid().getDataType() == RasterBuffer.TYPE_INT){
240
					for (int i = 0; i < lineRoi.getNX(); i++){
241
						for (int j = 0; j < lineRoi.getNY(); j++){	
242
							z= (int) lineRoi.getCellValueAsInt(i,j);
243
							if(!lineRoi.isNoDataValue(z)){
244
								series[0][k] =z;
245
								k++;
246
							}
226
			}
227
			else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_INT){
228
				for (int i = 0; i < roi.getNX(); i++){
229
					for (int j = 0; j < roi.getNY(); j++){	
230
						z= (int) roi.getCellValueAsInt(i,j);
231
						if(!roi.isNoDataValue(z)){
232
							series[0][k] =z;
233
							k++;
247 234
						}
248 235
					}
249 236
				}
250
		
251
				// Actualizacion del grafico
252
				optionsPanel.getJPanelChart().getChart().getChart().getXYPlot().getRenderer().setSeriesPaint(0, lineRoi.getColor());
253
				optionsPanel.getJPanelChart().setNewChart(series, names);
254
				optionsPanel.updateUI();
255 237
			}
238
			else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_FLOAT){
239
				for (int i = 0; i < roi.getNX(); i++){
240
					for (int j = 0; j < roi.getNY(); j++){	
241
						z= (int) roi.getCellValueAsFloat(i,j);
242
						if(!roi.isNoDataValue(z)){
243
							series[0][k] =z;
244
							k++;
245
						}
246
					}
247
				}
248
			}
256 249
			
257
		} catch (GridException e1) {
258
						e1.printStackTrace();
259
		} catch (NotInitializeException e3) {
250
			// Actualizacion del grafico
251
			optionsPanel.UpdateChart();
252
			optionsPanel.getJPanelChart().setNewChart(series, names);
253
			optionsPanel.updateUI();
260 254
		
261
				e3.printStackTrace();
255
		} catch (GridException e) {
256
			e.printStackTrace();
262 257
		}
263
		
258
	
264 259
	}
265

  
266
	public void actionButtonPressed(ButtonsPanelEvent e) {
267
		// TODO Auto-generated method stub
268
		
269
	}
270

  
260
			
271 261
}
trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/profiles/listener/DrawMouseProfileListener.java
119 119
			panel.getLineOptionsPanel().getMapControl().getMapContext().getGraphicsLayer().addGraphic(fGraphic);
120 120
			panel.getLineOptionsPanel().getRoiGraphics(roiName).add(fGraphic);
121 121
			panel.getLineOptionsPanel().getMapControl().drawGraphics();			
122
			// Se pinta el grafico asociado
123
			drawChartRoi(lineRoi,panel.getLineOptionsPanel().getComboBands().getSelectedIndex());
122 124
			
123
			int nSeries = panel.getLineOptionsPanel().getROIs().size();
124
			int[][] series = new int[nSeries][lineRoi.getValues()];
125
			String[] names = new String[nSeries];
126
	
127
			// Se establecen los colores de las graficas segun color de las rois
128
			for(int iSerie = 0; iSerie < nSeries; iSerie++){
129
				names[iSerie] = "Band " + (iSerie+1);
130
				lineRoi.setBandToOperate(panel.getLineOptionsPanel().getComboBands().getSelectedIndex());
131
				lineRoi=(VectorialROI) panel.getLineOptionsPanel().getROIs().get(iSerie);
132
				series = new int[nSeries][lineRoi.getValues()];
133
				int k=0; int z=0;
134
				
135
				if(lineRoi.getGrid().getDataType() == RasterBuffer.TYPE_BYTE){
136
					for (int i = 0; i < lineRoi.getNX(); i++){
137
						for (int j = 0; j < lineRoi.getNY(); j++){	
138
							z= (int) lineRoi.getCellValueAsByte(i,j)&0xff;
139
							if(!lineRoi.isNoDataValue(z)){
140
								series[iSerie][k] =z;
141
								k++;
142
							}
143
						}
144
					}
145
				}
146
				else if(lineRoi.getGrid().getDataType() == RasterBuffer.TYPE_SHORT){
147
					for (int i = 0; i < lineRoi.getNX(); i++){
148
						for (int j = 0; j < lineRoi.getNY(); j++){	
149
							z= (int) lineRoi.getCellValueAsShort(i,j);
150
							if(!lineRoi.isNoDataValue(z)){
151
								series[iSerie][k] =z;
152
								k++;
153
							}
154
						}
155
					}
156
				}
157
				else if(lineRoi.getGrid().getDataType() == RasterBuffer.TYPE_INT){
158
					for (int i = 0; i < lineRoi.getNX(); i++){
159
						for (int j = 0; j < lineRoi.getNY(); j++){	
160
							z= (int) lineRoi.getCellValueAsInt(i,j);
161
							if(!lineRoi.isNoDataValue(z)){
162
								series[iSerie][k] =z;
163
								k++;
164
							}
165
						}
166
					}
167
				}
168
			}
169
			// Actualizacion del grafico
170
			panel.getLineOptionsPanel().UpdateChart();
171
			panel.getLineOptionsPanel().getJPanelChart().setNewChart(series, names);
172
			panel.getLineOptionsPanel().getNewButton().setSelected(false);
173
			
174 125
		} catch (NotInitializeException e) {
175 126
			e.printStackTrace();
176 127
		} catch (GridException e) {
177
			RasterToolsUtil.messageBoxError(PluginServices.getText(this, "grid_error"), this, e);
128
			// TODO Auto-generated catch block
129
			e.printStackTrace();
178 130
		}
179 131

  
180 132
	}
......
261 213
	public void pointDoubleClick(PointEvent event) throws BehaviorException {	
262 214
	}
263 215

  
216

  
217

  
218

  
219
	/** 
220
	 * 	Metodo que se encarga de pintar la roi que se pasa como parametro sobre el grafico.
221
	 * 	La vanda de la que se tomar?n los valores es la que se pasa como par?metro.
222
	 * */
223
	private  void drawChartRoi(VectorialROI roi, int band){
224
		
225
		try {
226
			
227
			int[][] series;
228
			series = new int[1][roi.getValues()];
229
			String[] names = new String[1];
230
			names[0] = "Grafico";
231
			roi.setBandToOperate(band);
232
			series = new int[1][roi.getValues()];
233
			int k=0;
234
			int z=0;
235
			if(roi.getGrid().getDataType() == RasterBuffer.TYPE_BYTE){
236
				for (int i = 0; i < roi.getNX(); i++){
237
					for (int j = 0; j < roi.getNY(); j++){	
238
						z= (int) roi.getCellValueAsByte(i,j);
239
						if(!roi.isNoDataValue(z)){
240
							series[0][k] =z;
241
							k++;
242
						}
243
					}
244
				}
245
			}
246
			else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_SHORT){
247
				for (int i = 0; i < roi.getNX(); i++){
248
					for (int j = 0; j < roi.getNY(); j++){	
249
						z= (int) roi.getCellValueAsShort(i,j);
250
						if(!roi.isNoDataValue(z)){
251
							series[0][k] =z;
252
							k++;
253
						}
254
					}
255
				}
256
			}
257
			else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_INT){
258
				for (int i = 0; i < roi.getNX(); i++){
259
					for (int j = 0; j < roi.getNY(); j++){	
260
						z= (int) roi.getCellValueAsInt(i,j);
261
						if(!roi.isNoDataValue(z)){
262
							series[0][k] =z;
263
							k++;
264
						}
265
					}
266
				}
267
			}
268
			else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_FLOAT){
269
				for (int i = 0; i < roi.getNX(); i++){
270
					for (int j = 0; j < roi.getNY(); j++){	
271
						z= (int) roi.getCellValueAsFloat(i,j);
272
						if(!roi.isNoDataValue(z)){
273
							series[0][k] =z;
274
							k++;
275
						}
276
					}
277
				}
278
			}
279
			
280
			// Actualizacion del grafico
281
			panel.getLineOptionsPanel().UpdateChart();
282
			panel.getLineOptionsPanel().getJPanelChart().setNewChart(series, names);
283
			panel.getLineOptionsPanel().updateUI();
284
		
285
		} catch (GridException e) {
286
			e.printStackTrace();
287
		}
288
	
289
	}
290

  
291

  
292

  
293

  
294

  
295

  
296

  
297

  
298

  
299

  
300

  
264 301
}

Also available in: Unified diff