Revision 10799

View differences:

trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/properties/dialog/RasterPropertiesTocMenuEntry.java
60 60
		return PluginServices.getText(this, "propiedades_raster");
61 61
	}
62 62
	
63
	
64 63
	/**
65 64
	 * Los objetos que quieren que se ejecute su listerner deben ser
66 65
	 * registrados a traves de este m?todo. Cuando se ejecute el actionPerformed
......
81 80
		if (isTocItemBranch(item)) 
82 81
            return (getNodeLayer(item) instanceof FLyrRasterSE);
83 82
		return false;
84

  
85 83
	}
86 84
	
87 85
	/**
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramPersistence.java
1
package org.gvsig.rastertools.histogram;
2

  
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.FileWriter;
7
import java.io.IOException;
8
import java.io.InputStreamReader;
9
import java.io.Writer;
10

  
11
/**
12
 * Clase con herramientas la persistencia de los histogramas calculados.
13
 * Se implementan m?todos para ecribir y leer en los ficheros .rmf correspondientes
14
 * los histogramas calculados.
15
 * @author Miguel ?ngel Querol Carratal? <querol_mig@gva.es>
16
 *
17
 */
18
public class HistogramPersistence {
19

  
20
	
21
	public HistogramPersistence(){
22
	}
23
	
24
	/**
25
	 * Crea o modifica el archivo .rmf asociado al GeoRasterFile del que le pasamos
26
	 * el nombre con los valores del histograma.
27
	 * @param histogram
28
	 * @param grfName
29
	 * @throws IOException
30
	 */
31
	public void makeRMFHistogram(int histogram[][], String grfName, int numBands)throws IOException{
32
		File rmfFile = null;
33
		File rmfAux = null;
34
		Writer writer = null;
35
		boolean copy = true;
36

  
37
		rmfFile = new File(grfName.substring(0, grfName.lastIndexOf(".") + 1) + "rmf");
38
		if(rmfFile.exists()){
39
			BufferedReader inGrf = new BufferedReader(new InputStreamReader(new FileInputStream(rmfFile)));
40
			String str = inGrf.readLine();
41
			rmfAux = new File(grfName.substring(0, grfName.lastIndexOf(".") + 1) + "aux.rmf");
42
			rmfAux.createNewFile();
43
			writer = new FileWriter(rmfAux);
44
			
45
			while(str != null){
46
				if(!str.equals("</RasterMetaFile>")){
47
					if(str.equals("<Histogram>"))
48
						copy = false;
49
					if(str.equals("</Histogram>"))
50
						copy = true;
51
					if(copy && (!str.equals("</Histogram>")))
52
						writer.write(str + "\n");
53
				}else{
54
					writer.write(getRMFHistogramHeader());
55
					for (int i = 0; i < numBands ; i++){
56
						writer.write(getXMLRasterBandHistogram(histogram, i));
57
					}
58
					writer.write(getRMFHistogramEnd());
59
					writer.write(str + "\n");
60
				}
61
				str = inGrf.readLine();
62
			}
63
			writer.close();
64
			
65
			rmfAux.renameTo(rmfFile);
66
			
67
			
68
		}else{
69
			rmfFile.createNewFile();
70
			writer = new FileWriter(rmfFile);
71
			writer.write(getRMFHeader());
72
			writer.write(getRMFHistogramHeader());
73
			for (int i = 0; i < numBands ; i++){
74
				writer.write(getXMLRasterBandHistogram(histogram, i));
75
			}
76
			writer.write(getRMFHistogramEnd());
77
			writer.write(getRMFEnd());
78
			writer.close();
79
		}
80
	}
81
	
82
	
83
	
84
	/**
85
	 * Calcula la cabecera del archivo .rmf asociado a la imagen en el caso
86
	 * de que ?ste no exista.
87
	 * @return
88
	 */
89
	private String getRMFHeader(){
90
		StringBuffer buffer = new StringBuffer();
91
		
92
		buffer.append("<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n");
93
		buffer.append("<RasterMetaFile xmlns=\"http://www.gvsig.org\">\n");
94
		
95
		return buffer.toString();
96
	}
97
	
98
	/**
99
	 * Crea el final del archivo .rmf asociado a la imagen en el caso de que
100
	 * ?ste no exista.
101
	 * @return
102
	 */
103
	private String getRMFEnd(){
104
		StringBuffer buffer = new StringBuffer();
105
		
106
		buffer.append("</RasterMetaFile>\n");
107
		
108
		return buffer.toString();
109
	}
110
	
111
	/**
112
	 * Crea la cabecera en XML para el bloque del histograma completo de la
113
	 * imagen.
114
	 * @return
115
	 */
116
	private String getRMFHistogramHeader(){
117
		StringBuffer buffer = new StringBuffer();
118
		
119
		buffer.append("<Histogram>\n");
120
		buffer.append("\t<FullHistogram>\n");
121
		
122
		return buffer.toString();
123
	}
124
	
125
	/**
126
	 * Crea el final en XML para el bloque del histograma completo de la
127
	 * imagen.
128
	 * @return
129
	 */
130
	private String getRMFHistogramEnd(){
131
		StringBuffer buffer = new StringBuffer();
132
		
133
		buffer.append("\t</FullHistogram>\n");
134
		buffer.append("</Histogram>\n");
135
		
136
		return buffer.toString();
137
	}
138
	
139
	/**
140
	 * Crea el c?digo XML correspondiendte a los datos del histograma de la 
141
	 * imagen de la banda correspondiente.
142
	 * @param n_band: banda de la que crear el XML con los datos de su histograma.
143
	 * @return
144
	 */
145
	private String getXMLRasterBandHistogram(int histogram[][], int n_band){
146
		StringBuffer buffer = new StringBuffer();
147
		
148
		buffer.append("\t\t<Band>\n");
149
		buffer.append("\t\t\t<Values>");
150
		for (int i = 0 ; i <= 255 ; i++)
151
			buffer.append(histogram[n_band][i] + " ");
152
		buffer.append("</Values>\n");
153
		buffer.append("\t\t</Band>\n");
154
		
155
		return buffer.toString();
156
	}
157
	
158
}
0 159

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/Histogram.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.gvsig.rastertools.histogram;
25

  
26
import org.cresques.px.PxRaster;
27
import org.gvsig.raster.grid.Grid;
28
/**
29
 * Clase para la gesti?n de histogramas de un raster. Es la encargada del calculo de un histograma
30
 * total o parcial de un raster a partir de los datos de disco. Este calculo se hace leyendo los
31
 * datos por bloques para no cargarlo completamente en memoria. Adem?s tambi?n es la encargada de gestionar
32
 * salvar este histograma a .rmf. En caso de que solicite un histograma del raster completo este ir?
33
 * a buscarlo al fichero rmf asociado antes de calcularlo por si ya existise. Al realizar el calculo
34
 * del histograma de la imagen completa este ser? salvado en el fichero .rmf asociado al raster.
35
 * 
36
 * @author Nacho Brodin (brodin_ign@gva.es)
37
 */
