root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / vectorizacion / MainListener.java @ 27442
History | View | Annotate | Download (8.81 KB)
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.vectorizacion; |
20 |
|
21 |
import java.awt.event.ActionEvent; |
22 |
import java.awt.event.ActionListener; |
23 |
|
24 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
25 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
26 |
import org.gvsig.gui.beans.slidertext.listeners.SliderEvent; |
27 |
import org.gvsig.raster.IProcessActions; |
28 |
import org.gvsig.raster.beans.previewbase.IPreviewRenderProcess; |
29 |
import org.gvsig.raster.util.RasterNotLoadException; |
30 |
import org.gvsig.raster.util.RasterToolsUtil; |
31 |
import org.gvsig.rastertools.vectorizacion.clip.ClipListener; |
32 |
import org.gvsig.rastertools.vectorizacion.clip.ClipProcess; |
33 |
import org.gvsig.rastertools.vectorizacion.filter.GrayConversionListener; |
34 |
import org.gvsig.rastertools.vectorizacion.filter.GrayConversionProcess; |
35 |
import org.gvsig.rastertools.vectorizacion.filter.ui.GrayConversionPanel; |
36 |
import org.gvsig.rastertools.vectorizacion.stretch.StretchListener; |
37 |
import org.gvsig.rastertools.vectorizacion.stretch.StretchProcess; |
38 |
import org.gvsig.rastertools.vectorizacion.stretch.ui.StretchPanel; |
39 |
import org.gvsig.rastertools.vectorizacion.vector.VectorListener; |
40 |
import org.gvsig.rastertools.vectorizacion.vector.VectorProcess; |
41 |
|
42 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
43 |
|
44 |
/**
|
45 |
* Clase para la gesti?n de eventos de los componentes gr?ficos del panel de preproceso
|
46 |
* de vectorizaci?n.
|
47 |
*
|
48 |
* 12/06/2008
|
49 |
* @author Nacho Brodin nachobrodin@gmail.com
|
50 |
*/
|
51 |
public class MainListener implements ActionListener, IProcessActions { |
52 |
private MainPanel panel = null; |
53 |
private FLyrRasterSE lyr = null; |
54 |
|
55 |
private GrayConversionListener grayConvList = null; |
56 |
private ClipListener clipList = null; |
57 |
private VectorListener vectList = null; |
58 |
private StretchListener stretchList = null; |
59 |
|
60 |
private int tabIndexSelected = 0; |
61 |
private IPreviewRenderProcess prevRender = null; |
62 |
|
63 |
private FLyrRasterSE clip = null; |
64 |
private FLyrRasterSE gray = null; |
65 |
private MainDialog dialog = null; |
66 |
|
67 |
/**
|
68 |
* Constructor. Asigna los listeners a los componentes
|
69 |
* @param prepPanel
|
70 |
*/
|
71 |
public MainListener(FLyrRasterSE lyr, MainPanel prepPanel, GrayConversionListener grayConvList,
|
72 |
ClipListener clipList, VectorListener vectList, StretchListener stretchList) { |
73 |
this.lyr = lyr;
|
74 |
setDataView(prepPanel); |
75 |
this.grayConvList = grayConvList;
|
76 |
this.clipList = clipList;
|
77 |
this.vectList = vectList;
|
78 |
this.stretchList = stretchList;
|
79 |
this.grayConvList.setProcessActions(this); |
80 |
this.clipList.setProcessActions(this); |
81 |
this.vectList.setProcessActions(this); |
82 |
this.stretchList.setProcessActions(this); |
83 |
tabIndexSelected = 0;
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* Asigna la vista de datos. En este caso es el panel de preprocesado de la vectorizaci?n
|
88 |
* @param prepPanel
|
89 |
*/
|
90 |
private void setDataView(MainPanel prepPanel) { |
91 |
this.panel = prepPanel;
|
92 |
panel.getPreviewBasePanel().getButtonsPanel().getButton(13).addActionListener(this); |
93 |
panel.getPreviewBasePanel().getButtonsPanel().getButton(14).addActionListener(this); |
94 |
panel.getPreviewBasePanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(this);
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* Asigna el render de la preview
|
99 |
* @param prevRender
|
100 |
*/
|
101 |
public void setPreviewRender(IPreviewRenderProcess prevRender) { |
102 |
this.prevRender = prevRender;
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* Asigna el dialogo
|
107 |
* @param dialog
|
108 |
*/
|
109 |
public void setDialog(MainDialog dialog) { |
110 |
this.dialog = dialog;
|
111 |
} |
112 |
|
113 |
/*
|
114 |
* (non-Javadoc)
|
115 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
116 |
*/
|
117 |
public void actionPerformed(ActionEvent e) { |
118 |
if(!panel.isEnableValueChangedEvent())
|
119 |
return;
|
120 |
|
121 |
//Bot?n de pantalla siguiente
|
122 |
if(e.getSource() == panel.getPreviewBasePanel().getButtonsPanel().getButton(13)) { |
123 |
if(tabIndexSelected < (panel.getPanelCount() - 1)) { |
124 |
panel.getPreviewBasePanel().setUniquePanel(panel.getPanel(++tabIndexSelected)); |
125 |
panel.getPreviewBasePanel().getButtonsPanel().getButton(14).setEnabled(true); |
126 |
if(tabIndexSelected == (panel.getPanelCount() - 1)) |
127 |
panel.getPreviewBasePanel().getButtonsPanel().getButton(13).setText("finalizar"); |
128 |
} else { //Finalizar |
129 |
vectList.setProcessSource(gray); |
130 |
vectList.apply(); |
131 |
if(dialog != null) { |
132 |
dialog.close(); |
133 |
return;
|
134 |
} |
135 |
} |
136 |
} |
137 |
|
138 |
//Bot?n de pantalla anterior
|
139 |
if(e.getSource() == panel.getPreviewBasePanel().getButtonsPanel().getButton(14)) { |
140 |
if(tabIndexSelected > 0) { |
141 |
panel.getPreviewBasePanel().setUniquePanel(panel.getPanel(--tabIndexSelected)); |
142 |
panel.getPreviewBasePanel().getButtonsPanel().getButton(13).setText("siguiente"); |
143 |
if(tabIndexSelected == 0) |
144 |
panel.getPreviewBasePanel().getButtonsPanel().getButton(14).setEnabled(false); |
145 |
} |
146 |
} |
147 |
|
148 |
//Cancelar
|
149 |
if(e.getSource() == panel.getPreviewBasePanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL)) {
|
150 |
if(dialog != null) |
151 |
dialog.close(); |
152 |
} |
153 |
|
154 |
clipProcess(); |
155 |
grayScaleProcess(); |
156 |
stretchProcess(); |
157 |
|
158 |
//Mostrar u ocultar preview
|
159 |
if(tabIndexSelected == 0) { |
160 |
prevRender.setShowPreview(false);
|
161 |
panel.getPreviewBasePanel().refreshPreview(); |
162 |
} else
|
163 |
prevRender.setShowPreview(true);
|
164 |
|
165 |
//panel.getPreviewBasePanel().refreshPreview();
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* Lanza el proceso de recorte
|
170 |
*/
|
171 |
private void clipProcess() { |
172 |
//Generaci?n de recorte
|
173 |
if(tabIndexSelected == 1) { |
174 |
if(clip != null) |
175 |
if(!RasterToolsUtil.messageBoxYesOrNot("clip_raster_again", this)) { |
176 |
prevRender.setShowPreview(true);
|
177 |
panel.getPreviewBasePanel().refreshPreview(); |
178 |
return;
|
179 |
} |
180 |
|
181 |
clipList.setProcessSource(lyr); |
182 |
clipList.apply(); |
183 |
} |
184 |
} |
185 |
|
186 |
/**
|
187 |
* Lanza el proceso de conversi?n a escala de grises
|
188 |
*/
|
189 |
private void grayScaleProcess() { |
190 |
//Generaci?n de raster preprocesado con escala de grises y posterizaci?n
|
191 |
if(tabIndexSelected == 2 && panel.getPanel(1) instanceof GrayConversionPanel) { |
192 |
if(gray != null) |
193 |
if(!RasterToolsUtil.messageBoxYesOrNot("filter_raster_again", this)) { |
194 |
prevRender.setShowPreview(true);
|
195 |
panel.getPreviewBasePanel().refreshPreview(); |
196 |
return;
|
197 |
} |
198 |
grayConvList.setProcessSource(clip); |
199 |
grayConvList.apply(); |
200 |
} |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Lanza el proceso de generaci?n de tramos
|
205 |
*/
|
206 |
private void stretchProcess() { |
207 |
//Generaci?n de tramos
|
208 |
if(tabIndexSelected == 2 && panel.getPanel(1) instanceof StretchPanel) { |
209 |
if(gray != null) |
210 |
if(!RasterToolsUtil.messageBoxYesOrNot("filter_raster_again", this)) { |
211 |
prevRender.setShowPreview(true);
|
212 |
panel.getPreviewBasePanel().refreshPreview(); |
213 |
return;
|
214 |
} |
215 |
stretchList.setProcessSource(clip); |
216 |
stretchList.apply(); |
217 |
} |
218 |
} |
219 |
|
220 |
/*
|
221 |
* (non-Javadoc)
|
222 |
* @see org.gvsig.gui.beans.slidertext.listeners.SliderListener#actionValueDragged(org.gvsig.gui.beans.slidertext.listeners.SliderEvent)
|
223 |
*/
|
224 |
public void actionValueDragged(SliderEvent e) { |
225 |
} |
226 |
|
227 |
/*
|
228 |
* (non-Javadoc)
|
229 |
* @see org.gvsig.raster.IProcessActions#interrupted()
|
230 |
*/
|
231 |
public void interrupted() { |
232 |
} |
233 |
|
234 |
/*
|
235 |
* (non-Javadoc)
|
236 |
* @see org.gvsig.raster.IProcessActions#end(java.lang.Object)
|
237 |
*/
|
238 |
public void end(Object param) { |
239 |
if(param instanceof Object[] && ((Object[])param).length == 2) { |
240 |
if(((Object[])param)[0] instanceof ClipProcess) { |
241 |
clip = (FLyrRasterSE)((Object[])param)[1]; |
242 |
if(grayConvList != null) |
243 |
grayConvList.refreshPreview(); |
244 |
if(stretchList != null) |
245 |
stretchList.refreshPreview(); |
246 |
} |
247 |
if(((Object[])param)[0] instanceof GrayConversionProcess || |
248 |
((Object[])param)[0] instanceof StretchProcess) { |
249 |
gray = (FLyrRasterSE)((Object[])param)[1]; |
250 |
} |
251 |
if(((Object[])param)[0] instanceof VectorProcess) { |
252 |
if (RasterToolsUtil.messageBoxYesOrNot("cargar_toc", this)) { |
253 |
try {
|
254 |
RasterToolsUtil.loadLayer(null, (FLayer)((Object[])param)[1]); |
255 |
} catch (RasterNotLoadException e) {
|
256 |
RasterToolsUtil.messageBoxError("error_loading_layer", null, e); |
257 |
} |
258 |
} |
259 |
} |
260 |
} |
261 |
} |
262 |
|
263 |
} |