19 |
19 |
package org.gvsig.raster.grid.filter.convolution;
|
20 |
20 |
|
21 |
21 |
import java.awt.BorderLayout;
|
|
22 |
import java.awt.Color;
|
22 |
23 |
import java.awt.GridLayout;
|
23 |
24 |
import java.awt.event.ActionEvent;
|
24 |
25 |
import java.awt.event.ActionListener;
|
25 |
26 |
import java.awt.event.FocusEvent;
|
26 |
27 |
import java.awt.event.FocusListener;
|
|
28 |
import java.text.NumberFormat;
|
27 |
29 |
|
28 |
30 |
import javax.swing.JButton;
|
29 |
31 |
import javax.swing.JComboBox;
|
|
32 |
import javax.swing.JFormattedTextField;
|
30 |
33 |
import javax.swing.JLabel;
|
31 |
34 |
import javax.swing.JPanel;
|
32 |
35 |
import javax.swing.JTextField;
|
|
36 |
import javax.swing.text.DefaultFormatterFactory;
|
|
37 |
import javax.swing.text.NumberFormatter;
|
33 |
38 |
|
34 |
39 |
import org.gvsig.raster.dataset.Params;
|
35 |
40 |
import org.gvsig.raster.grid.filter.RegistrableFilterListener;
|
... | ... | |
54 |
59 |
private JPanel panelTest = null;
|
55 |
60 |
private JComboBox selector = null;
|
56 |
61 |
private JButton buttonTest = null;
|
|
62 |
private JFormattedTextField divisor = null;
|
57 |
63 |
private double lastValue = 0;
|
58 |
64 |
|
59 |
65 |
/**
|
... | ... | |
97 |
103 |
|
98 |
104 |
getPanelSelector().add(new JLabel("Kernel: "));
|
99 |
105 |
getPanelSelector().add(getSelector());
|
|
106 |
getPanelSelector().add(new JLabel("Divisor: "));
|
|
107 |
getPanelSelector().add(getDivisor());
|
100 |
108 |
|
101 |
109 |
getPanelMatrixSelector().add(getPanelMatrix(), BorderLayout.NORTH);
|
102 |
110 |
getPanelMatrixSelector().add(getPanelSelector(), BorderLayout.SOUTH);
|
... | ... | |
179 |
187 |
}
|
180 |
188 |
|
181 |
189 |
/**
|
|
190 |
* Obtiene el selector de lado
|
|
191 |
* @return JComboBox
|
|
192 |
*/
|
|
193 |
public JFormattedTextField getDivisor() {
|
|
194 |
if(divisor == null) {
|
|
195 |
NumberFormat doubleDisplayFormat = NumberFormat.getNumberInstance();
|
|
196 |
doubleDisplayFormat.setMinimumFractionDigits(0);
|
|
197 |
NumberFormat doubleEditFormat = NumberFormat.getNumberInstance();
|
|
198 |
divisor = new JFormattedTextField(new DefaultFormatterFactory(
|
|
199 |
new NumberFormatter(doubleDisplayFormat),
|
|
200 |
new NumberFormatter(doubleDisplayFormat),
|
|
201 |
new NumberFormatter(doubleEditFormat)));
|
|
202 |
divisor.setBackground(Color.white);
|
|
203 |
divisor.setValue(new Double(0));
|
|
204 |
divisor.setColumns(3);
|
|
205 |
}
|
|
206 |
return divisor;
|
|
207 |
}
|
|
208 |
|
|
209 |
/**
|
182 |
210 |
* Convierte la matrix de JTextField en un objeto de tipo Kernel
|
183 |
211 |
* @return Kernel
|
184 |
212 |
*/
|
185 |
213 |
private Kernel getKernel() {
|
186 |
214 |
Kernel k = null;
|
|
215 |
double[][] values = null;
|
187 |
216 |
if(((String)selector.getSelectedItem()).equals("3")) {
|
188 |
|
double[][] values = new double[matrix.length - 2][matrix[0].length - 2];
|
|
217 |
values = new double[matrix.length - 2][matrix[0].length - 2];
|
189 |
218 |
for (int i = 1; i < matrix.length - 1; i++)
|
190 |
219 |
for (int j = 1; j < matrix[0].length - 1; j++)
|
191 |
220 |
values[i - 1][j - 1] = new Double(matrix[i][j].getText()).doubleValue();
|
192 |
|
k = new Kernel(values);
|
|
221 |
|
193 |
222 |
}
|
194 |
223 |
if(((String)selector.getSelectedItem()).equals("5")) {
|
195 |
|
double[][] values = new double[matrix.length][matrix[0].length];
|
|
224 |
values = new double[matrix.length][matrix[0].length];
|
196 |
225 |
for (int i = 0; i < matrix.length; i++)
|
197 |
226 |
for (int j = 0; j < matrix[0].length; j++)
|
198 |
|
values[i][j] = new Double(matrix[i][j].getText()).doubleValue();
|
199 |
|
k = new Kernel(values);
|
|
227 |
values[i][j] = new Double(matrix[i][j].getText()).doubleValue();
|
200 |
228 |
}
|
|
229 |
double value = ((Number)divisor.getValue()).doubleValue();
|
|
230 |
if(value != 0)
|
|
231 |
k = new Kernel(values, value);
|
|
232 |
else
|
|
233 |
k = new Kernel(values);
|
201 |
234 |
return k;
|
202 |
235 |
}
|
203 |
236 |
|