38
public class Histogram extends Thread{
39
	
40
	/**
41
	 * Tama?o del bloque de calculo de histograma. La lectura del raster se divide en partes
42
	 * de BLOCK de altura para no cargar todo el raster en memoria de una vez.
43
	 */
44
	private static final int			BLOCK = 512;
45
	private Grid 						grid = null;
46

  
47
	/**
48
	 * Flag que dice si el histograma a calcualar es el seleccionado en el area de interes
49
	 * o el histograma completo.
50
	 */ 
51
	private boolean 					calcFullHistogram = true;
52
	/**
53
	 * Histograma de la imagen completa
54
	 */
55
	private int[][]						histogram = null;
56
	/**
57
	 * Histograma acumulado de la imagen completa
58
	 */
59
	private int[][]						accumulatedHistogram = null;
60
	/**
61
	 * Variables que definen una ?rea de interes
62
	 */
63
	private int 						xAOI, yAOI, widthAOI, heightAOI;
64
	/**
65
	 * Porcentaje que lleva construido el histograma
66
	 */
67
	private int							percent = 0;
68
	/**
69
	 * Renderizador para el calculo de histogramas a partir 
70
	 * de la visualizaci?n.
71
	 */
72
	private PxRaster					pxRaster = null;
73
	/**
74
	 * Histograma de la vista
75
	 */
76
	private int[][]						viewHistogram = null;
77
	/**
78
	 * Bandas que solicita el cliente. Cada elemento del array es una banda, si est? a true se devuelve 
79
	 * esa banda con histograma calculado y si est? a false se devolver? esa banda con el histograma a 0.
80
	 * Este array solo es ten?do en cuenta para el histograma con fuente de datos reales y no para el de
81
	 * la visualizaci?n.
82
	 */
83
	private boolean[]					showBands = {true, true, true};
84
	/**
85
	 * Constructor 
86
	 * @param grid
87
	 */
88
	public Histogram(Grid grid){
89
		addGrid(grid);
90
	}
91
	
92
	/**
93
	 * Sustituye el grid del histograma 
94
	 * @param grid
95
	 */
96
	public void addGrid(Grid grid){
97
		this.grid = grid;
98
	}
99

  
100
	/**
101
	 * Obtiene el grid asociado al histograma
102
	 * @return Grid
103
	 */
104
	public Grid getGrid() {
105
		return grid;
106
	}
107
	
108
	/**
109
	 * Obtiene el renderizador asociado al histograma
110
	 * @return PxRaster
111
	 */
112
	public PxRaster getRenderizer() {
113
		return pxRaster;
114
	}
115
	
116
	/**
117
	 * Asigna el renderizador para el calculo de histogramas a partir 
118
	 * de la visualizaci?n.
119
	 * @param pxR Renderizador.
120
	 */
121
	public void addRenderizer(PxRaster pxR){
122
		this.pxRaster = pxR;
123
	}
124
	
125
	/**
126
	 * Asigna un area de interes para el calculo de histograma
127
	 * @param x Posici?n X del area de interes
128
	 * @param y Posici?n Y del area de interes
129
	 * @param w Ancho del ?rea de interes
130
	 * @param h Alto del ?rea de interes
131
	 */
132
	public void setAreaOfInterest(int x, int y, int w, int h){
133
		this.xAOI = x;
134
		this.yAOI = y;
135
		this.widthAOI = w;
136
		this.heightAOI = h;
137
	}
138
	
139
	/**
140
	 * Obtiene el histograma de la imagen completa en caso de que este ya haya sido
141
	 * calculado. Si histogram es null habr? que llamar a la funci?n calcFullHistogram para
142
	 * calcularlo.
143
	 * @return histograma de la imagen completa
144
	 */
145
	public int[][] getFullHistogram(){
146
		return histogram;
147
	}
148
	
149
	/**
150
	 * Obtiene el histograma acumulado de la imagen completa en caso de que este ya haya sido
151
	 * calculado. Si histogram es null habr? que llamar a la funci?n calcFullAccumulatedHistogram para
152
	 * calcularlo.
153
	 * @return histograma acumulado de la imagen completa
154
	 */
155
	public int[][] getFullAccumulatedHistogram(){
156
		histogram = null;
157
		
158
		return accumulatedHistogram;
159
	}
160
	
161
	/**
162
	 * Calcula el histograma de la imagen completa.
163
	 */
164
	public synchronized void run(){
165
/*
166
 
167
		while(true){
168
			//Asignamos las bandas que van a dibujarse
169
			int[] drawableBands = new int[grid.getBandCount()];
170
			for(int i = 0; i < grid.getBandCount(); i++)
171
				drawableBands[i] = i;
172
			grid.clearDrawableBand();
173
			grid.addDrawableBands(drawableBands);
174
			
175
			int heightArea = grid.getHeight();
176
			int widthArea = grid.getWidth();
177
			int poxInitX = 0;
178
			int lastY = 0;
179
			if(!calcFullHistogram){ //Calculo del histograma en el ?rea de interes
180
				heightArea = heightAOI;
181
				widthArea = widthAOI;
182
				poxInitX = xAOI;
183
				lastY = yAOI;
184
			}
185
			
186
			//Calculamos bloques de tama?o BLOCK para no leer toda la imagen de golpe
187
			int nBlocks = (int)(heightArea / BLOCK);
188
			int lastBlock = heightArea - (nBlocks * BLOCK);
189
			int incrPercent = (int)(100 / (nBlocks + 1));
190
	
191
			switch(grid.getDataType()){
192
			case RasterBuf.TYPE_BYTE: byteHistogram(poxInitX, lastY, widthArea, nBlocks, lastBlock, incrPercent); break;
193
			case RasterBuf.TYPE_SHORT: shortHistogram(poxInitX, lastY, widthArea, nBlocks, lastBlock, incrPercent); break;
194
			case RasterBuf.TYPE_INT: intHistogram(poxInitX, lastY, widthArea, nBlocks, lastBlock, incrPercent); break;
195
			}
196
			percent = 100;
197
			
198
			//Si hemos calculado el histograma de la imagen completa lo salvamos a disco
199
			if(calcFullHistogram)
200
				try{
201
					writeFullHistogramToRMF();
202
				}catch(IOException ex){
203
					System.err.println("No se ha podido guardar el histograma");
204
				}
205
			grid.free();
206
			this.suspend();
207
		}
208
*/
209
	}
210
	
211
	/**
212
	 * Obtiene el porcentaje que lleva construido el histograma
213
	 * @return porcentaje de construcci?n
214
	 */
215
	public int getPercent() {
216
		return percent;
217
	}
218
}
0 219

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramDialog.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. 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
package org.gvsig.rastertools.histogram.ui;
20

  
21
import java.awt.BorderLayout;
22
import java.io.IOException;
23

  
24
import javax.swing.JPanel;
25

  
26
import com.iver.andami.PluginServices;
27
import com.iver.andami.ui.mdiManager.IWindow;
28
import com.iver.andami.ui.mdiManager.WindowInfo;
29
/**
30
 * <code>HistogramDialog</code>. Creaci?n de la ventana para gvSIG.
31
 * 
32
 * @version 20/03/2007
33
 * @author Nacho Brodin (brodin_ign@gva.es)
34
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
35
 */
