root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / scatterplot / gui / ChartScaterPlotPanel.java @ 17621
History | View | Annotate | Download (8.77 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.scatterplot.gui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
import java.awt.Image; |
46 |
|
47 |
import javax.swing.ImageIcon; |
48 |
import javax.swing.JPanel; |
49 |
|
50 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
51 |
import org.gvsig.raster.buffer.BufferFactory; |
52 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
53 |
import org.gvsig.raster.dataset.IBuffer; |
54 |
import org.gvsig.raster.grid.Grid; |
55 |
import org.gvsig.remotesensing.scatterplot.chart.ScatterPlotChart; |
56 |
import org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram; |
57 |
import org.jfree.chart.JFreeChart; |
58 |
import org.jfree.chart.axis.NumberAxis; |
59 |
|
60 |
import com.iver.andami.PluginServices; |
61 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
62 |
|
63 |
/**
|
64 |
* Clase que define el panel donde aparece el grafico de dispersion para dos bandas, determinadas por
|
65 |
* las variables bandaX y bandaY. El grafico es un FastScatterPlot de la libreria jfreeChart (personalizada para este
|
66 |
* apartado).
|
67 |
*
|
68 |
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
|
69 |
* @version 11/12/2007
|
70 |
*/
|
71 |
|
72 |
public class ChartScaterPlotPanel extends JPanel { |
73 |
|
74 |
private static final long serialVersionUID = 1L; |
75 |
private JFreeChart chart;
|
76 |
private ScatterPlotDiagram jPanelChart = null; |
77 |
private ScatterPlotChart plot = null; |
78 |
private int bandaX = 0; |
79 |
private int bandaY = 1; |
80 |
private Grid grid = null; |
81 |
private float data[][] = null; |
82 |
FLayer fLayer = null;
|
83 |
|
84 |
|
85 |
/**
|
86 |
* Constructor
|
87 |
* @param flayer capa
|
88 |
* @param band1 banda que se representa en el eje x.
|
89 |
* @param band2 banda que se representa en el eje y.
|
90 |
* */
|
91 |
public ChartScaterPlotPanel(FLayer fLayer, int band1, int band2){ |
92 |
this.fLayer= fLayer;
|
93 |
bandaX= band1; |
94 |
bandaY= band2; |
95 |
createChart(); |
96 |
initialize(); |
97 |
} |
98 |
|
99 |
|
100 |
/**
|
101 |
* Inicializacion del panel que contiene el grafico
|
102 |
* */
|
103 |
private void initialize() { |
104 |
this.setLayout(new BorderLayout()); |
105 |
this.add(getChart(), BorderLayout.CENTER); |
106 |
} |
107 |
|
108 |
|
109 |
/**
|
110 |
* @return grafico actual
|
111 |
* */
|
112 |
public ScatterPlotDiagram getChart(){
|
113 |
if(jPanelChart == null){ |
114 |
jPanelChart = new ScatterPlotDiagram(chart,getGrid());
|
115 |
chart=null;
|
116 |
jPanelChart.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
117 |
} |
118 |
return jPanelChart;
|
119 |
} |
120 |
|
121 |
|
122 |
|
123 |
/**
|
124 |
* Metodo que construye el grafico inicialmente. Antes de construirlo, llama a
|
125 |
* setDataChart() para cargar los datos a representar
|
126 |
*
|
127 |
* */
|
128 |
private void createChart() { |
129 |
|
130 |
NumberAxis domainAxis = new NumberAxis(PluginServices.getText(this,"banda")+" "+bandaX); |
131 |
domainAxis.setAutoRangeIncludesZero(false);
|
132 |
NumberAxis rangeAxis = new NumberAxis(PluginServices.getText(this,"banda")+" "+bandaY); |
133 |
rangeAxis.setAutoRangeIncludesZero(false);
|
134 |
|
135 |
// Se cargan los datos antes de construir el grafico
|
136 |
setDataChart(fLayer); |
137 |
plot = new ScatterPlotChart(this.data, domainAxis, rangeAxis); |
138 |
|
139 |
|
140 |
chart = new JFreeChart(PluginServices.getText(this,"diagrama_dispersion"), plot); |
141 |
data= null;
|
142 |
chart.getRenderingHints().clear(); |
143 |
|
144 |
//Image img = new ImageIcon(ScatterPlotPanel.class.getClassLoader().getResource("images/splash.png")).getImage();
|
145 |
plot.setBackgroundPaint(null);
|
146 |
plot.setBackgroundImageAlpha(0.18f);
|
147 |
//plot.setBackgroundImage(img);
|
148 |
chart.setBackgroundPaint(Color.white);
|
149 |
|
150 |
plot.setBackgroundPaint(new Color(245, 245, 245)); |
151 |
plot=null;
|
152 |
} |
153 |
|
154 |
|
155 |
/**
|
156 |
* Actualizacion del panel que contiene el grafico
|
157 |
* */
|
158 |
public void updateChartPanel(){ |
159 |
jPanelChart.setChart(chart); |
160 |
// hace un clear cuando se cambian las bandas
|
161 |
jPanelChart.getROIChartList().getListRois().clear(); |
162 |
jPanelChart.repaint(); |
163 |
updateUI(); |
164 |
|
165 |
} |
166 |
|
167 |
|
168 |
/**
|
169 |
* Actualizacion del grafico. Esta actualizacion se producira cuando haya variacion en la
|
170 |
* seleccion de las bandas por parte del usuario.
|
171 |
*
|
172 |
* */
|
173 |
public void updateChart() { |
174 |
|
175 |
NumberAxis domainAxis = new NumberAxis(PluginServices.getText(this,"banda")+bandaX); |
176 |
domainAxis.setAutoRangeIncludesZero(false);
|
177 |
NumberAxis rangeAxis = new NumberAxis(PluginServices.getText(this,"banda")+bandaY); |
178 |
rangeAxis.setAutoRangeIncludesZero(false);
|
179 |
chart=null;
|
180 |
plot=null;
|
181 |
|
182 |
// Se cargan los datos correspondiesntes a las bandas seleccionadas
|
183 |
setDataChart(fLayer); |
184 |
plot = new ScatterPlotChart(this.data, domainAxis, rangeAxis); |
185 |
|
186 |
chart = new JFreeChart(PluginServices.getText(this,"diagrama_dispersion"), plot); |
187 |
chart.getRenderingHints().clear(); |
188 |
data=null;
|
189 |
|
190 |
Image img = new ImageIcon(ScatterPlotPanel.class.getClassLoader().getResource("images/splash.png")).getImage(); |
191 |
plot.setBackgroundPaint(null);
|
192 |
plot.setBackgroundImageAlpha(0.18f);
|
193 |
plot.setBackgroundImage(img); |
194 |
chart.setBackgroundPaint(Color.white);
|
195 |
|
196 |
plot.setBackgroundPaint(new Color(245, 245, 245)); |
197 |
//chart.fireChartChanged();
|
198 |
plot=null;
|
199 |
updateChartPanel(); |
200 |
|
201 |
} |
202 |
|
203 |
|
204 |
|
205 |
/**
|
206 |
* Metodo que establece los datos a representar.
|
207 |
* El vector data[][] se rellena con los valores de cada punto para las bandas
|
208 |
* bandX y bandY.
|
209 |
* */
|
210 |
public void setDataChart(FLayer fLayer){ |
211 |
|
212 |
this.fLayer = fLayer;
|
213 |
FLyrRasterSE rasterLayer = (FLyrRasterSE) fLayer; |
214 |
|
215 |
BufferFactory dataSource = rasterLayer.getBufferFactory(); |
216 |
|
217 |
int bands[] = null; |
218 |
bands = new int[rasterLayer.getBandCount()]; |
219 |
for (int i = 0; i < rasterLayer.getBandCount(); i++) |
220 |
bands[i] = i; |
221 |
try {
|
222 |
grid = new Grid(dataSource, new int[]{bandaX, bandaY}); |
223 |
} catch (RasterBufferInvalidException e) {
|
224 |
e.printStackTrace(); |
225 |
} |
226 |
|
227 |
|
228 |
int width= grid.getRasterBuf().getWidth();
|
229 |
int height= grid.getRasterBuf().getHeight();
|
230 |
int indice=0; |
231 |
|
232 |
data= new float[2][width*height]; |
233 |
|
234 |
if (grid.getDataType()== IBuffer.TYPE_BYTE){
|
235 |
for(int i=0; i<width;i++){ |
236 |
for(int j=0; j<height; j++){ |
237 |
data[0][indice]= grid.getRasterBuf().getElemByte(j,i,0)&0x0ff; |
238 |
data[1][indice]= grid.getRasterBuf().getElemByte(j,i,1)&0x0ff; |
239 |
indice++; |
240 |
} |
241 |
} |
242 |
} |
243 |
|
244 |
if (grid.getDataType()== IBuffer.TYPE_SHORT){
|
245 |
|
246 |
for(int i=0; i<width;i++){ |
247 |
for(int j=0; j<height; j++){ |
248 |
data[0][indice]= grid.getRasterBuf().getElemShort(j,i,0); |
249 |
data[1][indice]= grid.getRasterBuf().getElemShort(j,i,1); |
250 |
indice++; |
251 |
} |
252 |
} |
253 |
} |
254 |
|
255 |
if (grid.getDataType()== IBuffer.TYPE_INT){
|
256 |
|
257 |
for(int i=0; i<width;i++){ |
258 |
for(int j=0; j<height; j++){ |
259 |
data[0][indice]= grid.getRasterBuf().getElemInt(j,i,0); |
260 |
data[1][indice]= grid.getRasterBuf().getElemInt(j,i,1); |
261 |
indice++; |
262 |
} |
263 |
} |
264 |
} |
265 |
|
266 |
if (grid.getDataType()== IBuffer.TYPE_FLOAT){
|
267 |
for(int i=0; i<width;i++){ |
268 |
for(int j=0; j<height; j++){ |
269 |
data[0][indice]= grid.getRasterBuf().getElemFloat(j,i,0); |
270 |
data[1][indice]= grid.getRasterBuf().getElemFloat(j,i,1); |
271 |
indice++; |
272 |
} |
273 |
} |
274 |
} |
275 |
// OJO AL CASTINTG DE DOUBLE A FLOAT
|
276 |
if (grid.getDataType()== IBuffer.TYPE_DOUBLE){
|
277 |
for(int i=0; i<width;i++){ |
278 |
for(int j=0; j<height; j++){ |
279 |
data[0][indice]= (float)grid.getRasterBuf().getElemDouble(j,i,bandaX); |
280 |
data[1][indice]= (float)grid.getRasterBuf().getElemDouble(j,i,bandaY); |
281 |
indice++; |
282 |
} |
283 |
} |
284 |
} |
285 |
|
286 |
} |
287 |
|
288 |
|
289 |
/**
|
290 |
* Asignacion de la banda X
|
291 |
* */
|
292 |
public void setBandX(int band){ |
293 |
bandaX= band; |
294 |
} |
295 |
|
296 |
|
297 |
/**
|
298 |
* Asignacion de la banda Y
|
299 |
* */
|
300 |
public void setBandY(int band){ |
301 |
bandaY= band; |
302 |
} |
303 |
|
304 |
|
305 |
/**
|
306 |
* @return banda X
|
307 |
* */
|
308 |
public int getBandX(){ |
309 |
return bandaX;
|
310 |
} |
311 |
|
312 |
|
313 |
/**
|
314 |
* @return banda Y
|
315 |
* */
|
316 |
public int getBandY(){ |
317 |
return bandaY;
|
318 |
} |
319 |
|
320 |
|
321 |
/**
|
322 |
* @return grid asociado
|
323 |
*
|
324 |
* */
|
325 |
public Grid getGrid(){
|
326 |
return grid;
|
327 |
} |
328 |
|
329 |
|
330 |
/**
|
331 |
* @return capa asociada al panel
|
332 |
*
|
333 |
* */
|
334 |
|
335 |
public FLayer getFLayer(){
|
336 |
return fLayer;
|
337 |
} |
338 |
} |
339 |
|
340 |
|