svn-gvsig-desktop / trunk / extensions / extRasterTools / src / com / iver / cit / gvsig / rasterTools / saveRaster / ui / SaveRasterDefaultPanel.java @ 4499
History | View | Annotate | Download (7.98 KB)
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 com.iver.cit.gvsig.rasterTools.saveRaster.ui; |
25 |
|
26 |
import java.awt.Container; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.geom.Rectangle2D; |
30 |
|
31 |
import javax.swing.JPanel; |
32 |
|
33 |
import org.cresques.cts.IProjection; |
34 |
import org.cresques.io.GeoRasterWriter; |
35 |
import org.cresques.ui.DefaultDialogPanel; |
36 |
|
37 |
import com.iver.andami.PluginServices; |
38 |
import com.iver.andami.ui.mdiManager.View; |
39 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
40 |
import com.iver.cit.gvsig.fmap.MapControl; |
41 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
42 |
import com.iver.cit.gvsig.rasterTools.saveRaster.ui.properties.ProgressSaveRasterDialog; |
43 |
import com.iver.cit.gvsig.rasterTools.saveRaster.ui.properties.SaveRasterPropsDialog; |
44 |
import com.iver.cit.gvsig.rasterTools.saveRaster.ui.toolListeners.DataInputListener; |
45 |
import com.iver.cit.gvsig.rasterTools.saveRaster.util.DriverProperties; |
46 |
|
47 |
|
48 |
/**
|
49 |
* Panel que contiene los botones de Aceptar, Cancelar y Aplicar heredando de
|
50 |
* DefaultDialogPanel. Dentro de este estar? el panel con los controles de
|
51 |
* salvar a raster.
|
52 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
53 |
*/
|
54 |
public class SaveRasterDefaultPanel extends DefaultDialogPanel implements View { |
55 |
final private static long serialVersionUID = -3370601314380922368L; |
56 |
private DataInputListener listener = null; |
57 |
private GeoRasterWriter writer=null; |
58 |
private IProjection currentProjection = null; |
59 |
private SaveRasterPropsDialog frameSaveRasterProps = null; |
60 |
private int compresion = 1; |
61 |
private int sizeBlock = 64; |
62 |
public DriverProperties driverProps = null; |
63 |
private FLayers layers = null; |
64 |
private MapControl mapCtrl = null; |
65 |
|
66 |
/**
|
67 |
* Constructor de la ventana de dialogo para gvSIG.
|
68 |
*/
|
69 |
public SaveRasterDefaultPanel(FLayers layers, MapControl mapCtrl) {
|
70 |
super(false); |
71 |
driverProps = new DriverProperties();
|
72 |
this.layers = layers;
|
73 |
this.mapCtrl = mapCtrl;
|
74 |
init(); |
75 |
} |
76 |
|
77 |
/**
|
78 |
* Constructor generico para poder visualizar la ventana desde
|
79 |
* una funci?n main.
|
80 |
*/
|
81 |
public SaveRasterDefaultPanel() {
|
82 |
super(false); |
83 |
init(); |
84 |
} |
85 |
|
86 |
/**
|
87 |
* Inicializaci?n del panel.
|
88 |
* @return void
|
89 |
*/
|
90 |
public void init() { |
91 |
super.initialize();
|
92 |
this.setSize(400, 370); |
93 |
this.getListener();
|
94 |
|
95 |
//Ocultamos el bot?n de aplicar
|
96 |
this.setLocation(new java.awt.Point(0,0)); |
97 |
this.getApplyButton().setVisible(false); |
98 |
this.getAcceptButton().setEnabled(false); |
99 |
|
100 |
setName("saveRaster");
|
101 |
|
102 |
//this.getAcceptButton().setEnabled(false);
|
103 |
this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
104 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
105 |
acceptButtonActionPerformed(evt); |
106 |
closeJDialog(); |
107 |
} |
108 |
}); |
109 |
this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
110 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
111 |
closeJDialog(); |
112 |
} |
113 |
}); |
114 |
this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
115 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
116 |
acceptButtonActionPerformed(evt); |
117 |
} |
118 |
}); |
119 |
|
120 |
//Captura de eventos para el bot?n de propiedades
|
121 |
|
122 |
((SaveRasterControlsPanel)this.getContentPanel()).getBProperties().addActionListener(new java.awt.event.ActionListener() { |
123 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
124 |
propsButtonActionPerformed(evt); |
125 |
} |
126 |
}); |
127 |
|
128 |
} |
129 |
|
130 |
/**
|
131 |
* Cierra esta ventana a trav?s de andami
|
132 |
*/
|
133 |
public void closeJDialog() { |
134 |
this.hide();
|
135 |
for(int i=0;i<layers.getLayersCount();i++){ |
136 |
layers.getLayer(i).getFMap().invalidate(); |
137 |
} |
138 |
PluginServices.getMDIManager().closeView(SaveRasterDefaultPanel.this); |
139 |
} |
140 |
|
141 |
/**
|
142 |
* Funci?n a ejecutar cuando se pulsa el bot?n de propiedades.
|
143 |
* @param e ActionEvent
|
144 |
*/
|
145 |
private void propsButtonActionPerformed(ActionEvent e){ |
146 |
String name = this.getListener().getFileName(); |
147 |
|
148 |
//Si no se ha seleccionado ning?n fichero salimos
|
149 |
if(name == null || name.equals("")) |
150 |
return;
|
151 |
|
152 |
GeoRasterWriter writer = GeoRasterWriter.getWriter(name); |
153 |
String ext = name.toLowerCase().substring(name.lastIndexOf(".") + 1); |
154 |
if(driverProps.getProperties(ext)!=null) |
155 |
writer.setProps(driverProps.getProperties(ext)); |
156 |
|
157 |
frameSaveRasterProps = new SaveRasterPropsDialog(writer);
|
158 |
frameSaveRasterProps.setParentDialog(this);
|
159 |
frameSaveRasterProps.show(); |
160 |
} |
161 |
|
162 |
/**
|
163 |
*
|
164 |
* @param e
|
165 |
*/
|
166 |
private void acceptButtonActionPerformed(ActionEvent e) { |
167 |
SaveRasterControlsPanel dialog = (SaveRasterControlsPanel)this.getContentPanel();
|
168 |
|
169 |
String fName = this.getListener().getFileName(); |
170 |
Dimension dimension = new Dimension( this.getListener().getWidthInPixels(), |
171 |
this.getListener().getHeightInPixels() );
|
172 |
|
173 |
double lrX = Double.parseDouble(dialog.getTInfDerX().getText()); |
174 |
double lrY = Double.parseDouble(dialog.getTInfDerY().getText()); |
175 |
double ulX = Double.parseDouble(dialog.getTSupIzqX().getText()); |
176 |
double ulY = Double.parseDouble(dialog.getTSupIzqY().getText()); |
177 |
double width = 0; |
178 |
if(ulX>lrX)width = (double)(ulX-lrX); |
179 |
else width = (double)(lrX-ulX); |
180 |
double height = 0; |
181 |
if(ulY>lrY)height = (double)(ulY-lrY); |
182 |
else height = (double)(lrY-ulY); |
183 |
Rectangle2D ext = null; |
184 |
|
185 |
if(ulY<lrY)
|
186 |
ext = new Rectangle2D.Double(ulX, ulY, width, height); |
187 |
else
|
188 |
ext = new Rectangle2D.Double(ulX, lrY, width, height); |
189 |
|
190 |
ProgressSaveRasterDialog progressBar = |
191 |
new ProgressSaveRasterDialog(mapCtrl, this.layers, this.currentProjection, |
192 |
dimension, ext); |
193 |
|
194 |
progressBar.setProps(driverProps); |
195 |
progressBar.setWriter(writer); |
196 |
progressBar.setFName(fName); |
197 |
progressBar.setBlockSize(sizeBlock); |
198 |
progressBar.setCompresion(compresion); |
199 |
progressBar.showWindow(); |
200 |
|
201 |
for(int i=0;i<layers.getLayersCount();i++){ |
202 |
layers.getLayer(i).getFMap().invalidate(); |
203 |
} |
204 |
} |
205 |
|
206 |
/**
|
207 |
* Obtiene el panel con los controles de Salvar a Raster.
|
208 |
* @return
|
209 |
*/
|
210 |
public JPanel getContentPanel() { |
211 |
if (contentPane == null) { |
212 |
contentPane = new SaveRasterControlsPanel();
|
213 |
contentPane.setPreferredSize(new java.awt.Dimension(359, 297)); |
214 |
} |
215 |
return contentPane;
|
216 |
} |
217 |
|
218 |
public DataInputListener getListener() {
|
219 |
if(listener == null){ |
220 |
listener = new DataInputListener((SaveRasterControlsPanel)this.getContentPanel()); |
221 |
listener.setDialogPanel(this);
|
222 |
} |
223 |
return listener;
|
224 |
} |
225 |
|
226 |
/**
|
227 |
* This method initializes jContentPane
|
228 |
*
|
229 |
* @return javax.swing.JPanel
|
230 |
*/
|
231 |
public Container getContentPane() { |
232 |
return this; |
233 |
} |
234 |
|
235 |
/**
|
236 |
*
|
237 |
* @param prj
|
238 |
*/
|
239 |
|
240 |
public void setProjection(IProjection prj) { |
241 |
this.currentProjection = prj;
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* Asigna la lista de capas
|
246 |
* @param layers
|
247 |
*/
|
248 |
public void setLayerList(FLayers layers){ |
249 |
this.layers = layers;
|
250 |
} |
251 |
|
252 |
/**
|
253 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
254 |
*/
|
255 |
public ViewInfo getViewInfo() {
|
256 |
ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
257 |
m_viewinfo.setTitle(PluginServices.getText(this, "salvar_raster")); |
258 |
return m_viewinfo;
|
259 |
} |
260 |
} |