36
public class HistogramDialog extends JPanel implements IWindow {
37
	private static final long serialVersionUID = 7362459094802955247L;
38
	private HistogramPanel 	histogramPanel = null;
39
	
40
	public HistogramDialog(int width, int height){
41
		this.setSize(width, height);
42
		this.setLayout(new BorderLayout(5, 5));
43
		
44
		this.add(getHistogramPanel(), java.awt.BorderLayout.CENTER);
45
	}
46
	
47
	/**
48
	 * Obtiene el panel con el histograma
49
	 * @return HistogramPanel
50
	 */
51
	public HistogramPanel getHistogramPanel(){
52
		if(histogramPanel == null){
53
			histogramPanel = new HistogramPanel();
54
//			histogramPanel.getBCreateTable().addActionListener(histogramPanel);
55
		}
56
		return histogramPanel;
57
	}
58
/*
59
	public void actionPerformed(ActionEvent e) {
60
		
61
		//Bot?n de cerrar
62
		if(e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CLOSE + "") == 0){
63
			try{
64
				PluginServices.getMDIManager().closeWindow(this);
65
			}catch(ArrayIndexOutOfBoundsException ex){
66
				//Si la ventana no se puede eliminar no hacemos nada
67
			}
68
		}
69
//		--------------------------------------		
70
		//Bot?n Crear tabla.
71
		JButton table = histogramPanel.getBCreateTable();
72
		if(e.getSource() == table){
73

  
74
	        try {
75
//	        	-------Mostrar un fileChooser------------------
76
	        	String fName;
77
	        	JFileChooser chooser = new JFileChooser();
78
	    		chooser.setDialogTitle(PluginServices.getText(this, "guardar_tabla"));
79
	    		
80
	    		int returnVal = chooser.showOpenDialog(this);
81
	    		if(returnVal == JFileChooser.APPROVE_OPTION){
82
	    		 	fName = chooser.getSelectedFile().toString();
83
	    			if(!fName.endsWith(".dbf"))
84
	    				fName += ".dbf";
85
	        	     
86
	    			//-------------Crear el dbf----------------------
87
	    		
88
		    		DbaseFileWriterNIO dbfWrite = null;
89
			        DbaseFileHeaderNIO myHeader;
90
			        Value[] record;
91
		        	
92
		        	int histogram[][]=histogramPanel.getLastHistogram();
93
		        	int numBands = histogram.length;
94
		        	int numRecors = histogram[0].length;
95
		        	
96
		        	File file = new File(fName);
97
		        	
98
		        	String names[] = new String[numBands+1];
99
		        	int types[] = new int [numBands+1];
100
		        	int lengths[] = new int [numBands+1];
101
		        	
102
		        	names[0]="Value";
103
	        		types[0]=4;
104
	        		lengths[0]=15;
105
		        	for (int band = 0; band < numBands; band++){
106
		        		names[band+1]="Band"+band;
107
		        		types[band+1]=4;
108
		        		lengths[band+1]=15;
109
		        	}
110
		        	
111
		            myHeader = DbaseFileHeaderNIO.createDbaseHeader(names,types,lengths);
112
	
113
		            myHeader.setNumRecords(numRecors);
114
		            dbfWrite = new DbaseFileWriterNIO(myHeader,
115
		                    (FileChannel) getWriteChannel(file.getPath()));
116
		            record = new Value[numBands+1];
117
	
118
		            for (int j = 0; j < numRecors; j++) {
119
		            	record[0] = ValueFactory.createValue(j);
120
		                for (int r = 0; r < numBands; r++) {
121
		                    record[r+1] = ValueFactory.createValue(histogram[r][j]);
122
		                }
123
	
124
		                dbfWrite.write(record);
125
		            }
126
	
127
		            dbfWrite.close();
128
		            
129
		            //------------A?adir el dbf al proyecto--------------
130
					ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
131
					String name = file.getName();
132
					LayerFactory.getDataSourceFactory().addFileDataSource("gdbms dbf driver", name, fName);
133
					DataSource dataSource;
134
					dataSource = LayerFactory.getDataSourceFactory().createRandomDataSource(name, DataSourceFactory.AUTOMATIC_OPENING);
135
					
136
					SelectableDataSource sds = new SelectableDataSource(dataSource);
137
					EditableAdapter auxea=new EditableAdapter();
138
					auxea.setOriginalDataSource(sds);
139
					ProjectTable projectTable = ProjectFactory.createTable(name, auxea);
140
					//ext.getProject().addTable(projectTable);
141
					ext.getProject().addDocument(projectTable);
142
					
143
					Table t = new Table();
144
					t.setModel(projectTable);
145
					//projectTable.setAndamiWindow(t);
146
					PluginServices.getMDIManager().addWindow(t);
147
	    		}
148
			} catch (DriverLoadException e1) {
149
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),this.getName() + " " +
150
						PluginServices.getText(this,"table_not_create"));
151
				NotificationManager.addError(e1);
152
			} catch (NoSuchTableException e1) {
153
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),this.getName() + " " +
154
						PluginServices.getText(this,"table_not_create"));
155
				NotificationManager.addError(e1);
156
			} catch (ReadDriverException e1) {
157
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),this.getName() + " " +
158
						PluginServices.getText(this,"table_not_create"));
159
				NotificationManager.addError(e1);
160
			}catch (IOException ex) {
161
				JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),this.getName() + " " +
162
						PluginServices.getText(this,"table_not_create"));
163
				NotificationManager.addError("Error al crear un DbaseFileHeaderNIO", ex);
164
	        }
165
		}
166
		
167
		//--------------------------------------
168
	}
169
*/
170
	/**
171
	 * 
172
	 * @param path
173
	 * @return
174
	 * @throws IOException
175
	 */
176
/*
177
	private WritableByteChannel getWriteChannel(String path)throws IOException {
178
		WritableByteChannel channel;
179
		
180
		File f = new File(path);
181
		
182
		if (!f.exists()) {
183
			System.out.println("Creando fichero " + f.getAbsolutePath());
184
			
185
			if (!f.createNewFile()) {
186
				throw new IOException("Cannot create file " + f);
187
			}
188
		}
189
		
190
		RandomAccessFile raf = new RandomAccessFile(f, "rw");
191
		channel = raf.getChannel();
192
		
193
		return channel;
194
	}
195
*/
196

  
197
	public WindowInfo getWindowInfo() {
198
		WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
199
    	m_viewinfo.setTitle(PluginServices.getText(this, "histograma"));
200
     	m_viewinfo.setHeight(this.getHeight());
201
     	m_viewinfo.setWidth(this.getWidth());
202
		return m_viewinfo;
203
	}
204
}
0 205

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. 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
package org.gvsig.rastertools.histogram.ui;
20

  
21
import java.awt.BorderLayout;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24

  
25
import javax.swing.JButton;
26
import javax.swing.JComboBox;
27
import javax.swing.JLabel;
28
import javax.swing.JPanel;
29

  
30
import org.cresques.i18n.Messages;
31
import org.gvsig.gui.beans.buttonsPanel.ButtonsPanel;
32
import org.gvsig.gui.beans.dialogPanel.DialogPanel;
33
import org.gvsig.gui.beans.graphic.GraphicChartPanel;
34
import org.gvsig.gui.beans.graphic.GraphicContainer;
35
import org.gvsig.gui.beans.table.TableContainer;
36
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
37
/**
38
 * <code>HistogramPanel</code>. Interfaz de usuario para la representaci?n de
39
 * histogramas.
40
 * 
41
 * @version 20/03/2007
42
 * @author Diego Guerrero (diego.guerrero@uclm.es)
43
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
44
 */
