Revision 11042
trunk/extensions/extRasterTools-SE/src-test/org/gvsig/rasterTools/histogram/TestHistogramDialog.java | ||
---|---|---|
99 | 99 |
|
100 | 100 |
//Par?metros de inicializaci?n del histograma |
101 | 101 |
|
102 |
hp.getHistogramPanel().setHistogramDataSource(0); //Fuente de datos; la vista |
|
103 |
hp.getHistogramPanel().setType(0); //Tipo de histograma; no acumulado |
|
104 | 102 |
hp.getHistogramPanel().setRGBInBandList(); //Asignaci?n R,G,B en el combo |
105 | 103 |
|
106 | 104 |
hp.getHistogramPanel().firstRun(); // Mostar por primera vez el histograma |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramPanelListener.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
import org.gvsig.gui.beans.graphic.GraphicEvent; |
38 | 38 |
import org.gvsig.gui.beans.graphic.GraphicListener; |
39 |
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent; |
|
40 |
import org.gvsig.gui.beans.incrementabletask.IncrementableListener; |
|
41 | 39 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
42 | 40 |
import org.gvsig.raster.util.Histogram; |
43 | 41 |
import org.gvsig.raster.util.IHistogramable; |
... | ... | |
67 | 65 |
* @author Nacho Brodin (brodin_ign@gva.es) |
68 | 66 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es) |
69 | 67 |
*/ |
70 |
public class HistogramPanelListener implements IncrementableListener, GraphicListener, ActionListener {
|
|
68 |
public class HistogramPanelListener implements GraphicListener, ActionListener { |
|
71 | 69 |
private HistogramPanel histogramPanel = null; |
72 | 70 |
private IncrementableTask incrementableTask = null; |
73 | 71 |
private HistogramProcess histogramProcess = null; |
74 | 72 |
private Histogram lastHistogram = null; |
75 |
private int bandCount = 0; |
|
76 | 73 |
|
77 |
public boolean comboEventEnable = false;
|
|
74 |
public boolean eventsEnabled = false;
|
|
78 | 75 |
|
79 |
private boolean[] showBands = {true, true, true}; |
|
76 |
/** |
|
77 |
* Bandas que se est?n mostrando en el gr?fico. Se inicializa con las 3 bandas |
|
78 |
* RGB de la visualizaci?n. Este array puede tener m?s elementos ya que si las |
|
79 |
* bandas no son de visualizaci?n (bandas de la imagen en disco) tendr? un elemento |
|
80 |
* por cada una. |
|
81 |
*/ |
|
82 |
private boolean[] showBands = null; |
|
80 | 83 |
private Color[] bandsColor = { |
81 | 84 |
Color.red, |
82 | 85 |
Color.green, |
... | ... | |
96 | 99 |
public void setControlListeners(){ |
97 | 100 |
histogramPanel.getGraphicContainer().addValueChangedListener(this); |
98 | 101 |
} |
99 |
|
|
100 | 102 |
|
101 | 103 |
private void updateStatistic() { |
102 |
// long[][] auxHistogram = lastHistogram.getHistogramByType(Histogram.getType(histogramPanel.getJComboBoxTipo().getSelectedIndex()));
|
|
103 |
// long[][] auxHistogram = lastHistogram.getHistogram();
|
|
104 |
int first = (int) histogramPanel.getBoxesValues()[1];
|
|
105 |
int end = (int) histogramPanel.getBoxesValues()[0];
|
|
104 | 106 |
|
105 |
int first = (int) ((histogramPanel.getGraphicContainer().getX1()*(lastHistogram.getNumValues()-1))/100); |
|
106 |
int end = (int) ((histogramPanel.getGraphicContainer().getX2()*(lastHistogram.getNumValues()-1))/100); |
|
107 |
|
|
108 |
// first = histogramPanel.getGraphicContainer().getX1(); |
|
109 |
// end = histogramPanel.getGraphicContainer().getX2(); |
|
110 |
|
|
111 |
// Histogram aux = new Histogram(); |
|
112 |
// aux.setHistogram(auxHistogram); |
|
113 |
|
|
114 |
// histogramPanel.setStatistic(aux.getBasicStats(first, end, showBands)); |
|
115 | 107 |
histogramPanel.setStatistic(lastHistogram.getBasicStats((int) first, (int) end, showBands)); |
116 | 108 |
} |
117 | 109 |
|
118 | 110 |
public void actionPerformed(ActionEvent e) { |
111 |
if (!eventsEnabled) return; |
|
119 | 112 |
//-------------------------------------- |
120 | 113 |
//Cambiar las bandas en el combo |
121 | 114 |
JComboBox cbb = histogramPanel.getJComboBands(); |
122 |
if (comboEventEnable && (e.getSource() == cbb)) {
|
|
115 |
if (e.getSource() == cbb) {
|
|
123 | 116 |
if (cbb.getSelectedItem() == null) return; |
124 | 117 |
|
125 | 118 |
if (cbb.getSelectedIndex() == 0) |
... | ... | |
149 | 142 |
//-------------------------------------- |
150 | 143 |
//Selecci?n de fuente de datos del histograma |
151 | 144 |
JComboBox cbo = histogramPanel.getJComboBoxOrigen(); |
152 |
if (comboEventEnable && e.getSource() == cbo) { |
|
153 |
//En caso de que el histograma se monte a partir de los datos de la vista ponemos RGB en el combo |
|
154 |
if(cbo.getSelectedIndex() == 0) { |
|
155 |
histogramPanel.setRGBInBandList(); |
|
156 |
} |
|
157 |
|
|
158 |
//En caso de que el histograma se monte a partir de los datos reales ponemos el n?mero de bandas en el combo |
|
159 |
if (cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2) { |
|
160 |
bandCount = lastHistogram.getNumBands(); |
|
161 |
histogramPanel.setBands(bandCount); |
|
162 |
showBands = new boolean[bandCount]; |
|
163 |
for (int i = 0; i < showBands.length; i++) |
|
164 |
showBands[i] = true; |
|
165 |
} |
|
145 |
if (e.getSource() == cbo) { |
|
166 | 146 |
showHistogram(); |
167 | 147 |
return; |
168 | 148 |
} |
... | ... | |
170 | 150 |
//-------------------------------------- |
171 | 151 |
//Selecci?n de histograma acumulado y no acumulado |
172 | 152 |
JComboBox cbt = histogramPanel.getJComboBoxTipo(); |
173 |
if (comboEventEnable && e.getSource() == cbt) { |
|
174 |
histogramPanel.setType(cbt.getSelectedIndex()); |
|
153 |
if (e.getSource() == cbt) { |
|
175 | 154 |
updateStatistic(); |
176 | 155 |
updateGraphic(); |
177 | 156 |
return; |
... | ... | |
266 | 245 |
} |
267 | 246 |
} |
268 | 247 |
|
248 |
private void refreshBands() { |
|
249 |
histogramPanel.refreshBands(); |
|
250 |
showBands = new boolean[getHistogram().getNumBands()]; |
|
251 |
for (int i = 0; i < showBands.length; i++) |
|
252 |
showBands[i] = true; |
|
253 |
} |
|
254 |
|
|
269 | 255 |
public void showHistogram() { |
270 | 256 |
if (histogramPanel.getJComboBoxOrigen().getSelectedIndex() < 0) return; |
271 |
closeHistogramProcess(); |
|
257 |
|
|
272 | 258 |
IHistogramable iaux = (IHistogramable) ((ArrayList) histogramPanel.getComboSource().get(histogramPanel.getJComboBoxOrigen().getSelectedIndex())).get(0); |
273 |
histogramProcess = new HistogramProcess(iaux); |
|
259 |
histogramProcess = new HistogramProcess(iaux, this);
|
|
274 | 260 |
incrementableTask = new IncrementableTask(histogramProcess); |
275 |
incrementableTask.addIncrementableListener(this);
|
|
261 |
histogramProcess.setIncrementableTask(incrementableTask);
|
|
276 | 262 |
incrementableTask.showWindow(); |
263 |
histogramProcess.start(); |
|
264 |
incrementableTask.start(); |
|
277 | 265 |
} |
278 | 266 |
|
279 | 267 |
/** |
... | ... | |
290 | 278 |
long[][] auxHistogram = lastHistogram.getHistogramByType(Histogram.getType(histogramPanel.getJComboBoxTipo().getSelectedIndex())); |
291 | 279 |
if (auxHistogram == null) return; |
292 | 280 |
|
293 |
int first = (int) ((histogramPanel.getGraphicContainer().getX1()*(auxHistogram[0].length-1))/100);
|
|
294 |
int end = (int) ((histogramPanel.getGraphicContainer().getX2()*(auxHistogram[0].length-1))/100);
|
|
281 |
int first = (int) histogramPanel.getBoxesValues()[1];
|
|
282 |
int end = (int) histogramPanel.getBoxesValues()[0];
|
|
295 | 283 |
|
296 | 284 |
int bandCount = 0; |
297 | 285 |
for (int i = 0; i < showBands.length; i++) { |
... | ... | |
304 | 292 |
bandCount = auxHistogram.length; |
305 | 293 |
|
306 | 294 |
int numBand = 0; |
307 |
for (int iBand = 0; iBand < showBands.length; iBand++) {
|
|
295 |
for (int iBand = 0; iBand < auxHistogram.length; iBand++) {
|
|
308 | 296 |
if (!showBands[iBand]) continue; |
309 | 297 |
|
310 | 298 |
for (int j=first; j<end; j++) |
... | ... | |
319 | 307 |
histogramPanel.getGraphicContainer().getPGraphic().setNewChart(newHistogram, bandNames); |
320 | 308 |
updateStatistic(); |
321 | 309 |
} |
322 |
private void closeHistogramProcess() { |
|
323 |
histogramProcess = null; |
|
324 |
incrementableTask = null; |
|
325 |
} |
|
326 | 310 |
|
327 |
public void actionCanceled(IncrementableEvent e) { |
|
328 |
// if (histogramProcess != null) histogramProcess.suspend(); |
|
329 |
closeHistogramProcess(); |
|
330 |
} |
|
331 |
|
|
332 |
public void actionClosed(IncrementableEvent e) { |
|
333 |
if (histogramProcess == null) return; |
|
334 |
lastHistogram = histogramProcess.getLastHistogram(); |
|
311 |
public void setNewHistogram(Histogram value) { |
|
312 |
histogramPanel.panelInizialited = false; |
|
313 |
eventsEnabled = false; |
|
314 |
lastHistogram = value; |
|
315 |
refreshBands(); |
|
335 | 316 |
updateGraphic(); |
336 |
closeHistogramProcess(); |
|
337 |
} |
|
317 |
|
|
318 |
incrementableTask = null; |
|
319 |
histogramProcess = null; |
|
338 | 320 |
|
339 |
public void actionResumed(IncrementableEvent e) {
|
|
340 |
if (histogramProcess == null) return;
|
|
341 |
histogramProcess.resume();
|
|
321 |
// Activo la ejecucion de los eventos porque seguro que ya tenemos un histograma
|
|
322 |
eventsEnabled = true;
|
|
323 |
histogramPanel.panelInizialited = true;
|
|
342 | 324 |
} |
343 | 325 |
|
344 |
public void actionSuspended(IncrementableEvent e) { |
|
345 |
if (histogramProcess == null) return; |
|
346 |
histogramProcess.suspend(); |
|
326 |
public Histogram getHistogram() { |
|
327 |
return lastHistogram; |
|
347 | 328 |
} |
348 | 329 |
|
349 | 330 |
public void actionValueChanged(GraphicEvent e) { |
... | ... | |
368 | 349 |
|
369 | 350 |
return channel; |
370 | 351 |
} |
371 |
|
|
372 | 352 |
} |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramProcess.java | ||
---|---|---|
19 | 19 |
package org.gvsig.rastertools.histogram; |
20 | 20 |
|
21 | 21 |
import org.gvsig.gui.beans.incrementabletask.IIncrementable; |
22 |
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent; |
|
23 |
import org.gvsig.gui.beans.incrementabletask.IncrementableListener; |
|
24 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
|
22 | 25 |
import org.gvsig.raster.util.Histogram; |
23 | 26 |
import org.gvsig.raster.util.HistogramException; |
24 | 27 |
import org.gvsig.raster.util.IHistogramable; |
25 | 28 |
|
26 |
public class HistogramProcess extends Thread implements IIncrementable {
|
|
29 |
public class HistogramProcess implements Runnable, IIncrementable, IncrementableListener {
|
|
27 | 30 |
IHistogramable iHistogramable = null; |
28 |
Histogram histogram = null; |
|
29 |
|
|
30 |
public HistogramProcess(IHistogramable iHistogramable) { |
|
31 |
HistogramPanelListener hpl = null; |
|
32 |
|
|
33 |
IncrementableTask incrementableTask = null; |
|
34 |
private volatile Thread blinker; |
|
35 |
|
|
36 |
public HistogramProcess(IHistogramable iHistogramable, HistogramPanelListener hpl) { |
|
31 | 37 |
this.iHistogramable = iHistogramable; |
32 |
this.start();
|
|
38 |
this.hpl = hpl;
|
|
33 | 39 |
} |
34 | 40 |
|
41 |
public void start() { |
|
42 |
blinker = new Thread(this); |
|
43 |
blinker.start(); |
|
44 |
} |
|
45 |
|
|
46 |
public synchronized void stop() { |
|
47 |
blinker = null; |
|
48 |
notify(); |
|
49 |
} |
|
50 |
|
|
35 | 51 |
public void run() { |
36 | 52 |
try { |
37 |
histogram = iHistogramable.getHistogram(); |
|
53 |
Histogram histogram = iHistogramable.getHistogram(); |
|
54 |
hpl.setNewHistogram(histogram); |
|
38 | 55 |
} catch (HistogramException e) { |
39 | 56 |
e.printStackTrace(); |
40 | 57 |
} |
58 |
while (!incrementableTask.getStarted()); |
|
59 |
while (incrementableTask.isAlive()); |
|
60 |
incrementableTask.Hide(); |
|
61 |
incrementableTask = null; |
|
41 | 62 |
} |
42 | 63 |
|
43 |
public Histogram getLastHistogram() {
|
|
44 |
return histogram;
|
|
64 |
public void setIncrementableTask(IncrementableTask value) {
|
|
65 |
incrementableTask = value;
|
|
45 | 66 |
} |
67 |
|
|
46 | 68 |
/* |
47 | 69 |
* (non-Javadoc) |
48 | 70 |
* @see org.gvsig.gui.beans.IncrementableTask.IIncrementable#getLabel() |
... | ... | |
74 | 96 |
public String getTitle() { |
75 | 97 |
return "Calculando histograma"; |
76 | 98 |
} |
99 |
|
|
100 |
public void actionCanceled(IncrementableEvent e) { |
|
101 |
// TODO Implementar la forma de cancelar el proceso |
|
102 |
} |
|
103 |
|
|
104 |
public void actionResumed(IncrementableEvent e) { |
|
105 |
} |
|
106 |
|
|
107 |
public void actionSuspended(IncrementableEvent e) { |
|
108 |
} |
|
77 | 109 |
} |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramTocMenuEntry.java | ||
---|---|---|
73 | 73 |
histogramDialog.setHistogramableSource(((FLyrRasterSE)lyr).getSource().getDatasource().getGeoRasterMultiFile(), PluginServices.getText(this, "imagen_completa")); |
74 | 74 |
|
75 | 75 |
//Par?metros de inicializaci?n del histograma |
76 |
|
|
77 |
histogramDialog.getHistogramPanel().setHistogramDataSource(0); //Fuente de datos; la vista |
|
78 |
histogramDialog.getHistogramPanel().setType(0); //Tipo de histograma; no acumulado |
|
79 |
histogramDialog.getHistogramPanel().setRGBInBandList(); //Asignaci?n R,G,B en el combo |
|
80 |
|
|
81 | 76 |
histogramDialog.getHistogramPanel().firstRun(); // Mostar por primera vez el histograma |
82 | 77 |
histogramDialog.setVisible(true); |
83 | 78 |
|
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramDialog.java | ||
---|---|---|
19 | 19 |
package org.gvsig.rastertools.histogram.ui; |
20 | 20 |
|
21 | 21 |
import java.awt.BorderLayout; |
22 |
import java.awt.event.ActionEvent; |
|
23 |
import java.awt.event.ActionListener; |
|
24 | 22 |
|
25 | 23 |
import javax.swing.JPanel; |
26 | 24 |
|
27 | 25 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
26 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
|
27 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
|
28 | 28 |
import org.gvsig.raster.util.IHistogramable; |
29 | 29 |
|
30 | 30 |
import com.iver.andami.PluginServices; |
... | ... | |
37 | 37 |
* @author Nacho Brodin (brodin_ign@gva.es) |
38 | 38 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es) |
39 | 39 |
*/ |
40 |
public class HistogramDialog extends JPanel implements IWindow, ActionListener {
|
|
40 |
public class HistogramDialog extends JPanel implements IWindow, ButtonsPanelListener {
|
|
41 | 41 |
private static final long serialVersionUID = 7362459094802955247L; |
42 | 42 |
private HistogramPanel histogramPanel = null; |
43 | 43 |
|
... | ... | |
55 | 55 |
public HistogramPanel getHistogramPanel(){ |
56 | 56 |
if(histogramPanel == null){ |
57 | 57 |
histogramPanel = new HistogramPanel(); |
58 |
histogramPanel.getButtonsPanel().addActionListener(this);
|
|
58 |
histogramPanel.addButtonPressedListener(this);
|
|
59 | 59 |
} |
60 | 60 |
return histogramPanel; |
61 | 61 |
} |
... | ... | |
79 | 79 |
} |
80 | 80 |
} |
81 | 81 |
|
82 |
public void actionPerformed(ActionEvent e) { |
|
83 |
// TODO: ARQUITECTURA: Este close deberia ir en un listener |
|
84 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CLOSE + "") == 0){ |
|
85 |
close(); |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 | 82 |
public void clearSources() { |
90 | 83 |
getHistogramPanel().clearSources(); |
91 | 84 |
} |
... | ... | |
93 | 86 |
public void setHistogramableSource(IHistogramable lyr, String name) { |
94 | 87 |
getHistogramPanel().setHistogramableSource(lyr, name); |
95 | 88 |
} |
89 |
|
|
90 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
|
91 |
if (e.getButton() == ButtonsPanel.BUTTON_CLOSE){ |
|
92 |
close(); |
|
93 |
} |
|
94 |
} |
|
96 | 95 |
} |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/ui/HistogramPanel.java | ||
---|---|---|
50 | 50 |
public class HistogramPanel extends DefaultButtonsPanel { |
51 | 51 |
private static final long serialVersionUID = 2772897994667886753L; |
52 | 52 |
|
53 |
private HistogramPanelListener histogramPanelListener = getHistogramPanelListener(); |
|
54 |
private ArrayList comboSource = new ArrayList(); |
|
55 |
private boolean panelInizialited = false; |
|
53 |
/** |
|
54 |
* Objeto que controlara toda la carga pesada del panel |
|
55 |
*/ |
|
56 |
private HistogramPanelListener histogramPanelListener = null; |
|
56 | 57 |
|
57 |
public static int MAXBANDS = 10; |
|
58 |
private int HSUP = 60; |
|
58 |
/** |
|
59 |
* Array para la seleccion del origen |
|
60 |
*/ |
|
61 |
private ArrayList comboSource = new ArrayList(); |
|
59 | 62 |
|
63 |
/** |
|
64 |
* Variable para controlar si se dispararan los eventos del panel, |
|
65 |
* si es la primera vez no tiene porque disparar eventos. |
|
66 |
*/ |
|
67 |
public boolean panelInizialited = false; |
|
68 |
|
|
69 |
/** |
|
70 |
* Componentes graficos |
|
71 |
*/ |
|
60 | 72 |
private GraphicContainer graphicContainer = null; |
61 | 73 |
private JPanel pTable = null; |
62 | 74 |
private JComboBox jComboBoxOrigen = null; |
... | ... | |
65 | 77 |
private JButton jButtonClear = null; |
66 | 78 |
private JButton bTable = null; |
67 | 79 |
private TableContainer tableContainer = null; |
68 |
|
|
69 | 80 |
private JPanel cbSup = null; |
70 | 81 |
private JLabel lOrigin = null; |
71 | 82 |
private JLabel lBands = null; |
72 | 83 |
private JLabel lType = null; |
73 |
/** |
|
74 |
* Bandas que se est?n mostrando en el gr?fico. Se inicializa con las 3 bandas |
|
75 |
* RGB de la visualizaci?n. Este array puede tener m?s elementos ya que si las |
|
76 |
* bandas no son de visualizaci?n (bandas de la imagen en disco) tendr? un elemento |
|
77 |
* por cada una. |
|
78 |
*/ |
|
79 |
// public boolean[] showBands = {true, true, true}; |
|
80 |
|
|
81 |
/** |
|
82 |
* Tipo de histograma |
|
83 |
* 0 = acumulado |
|
84 |
* 1 = No acumulado |
|
85 |
*/ |
|
86 |
private int type = 0; |
|
87 |
|
|
88 |
/** |
|
89 |
* Tipo de fuente de datos para el histograma |
|
90 |
* 0 = Datos de la vista |
|
91 |
* 1 = extent de la vista y datos leidos desde la imagen |
|
92 |
* 2 = histograma de la imagen completa |
|
93 |
*/ |
|
94 |
private int histogramDataSource = 0; |
|
95 | 84 |
|
96 | 85 |
/** |
97 | 86 |
* Tipo de dato de la petici?n. Si la petici?n del histograma es de la vista el tipo |
... | ... | |
107 | 96 |
*/ |
108 | 97 |
public HistogramPanel() { |
109 | 98 |
super(ButtonsPanel.BUTTONS_CLOSE); |
99 |
histogramPanelListener = getHistogramPanelListener(); |
|
110 | 100 |
initialize(); |
111 | 101 |
} |
112 | 102 |
|
... | ... | |
222 | 212 |
|
223 | 213 |
cbSup = new JPanel(); |
224 | 214 |
|
225 |
cbSup.setPreferredSize(new java.awt.Dimension(0, HSUP));
|
|
215 |
cbSup.setPreferredSize(new java.awt.Dimension(0, 60));
|
|
226 | 216 |
|
227 | 217 |
cbSup.setLayout(new GridBagLayout()); |
228 | 218 |
cbSup.add(lOrigin, gridBagConstraints); |
... | ... | |
274 | 264 |
*utilizada para extensiones que necesitan histograma pero no pueden acceder a la fuente de datos. |
275 | 265 |
*/ |
276 | 266 |
public void setOnlyViewValue(){ |
277 |
getHistogramPanelListener().comboEventEnable = false;
|
|
267 |
getHistogramPanelListener().eventsEnabled = false;
|
|
278 | 268 |
getJComboBoxOrigen().removeAllItems(); |
279 | 269 |
getJComboBoxOrigen().addItem(Messages.getText("vista")); |
280 |
getHistogramPanelListener().comboEventEnable = panelInizialited;
|
|
270 |
getHistogramPanelListener().eventsEnabled = panelInizialited;
|
|
281 | 271 |
} |
282 | 272 |
|
283 | 273 |
/** |
... | ... | |
319 | 309 |
* @return javax.swing.JComboBox |
320 | 310 |
*/ |
321 | 311 |
public JComboBox getJComboBands() { |
322 |
getHistogramPanelListener().comboEventEnable = false;
|
|
312 |
getHistogramPanelListener().eventsEnabled = false;
|
|
323 | 313 |
if (jComboBands == null) { |
324 | 314 |
String lista [] = {Messages.getText("todas")}; |
325 | 315 |
jComboBands = new JComboBox(lista); |
326 | 316 |
jComboBands.addActionListener(getHistogramPanelListener()); |
327 | 317 |
jComboBands.setPreferredSize(new java.awt.Dimension(100,25)); |
328 | 318 |
} |
329 |
getHistogramPanelListener().comboEventEnable = panelInizialited;
|
|
319 |
getHistogramPanelListener().eventsEnabled = panelInizialited;
|
|
330 | 320 |
return jComboBands; |
331 | 321 |
} |
332 | 322 |
|
... | ... | |
335 | 325 |
* @param bands N?mero de bandas de la imagen |
336 | 326 |
*/ |
337 | 327 |
public void setBands(int bands){ |
338 |
getHistogramPanelListener().comboEventEnable = false;
|
|
328 |
getHistogramPanelListener().eventsEnabled = false;
|
|
339 | 329 |
getJComboBands().removeAllItems(); |
340 | 330 |
getJComboBands().addItem(Messages.getText("todas")); |
341 |
// showBands = new boolean[bands]; |
|
342 | 331 |
for(int i = 0; i < bands; i++){ |
343 | 332 |
getJComboBands().addItem("Band "+String.valueOf(i)); |
344 |
// showBands[i] = true; |
|
345 | 333 |
} |
346 |
getHistogramPanelListener().comboEventEnable = panelInizialited;
|
|
334 |
getHistogramPanelListener().eventsEnabled = panelInizialited;
|
|
347 | 335 |
} |
348 | 336 |
|
349 | 337 |
|
... | ... | |
378 | 366 |
* |
379 | 367 |
*/ |
380 | 368 |
public void setRGBInBandList(){ |
381 |
getHistogramPanelListener().comboEventEnable = false; |
|
382 |
// boolean[] list = {true, true, true}; |
|
383 |
// showBands = list; |
|
369 |
getHistogramPanelListener().eventsEnabled = false; |
|
384 | 370 |
getJComboBands().removeAllItems(); |
385 | 371 |
getJComboBands().addItem(Messages.getText("todas")); |
386 | 372 |
getJComboBands().addItem("R"); |
387 | 373 |
getJComboBands().addItem("G"); |
388 | 374 |
getJComboBands().addItem("B"); |
389 |
getHistogramPanelListener().comboEventEnable = panelInizialited;
|
|
375 |
getHistogramPanelListener().eventsEnabled = panelInizialited;
|
|
390 | 376 |
} |
391 |
|
|
392 |
/** |
|
393 |
* Obtiene el tipo de datos de la fuente de la imagen |
|
394 |
* @return tipo de datos de la fuente de la imagen |
|
395 |
*/ |
|
396 |
public int getHistogramDataSource() { |
|
397 |
return histogramDataSource; |
|
398 |
} |
|
399 | 377 |
|
400 | 378 |
/** |
401 |
* Asigna el tipo de datos de la fuente de la imagen |
|
402 |
* @param histogramDataSource tipo de datos de la fuente de la imagen |
|
403 |
*/ |
|
404 |
public void setHistogramDataSource(int histogramDataSource) { |
|
405 |
this.histogramDataSource = histogramDataSource; |
|
406 |
} |
|
407 |
|
|
408 |
/** |
|
409 |
* Obtiene el tipo de histograma a mostrar |
|
410 |
* @return acumulado/no acumulado |
|
411 |
*/ |
|
412 |
public int getType() { |
|
413 |
return type; |
|
414 |
} |
|
415 |
|
|
416 |
/** |
|
417 |
* Asigna el tipo de histograma a mostrar |
|
418 |
* @param type acumulado/no acumulado |
|
419 |
*/ |
|
420 |
public void setType(int type) { |
|
421 |
this.type = type; |
|
422 |
} |
|
423 |
|
|
424 |
/** |
|
425 | 379 |
* Obtiene el valor de los controles en el rango 0-255. Los controles dan un rango en tanto por cien 0-100 |
426 | 380 |
* pero para el calculo de estadisticas necesitamos un rango de valor de pixel. |
427 | 381 |
* @return Array con los valores de ambos controles. El primer valor del array es el control de la derecha |
... | ... | |
433 | 387 |
currentValues[0] = getGraphicContainer().getX2(); |
434 | 388 |
currentValues[1] = getGraphicContainer().getX1(); |
435 | 389 |
switch (requestDataType){ |
436 |
case RasterBuf.TYPE_BYTE: v[0] = (currentValues[0] * RasterUtilities.MAX_BYTE_BIT_VALUE) / 100; |
|
390 |
case RasterBuf.TYPE_BYTE: |
|
391 |
v[0] = (currentValues[0] * RasterUtilities.MAX_BYTE_BIT_VALUE) / 100; |
|
437 | 392 |
v[1] = (currentValues[1] * RasterUtilities.MAX_BYTE_BIT_VALUE) / 100; |
438 | 393 |
break; |
439 |
case RasterBuf.TYPE_SHORT: v[0] = (currentValues[0] * RasterUtilities.MAX_SHORT_BIT_VALUE) / 100; |
|
394 |
case RasterBuf.TYPE_SHORT: |
|
395 |
v[0] = (currentValues[0] * RasterUtilities.MAX_SHORT_BIT_VALUE) / 100; |
|
440 | 396 |
v[1] = (currentValues[1] * RasterUtilities.MAX_SHORT_BIT_VALUE) / 100; |
441 | 397 |
break; |
442 | 398 |
} |
... | ... | |
451 | 407 |
} |
452 | 408 |
|
453 | 409 |
public void setHistogramableSource(IHistogramable lyr, String name) { |
454 |
getHistogramPanelListener().comboEventEnable = false;
|
|
410 |
getHistogramPanelListener().eventsEnabled = false;
|
|
455 | 411 |
ArrayList aux = new ArrayList(); |
456 | 412 |
aux.add(lyr); |
457 | 413 |
aux.add(name); |
458 | 414 |
comboSource.add(aux); |
459 | 415 |
updateComboBoxSource(); |
460 |
getHistogramPanelListener().comboEventEnable = panelInizialited;
|
|
416 |
getHistogramPanelListener().eventsEnabled = panelInizialited;
|
|
461 | 417 |
} |
462 | 418 |
|
463 | 419 |
public ArrayList getComboSource() { |
... | ... | |
465 | 421 |
} |
466 | 422 |
|
467 | 423 |
private void updateComboBoxSource() { |
468 |
getHistogramPanelListener().comboEventEnable = false;
|
|
424 |
getHistogramPanelListener().eventsEnabled = false;
|
|
469 | 425 |
getJComboBoxOrigen().removeAllItems(); |
470 | 426 |
for (int i = 0; i < comboSource.size(); i++) { |
471 | 427 |
getJComboBoxOrigen().addItem(((ArrayList) comboSource.get(i)).get(1)); |
472 | 428 |
} |
473 |
getHistogramPanelListener().comboEventEnable = panelInizialited;
|
|
429 |
getHistogramPanelListener().eventsEnabled = panelInizialited;
|
|
474 | 430 |
} |
475 | 431 |
|
476 | 432 |
public void clearSources() { |
... | ... | |
478 | 434 |
updateComboBoxSource(); |
479 | 435 |
} |
480 | 436 |
|
437 |
public void refreshBands() { |
|
438 |
//En caso de que el histograma se monte a partir de los datos de la vista ponemos RGB en el combo |
|
439 |
int bandCount = getHistogramPanelListener().getHistogram().getNumBands(); |
|
440 |
if ((getJComboBoxOrigen().getSelectedIndex() == 0) && (bandCount == 3)) { |
|
441 |
setRGBInBandList(); |
|
442 |
} else { |
|
443 |
setBands(bandCount); |
|
444 |
} |
|
445 |
} |
|
446 |
|
|
481 | 447 |
public void firstRun() { |
482 |
panelInizialited = true; |
|
483 |
getHistogramPanelListener().comboEventEnable = true; |
|
484 | 448 |
getHistogramPanelListener().showHistogram(); |
485 | 449 |
} |
486 | 450 |
} |
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/dialogPanel/TestDialogPanel.java | ||
---|---|---|
19 | 19 |
package org.gvsig.gui.beans.dialogPanel; |
20 | 20 |
|
21 | 21 |
import java.awt.BorderLayout; |
22 |
import java.awt.event.ActionEvent; |
|
23 |
import java.awt.event.ActionListener; |
|
24 | 22 |
|
25 | 23 |
import javax.swing.JButton; |
26 | 24 |
import javax.swing.JFrame; |
27 | 25 |
import javax.swing.UIManager; |
28 | 26 |
|
29 | 27 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
28 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
|
29 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
|
30 | 30 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
31 | 31 |
/** |
32 | 32 |
* <code>TestDialogPanel</code>. Test para comprobar el funcionamiento de la |
... | ... | |
35 | 35 |
* @version 15/03/2007 |
36 | 36 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es) |
37 | 37 |
*/ |
38 |
public class TestDialogPanel implements ActionListener {
|
|
38 |
public class TestDialogPanel implements ButtonsPanelListener {
|
|
39 | 39 |
private JFrame frame = new JFrame(); |
40 | 40 |
|
41 | 41 |
class NewComponentDialog extends DefaultButtonsPanel { |
... | ... | |
60 | 60 |
frame.getContentPane().add(ncd); |
61 | 61 |
frame.show(); |
62 | 62 |
|
63 |
ncd.getButtonsPanel().addActionListener(this);
|
|
63 |
ncd.addButtonPressedListener(this);
|
|
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
public static void main(String[] args) { |
... | ... | |
72 | 72 |
new TestDialogPanel(); |
73 | 73 |
} |
74 | 74 |
|
75 |
public void actionPerformed(ActionEvent e) {
|
|
76 |
System.out.println("Bot?n pulsado: " + e.getActionCommand());
|
|
75 |
public void actionButtonPressed(ButtonsPanelEvent e) {
|
|
76 |
System.out.println("Bot?n pulsado: " + e.getButton());
|
|
77 | 77 |
} |
78 | 78 |
} |
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/progressPanel/TestProgressPanel.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.gui.beans.progressPanel; |
20 | 20 |
|
21 |
import java.awt.event.ActionEvent; |
|
22 |
import java.awt.event.ActionListener; |
|
23 |
|
|
24 | 21 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
22 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
|
23 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
|
25 | 24 |
import org.gvsig.gui.beans.progresspanel.ProgressPanel; |
26 | 25 |
|
27 | 26 |
/** |
... | ... | |
35 | 34 |
|
36 | 35 |
private tryPanel frame = null; |
37 | 36 |
|
38 |
public class tryPanel implements Runnable, ActionListener {
|
|
37 |
public class tryPanel implements Runnable, ButtonsPanelListener {
|
|
39 | 38 |
private ProgressPanel frame = new ProgressPanel(); |
40 | 39 |
private volatile Thread blinker; |
41 | 40 |
|
... | ... | |
44 | 43 |
frame.setTitle("Actualizando datos"); |
45 | 44 |
frame.showLog(false); |
46 | 45 |
frame.show(); |
47 |
frame.getButtonsPanel().addActionListener(this);
|
|
46 |
frame.getButtonsPanel().addButtonPressedListener(this);
|
|
48 | 47 |
} |
49 | 48 |
|
50 | 49 |
private boolean threadSuspended = false; |
... | ... | |
99 | 98 |
frame = null; |
100 | 99 |
} |
101 | 100 |
|
102 |
public void actionPerformed(ActionEvent e) {
|
|
103 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CANCEL + "" ) == 0) {
|
|
101 |
public void actionButtonPressed(ButtonsPanelEvent e) {
|
|
102 |
if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
|
|
104 | 103 |
this.stop(); |
105 | 104 |
} |
106 |
|
|
107 | 105 |
} |
108 | 106 |
} |
109 | 107 |
|
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/incrementableTask/testThread.java | ||
---|---|---|
1 |
package org.gvsig.gui.beans.incrementableTask; |
|
2 |
|
|
3 |
public class testThread { |
|
4 |
public class miThread1 extends Thread { |
|
5 |
public void run() { |
|
6 |
System.out.println("miThread1 begin"); |
|
7 |
for (int i=0; i<=10; i++) { |
|
8 |
System.out.println(i); |
|
9 |
try { |
|
10 |
Thread.sleep(500); |
|
11 |
} catch (InterruptedException e) { |
|
12 |
e.printStackTrace(); |
|
13 |
} |
|
14 |
} |
|
15 |
System.out.println("miThread1 end"); |
|
16 |
} |
|
17 |
} |
|
18 |
|
|
19 |
public testThread() { |
|
20 |
System.out.println("testThread begin"); |
|
21 |
miThread1 a = new miThread1(); |
|
22 |
a.start(); |
|
23 |
while (true) { |
|
24 |
try { |
|
25 |
Thread.sleep(250); |
|
26 |
} catch (InterruptedException e) { |
|
27 |
e.printStackTrace(); |
|
28 |
} |
|
29 |
System.out.println("isAlive(): " + a.isAlive()); |
|
30 |
if (!a.isAlive()) break; |
|
31 |
} |
|
32 |
System.out.println("testThread end"); |
|
33 |
} |
|
34 |
|
|
35 |
public static void main(String[] args) { |
|
36 |
System.out.println("main begin"); |
|
37 |
new testThread(); |
|
38 |
System.out.println("main end"); |
|
39 |
} |
|
40 |
|
|
41 |
} |
|
0 | 42 |
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/incrementableTask/TestIncrementableTask.java | ||
---|---|---|
25 | 25 |
import org.gvsig.gui.beans.progresspanel.LogControl; |
26 | 26 |
|
27 | 27 |
public class TestIncrementableTask { |
28 |
class ClassProcess extends Thread implements IIncrementable, IncrementableListener {
|
|
28 |
class ClassProcess implements Runnable, IIncrementable, IncrementableListener {
|
|
29 | 29 |
int i = 0; |
30 | 30 |
long j = 0; |
31 | 31 |
LogControl log = new LogControl(); |
32 |
IncrementableTask incrementableTask = null; |
|
32 | 33 |
|
34 |
private volatile Thread blinker; |
|
35 |
private boolean ended = false; |
|
36 |
private boolean threadSuspended = false; |
|
37 |
|
|
33 | 38 |
public ClassProcess() { |
34 |
this.start(); |
|
35 | 39 |
} |
36 | 40 |
|
41 |
public void start() { |
|
42 |
blinker = new Thread(this); |
|
43 |
blinker.start(); |
|
44 |
} |
|
45 |
|
|
46 |
public synchronized void stop() { |
|
47 |
ended = true; |
|
48 |
blinker = null; |
|
49 |
notify(); |
|
50 |
} |
|
51 |
|
|
52 |
public boolean isAlive() { |
|
53 |
return blinker.isAlive(); |
|
54 |
} |
|
55 |
|
|
56 |
|
|
37 | 57 |
public synchronized void run(){ |
38 | 58 |
for (j=0; j<=65535; j++) { |
59 |
if (ended) break; |
|
39 | 60 |
for (long i=0; i<=65535; i++); |
40 | 61 |
log.replaceLastLine(j + ""); |
41 | 62 |
if ((j%1000)==0) { |
42 | 63 |
log.addLine(j + ""); |
43 | 64 |
} |
65 |
synchronized(this) { |
|
66 |
while (threadSuspended && !ended) |
|
67 |
try { |
|
68 |
wait(500); |
|
69 |
} catch (InterruptedException e) { |
|
70 |
e.printStackTrace(); |
|
71 |
} |
|
72 |
} |
|
44 | 73 |
} |
74 |
while (incrementableTask.isAlive()); |
|
75 |
incrementableTask.Hide(); |
|
76 |
incrementableTask = null; |
|
45 | 77 |
} |
46 | 78 |
|
47 | 79 |
public String getLabel() { |
... | ... | |
60 | 92 |
return "TestIncrementTask"; |
61 | 93 |
} |
62 | 94 |
|
63 |
public void actionCanceled(IncrementableEvent e) {
|
|
64 |
this.suspend();
|
|
95 |
public void setIncrementableTask(IncrementableTask value) {
|
|
96 |
incrementableTask = value;
|
|
65 | 97 |
} |
66 | 98 |
|
67 |
public void actionClosed(IncrementableEvent e) {
|
|
68 |
this.suspend();
|
|
99 |
public void actionCanceled(IncrementableEvent e) {
|
|
100 |
ended = true;
|
|
69 | 101 |
} |
70 | 102 |
|
71 | 103 |
public void actionResumed(IncrementableEvent e) { |
72 |
this.resume();
|
|
104 |
threadSuspended = false;
|
|
73 | 105 |
} |
74 | 106 |
|
75 | 107 |
public void actionSuspended(IncrementableEvent e) { |
76 |
this.suspend();
|
|
108 |
threadSuspended = true;
|
|
77 | 109 |
} |
78 | 110 |
} |
79 | 111 |
|
80 |
ClassProcess ncp = new ClassProcess();
|
|
112 |
ClassProcess classProcess = null;
|
|
81 | 113 |
|
82 | 114 |
public TestIncrementableTask() { |
83 | 115 |
super(); |
... | ... | |
85 | 117 |
} |
86 | 118 |
|
87 | 119 |
private void initialize() { |
88 |
IncrementableTask it = new IncrementableTask(ncp); |
|
89 |
it.showWindow(); |
|
90 |
it.addIncrementableListener(ncp); |
|
120 |
classProcess = new ClassProcess(); |
|
121 |
IncrementableTask incrementableTask = new IncrementableTask(classProcess); |
|
122 |
classProcess.setIncrementableTask(incrementableTask); |
|
123 |
incrementableTask.showWindow(); |
|
124 |
incrementableTask.addIncrementableListener(classProcess); |
|
125 |
|
|
126 |
incrementableTask.start(); |
|
127 |
classProcess.start(); |
|
128 |
while (classProcess.isAlive()) { |
|
129 |
try { |
|
130 |
Thread.sleep(500); |
|
131 |
} catch (InterruptedException e) { |
|
132 |
e.printStackTrace(); |
|
133 |
} |
|
134 |
} |
|
135 |
classProcess.stop(); |
|
136 |
classProcess = null; |
|
137 |
incrementableTask = null; |
|
91 | 138 |
} |
92 | 139 |
|
93 | 140 |
public static void main(String[] args) { |
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/doubleslider/TestDoubleSlider.java | ||
---|---|---|
3 | 3 |
import java.awt.BorderLayout; |
4 | 4 |
import java.awt.Dimension; |
5 | 5 |
|
6 |
import javax.swing.JButton; |
|
7 | 6 |
import javax.swing.JFrame; |
8 | 7 |
import javax.swing.JPanel; |
9 | 8 |
|
10 |
import org.gvsig.gui.beans.doubleslider.DoubleSlider; |
|
11 |
|
|
12 | 9 |
public class TestDoubleSlider { |
13 | 10 |
|
14 | 11 |
private JFrame jFrame = new JFrame(); |
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/buttonsPanel/TestButtonsPanel.java | ||
---|---|---|
19 | 19 |
package org.gvsig.gui.beans.buttonsPanel; |
20 | 20 |
|
21 | 21 |
import java.awt.FlowLayout; |
22 |
import java.awt.event.ActionEvent; |
|
23 |
import java.awt.event.ActionListener; |
|
24 | 22 |
|
25 | 23 |
import javax.swing.JFrame; |
26 | 24 |
|
27 | 25 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
26 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
|
27 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
|
28 | 28 |
/** |
29 | 29 |
* <code>TestButtonsPanel</code> es un test para comprobar el funcionamiento de |
30 | 30 |
* la clase <code>ButtonsPanel</code>. |
... | ... | |
32 | 32 |
* @version 15/03/2007 |
33 | 33 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es) |
34 | 34 |
*/ |
35 |
public class TestButtonsPanel implements ActionListener{
|
|
35 |
public class TestButtonsPanel implements ButtonsPanelListener {
|
|
36 | 36 |
private JFrame frame = new JFrame(); |
37 | 37 |
|
38 | 38 |
public TestButtonsPanel(){ |
... | ... | |
40 | 40 |
|
41 | 41 |
frame.setSize(320, 320); |
42 | 42 |
ButtonsPanel bp = new ButtonsPanel(ButtonsPanel.BUTTONS_ACCEPT); |
43 |
bp.addActionListener(this);
|
|
43 |
bp.addButtonPressedListener(this);
|
|
44 | 44 |
frame.getContentPane().add(bp); |
45 | 45 |
bp = new ButtonsPanel(ButtonsPanel.BUTTONS_ACCEPTCANCEL); |
46 |
bp.addActionListener(this);
|
|
46 |
bp.addButtonPressedListener(this);
|
|
47 | 47 |
bp.setLayout(new java.awt.FlowLayout(FlowLayout.CENTER)); |
48 | 48 |
frame.getContentPane().add(bp); |
49 | 49 |
bp = new ButtonsPanel(ButtonsPanel.BUTTONS_ACCEPTCANCELAPPLY); |
50 | 50 |
bp.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT)); |
51 |
bp.addActionListener(this);
|
|
51 |
bp.addButtonPressedListener(this);
|
|
52 | 52 |
frame.getContentPane().add(bp); |
53 | 53 |
bp = new ButtonsPanel(ButtonsPanel.BUTTONS_YESNO); |
54 |
bp.addActionListener(this);
|
|
54 |
bp.addButtonPressedListener(this);
|
|
55 | 55 |
frame.getContentPane().add(bp); |
56 | 56 |
bp = new ButtonsPanel(ButtonsPanel.BUTTONS_CLOSE); |
57 |
bp.addActionListener(this);
|
|
57 |
bp.addButtonPressedListener(this);
|
|
58 | 58 |
frame.getContentPane().add(bp); |
59 | 59 |
bp = new ButtonsPanel(ButtonsPanel.BUTTONS_EXIT); |
60 |
bp.addActionListener(this);
|
|
60 |
bp.addButtonPressedListener(this);
|
|
61 | 61 |
frame.getContentPane().add(bp); |
62 | 62 |
frame.show(); |
63 | 63 |
} |
... | ... | |
66 | 66 |
new TestButtonsPanel(); |
67 | 67 |
} |
68 | 68 |
|
69 |
public void actionPerformed(ActionEvent e) {
|
|
70 |
System.out.println(e.getActionCommand());
|
|
71 |
if (String.valueOf(ButtonsPanel.BUTTON_EXIT).compareTo(e.getActionCommand()) == 0) {
|
|
69 |
public void actionButtonPressed(ButtonsPanelEvent e) {
|
|
70 |
System.out.println(e.getButton());
|
|
71 |
if (ButtonsPanel.BUTTON_EXIT == e.getButton()) {
|
|
72 | 72 |
frame.dispose(); |
73 | 73 |
} |
74 | 74 |
} |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/listeners/GraphicListener.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import javax.swing.JLabel; |
28 | 28 |
|
29 |
import org.gvsig.gui.beans.graphic.GraphicContainer; |
|
30 |
|
|
31 | 29 |
/** |
32 | 30 |
* |
33 | 31 |
* @author Nacho Brodin <brodin_ign@gva.es> |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/buttonspanel/ButtonsPanel.java | ||
---|---|---|
108 | 108 |
} |
109 | 109 |
} |
110 | 110 |
|
111 |
public void addActionListener(ActionListener listener) {
|
|
111 |
public void addButtonPressedListener(ButtonsPanelListener listener) {
|
|
112 | 112 |
if (!actionCommandListeners.contains(listener)) |
113 | 113 |
actionCommandListeners.add(listener); |
114 | 114 |
} |
115 | 115 |
|
116 |
public void removeActionListener(ActionListener listener) {
|
|
116 |
public void removeButtonPressedListener(ButtonsPanelListener listener) {
|
|
117 | 117 |
actionCommandListeners.remove(listener); |
118 | 118 |
} |
119 | 119 |
|
120 |
private void callActionCommandListeners(String buttonID) {
|
|
120 |
private void callActionCommandListeners(int buttonID) {
|
|
121 | 121 |
Iterator acIterator = actionCommandListeners.iterator(); |
122 | 122 |
while (acIterator.hasNext()) { |
123 |
ActionListener listener = (ActionListener) acIterator.next();
|
|
124 |
listener.actionPerformed(new ActionEvent(this, eventId, buttonID));
|
|
123 |
ButtonsPanelListener listener = (ButtonsPanelListener) acIterator.next();
|
|
124 |
listener.actionButtonPressed(new ButtonsPanelEvent(this, buttonID));
|
|
125 | 125 |
} |
126 | 126 |
eventId++; |
127 | 127 |
} |
... | ... | |
216 | 216 |
button.setActionCommand(id + ""); |
217 | 217 |
button.addActionListener(new ActionListener() { |
218 | 218 |
public void actionPerformed(ActionEvent e) { |
219 |
callActionCommandListeners(e.getActionCommand());
|
|
219 |
callActionCommandListeners(Integer.parseInt(e.getActionCommand()));
|
|
220 | 220 |
} |
221 | 221 |
}); |
222 | 222 |
|
... | ... | |
232 | 232 |
Iterator acIterator = buttonsList.iterator(); |
233 | 233 |
while (acIterator.hasNext()) { |
234 | 234 |
JButton button = (JButton) acIterator.next(); |
235 |
if (button.getActionCommand().compareTo(id + "") == 0)
|
|
235 |
if (Integer.parseInt(button.getActionCommand()) == id)
|
|
236 | 236 |
return button; |
237 | 237 |
} |
238 | 238 |
return null; |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/buttonspanel/ButtonsPanelEvent.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.gui.beans.buttonspanel; |
|
20 |
|
|
21 |
import java.util.EventObject; |
|
22 |
|
|
23 |
public class ButtonsPanelEvent extends EventObject { |
|
24 |
private static final long serialVersionUID = -684281519921935004L; |
|
25 |
int button = 0; |
|
26 |
|
|
27 |
public ButtonsPanelEvent(Object source, int button) { |
|
28 |
super(source); |
|
29 |
this.button = button; |
|
30 |
} |
|
31 |
|
|
32 |
public int getButton() { |
|
33 |
return button; |
|
34 |
} |
|
35 |
} |
|
0 | 36 |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/buttonspanel/ButtonsPanelListener.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.gui.beans.buttonspanel; |
|
20 |
|
|
21 |
import java.util.EventListener; |
|
22 |
|
|
23 |
public interface ButtonsPanelListener extends EventListener { |
|
24 |
public void actionButtonPressed(ButtonsPanelEvent e); |
|
25 |
} |
|
0 | 26 |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/defaultbuttonspanel/DefaultButtonsPanel.java | ||
---|---|---|
24 | 24 |
import javax.swing.JPanel; |
25 | 25 |
|
26 | 26 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
27 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
|
27 | 28 |
/** |
28 | 29 |
* <code>DefaultButtonsPanel</code> es un Panel que hereda de <code>JPanel</code> con |
29 | 30 |
* el a?adido de poder definir una botonera por defecto. |
... | ... | |
84 | 85 |
content = new JPanel(); |
85 | 86 |
return content; |
86 | 87 |
} |
88 |
|
|
89 |
public void addButtonPressedListener(ButtonsPanelListener listener) { |
|
90 |
getButtonsPanel().addButtonPressedListener(listener); |
|
91 |
} |
|
87 | 92 |
|
93 |
public void removeButtonPressedListener(ButtonsPanelListener listener) { |
|
94 |
getButtonsPanel().removeButtonPressedListener(listener); |
|
95 |
} |
|
96 |
|
|
88 | 97 |
/* |
89 | 98 |
* (non-Javadoc) |
90 | 99 |
* @see java.awt.Container#getLayout() |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/progresspanel/ProgressPanel.java | ||
---|---|---|
30 | 30 |
import javax.swing.JTextPane; |
31 | 31 |
|
32 | 32 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
33 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
|
34 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
|
35 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
|
33 | 36 |
/** |
34 | 37 |
* <code>ProgressPanel</code>. Muestra una ventana de di?logo para representar |
35 | 38 |
* una barra de progreso con su ventana de registro. |
... | ... | |
44 | 47 |
private JLabel jLabel1 = null; |
45 | 48 |
private JPanel jPanel1 = null; |
46 | 49 |
private JPanel njp = null; |
47 |
private ButtonsPanel buttonsPanel = null;
|
|
50 |
private DefaultButtonsPanel defaultButtonsPanel = null;
|
|
48 | 51 |
private JProgressBar jProgressBar = null; |
49 | 52 |
private JScrollPane jScrollPane = null; |
50 | 53 |
private JTextPane jTextPane = null; |
... | ... | |
112 | 115 |
return jPanel1; |
113 | 116 |
} |
114 | 117 |
|
118 |
public void addButtonPressedListener(ButtonsPanelListener listener) { |
|
119 |
getDefaultButtonsPanel().addButtonPressedListener(listener); |
|
120 |
} |
|
121 |
|
|
122 |
public void removeButtonPressedListener(ButtonsPanelListener listener) { |
|
123 |
getDefaultButtonsPanel().removeButtonPressedListener(listener); |
|
124 |
} |
|
125 |
|
|
115 | 126 |
public void showLog(boolean visible) { |
116 | 127 |
|
117 |
buttonsPanel.getButton(ButtonsPanel.BUTTON_SEEDETAILS).setVisible(!visible);
|
|
118 |
buttonsPanel.getButton(ButtonsPanel.BUTTON_HIDEDETAILS).setVisible(visible);
|
|
128 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_SEEDETAILS).setVisible(!visible);
|
|
129 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_HIDEDETAILS).setVisible(visible);
|
|
119 | 130 |
jScrollPane.setVisible(visible); |
120 | 131 |
|
121 | 132 |
int width = (this.getWidth()<400?400:this.getWidth()); |
... | ... | |
129 | 140 |
} |
130 | 141 |
|
131 | 142 |
public void showPause(boolean visible) { |
132 |
buttonsPanel.getButton(ButtonsPanel.BUTTON_RESTART).setVisible(!visible);
|
|
133 |
buttonsPanel.getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(visible);
|
|
143 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_RESTART).setVisible(!visible);
|
|
144 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_PAUSE).setVisible(visible);
|
|
134 | 145 |
} |
135 | 146 |
|
147 |
public ButtonsPanel getButtonsPanel() { |
|
148 |
return getDefaultButtonsPanel().getButtonsPanel(); |
|
149 |
} |
|
136 | 150 |
/** |
137 |
* This method initializes ButtonsPanel |
|
151 |
* This method initializes DefaultButtonsPanel
|
|
138 | 152 |
* |
139 |
* @return ButtonsPanel |
|
153 |
* @return DefaultButtonsPanel
|
|
140 | 154 |
*/ |
141 |
public ButtonsPanel getButtonsPanel() {
|
|
142 |
if (buttonsPanel == null) {
|
|
143 |
buttonsPanel = new ButtonsPanel(ButtonsPanel.BUTTONS_NONE);
|
|
144 |
buttonsPanel.addSeeDetails();
|
|
145 |
buttonsPanel.addHideDetails();
|
|
146 |
buttonsPanel.addPause();
|
|
147 |
buttonsPanel.addRestart();
|
|
155 |
public DefaultButtonsPanel getDefaultButtonsPanel() {
|
|
156 |
if (defaultButtonsPanel == null) {
|
|
157 |
defaultButtonsPanel = new DefaultButtonsPanel(ButtonsPanel.BUTTONS_NONE);
|
|
158 |
getButtonsPanel().addSeeDetails();
|
|
159 |
getButtonsPanel().addHideDetails();
|
|
160 |
getButtonsPanel().addPause();
|
|
161 |
getButtonsPanel().addRestart();
|
|
148 | 162 |
showPause(true); |
149 |
buttonsPanel.addCancel(); |
|
150 |
buttonsPanel.setLayout(new java.awt.FlowLayout(FlowLayout.CENTER)); |
|
151 |
buttonsPanel.addActionListener(new java.awt.event.ActionListener() { |
|
152 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
153 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_SEEDETAILS + "") == 0) { |
|
154 |
showLog(true); |
|
163 |
getButtonsPanel().addCancel(); |
|
164 |
getButtonsPanel().setLayout(new java.awt.FlowLayout(FlowLayout.CENTER)); |
|
165 |
getButtonsPanel().addButtonPressedListener(new ButtonsPanelListener() { |
|
166 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
|
167 |
switch (e.getButton()) { |
|
168 |
case ButtonsPanel.BUTTON_SEEDETAILS: |
|
169 |
showLog(true); |
|
170 |
break; |
|
171 |
case ButtonsPanel.BUTTON_HIDEDETAILS: |
|
172 |
showLog(false); |
|
173 |
break; |
|
174 |
case ButtonsPanel.BUTTON_PAUSE: |
|
175 |
showPause(false); |
|
176 |
break; |
|
177 |
case ButtonsPanel.BUTTON_RESTART: |
|
178 |
showPause(true); |
|
179 |
break; |
|
155 | 180 |
} |
156 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_HIDEDETAILS + "") == 0) { |
|
157 |
showLog(false); |
|
158 |
} |
|
159 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_PAUSE + "") == 0) { |
|
160 |
showPause(false); |
|
161 |
} |
|
162 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_RESTART + "") == 0) { |
|
163 |
showPause(true); |
|
164 |
} |
|
165 | 181 |
} |
166 | 182 |
}); |
167 | 183 |
} |
168 |
return buttonsPanel;
|
|
184 |
return defaultButtonsPanel;
|
|
169 | 185 |
} |
170 | 186 |
|
171 | 187 |
/** |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/incrementabletask/IncrementableListener.java | ||
---|---|---|
21 | 21 |
import java.util.EventListener; |
22 | 22 |
|
23 | 23 |
public interface IncrementableListener extends EventListener { |
24 |
public void actionClosed(IncrementableEvent e); |
|
25 | 24 |
public void actionResumed(IncrementableEvent e); |
26 | 25 |
public void actionSuspended(IncrementableEvent e); |
27 | 26 |
public void actionCanceled(IncrementableEvent e); |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/incrementabletask/IncrementableEvent.java | ||
---|---|---|
22 | 22 |
|
23 | 23 |
public class IncrementableEvent extends EventObject { |
24 | 24 |
private static final long serialVersionUID = 75795297813891036L; |
25 |
public static final int CLOSED = 1;
|
|
26 |
public static final int RESUMED = 2;
|
|
25 |
public static final int RESUMED = 1;
|
|
26 |
public static final int SUSPENDED = 2;
|
|
27 | 27 |
public static final int CANCELED = 3; |
28 |
public static final int SUSPENDED = 4; |
|
29 | 28 |
|
30 | 29 |
public IncrementableEvent(Object source) { |
31 | 30 |
super(source); |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/incrementabletask/IncrementableTask.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.gui.beans.incrementabletask; |
20 | 20 |
|
21 |
import java.awt.event.ActionEvent; |
|
22 |
import java.awt.event.ActionListener; |
|
23 | 21 |
import java.awt.event.WindowAdapter; |
24 | 22 |
import java.awt.event.WindowEvent; |
25 | 23 |
import java.util.ArrayList; |
26 | 24 |
import java.util.Iterator; |
27 | 25 |
|
28 | 26 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
27 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
|
28 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
|
29 | 29 |
import org.gvsig.gui.beans.progresspanel.ProgressPanel; |
30 | 30 |
/** |
31 | 31 |
* <code>IncrementableTask</code>. Es un dialogo que contiene un ProgressPanel. |
... | ... | |
35 | 35 |
* @version 29/03/2007 |
36 | 36 |
* @author Borja S?nchez Zamorano (borja.sanchez@iver.es) |
37 | 37 |
*/ |
38 |
public class IncrementableTask implements Runnable, ActionListener {
|
|
39 |
IIncrementable iIncrementable; |
|
40 |
private volatile ProgressPanel progressPanel = getProgressPanel();
|
|
41 |
private volatile Thread blinker; |
|
38 |
public class IncrementableTask implements Runnable, ButtonsPanelListener {
|
|
39 |
IIncrementable iIncrementable = null;
|
|
40 |
private volatile ProgressPanel progressPanel = null;
|
|
41 |
private volatile Thread blinker = null;
|
|
42 | 42 |
private boolean threadSuspended = false; |
43 |
private boolean ended = false; |
|
44 |
private boolean started = false; |
|
43 | 45 |
|
44 | 46 |
private ArrayList actionCommandListeners = new ArrayList(); |
45 | 47 |
private boolean bDoCallListeners = true; |
46 | 48 |
static private int eventId = Integer.MIN_VALUE; |
47 | 49 |
|
48 | 50 |
public IncrementableTask(IIncrementable incrementable) { |
51 |
progressPanel = getProgressPanel(); |
|
49 | 52 |
iIncrementable = incrementable; |
50 | 53 |
} |
51 |
|
|
54 |
|
|
52 | 55 |
public void start() { |
53 | 56 |
blinker = new Thread(this); |
54 | 57 |
blinker.start(); |
55 | 58 |
} |
56 | 59 |
|
57 | 60 |
public synchronized void stop() { |
61 |
ended = true; |
|
58 | 62 |
blinker = null; |
59 | 63 |
notify(); |
60 | 64 |
} |
... | ... | |
62 | 66 |
/** |
63 | 67 |
* Este thread va leyendo el porcentaje hasta que se completa el histograma. |
64 | 68 |
*/ |
65 |
public synchronized void run(){ |
|
66 |
Thread thisThread = Thread.currentThread();
|
|
67 |
while ((blinker == thisThread) && (iIncrementable.getPercent() < 100)) {
|
|
69 |
public synchronized void run() {
|
|
70 |
getProgressPanel().setPercent(0);
|
|
71 |
while (!ended && (iIncrementable.getPercent() < 100)) {
|
|
68 | 72 |
try { |
69 |
Thread.sleep(100); |
|
70 | 73 |
getProgressPanel().setLabel(iIncrementable.getLabel()); |
71 | 74 |
getProgressPanel().setPercent(iIncrementable.getPercent()); |
72 | 75 |
getProgressPanel().setTitle(iIncrementable.getTitle()); |
73 | 76 |
getProgressPanel().setLog(iIncrementable.getLog()); |
77 |
started = true; |
|
78 |
Thread.sleep(100); |
|
74 | 79 |
synchronized(this) { |
75 |
while (threadSuspended && blinker==thisThread)
|
|
80 |
while (threadSuspended && !ended)
|
|
76 | 81 |
wait(500); |
77 | 82 |
} |
78 | 83 |
} catch (InterruptedException e) { |
79 | 84 |
} |
80 | 85 |
} |
81 |
//Cerramos la ventana |
|
82 |
handleClose(); |
|
83 | 86 |
} |
87 |
|
|
88 |
public boolean getStarted() { |
|
89 |
return started; |
|
90 |
} |
|
84 | 91 |
|
85 |
private void handleClose() {
|
|
92 |
public void Hide() {
|
|
86 | 93 |
getProgressPanel().setVisible(false); |
87 | 94 |
getProgressPanel().hide(); |
88 | 95 |
progressPanel = null; |
89 |
if (iIncrementable.getPercent() == 100) |
|
90 |
callActionCommandListeners(IncrementableEvent.CLOSED); |
|
91 |
else |
|
92 |
callActionCommandListeners(IncrementableEvent.CANCELED); |
|
96 |
this.stop(); |
|
93 | 97 |
} |
98 |
|
|
99 |
public boolean isAlive() { |
|
100 |
return blinker.isAlive(); |
|
101 |
} |
|
102 |
|
|
94 | 103 |
/** |
95 | 104 |
* Muestra la ventana de incremento con el porcentaje de la construcci?n del |
96 | 105 |
* histograma. |
... | ... | |
99 | 108 |
getProgressPanel().setTitle(iIncrementable.getTitle()); |
100 | 109 |
getProgressPanel().showLog(false); |
101 | 110 |
getProgressPanel().show(); |
102 |
|
|
103 |
this.start(); |
|
104 | 111 |
} |
105 | 112 |
|
106 | 113 |
private ProgressPanel getProgressPanel() { |
107 | 114 |
if (progressPanel == null) { |
108 | 115 |
progressPanel = new ProgressPanel(); |
109 |
progressPanel.getButtonsPanel().addActionListener(this);
|
|
116 |
progressPanel.addButtonPressedListener(this);
|
|
110 | 117 |
progressPanel.addWindowListener( new WindowAdapter() { |
111 | 118 |
public void windowClosing(WindowEvent e) |
112 | 119 |
{ |
113 |
blinker = null; |
|
120 |
ended = true; |
|
121 |
callActionCommandListeners(IncrementableEvent.CANCELED); |
|
114 | 122 |
} |
115 | 123 |
}); |
116 | 124 |
} |
117 | 125 |
return progressPanel; |
118 | 126 |
} |
119 | 127 |
|
120 |
public void actionPerformed(ActionEvent e) { |
|
121 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_CANCEL + "") == 0) { |
|
122 |
blinker = null; |
|
123 |
} |
|
124 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_PAUSE + "") == 0) { |
|
125 |
callActionCommandListeners(IncrementableEvent.SUSPENDED); |
|
126 |
threadSuspended = true; |
|
127 |
} |
|
128 |
if (e.getActionCommand().compareTo(ButtonsPanel.BUTTON_RESTART + "") == 0) { |
|
129 |
callActionCommandListeners(IncrementableEvent.RESUMED); |
|
130 |
threadSuspended = false; |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 | 128 |
private void callActionCommandListeners(int actions) { |
135 | 129 |
if (!bDoCallListeners) |
136 | 130 |
return; |
... | ... | |
138 | 132 |
while (acIterator.hasNext()) { |
139 | 133 |
IncrementableListener listener = (IncrementableListener) acIterator.next(); |
140 | 134 |
switch (actions) { |
141 |
case IncrementableEvent.CLOSED: |
|
142 |
listener.actionClosed(new IncrementableEvent(this)); |
|
143 |
break; |
|
144 | 135 |
case IncrementableEvent.RESUMED: |
145 | 136 |
listener.actionResumed(new IncrementableEvent(this)); |
146 | 137 |
break; |
... | ... | |
163 | 154 |
public void removeIncrementableListener(IncrementableListener listener) { |
164 | 155 |
actionCommandListeners.remove(listener); |
165 | 156 |
} |
157 |
|
|
158 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
|
159 |
switch (e.getButton()) { |
|
160 |
case ButtonsPanel.BUTTON_CANCEL: |
|
161 |
ended = true; |
|
162 |
callActionCommandListeners(IncrementableEvent.CANCELED); |
|
163 |
break; |
|
164 |
case ButtonsPanel.BUTTON_PAUSE: |
|
165 |
threadSuspended = true; |
|
166 |
callActionCommandListeners(IncrementableEvent.SUSPENDED); |
|
167 |
break; |
|
168 |
case ButtonsPanel.BUTTON_RESTART: |
|
169 |
threadSuspended = false; |
|
170 |
callActionCommandListeners(IncrementableEvent.RESUMED); |
Also available in: Unified diff