41 |
41 |
import org.gvsig.gui.beans.datainput.DataInputContainerListener;
|
42 |
42 |
import org.gvsig.gui.beans.swing.JFileChooser;
|
43 |
43 |
import org.gvsig.raster.tools.algorithm.swing.saveraster.SaveRasterPanel;
|
|
44 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
|
44 |
45 |
import org.gvsig.raster.tools.app.basic.tool.saveviewtoraster.ui.SaveViewToRasterDialog;
|
45 |
46 |
import org.gvsig.raster.util.ExtendedFileFilter;
|
46 |
47 |
|
47 |
48 |
/**
|
48 |
|
* Panel encargado de manejar los eventos del los controles de Salvar a Raster
|
|
49 |
* Listener to synchronize the components in the main panel
|
49 |
50 |
*
|
50 |
51 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
51 |
52 |
*/
|
... | ... | |
90 |
91 |
public void setDialogPanel(SaveViewToRasterDialog dialog) {
|
91 |
92 |
this.dialog = dialog;
|
92 |
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* Checks a integer value
|
|
97 |
* @param value
|
|
98 |
* @return
|
|
99 |
*/
|
|
100 |
private boolean checkInteger(String value) {
|
|
101 |
if(value == null)
|
|
102 |
return false;
|
|
103 |
if(value.length() > 8) {
|
|
104 |
RasterToolsUtil.messageBoxError("output_too_big", controlPanel);
|
|
105 |
return false;
|
|
106 |
}
|
|
107 |
int v = 0;
|
|
108 |
try {
|
|
109 |
v = Integer.parseInt(value);
|
|
110 |
} catch (NumberFormatException e) {
|
|
111 |
return false;
|
|
112 |
}
|
|
113 |
if(v <= 0)
|
|
114 |
return false;
|
|
115 |
return true;
|
|
116 |
}
|
|
117 |
|
|
118 |
/**
|
|
119 |
* Checks a double value
|
|
120 |
* @param value
|
|
121 |
* @return
|
|
122 |
*/
|
|
123 |
private boolean checkDouble(String value) {
|
|
124 |
if(value == null)
|
|
125 |
return false;
|
|
126 |
double v = 0;
|
|
127 |
try {
|
|
128 |
v = Double.parseDouble(value);
|
|
129 |
} catch (NumberFormatException e) {
|
|
130 |
return false;
|
|
131 |
}
|
|
132 |
if(v <= 0)
|
|
133 |
return false;
|
|
134 |
return true;
|
|
135 |
}
|
93 |
136 |
|
94 |
137 |
/**
|
95 |
138 |
* Calculo del tama?o en pixels de la imagen a partir de las coordenadas del
|
96 |
139 |
* mundo real, la escala y los puntos por pulgada
|
97 |
140 |
*/
|
98 |
|
private void recalcParams(Object obj) {
|
|
141 |
private void recalcParams(Object obj, Object oldValue) {
|
99 |
142 |
controlPanel.validateFields();
|
100 |
143 |
double widthMts = 0;
|
101 |
144 |
double heightMts = 0;
|
... | ... | |
111 |
154 |
return;
|
112 |
155 |
}
|
113 |
156 |
|
114 |
|
double rel = (widthMts / heightMts);
|
115 |
|
//math.clipDecimals(mtsPerPixel, 5);
|
116 |
|
|
117 |
157 |
//M?todo por tama?o seleccionado
|
118 |
158 |
if(controlPanel.isPixelMethodSelected()) {
|
119 |
|
if( controlPanel.getComponentID(obj) == SaveRasterPanel.WIDTH_COMPONENT &&
|
120 |
|
!controlPanel.getWidthPxValue().equals("")) {
|
121 |
|
int w = Integer.parseInt(controlPanel.getWidthPxValue());
|
122 |
|
if(w == 0)
|
123 |
|
return;
|
124 |
|
int h = (int)Math.floor(w / rel);
|
125 |
|
controlPanel.setHeightPxValue(String.valueOf(h));
|
126 |
|
controlPanel.setCellSize(String.valueOf(widthMts / w));
|
|
159 |
modifyPixelMethod(obj, widthMts, heightMts, oldValue);
|
|
160 |
} else {
|
|
161 |
modifyPrintMethod(obj, widthMts, heightMts, oldValue);
|
|
162 |
}
|
|
163 |
calculateFileSize();
|
|
164 |
}
|
|
165 |
|
|
166 |
/**
|
|
167 |
* When the event comes from a component in the pixel size method
|
|
168 |
* @param obj
|
|
169 |
* @param widthMts
|
|
170 |
* @param heightMts
|
|
171 |
* @param oldValue
|
|
172 |
*/
|
|
173 |
private void modifyPixelMethod(Object obj, double widthMts, double heightMts, Object oldValue) {
|
|
174 |
double rel = (widthMts / heightMts);
|
|
175 |
if( controlPanel.getComponentID(obj) == SaveRasterPanel.WIDTH_COMPONENT &&
|
|
176 |
!controlPanel.getWidthPxValue().equals("")) {
|
|
177 |
if(!checkInteger(controlPanel.getWidthPxValue())) {
|
|
178 |
controlPanel.setWidthPxValue(String.valueOf(oldValue));
|
127 |
179 |
return;
|
128 |
180 |
}
|
129 |
|
if( controlPanel.getComponentID(obj) == SaveRasterPanel.HEIGHT_COMPONENT &&
|
130 |
|
!controlPanel.getHeightPxValue().equals("")) {
|
131 |
|
int h = Integer.parseInt(controlPanel.getHeightPxValue());
|
132 |
|
if(h == 0)
|
133 |
|
return;
|
134 |
|
int w = (int)Math.ceil(h * rel);
|
135 |
|
controlPanel.setWidthPxValue(String.valueOf(w));
|
136 |
|
controlPanel.setCellSize(String.valueOf(widthMts / w));
|
|
181 |
int w = Integer.parseInt(controlPanel.getWidthPxValue());
|
|
182 |
int h = (int)Math.floor(w / rel);
|
|
183 |
controlPanel.setHeightPxValue(String.valueOf(h));
|
|
184 |
controlPanel.setCellSize(String.valueOf(widthMts / w));
|
|
185 |
} else if( controlPanel.getComponentID(obj) == SaveRasterPanel.HEIGHT_COMPONENT &&
|
|
186 |
!controlPanel.getHeightPxValue().equals("")) {
|
|
187 |
if(!checkInteger(controlPanel.getHeightPxValue())) {
|
|
188 |
controlPanel.setHeightPxValue(String.valueOf(oldValue));
|
137 |
189 |
return;
|
138 |
190 |
}
|
139 |
|
if( controlPanel.getComponentID(obj) == SaveRasterPanel.CELLSIZE_COMPONENT &&
|
140 |
|
!controlPanel.getScaleValue().equals("")) {
|
141 |
|
double cellsize = Double.parseDouble(controlPanel.getCellSize());
|
142 |
|
if(cellsize == 0)
|
143 |
|
return;
|
144 |
|
int w = (int)Math.round(widthMts / cellsize);
|
145 |
|
int h = (int)Math.round(heightMts / cellsize);
|
146 |
|
controlPanel.setWidthPxValue(String.valueOf(w));
|
147 |
|
controlPanel.setHeightPxValue(String.valueOf(h));
|
148 |
|
controlPanel.setCellSize(String.valueOf(widthMts / w));
|
|
191 |
int h = Integer.parseInt(controlPanel.getHeightPxValue());
|
|
192 |
int w = (int)Math.ceil(h * rel);
|
|
193 |
controlPanel.setWidthPxValue(String.valueOf(w));
|
|
194 |
controlPanel.setCellSize(String.valueOf(widthMts / w));
|
|
195 |
} else if( controlPanel.getComponentID(obj) == SaveRasterPanel.CELLSIZE_COMPONENT &&
|
|
196 |
!controlPanel.getScaleValue().equals("")) {
|
|
197 |
if(!checkDouble(controlPanel.getCellSize())) {
|
|
198 |
controlPanel.setCellSize(String.valueOf(oldValue));
|
149 |
199 |
return;
|
150 |
200 |
}
|
151 |
|
|
152 |
|
} else {
|
153 |
|
if( controlPanel.getComponentID(obj) == SaveRasterPanel.WCMS_COMPONENT &&
|
154 |
|
!controlPanel.getValueXCms().equals("")) {
|
155 |
|
int cmsx = Integer.parseInt(controlPanel.getValueXCms());
|
156 |
|
if(cmsx == 0)
|
157 |
|
return;
|
158 |
|
int cmsy = (int)Math.round(cmsx / rel);
|
159 |
|
double scale = widthMts / (cmsx / 100);
|
160 |
|
controlPanel.setValueYCms(String.valueOf(cmsy));
|
161 |
|
controlPanel.setScaleValue(String.valueOf(scale));
|
|
201 |
double cellsize = Double.parseDouble(controlPanel.getCellSize());
|
|
202 |
int w = (int)Math.round(widthMts / cellsize);
|
|
203 |
int h = (int)Math.round(heightMts / cellsize);
|
|
204 |
if((widthMts / cellsize) >= Integer.MAX_VALUE || (heightMts / cellsize) >= Integer.MAX_VALUE) {
|
|
205 |
RasterToolsUtil.messageBoxError("output_too_big", controlPanel);
|
|
206 |
controlPanel.setCellSize(String.valueOf(oldValue));
|
162 |
207 |
return;
|
163 |
208 |
}
|
164 |
|
if( controlPanel.getComponentID(obj) == SaveRasterPanel.HCMS_COMPONENT &&
|
165 |
|
!controlPanel.getValueYCms().equals("")) {
|
166 |
|
int cmsy = Integer.parseInt(controlPanel.getValueYCms());
|
167 |
|
if(cmsy == 0)
|
168 |
|
return;
|
169 |
|
int cmsx = (int)Math.round(cmsy / rel);
|
170 |
|
double scale = heightMts / (cmsy / 100);
|
171 |
|
controlPanel.setValueXCms(String.valueOf(cmsx));
|
172 |
|
controlPanel.setScaleValue(String.valueOf(scale));
|
|
209 |
controlPanel.setWidthPxValue(String.valueOf(w));
|
|
210 |
controlPanel.setHeightPxValue(String.valueOf(h));
|
|
211 |
controlPanel.setCellSize(String.valueOf(widthMts / w));
|
|
212 |
} else if(controlPanel.getComponentID(obj) == SaveRasterPanel.ULX_COMPONENT ||
|
|
213 |
controlPanel.getComponentID(obj) == SaveRasterPanel.ULY_COMPONENT ||
|
|
214 |
controlPanel.getComponentID(obj) == SaveRasterPanel.LRX_COMPONENT ||
|
|
215 |
controlPanel.getComponentID(obj) == SaveRasterPanel.LRY_COMPONENT) {
|
|
216 |
int w = Integer.parseInt(controlPanel.getWidthPxValue());
|
|
217 |
if(w == 0)
|
173 |
218 |
return;
|
|
219 |
controlPanel.setCellSize(String.valueOf(widthMts / w));
|
|
220 |
}
|
|
221 |
}
|
|
222 |
|
|
223 |
/**
|
|
224 |
* When the event comes from a component in the print method
|
|
225 |
* @param obj
|
|
226 |
* @param widthMts
|
|
227 |
* @param heightMts
|
|
228 |
* @param oldValue
|
|
229 |
*/
|
|
230 |
private void modifyPrintMethod(Object obj, double widthMts, double heightMts, Object oldValue) {
|
|
231 |
double rel = (widthMts / heightMts);
|
|
232 |
if( controlPanel.getComponentID(obj) == SaveRasterPanel.WCMS_COMPONENT &&
|
|
233 |
!controlPanel.getValueXCms().equals("")) {
|
|
234 |
if(!checkInteger(controlPanel.getValueXCms())) {
|
|
235 |
controlPanel.setValueXCms(String.valueOf(oldValue));
|
|
236 |
return;
|
174 |
237 |
}
|
175 |
|
if( controlPanel.getComponentID(obj) == SaveRasterPanel.SCALE_COMPONENT &&
|
176 |
|
!controlPanel.getScaleValue().equals("")) {
|
177 |
|
double scale = Double.parseDouble(controlPanel.getScaleValue());
|
178 |
|
if(scale == 0)
|
179 |
|
return;
|
180 |
|
double cmsx = (widthMts / scale) * 100;
|
181 |
|
double cmsy = (heightMts / scale) * 100;
|
182 |
|
controlPanel.setValueXCms(String.valueOf(cmsx));
|
183 |
|
controlPanel.setValueYCms(String.valueOf(cmsy));
|
184 |
|
controlPanel.setScaleValue(String.valueOf(heightMts / (cmsy / 100)));
|
185 |
|
calculateSizePxResult();
|
|
238 |
int cmsx = Integer.parseInt(controlPanel.getValueXCms());
|
|
239 |
int cmsy = (int)Math.round(cmsx / rel);
|
|
240 |
int scale = (int)Math.round(widthMts / (cmsx / 100D));
|
|
241 |
controlPanel.setValueYCms(String.valueOf(cmsy));
|
|
242 |
controlPanel.setScaleValue(String.valueOf(scale));
|
|
243 |
} else if( controlPanel.getComponentID(obj) == SaveRasterPanel.HCMS_COMPONENT &&
|
|
244 |
!controlPanel.getValueYCms().equals("")) {
|
|
245 |
if(!checkInteger(controlPanel.getValueYCms())) {
|
|
246 |
controlPanel.setValueYCms(String.valueOf(oldValue));
|
186 |
247 |
return;
|
187 |
248 |
}
|
188 |
|
if( controlPanel.getComponentID(obj) == SaveRasterPanel.RESOLUTION_COMPONENT &&
|
189 |
|
!controlPanel.getResolutionValue().equals("") &&
|
190 |
|
!controlPanel.getScaleValue().equals("") &&
|
191 |
|
!controlPanel.getValueXCms().equals("") &&
|
192 |
|
!controlPanel.getValueYCms().equals("")) {
|
193 |
|
calculateSizePxResult();
|
|
249 |
int cmsy = Integer.parseInt(controlPanel.getValueYCms());
|
|
250 |
int cmsx = (int)Math.round(cmsy * rel);
|
|
251 |
int scale = (int)Math.round(widthMts / (cmsx / 100D));
|
|
252 |
controlPanel.setValueXCms(String.valueOf(cmsx));
|
|
253 |
controlPanel.setScaleValue(String.valueOf(scale));
|
|
254 |
} else if( controlPanel.getComponentID(obj) == SaveRasterPanel.SCALE_COMPONENT &&
|
|
255 |
!controlPanel.getScaleValue().equals("")) {
|
|
256 |
if(!checkInteger(controlPanel.getScaleValue())) {
|
|
257 |
controlPanel.setScaleValue(String.valueOf(oldValue));
|
194 |
258 |
return;
|
195 |
259 |
}
|
|
260 |
int scale = Integer.parseInt(controlPanel.getScaleValue());
|
|
261 |
int cmsx = (int)Math.round((widthMts / scale) * 100D);
|
|
262 |
int cmsy = (int)Math.round((heightMts / scale) * 100D);
|
|
263 |
controlPanel.setValueXCms(String.valueOf(cmsx));
|
|
264 |
controlPanel.setValueYCms(String.valueOf(cmsy));
|
|
265 |
scale = (int)Math.round(widthMts / (cmsx / 100D));
|
|
266 |
controlPanel.setScaleValue(String.valueOf(scale));
|
|
267 |
} else if(controlPanel.getComponentID(obj) == SaveRasterPanel.ULX_COMPONENT ||
|
|
268 |
controlPanel.getComponentID(obj) == SaveRasterPanel.ULY_COMPONENT ||
|
|
269 |
controlPanel.getComponentID(obj) == SaveRasterPanel.LRX_COMPONENT ||
|
|
270 |
controlPanel.getComponentID(obj) == SaveRasterPanel.LRY_COMPONENT) {
|
|
271 |
int cmsx = Integer.parseInt(controlPanel.getValueXCms());
|
|
272 |
if(cmsx == 0)
|
|
273 |
return;
|
|
274 |
int scale = (int)Math.round(widthMts / (cmsx / 100D));
|
|
275 |
controlPanel.setScaleValue(String.valueOf(scale));
|
196 |
276 |
}
|
197 |
|
calculateFileSize();
|
|
277 |
calculateSizePxResult();
|
198 |
278 |
}
|
199 |
279 |
|
|
280 |
/**
|
|
281 |
* Calculates the size in pixels for the print method
|
|
282 |
*/
|
200 |
283 |
private void calculateSizePxResult() {
|
201 |
284 |
int resolution = Integer.parseInt((String)controlPanel.getCbResolution().getSelectedItem());
|
202 |
|
double cmsx = Double.parseDouble(controlPanel.getValueXCms());
|
203 |
|
double cmsy = Double.parseDouble(controlPanel.getValueYCms());
|
204 |
|
double wpx = (cmsx * MathUtils.INCHESCM) * resolution;
|
205 |
|
double hpx = (cmsy * MathUtils.INCHESCM) * resolution;
|
206 |
|
controlPanel.setSizePxPrintResult((int)wpx, (int)hpx);
|
|
285 |
int cmsx = Integer.parseInt(controlPanel.getValueXCms());
|
|
286 |
int cmsy = Integer.parseInt(controlPanel.getValueYCms());
|
|
287 |
int wpx = (int)Math.round((cmsx * MathUtils.INCHESCM) * resolution);
|
|
288 |
int hpx = (int)Math.round((cmsy * MathUtils.INCHESCM) * resolution);
|
|
289 |
controlPanel.setSizePxPrintResult(wpx, hpx);
|
207 |
290 |
}
|
208 |
291 |
|
|
292 |
/**
|
|
293 |
* Calculates the output file size in megabytes
|
|
294 |
*/
|
209 |
295 |
private void calculateFileSize() {
|
210 |
296 |
int w = 0;
|
211 |
297 |
int h = 0;
|
... | ... | |
213 |
299 |
w = Integer.parseInt(controlPanel.getWidthPxValue());
|
214 |
300 |
h = Integer.parseInt(controlPanel.getHeightPxValue());
|
215 |
301 |
} else {
|
216 |
|
w = Integer.parseInt(controlPanel.getWidthPxPrint());
|
217 |
|
h = Integer.parseInt(controlPanel.getHeightPxPrint());
|
|
302 |
w = controlPanel.getWidthPxPrint();
|
|
303 |
h = controlPanel.getHeightPxPrint();
|
218 |
304 |
}
|
219 |
|
controlPanel.setSizeMB((w * h * 4) / 1048576);
|
|
305 |
controlPanel.setSizeMB(math.clipDecimals((((long)w * (long)h * (long)3) / 1048576D), 1));
|
220 |
306 |
}
|
221 |
307 |
|
222 |
308 |
/**
|
... | ... | |
271 |
357 |
if(Math.abs(uly - ulx) == 0 || Math.abs(lry - lrx) == 0) {
|
272 |
358 |
dialog.getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(false);
|
273 |
359 |
return;
|
274 |
|
}
|
275 |
|
|
|
360 |
}
|
|
361 |
|
276 |
362 |
if(controlPanel.isPixelMethodSelected()) {
|
277 |
|
double wpx = Double.parseDouble(controlPanel.getWidthPxValue());
|
278 |
|
double hpx = Double.parseDouble(controlPanel.getHeightPxValue());
|
|
363 |
int wpx = Integer.parseInt(controlPanel.getWidthPxValue());
|
|
364 |
int hpx = Integer.parseInt(controlPanel.getHeightPxValue());
|
279 |
365 |
double cellsize = Double.parseDouble(controlPanel.getCellSize());
|
280 |
366 |
if(wpx == 0 || hpx == 0 || cellsize == 0) {
|
281 |
367 |
dialog.getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(false);
|
282 |
368 |
return;
|
283 |
369 |
}
|
284 |
370 |
} else {
|
285 |
|
double cmsx = Double.parseDouble(controlPanel.getValueXCms());
|
286 |
|
double cmsy = Double.parseDouble(controlPanel.getValueYCms());
|
287 |
|
double scale = Double.parseDouble(controlPanel.getScaleValue());
|
|
371 |
int cmsx = Integer.parseInt(controlPanel.getValueXCms());
|
|
372 |
int cmsy = Integer.parseInt(controlPanel.getValueYCms());
|
|
373 |
int scale = Integer.parseInt(controlPanel.getScaleValue());
|
288 |
374 |
if(cmsx == 0 || cmsy == 0 || scale == 0) {
|
289 |
375 |
dialog.getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(false);
|
290 |
376 |
return;
|
... | ... | |
352 |
438 |
JFileChooser.setLastPath("DATA_INPUT_LISTENER", chooser.getSelectedFile());
|
353 |
439 |
}
|
354 |
440 |
}
|
|
441 |
|
|
442 |
if( controlPanel.getComponentID(obj) == SaveRasterPanel.RESOLUTION_COMPONENT) {
|
|
443 |
if(!enableEventValueChanged)
|
|
444 |
return;
|
|
445 |
enableEventValueChanged = false;
|
|
446 |
this.recalcParams(e.getSource(), null);
|
|
447 |
enableButtons();
|
|
448 |
enableEventValueChanged = true;
|
|
449 |
}
|
355 |
450 |
|
356 |
451 |
this.enableButtons();
|
357 |
452 |
|
... | ... | |
414 |
509 |
if(!enableEventValueChanged)
|
415 |
510 |
return;
|
416 |
511 |
enableEventValueChanged = false;
|
417 |
|
this.recalcParams(e.getSource());
|
|
512 |
this.recalcParams(e.getSource(), "0");
|
418 |
513 |
enableButtons();
|
419 |
514 |
enableEventValueChanged = true;
|
420 |
515 |
}
|
... | ... | |
423 |
518 |
if(!enableEventValueChanged)
|
424 |
519 |
return;
|
425 |
520 |
enableEventValueChanged = false;
|
426 |
|
this.recalcParams(e.getSource());
|
|
521 |
this.recalcParams(e.getSource(), e.getOldValue());
|
427 |
522 |
enableButtons();
|
428 |
523 |
enableEventValueChanged = true;
|
429 |
524 |
}
|