45
public class HistogramPanel extends DialogPanel {
46
	private static final long serialVersionUID = 2772897994667886753L;
47

  
48

  
49
	private HistogramPanelListener  	histogramPanelListener = null;
50
	
51

  
52
	public static int					MAXBANDS = 10;  
53
	private int 						HSUP = 60;
54
	
55
	private GraphicContainer 			graphicContainer = null;
56
	private JPanel 						pTable = null;
57
	private JComboBox 					jComboBoxOrigen = null;
58
	private JComboBox 					jComboBoxTipo = null;
59
	private JComboBox 					jComboBands = null;
60
	private JButton 					jButtonClear = null;
61
	private JButton 					bTable = null;
62
	private TableContainer 				tableContainer = null;
63
		
64
	private JPanel 						cbSup = null;
65
	private JLabel 						lOrigin = null;
66
	private JLabel 						lBands = null;
67
	private JLabel 						lType = null;
68
	/**
69
	 * Bandas que se est?n mostrando en el gr?fico. Se inicializa con las 3 bandas
70
	 * RGB de la visualizaci?n. Este array puede tener m?s elementos ya que si las 
71
	 * bandas no son de visualizaci?n (bandas de la imagen en disco) tendr? un elemento
72
	 * por cada una. 
73
	 */
74
	public boolean[]					showBands = {true, true, true};
75
	
76
	/**
77
	 * Tipo de histograma 
78
	 * 0 = acumulado 
79
	 * 1 = No acumulado
80
	 */
81
	private int							type = 0;
82
	
83
	/**
84
	 * Tipo de fuente de datos para el histograma
85
	 * 0 = Datos de la vista
86
	 * 1 = extent de la vista y datos leidos desde la imagen
87
	 * 2 = histograma de la imagen completa
88
	 */
89
	private int 						histogramDataSource = 0;
90
	
91
	/**
92
	 * Crea un dialogo para los histogramas.
93
	 *
94
	 */
95
	public HistogramPanel() {
96
		super(ButtonsPanel.BUTTONS_CLOSE);
97
		initialize();
98
	}
99

  
100
	/**
101
	 * This method initializes this
102
	 * 
103
	 */
104
	private void initialize() {
105
		this.setLayout(new BorderLayout(5, 5));
106
    this.add(getCbSup(), java.awt.BorderLayout.NORTH);
107
    this.add(getGraphicContainer(), java.awt.BorderLayout.CENTER);
108
    this.add(getPTable(), java.awt.BorderLayout.SOUTH);
109
		this.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
110
		getHistogramPanelListener().setControlListeners();
111
	}
112

  
113
	/**
114
	 * This method initializes jPanel	
115
	 * 	
116
	 * @return javax.swing.JPanel	
117
	 */
118
	public GraphicContainer getGraphicContainer() {
119
		if (graphicContainer == null) {
120
			graphicContainer = new GraphicContainer( false);
121
		}
122
		return graphicContainer;
123
	}
124

  
125
	/**
126
	 * This method initializes jPanel	
127
	 * 	
128
	 * @return javax.swing.JPanel	
129
	 */
130
	private JPanel getPTable() {
131
		if (pTable == null) {
132
			pTable = new JPanel();
133
			pTable.setLayout(new BorderLayout(5,5));
134
			pTable.add(getTableContainer(), BorderLayout.CENTER);
135

  
136
			JPanel jPanel2 = new JPanel();
137
      jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS));
138
      jPanel2.add(getBCreateTable());
139
  		jPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
140

  
141
			pTable.add(jPanel2, BorderLayout.EAST);
142
		}
143
		return pTable;
144
	}
145

  
146
	/**
147
	 * Obtiene la tabla de estadisticas
148
	 * @return
149
	 */
150
	public TableContainer getTableContainer(){
151
		if(tableContainer == null){
152
			String[] columnNames = {Messages.getText("banda"), Messages.getText("minimo"), Messages.getText("maximo"), Messages.getText("media"), Messages.getText("mediana"), Messages.getText("npixeles")};
153
			int[] columnWidths = {50, 65, 65, 65, 65, 115};
154
			tableContainer = new TableContainer(columnNames, columnWidths);
155
			tableContainer.setControlVisible(true);
156
			tableContainer.setModel("ListModel");
157
			tableContainer.initialize();
158
			tableContainer.setName("tableContainer");
159
			tableContainer.setControlVisible(false);
160
			
161
			try{
162
				tableContainer.setEditable(false);
163
			}catch(NotInitializeException ex){
164
				System.out.println("Tabla no inicializada");
165
			}	
166
		}
167
		return tableContainer;
168
	}
169

  
170
	/**
171
	 * This method initializes jPanel	
172
	 * 	
173
	 * @return javax.swing.JPanel	
174
	 */
175
	private JPanel getCbSup() {
176
		if (cbSup == null) {
177
			lOrigin = new JLabel();
178
			lOrigin.setText(Messages.getText("origen")+":");
179
			lBands = new JLabel();
180
			lBands.setText(Messages.getText("bandas")+":");
181
			lType = new JLabel();
182
			lType.setText(Messages.getText("tipo")+":");
183
			
184
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
185
			gridBagConstraints.gridy = 0;
186
			gridBagConstraints.gridx = 0;
187
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
188
			gridBagConstraints1.insets = new java.awt.Insets(0,0,0,80);
189
			gridBagConstraints1.gridy = 0;
190
			gridBagConstraints1.gridx = 1;
191
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
192
			gridBagConstraints2.gridy = 0;
193
			gridBagConstraints2.gridx = 3;
194
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
195
			gridBagConstraints3.insets = new java.awt.Insets(2,0,0,0);
196
			gridBagConstraints3.gridy = 1;
197
			gridBagConstraints3.gridx = 0;
198
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
199
			gridBagConstraints4.insets = new java.awt.Insets(2,0,0,80);
200
			gridBagConstraints4.gridy = 1;
201
			gridBagConstraints4.gridx = 1;
202
			GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
203
			gridBagConstraints5.insets = new java.awt.Insets(2,0,0,0);
204
			gridBagConstraints5.gridy = 1;
205
			gridBagConstraints5.gridx = 3;
206
			GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
207
			gridBagConstraints6.gridy = 0;
208
			gridBagConstraints6.gridx = 2;
209
			
210
			cbSup = new JPanel();
211
			
212
		cbSup.setPreferredSize(new java.awt.Dimension(0, HSUP));
213
			
214
			cbSup.setLayout(new GridBagLayout());
215
			cbSup.add(lOrigin, gridBagConstraints);
216
			cbSup.add(getJComboBoxOrigen(), gridBagConstraints1);
217
			
218
			cbSup.add(lBands, gridBagConstraints6);
219
			
220
			cbSup.add(getJComboBands(), gridBagConstraints2);
221
			cbSup.add(lType, gridBagConstraints3);
222
			cbSup.add(getJComboBoxTipo(), gridBagConstraints4);
223
			cbSup.add(getJButtonClear(), gridBagConstraints5);
224
		}
225
		return cbSup;
226
	}
227
	
228
	/**
229
	 * Obtiene el combo con la selecci?n de tipo de histograma, acumulado/no acumulado
230
	 * @return javax.swing.JComboBox	
231
	 */
232
	public JComboBox getJComboBoxTipo() {
233
		if (jComboBoxTipo == null) {
234
			String lista [] = {Messages.getText("no_acumulado"),Messages.getText("acumulado")};
235
			jComboBoxTipo = new JComboBox(lista);
236
			jComboBoxTipo.addActionListener(getHistogramPanelListener());
237
			jComboBoxTipo.setPreferredSize(new java.awt.Dimension(150,25));
238
		}
239
		return jComboBoxTipo;
240
	}
241
	
242
	/**
243
	 * Obtiene el combo con la selecci?n de la fuente de datos en el calculo del histograma,
244
	 * datos de la vista, datos reales con el extent de la vista e imagen completa.
245
	 * @return javax.swing.JComboBox	
246
	 */
247
	public JComboBox getJComboBoxOrigen() {
248
		if (jComboBoxOrigen == null) {
249
			String lista [] = {Messages.getText("datos_visualizados"),Messages.getText("vista_datasource"),Messages.getText("imagen_completa")};
250
			jComboBoxOrigen = new JComboBox(lista);
251
			jComboBoxOrigen.addActionListener(getHistogramPanelListener());
252
			jComboBoxOrigen.setPreferredSize(new java.awt.Dimension(150,25));
253
		}
254
		return jComboBoxOrigen;
255
	}
256
	
257
	/**
258
	 *Asigna el combo "Origen" el valor de solo vista para el calculo del histograma. Esa opci?n es 
259
	 *utilizada para extensiones que necesitan histograma pero no pueden acceder a la fuente de datos.
260
	 */
261
	public void setOnlyViewValue(){
262
		HistogramPanelListener.comboEventEnable = false;
263
		getJComboBoxOrigen().removeAllItems();
264
		getJComboBoxOrigen().addItem(Messages.getText("vista"));
265
		HistogramPanelListener.comboEventEnable = true;
266
	}
267
	
268
	/**
269
	 * This method initializes jButton	
270
	 * 	
271
	 * @return javax.swing.JButton	
272
	 */
273
	public JButton getJButtonClear() {
274
		if (jButtonClear == null) {
275
			jButtonClear = new JButton();
276
			jButtonClear.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
277
			jButtonClear.setText(Messages.getText("limpiar"));
278
			jButtonClear.addActionListener(getHistogramPanelListener());
279
			jButtonClear.setPreferredSize(new java.awt.Dimension(100,25));
280
		}
281
		return jButtonClear;
282
	}
283
	
284
	/**
285
	 * This method initializes jButton	
286
	 * 	
287
	 * @return javax.swing.JButton	
288
	 */
289
	public JButton getBCreateTable() {
290
		if (bTable == null) {
291
			bTable = new JButton();
292
			bTable.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
293
			bTable.setText(Messages.getText("crear_tabla"));
294
			bTable.setName("bTable");
295
			bTable.addActionListener(getHistogramPanelListener());
296
			bTable.setPreferredSize(new java.awt.Dimension(150,25));
297
		}
298
		return bTable;
299
	}
300
	
301
	/**
302
	 * This method initializes jComboBox	
303
	 * 	
304
	 * @return javax.swing.JComboBox	
305
	 */
306
	public JComboBox getJComboBands() {
307
		if (jComboBands == null) {
308
			String lista [] = {Messages.getText("todas")};
309
			jComboBands = new JComboBox(lista);
310
			jComboBands.addActionListener(getHistogramPanelListener());
311
			jComboBands.setPreferredSize(new java.awt.Dimension(100,25));
312
		}
313
		return jComboBands;
314
	}
315
		
316
	/**
317
	 * Asigna el n?mero de bandas al combobox
318
	 * @param bands N?mero de bandas de la imagen
319
	 */
320
	public void setBands(int bands){
321
		HistogramPanelListener.comboEventEnable = false;
322
		getJComboBands().removeAllItems();
323
		getJComboBands().addItem(Messages.getText("todas"));
324
		showBands = new boolean[bands];
325
		for(int i = 0; i < bands; i++){
326
			getJComboBands().addItem("Band "+String.valueOf(i));
327
			showBands[i] = true;
328
		}
329
		HistogramPanelListener.comboEventEnable = true;
330
	}
331
	
332
	
333
	/**
334
	 * Asigna la estadistica a la tabla
335
	 * @param stat
336
	 */
337
	public void setStatistic(long[][] stat){
338
		if(stat == null)
339
			return;
340
		try {
341
			getTableContainer().removeAllRows();
342
			for(int iBand = 0; iBand < stat[0].length; iBand++){
343
				Object[] list = new Object[stat.length + 1];
344
				list[0] = new Integer(iBand);
345
				for(int iStat = 1; iStat <= stat.length; iStat++)
346
					list[iStat] = new Long(stat[iStat - 1][iBand]);				
347
					
348
				getTableContainer().addRow(list);
349
				list = null;
350
			}
351
		} catch (NotInitializeException e) {
352
			// TODO Auto-generated catch block
353
			e.printStackTrace();
354
		}
355
	}
356
	
357
	/**
358
	 * Resetea el control de bandas del panel con los valores RGB para 
359
	 * cuando se est? haciendo el histograma de la visualizaci?n en
360
	 * vez del histograma con los datos
361
	 *
362
	 */
363
	public void setRGBInBandList(){
364
		HistogramPanelListener.comboEventEnable = false;
365
		boolean[] list = {true, true, true};
366
		showBands = list;
367
		getJComboBands().removeAllItems();
368
		getJComboBands().addItem(Messages.getText("todas"));
369
		getJComboBands().addItem("R");
370
		getJComboBands().addItem("G");
371
		getJComboBands().addItem("B");
372
		HistogramPanelListener.comboEventEnable = true;
373
	}
374
	
375
	/**
376
	 * A?ade o elimina una banda de la visualizaci?n. Si la banda se est? visualizando
377
	 * se elimina y si no entonces se muestra
378
	 * @param band banda a visualizar o borrar del gr?fico
379
	 */
380
	public void addOrRemoveGraphicBand(int band){
381
		if(band > showBands.length)
382
			return;
383
		showBands[band] = !showBands[band];
384
	}
385
	
386
	/**
387
	 * Limpia la gr?fica
388
	 */
389
	public void cleanChart(){
390
		GraphicChartPanel gcp = graphicContainer.getPGraphic();
391
		gcp.cleanChart();
392
		for(int i = 0; i < showBands.length; i++)
393
			showBands[i] = false;
394
	}
395
	
396
	/**
397
	 * Obtiene el tipo de datos de la fuente de la imagen
398
	 * @return tipo de datos de la fuente de la imagen
399
	 */
400
	public int getHistogramDataSource() {
401
		return histogramDataSource;
402
	}
403

  
404
	/**
405
	 * Asigna el tipo de datos de la fuente de la imagen
406
	 * @param histogramDataSource tipo de datos de la fuente de la imagen
407
	 */
408
	public void setHistogramDataSource(int histogramDataSource) {
409
		this.histogramDataSource = histogramDataSource;
410
	}
411

  
412
	/**
413
	 * Obtiene la lista de bandas que se muestran en el histograma
414
	 * @return Lista de bandas donde cada elemento es un booleano. True si la banda
415
	 * se muestra y false si no se muestra.
416
	 */
417
	public boolean[] getBandListShowInChart(){
418
		return showBands;
419
	}
420

  
421
	/**
422
	 * Asigna la lista de bandas que se muestran en el histograma
423
	 * @param Lista de bandas donde cada elemento es un booleano. True si la banda
424
	 * se muestra y false si no se muestra.
425
	 */
426
	public void setBandListShowInChart(boolean[] showBands) {
427
		this.showBands = showBands;
428
	}
429
	
430
	/**
431
	 * Obtiene el tipo de histograma a mostrar
432
	 * @return acumulado/no acumulado
433
	 */
434
	public int getType() {
435
		return type;
436
	}
437

  
438
	/**
439
	 * Asigna el tipo de histograma a mostrar
440
	 * @param type acumulado/no acumulado 
441
	 */
442
	public void setType(int type) {
443
		this.type = type;
444
	}
445

  
446
	/**
447
	 * Obtiene el valor de los controles en el rango 0-255. Los controles dan un rango en tanto por cien 0-100
448
	 * pero para el calculo de estadisticas necesitamos un rango de valor de pixel. 
449
	 * @return Array con los valores de ambos controles. El primer valor del array es el control de la derecha
450
	 * y el segundo el de la izquierda.  
451
	 */
452
	public double[] getBoxesValues(){
453
		return null;
454
/*		double[] v = new double[2];
455
		double[] currentValues = getPHistogram().getBoxesValues();
456
		switch(requestDataType){
457
		case RasterBuf.TYPE_BYTE: 	v[0] = (currentValues[0] * Utilities.MAX_BYTE_BIT_VALUE) / 100; 
458
									v[1] = (currentValues[1] * Utilities.MAX_BYTE_BIT_VALUE) / 100;
459
									break;
460
		case RasterBuf.TYPE_SHORT: 	v[0] = (currentValues[0] * Utilities.MAX_SHORT_BIT_VALUE) / 100;
461
									v[1] = (currentValues[1] * Utilities.MAX_SHORT_BIT_VALUE) / 100;
462
									break;
463
		}
464
		return v;
465
*/
466
	}
467
	
468
	public HistogramPanelListener getHistogramPanelListener() {
469
		if (histogramPanelListener == null) {
470
			histogramPanelListener = new HistogramPanelListener(this);
471
		}
472
		return histogramPanelListener;
473
	}
474
}
0 475

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramIncrement.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. 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
package org.gvsig.rastertools.histogram.ui;
20

  
21
import java.awt.Dimension;
22
import java.awt.FlowLayout;
23
import java.awt.Toolkit;
24

  
25
import javax.swing.JFrame;
26
import javax.swing.JLabel;
27
import javax.swing.JPanel;
28

  
29
import org.cresques.i18n.Messages;
30
import org.gvsig.rastertools.histogram.Histogram;
31
/**
32
 * <code>HistogramIncrement</code>. Ventana de incremento para la construcci?n
33
 * del histograma
34
 *
35
 * @version 20/03/2007
36
 * @author Nacho Brodin (brodin_ign@gva.es)
37
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
38
 */
39
public class HistogramIncrement extends Thread {
40
	private HistogramPanelListener histogramPanelListener = null;
41

  
42
	private JPanel panel = null;
43
	private JLabel label = null;
44
	private JFrame window = new JFrame();
45

  
46
	/**
47
	 * Constructor del <code>HistogramIncrement</code>.
48
	 * @param hpl Se le pasa el objecto de {@link HistogramPanelListener}
49
	 */
50
	public HistogramIncrement(HistogramPanelListener hpl){
51
		this.setHistogramPanelListener(hpl);
52
	}
53
	
54
	/**
55
	 * Muestra la ventana de incremento con el porcentaje de la construcci?n del
56
	 * histograma.
57
	 */
58
	public void showWindow(){
59
		window.getContentPane().add(getJPanel());
60
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
61
		window.setLocation(	((int)d.getWidth()) >> 1, 
62
	    					((int)d.getHeight()) >> 1);
63
		window.setSize(200, 60);
64
		window.show();
65
		if(this.isAlive())
66
			this.resume();
67
		else
68
			this.start();
69
	}
70
	
71
	/**
72
	 * Obtiene el panel del interior de la ventana de incremento
73
	 * @return JPanel
74
	 */
75
	private JPanel getJPanel(){
76
		if (panel == null){
77
			FlowLayout f = new FlowLayout();
78
			panel = new JPanel();
79
			panel.setLayout(f);
80
			label = new JLabel();
81
			label.setText(Messages.getText("calculando... ") + 0  + "%");
82
			panel.add(label, null);
83
		}
84
		return panel;
85
	}
86
	
87
	/**
88
	 * Este thread va leyendo el porcentaje hasta que se completa el histograma.
89
	 */
90
	public synchronized void run(){
91
		while(true){
92
			Histogram hist = this.getHistogramPanelListener().getHistogram();
93
			while (hist.getPercent() < 100){
94
				label.setText(Messages.getText("calculando ...") +  hist.getPercent() +"%");
95
				try {
96
					sleep(100);
97
				} catch (InterruptedException e) {
98
					e.printStackTrace();
99
				}
100
			}
101
			//Cerramos la ventana
102
			window.hide();
103
			window = null;
104
			
105
			//Mostramos el resultado
106
			this.getHistogramPanelListener().readFullHistogramFromThread();
107
			
108
			this.suspend();
109
		}
110
	}
111

  
112
	/**
113
	 * M?todo para obtener el {@link HistogramPanelListener}
114
	 * @return <code>HistogramPanelListener</code>
115
	 */
116
	public HistogramPanelListener getHistogramPanelListener() {
117
		return histogramPanelListener;
118
	}
119

  
120
	/**
121
	 * Definir el {@link HistogramPanelListener}
122
	 * @param hpl {@link HistogramPanelListener}
123
	 */
124
	public void setHistogramPanelListener(HistogramPanelListener hpl) {
125
		histogramPanelListener = hpl;
126
	}
127
} 
0 128

  
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramPanelListener.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 IVER T.I. 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
package org.gvsig.rastertools.histogram.ui;
20

  
21
import java.awt.event.ActionEvent;
22
import java.awt.event.ActionListener;
23
import java.awt.event.FocusEvent;
24
import java.awt.event.FocusListener;
25
import java.awt.event.KeyEvent;
26
import java.awt.event.KeyListener;
27
import java.awt.event.MouseEvent;
28
import java.awt.event.MouseListener;
29
import java.awt.event.MouseMotionListener;
30

  
31
import javax.swing.JLabel;
32
import javax.swing.event.TableModelEvent;
33

  
34
import org.gvsig.rastertools.histogram.Histogram;
35
/**
36
 * Listener para eventos del panel de histograma
37
 *
38
 * @version 20/03/2007
39
 * @author Nacho Brodin (brodin_ign@gva.es)
40
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
41
 */
42
public class HistogramPanelListener implements FocusListener, KeyListener, MouseListener, ActionListener, MouseMotionListener{
43

  
44
	private HistogramPanel			panel = null;
45
	/**
46
	 * Objeto histograma para la gesti?n de procesos de histograma
47
	 */
48
	private	Histogram				histogramObj = null;
49
	/**
50
	 * ?ltimo histograma visualizado en el gr?fico
51
	 */
52
	private int[][]						lastHistogram = null;
53

  
54
	public static boolean 			comboEventEnable = true;
55
		
56
	public HistogramPanelListener(HistogramPanel p){
57
		panel = p;
58
	}
59
	
60
	public void setControlListeners(){
61
		panel.getGraphicContainer().getPlusButtonControlLeft().addActionListener(this);
62
		panel.getGraphicContainer().getPlusButtonControlRight().addActionListener(this);
63
		panel.getGraphicContainer().getLessButtonControlLeft().addActionListener(this);
64
		panel.getGraphicContainer().getLessButtonControlRight().addActionListener(this);
65
		panel.getGraphicContainer().getTextControlRight().addKeyListener(this);
66
		panel.getGraphicContainer().getTextControlLeft().addKeyListener(this);
67
		panel.getGraphicContainer().getTextControlRight().addFocusListener(this);
68
		panel.getGraphicContainer().getTextControlLeft().addFocusListener(this);
69
	}
70
	
71
	public void mouseDragged(MouseEvent e) {
72
				
73
	}
74

  
75
	public void mousePressed(MouseEvent e) {
76
		
77
	}
78

  
79
	public void mouseReleased(MouseEvent e) {
80
			
81
	}
82
	
83
	public void setLabels(JLabel left, JLabel right){
84
		  
85
	}
86
	
87
	public void mouseMoved(MouseEvent e) {
88
			
89
	}
90

  
91
	private void initialize(){
92

  
93
	}
94
	
95
	public void actionPerformed(ActionEvent e) {
96
/*		
97
		//--------------------------------------
98
		//Botones de m?s y menos
99
		if(	e.getSource() == panel.getPHistogram().getPlusButtonControlLeft() ||
100
			e.getSource() == panel.getPHistogram().getLessButtonControlLeft() ||
101
			e.getSource() == panel.getPHistogram().getPlusButtonControlRight() ||
102
			e.getSource() == panel.getPHistogram().getLessButtonControlRight()){
103
			panel.setStatistic(Statistic.getBasicStatsFromHistogram(panel.getLastHistogram(),
104
																	(int)panel.getBoxesValues()[1], 
105
																	(int)panel.getBoxesValues()[0],
106
																	panel.showBands));
107
			return;
108
		}
109
			
110
		
111
		//--------------------------------------
112
		//Cambiar las bandas en el combo
113
		JComboBox cbb = panel.getJComboBands();
114
		if(comboEventEnable && e.getSource() == cbb){
115
			if(cbb.getSelectedIndex() == 0){
116
				boolean[] list = panel.getBandListShowInChart();
117
				for(int i = 0; i < list.length; i++)
118
					list[i] = true;
119
				panel.setBandListShowInChart(list);
120
			}else if(cbb.getSelectedItem().equals("R") || cbb.getSelectedItem().equals("Band 0"))
121
				panel.addOrRemoveGraphicBand(0);
122
			else if(cbb.getSelectedItem().equals("G") || cbb.getSelectedItem().equals("Band 1"))
123
				panel.addOrRemoveGraphicBand(1);
124
			else if(cbb.getSelectedItem().equals("B") || cbb.getSelectedItem().equals("Band 2"))
125
				panel.addOrRemoveGraphicBand(2);
126
			else{
127
				for(int i = 3; i < HistogramPanel.MAXBANDS; i++){
128
					if(cbb.getSelectedItem().equals("Band "+i))
129
						panel.addOrRemoveGraphicBand(i);
130
				}
131
			}
132
		}
133
		
134
		//--------------------------------------		
135
		//Limpiar
136
		JButton clean = panel.getJButtonClear();
137
		if(e.getSource() == clean){
138
			panel.cleanChart();
139
		}
140
		
141
		//--------------------------------------
142
		//Selecci?n de fuente de datos del histograma
143
		JComboBox cbo = panel.getJComboBoxOrigen();
144
		if(comboEventEnable && e.getSource() == cbo){
145
			panel.setHistogramDataSource(cbo.getSelectedIndex());
146
			
147
			//En caso de que el histograma se monte a partir de los datos de la vista ponemos RGB en el combo
148
			if(cbo.getSelectedIndex() == 0)
149
				panel.setRGBInBandList();
150
			
151
			//En caso de que el histograma se monte a partir de los datos reales ponemos el n?mero de bandas en el combo
152
			if(cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2)
153
				panel.setBands(panel.getHistogram().getGrid().getBandCount());			
154
		}
155
				
156
		//--------------------------------------
157
		//Selecci?n de histograma acumulado y no acumulado
158
		JComboBox cbt = panel.getJComboBoxTipo();
159
		if(comboEventEnable && e.getSource() == cbt)
160
			panel.setType(cbt.getSelectedIndex());
161
	
162
		if(comboEventEnable)
163
			panel.showHistogram();
164
*/
165
	}
166

  
167
	public void tableChanged(TableModelEvent e) {
168
				
169
	}
170

  
171
	public void mouseClicked(MouseEvent e) {
172
		
173
	}
174

  
175
	public void mouseEntered(MouseEvent e) {
176
				
177
	}
178

  
179
	public void mouseExited(MouseEvent e) {
180
				
181
	}
182

  
183
	/**
184
	 * Obtiene el ?ltimo histograma visualizado
185
	 * @return
186
	 */
187
	public int[][] getLastHistogram() {
188
		return lastHistogram;
189
	}
190

  
191
	/**
192
	 * Asigna el objeto histograma para la gesti?n de procesos de histograma
193
	 * @param histogramObj
194
	 */
195
	public void setHistogram(Histogram histogramObj) {
196
		this.histogramObj = histogramObj;
197
	}
198
	
199
	/**
200
	 * M?todo que ejecuta el thread que comprueba cuando se ha acabado de generar
201
	 * el histograma. Al finalizar, se lee el histograma de la imagen completa 
202
	 * calculado y se muestra.
203
	 */
204
	public void readFullHistogramFromThread(){
205
		if (panel.getType() == 0)
206
			lastHistogram = histogramObj.getFullHistogram();
207
		else if(panel.getType() == 1)
208
			lastHistogram = histogramObj.getFullAccumulatedHistogram();
209
		
210
/*		setStatistic(Statistic.getBasicStatsFromHistogram(	lastHistogram, 
211
															(int)getBoxesValues()[1], 
212
															(int)getBoxesValues()[0], 
213
															showBands));
214
*/
215
		//Si el histograma es grande lo recortamos para mostrarlo porque jfreeChart se vuelve
216
		//inestable al poner muchos elementos en las X
217
		
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff