gvsig-raster / org.gvsig.raster.mosaic / trunk / org.gvsig.raster.mosaic / org.gvsig.raster.mosaic.swing / org.gvsig.raster.mosaic.swing.impl / src / main / java / org / gvsig / raster / mosaic / swing / impl / main / AddFilesPanelImpl.java @ 2213
History | View | Annotate | Download (24.2 KB)
1 |
package org.gvsig.raster.mosaic.swing.impl.main; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.FlowLayout; |
5 |
import java.awt.GridBagConstraints; |
6 |
import java.awt.GridBagLayout; |
7 |
import java.awt.Insets; |
8 |
import java.awt.event.ActionEvent; |
9 |
import java.awt.event.ActionListener; |
10 |
import java.io.File; |
11 |
import java.util.ArrayList; |
12 |
import java.util.Arrays; |
13 |
import java.util.List; |
14 |
|
15 |
import javax.swing.ImageIcon; |
16 |
import javax.swing.JButton; |
17 |
import javax.swing.JCheckBox; |
18 |
import javax.swing.JComboBox; |
19 |
import javax.swing.JComponent; |
20 |
import javax.swing.JLabel; |
21 |
import javax.swing.JPanel; |
22 |
import javax.swing.JScrollPane; |
23 |
import javax.swing.JTable; |
24 |
import javax.swing.JTextField; |
25 |
import javax.swing.table.DefaultTableModel; |
26 |
import javax.swing.table.TableColumnModel; |
27 |
|
28 |
import org.gvsig.andami.IconThemeHelper; |
29 |
import org.gvsig.fmap.dal.DALLocator; |
30 |
import org.gvsig.fmap.dal.DataManager; |
31 |
import org.gvsig.fmap.dal.DataServerExplorer; |
32 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
33 |
import org.gvsig.fmap.dal.DataStoreProvider; |
34 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
35 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
36 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
37 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
38 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
39 |
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters; |
40 |
import org.gvsig.fmap.dal.exception.InitializeException; |
41 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
42 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
43 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
44 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
45 |
import org.gvsig.gui.beans.swing.JFileChooser; |
46 |
import org.gvsig.i18n.Messages; |
47 |
import org.gvsig.raster.impl.provider.RasterProvider; |
48 |
import org.gvsig.raster.mosaic.io.MosaicDataParameters; |
49 |
import org.gvsig.raster.mosaic.io.MosaicProvider; |
50 |
import org.gvsig.raster.mosaic.io.MosaicRasterFormat; |
51 |
import org.gvsig.raster.mosaic.swing.main.AddFilesEvent; |
52 |
import org.gvsig.raster.mosaic.swing.main.AddFilesListener; |
53 |
import org.gvsig.raster.mosaic.swing.main.AddFilesPanel; |
54 |
import org.gvsig.tools.locator.LocatorException; |
55 |
import org.slf4j.Logger; |
56 |
import org.slf4j.LoggerFactory; |
57 |
|
58 |
/**
|
59 |
* Main panel to add files in a mosaic
|
60 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
61 |
*/
|
62 |
public class AddFilesPanelImpl extends JPanel implements ActionListener, AddFilesPanel { |
63 |
private static final long serialVersionUID = 1L; |
64 |
private String pathToImagesForTest = "/src/main/resources/images/"; |
65 |
private String lastFolder = System.getProperty("user.home"); |
66 |
private Logger log = LoggerFactory.getLogger(AddFilesPanelImpl.class); |
67 |
|
68 |
private final String BYTE = "Byte"; |
69 |
private final String SHORT = "Short"; |
70 |
private final String INTEGER = "Integer"; |
71 |
private final String FLOAT = "Float"; |
72 |
private final String DOUBLE = "Double"; |
73 |
|
74 |
private JPanel arrowButtonsPanel = null; |
75 |
private JButton downArrowButton = null; |
76 |
private JButton upArrowButton = null; |
77 |
private JButton addAllButton = null; |
78 |
private JButton removeAllButton = null; |
79 |
|
80 |
private String[] columnNames = null; |
81 |
private JScrollPane scrollPanelSrc = null; |
82 |
//private PagedTable pagedSrcTable = null;
|
83 |
private JTable tableSrc = null; |
84 |
private DefaultTableModel modelSrc = null; |
85 |
|
86 |
private JScrollPane scrollPanelDst = null; |
87 |
//private PagedTable pagedDstTable = null;
|
88 |
private JTable tableDst = null; |
89 |
private DefaultTableModel modelDst = null; |
90 |
|
91 |
private JPanel buttonsPanel = null; |
92 |
private JButton addDirButton = null; |
93 |
private JButton addFilesButton = null; |
94 |
private JButton optionsButton = null; |
95 |
|
96 |
private JPanel optionsPanel = null; |
97 |
private JComboBox nbandsCombo = null; |
98 |
private JTextField datatypeTextField = null; |
99 |
private JComboBox rgbTypeCombo = null; |
100 |
private JCheckBox rgbCheckBox = null; |
101 |
private List<TableEntry> entriesSrc = null; |
102 |
private List<TableEntry> entriesDst = null; |
103 |
|
104 |
private AddFilesListener listener = null; |
105 |
private List<String> suffixList = null; |
106 |
private String file = null; |
107 |
private String folder = null; |
108 |
|
109 |
public AddFilesPanelImpl(String file, String folder, List<String> suffixList) { |
110 |
columnNames = new String[]{ Messages.getText("bands"), Messages.getText("file")}; |
111 |
entriesSrc = new ArrayList<TableEntry>(); |
112 |
entriesDst = new ArrayList<TableEntry>(); |
113 |
this.suffixList = suffixList;
|
114 |
this.file = file;
|
115 |
this.folder = folder;
|
116 |
initialize(); |
117 |
} |
118 |
|
119 |
public AddFilesPanelImpl(String file, String folder, String[] suffixList) { |
120 |
columnNames = new String[]{ Messages.getText("bands"), Messages.getText("file")}; |
121 |
entriesSrc = new ArrayList<TableEntry>(); |
122 |
entriesDst = new ArrayList<TableEntry>(); |
123 |
this.suffixList = Arrays.asList(suffixList); |
124 |
this.file = file;
|
125 |
this.folder = folder;
|
126 |
initialize(); |
127 |
} |
128 |
|
129 |
class TableEntry { |
130 |
Object obj = null; |
131 |
String text = null; |
132 |
int bandCount = 0; |
133 |
int dataType = 0; |
134 |
double cellsize = 0; |
135 |
double nodata = 0; |
136 |
|
137 |
public TableEntry(String text, Object obj, int bandCount, int dataType, double cellsize, double nodata) { |
138 |
this.obj = obj;
|
139 |
this.text = text;
|
140 |
this.bandCount = bandCount;
|
141 |
this.dataType = dataType;
|
142 |
this.cellsize = cellsize;
|
143 |
this.nodata = nodata;
|
144 |
} |
145 |
|
146 |
public String toString() { |
147 |
return text;
|
148 |
} |
149 |
} |
150 |
|
151 |
//*******************************************************
|
152 |
//***************API Implementation**********************
|
153 |
|
154 |
public void addSrcFile(Object data, String text, int nBands, int datatype, double cellsize, double nodata) { |
155 |
TableEntry entry = new TableEntry(text, data, nBands, datatype, cellsize, nodata);
|
156 |
entriesSrc.add(entry); |
157 |
updateUISrcTable(); |
158 |
} |
159 |
|
160 |
public void addDstFile(Object data, String text, int nBands, int datatype, double cellsize, double nodata) { |
161 |
TableEntry entry = new TableEntry(text, data, nBands, datatype, cellsize, nodata);
|
162 |
entriesDst.add(entry); |
163 |
updateUIDstTable(); |
164 |
} |
165 |
|
166 |
public void addListener(AddFilesListener filesListener) { |
167 |
this.listener = filesListener;
|
168 |
} |
169 |
|
170 |
public JComponent getJComponent() { |
171 |
return this; |
172 |
} |
173 |
|
174 |
//*****************************************************
|
175 |
|
176 |
private void updateUISrcTable() { |
177 |
modelSrc = new DefaultTableModel(columnNames, entriesSrc.size()); |
178 |
getFileListSrc().setModel(modelSrc); |
179 |
getFileListSrc().getColumnModel().getColumn(0).setMaxWidth(55); |
180 |
for (int i = 0; i < entriesSrc.size(); i++) { |
181 |
getFileListSrc().getModel().setValueAt(entriesSrc.get(i).bandCount, i, 0);
|
182 |
getFileListSrc().getModel().setValueAt(entriesSrc.get(i), i, 1);
|
183 |
} |
184 |
} |
185 |
|
186 |
private void updateUIDstTable() { |
187 |
modelDst = new DefaultTableModel(columnNames, entriesDst.size()); |
188 |
getFileListDst().setModel(modelDst); |
189 |
getFileListDst().getColumnModel().getColumn(0).setMaxWidth(55); |
190 |
for (int i = 0; i < entriesDst.size(); i++) { |
191 |
getFileListDst().getModel().setValueAt(entriesDst.get(i).bandCount, i, 0);
|
192 |
getFileListDst().getModel().setValueAt(entriesDst.get(i), i, 1);
|
193 |
} |
194 |
updateOutputDataTypes(); |
195 |
updateOutputNumBands(); |
196 |
} |
197 |
|
198 |
private void updateOutputNumBands() { |
199 |
setUIOutputNumBands(0);
|
200 |
|
201 |
if(entriesDst.size() <= 0) |
202 |
return;
|
203 |
|
204 |
int currentOutputBands = entriesDst.get(0).bandCount; |
205 |
|
206 |
for (int i = 1; i < entriesDst.size(); i++) { |
207 |
int bandCount = entriesDst.get(i).bandCount;
|
208 |
if(bandCount > currentOutputBands)
|
209 |
currentOutputBands = bandCount; |
210 |
} |
211 |
|
212 |
setUIOutputNumBands(currentOutputBands); |
213 |
enableUIRGBOutput(); |
214 |
} |
215 |
|
216 |
/**
|
217 |
* Update output data types depending on the layer type.
|
218 |
*/
|
219 |
private void updateOutputDataTypes() { |
220 |
if(entriesDst.size() == 0) { |
221 |
getDatatypeJTextField().setText("");
|
222 |
return;
|
223 |
} |
224 |
|
225 |
if(getDatatypeJTextField().getText().compareTo("") == 0) |
226 |
getDatatypeJTextField().setText(BYTE); |
227 |
|
228 |
for (int i = 0; i < entriesDst.size(); i++) { |
229 |
int currentDatatype = getDataTypeFromText(getDatatypeJTextField().getText());
|
230 |
int dataType = entriesDst.get(i).dataType;
|
231 |
switch (dataType) {
|
232 |
case Buffer.TYPE_DOUBLE: |
233 |
setDataType(Buffer.TYPE_DOUBLE);
|
234 |
return;
|
235 |
case Buffer.TYPE_FLOAT: |
236 |
if(currentDatatype == Buffer.TYPE_BYTE || currentDatatype == Buffer.TYPE_FLOAT) |
237 |
setDataType(Buffer.TYPE_FLOAT);
|
238 |
else
|
239 |
setDataType(Buffer.TYPE_DOUBLE);
|
240 |
break;
|
241 |
case Buffer.TYPE_BYTE: |
242 |
if(currentDatatype == Buffer.TYPE_BYTE) |
243 |
setDataType(Buffer.TYPE_BYTE);
|
244 |
break;
|
245 |
case Buffer.TYPE_SHORT: |
246 |
if(currentDatatype < Buffer.TYPE_SHORT) |
247 |
setDataType(Buffer.TYPE_SHORT);
|
248 |
break;
|
249 |
case Buffer.TYPE_INT: |
250 |
if(currentDatatype < Buffer.TYPE_INT) |
251 |
setDataType(Buffer.TYPE_INT);
|
252 |
break;
|
253 |
} |
254 |
} |
255 |
} |
256 |
|
257 |
private int getDataTypeFromText(String text) { |
258 |
if(text.compareTo(BYTE) == 0) |
259 |
return Buffer.TYPE_BYTE; |
260 |
if(text.compareTo(SHORT) == 0) |
261 |
return Buffer.TYPE_SHORT; |
262 |
if(text.compareTo(INTEGER) == 0) |
263 |
return Buffer.TYPE_INT; |
264 |
if(text.compareTo(FLOAT) == 0) |
265 |
return Buffer.TYPE_FLOAT; |
266 |
if(text.compareTo(DOUBLE) == 0) |
267 |
return Buffer.TYPE_DOUBLE; |
268 |
return -1; |
269 |
} |
270 |
|
271 |
private void setDataType(int datatype) { |
272 |
switch (datatype) {
|
273 |
case Buffer.TYPE_BYTE: |
274 |
getDatatypeJTextField().setText(BYTE); |
275 |
break;
|
276 |
case Buffer.TYPE_SHORT: |
277 |
getDatatypeJTextField().setText(SHORT); |
278 |
break;
|
279 |
case Buffer.TYPE_INT: |
280 |
getDatatypeJTextField().setText(INTEGER); |
281 |
break;
|
282 |
case Buffer.TYPE_FLOAT: |
283 |
getDatatypeJTextField().setText(FLOAT); |
284 |
break;
|
285 |
case Buffer.TYPE_DOUBLE: |
286 |
getDatatypeJTextField().setText(DOUBLE); |
287 |
break;
|
288 |
} |
289 |
} |
290 |
|
291 |
private void setUIOutputNumBands(int numBands) { |
292 |
getNbandsJComboBox().removeAllItems(); |
293 |
for (int i = 0; i < numBands; i++) { |
294 |
getNbandsJComboBox().addItem((i + 1) + ""); |
295 |
} |
296 |
getNbandsJComboBox().setSelectedIndex(getNbandsJComboBox().getItemCount() - 1);
|
297 |
} |
298 |
|
299 |
private int getUIOutputNumBands() { |
300 |
String value = (String)getNbandsJComboBox().getSelectedItem(); |
301 |
try {
|
302 |
return Integer.valueOf(value); |
303 |
} catch (NumberFormatException e) { |
304 |
return -1; |
305 |
} |
306 |
} |
307 |
|
308 |
private void enableUIRGBOutput() { |
309 |
int outputNumBands = getUIOutputNumBands();
|
310 |
boolean enable = outputNumBands >= 3; |
311 |
|
312 |
getRGBOutputCheckBox().setEnabled(enable); |
313 |
if(!enable) {
|
314 |
getRGBTypeComboBox().setSelectedIndex(0);
|
315 |
getRGBTypeComboBox().setEnabled(enable); |
316 |
} else {
|
317 |
if(getRGBOutputCheckBox().isSelected()) {
|
318 |
//solo con 4 bandas o m?s se puede elegir el tipo de interpretaci?n de color
|
319 |
if(outputNumBands >= 4) { |
320 |
if(getRGBTypeComboBox().getSelectedIndex() == 0) |
321 |
getRGBTypeComboBox().setSelectedIndex(1);
|
322 |
getRGBTypeComboBox().setEnabled(true);
|
323 |
} else {
|
324 |
getRGBTypeComboBox().setSelectedIndex(2);
|
325 |
getRGBTypeComboBox().setEnabled(false);
|
326 |
} |
327 |
} else {
|
328 |
getRGBTypeComboBox().setSelectedIndex(0);
|
329 |
getRGBTypeComboBox().setEnabled(false);
|
330 |
} |
331 |
} |
332 |
|
333 |
} |
334 |
|
335 |
protected void initialize() { |
336 |
enableUIRGBOutput(); |
337 |
setLayout(new GridBagLayout()); |
338 |
|
339 |
GridBagConstraints gbc = new GridBagConstraints(); |
340 |
gbc.insets = new Insets(2, 2, 2, 2); |
341 |
gbc.fill = GridBagConstraints.BOTH;
|
342 |
gbc.weightx = 1.0;
|
343 |
gbc.weighty = 1.0;
|
344 |
gbc.gridwidth = 2;
|
345 |
add(getScrollTableSrc(), gbc); |
346 |
|
347 |
gbc.gridy = 2;
|
348 |
add(getScrollTableDst(), gbc); |
349 |
|
350 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
351 |
gbc.weighty = 0.0;
|
352 |
|
353 |
gbc.gridy = 1;
|
354 |
add(getIconsPanel(), gbc); |
355 |
|
356 |
gbc.gridy = 3;
|
357 |
add(getButtonsPanel(), gbc); |
358 |
|
359 |
gbc.gridwidth = 1;
|
360 |
gbc.gridx = 0;
|
361 |
gbc.gridy = 4;
|
362 |
add(new JPanel(), gbc); |
363 |
|
364 |
gbc.fill = GridBagConstraints.NONE;
|
365 |
gbc.weightx = 0.0;
|
366 |
gbc.gridx = 1;
|
367 |
gbc.gridy = 4;
|
368 |
add(getOptionsPanel(), gbc); |
369 |
} |
370 |
|
371 |
//******************************************************
|
372 |
|
373 |
public JPanel getOptionsPanel() { |
374 |
if(optionsPanel == null) { |
375 |
optionsPanel = new JPanel(new GridBagLayout()); |
376 |
//optionsPanel.setBorder(BorderFactory.createLineBorder(Color.red));
|
377 |
JLabel l1 = new JLabel(Messages.getText("n_output_bands")); |
378 |
JLabel l2 = new JLabel(Messages.getText("output_datatype")); |
379 |
|
380 |
GridBagConstraints gbc = new GridBagConstraints(); |
381 |
gbc.insets = new Insets(0, 0, 2, 20); |
382 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
383 |
|
384 |
gbc.gridx = 0;
|
385 |
gbc.gridy = 0;
|
386 |
optionsPanel.add(l1, gbc); |
387 |
|
388 |
gbc.gridx = 1;
|
389 |
gbc.gridy = 0;
|
390 |
optionsPanel.add(getNbandsJComboBox(), gbc); |
391 |
|
392 |
gbc.gridx = 0;
|
393 |
gbc.gridy = 1;
|
394 |
optionsPanel.add(l2, gbc); |
395 |
|
396 |
gbc.gridx = 1;
|
397 |
gbc.gridy = 1;
|
398 |
optionsPanel.add(getDatatypeJTextField(), gbc); |
399 |
|
400 |
gbc.gridx = 0;
|
401 |
gbc.gridy = 2;
|
402 |
optionsPanel.add(getRGBOutputCheckBox(), gbc); |
403 |
|
404 |
gbc.gridx = 1;
|
405 |
gbc.gridy = 2;
|
406 |
optionsPanel.add(getRGBTypeComboBox(), gbc); |
407 |
} |
408 |
return optionsPanel;
|
409 |
} |
410 |
|
411 |
public JComboBox getNbandsJComboBox() { |
412 |
if(nbandsCombo == null) { |
413 |
nbandsCombo = new JComboBox(); |
414 |
nbandsCombo.addItem("0");
|
415 |
nbandsCombo.addActionListener(this);
|
416 |
} |
417 |
return nbandsCombo;
|
418 |
} |
419 |
|
420 |
public JTextField getDatatypeJTextField() { |
421 |
if(datatypeTextField == null) { |
422 |
datatypeTextField = new JTextField(); |
423 |
datatypeTextField.setEditable(false);
|
424 |
datatypeTextField.setPreferredSize(new Dimension(30, 30)); |
425 |
} |
426 |
return datatypeTextField;
|
427 |
} |
428 |
|
429 |
public JComboBox getRGBTypeComboBox() { |
430 |
if(rgbTypeCombo == null) { |
431 |
rgbTypeCombo = new JComboBox(); |
432 |
rgbTypeCombo.addItem("------");
|
433 |
rgbTypeCombo.addItem("ARGB");
|
434 |
rgbTypeCombo.addItem("RGB");
|
435 |
rgbTypeCombo.addItem("BGR IR");
|
436 |
} |
437 |
return rgbTypeCombo;
|
438 |
} |
439 |
|
440 |
public JCheckBox getRGBOutputCheckBox() { |
441 |
if(rgbCheckBox == null) { |
442 |
rgbCheckBox = new JCheckBox(Messages.getText("rgb_output")); |
443 |
rgbCheckBox.addActionListener(this);
|
444 |
} |
445 |
return rgbCheckBox;
|
446 |
} |
447 |
|
448 |
//******************************************************
|
449 |
|
450 |
public JPanel getButtonsPanel() { |
451 |
if(buttonsPanel == null) { |
452 |
FlowLayout fl = new FlowLayout(); |
453 |
fl.setAlignment(FlowLayout.LEFT);
|
454 |
buttonsPanel = new JPanel(fl); |
455 |
//iconsPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
|
456 |
buttonsPanel.add(getAddDirButton()); |
457 |
buttonsPanel.add(getAddFilesButton()); |
458 |
buttonsPanel.add(getOptionsButton()); |
459 |
} |
460 |
return buttonsPanel;
|
461 |
} |
462 |
|
463 |
public JButton getAddDirButton() { |
464 |
if(addDirButton == null) { |
465 |
addDirButton = new JButton(Messages.getText("add_dir")); |
466 |
addDirButton.addActionListener(this);
|
467 |
} |
468 |
return addDirButton;
|
469 |
} |
470 |
|
471 |
public JButton getAddFilesButton() { |
472 |
if(addFilesButton == null) { |
473 |
addFilesButton = new JButton(Messages.getText("add_files")); |
474 |
addFilesButton.addActionListener(this);
|
475 |
} |
476 |
return addFilesButton;
|
477 |
} |
478 |
|
479 |
public JButton getOptionsButton() { |
480 |
if(optionsButton == null) { |
481 |
optionsButton = new JButton(Messages.getText("options")); |
482 |
} |
483 |
return optionsButton;
|
484 |
} |
485 |
|
486 |
//******************************************************
|
487 |
|
488 |
public JScrollPane getScrollTableDst() { |
489 |
if(scrollPanelDst == null) { |
490 |
scrollPanelDst = new JScrollPane(); |
491 |
scrollPanelDst.setViewportView(getFileListDst()); |
492 |
} |
493 |
return scrollPanelDst;
|
494 |
} |
495 |
|
496 |
public JTable getFileListDst() { |
497 |
if(tableDst == null) { |
498 |
tableDst = new JTable(getModelDst()); |
499 |
TableColumnModel columnModel = tableDst.getColumnModel();
|
500 |
columnModel.getColumn(0).setMaxWidth(55); |
501 |
} |
502 |
return tableDst;
|
503 |
} |
504 |
|
505 |
public DefaultTableModel getModelDst() { |
506 |
if(modelDst == null) |
507 |
modelDst = new DefaultTableModel(columnNames, 0); |
508 |
return modelDst;
|
509 |
} |
510 |
|
511 |
|
512 |
//******************************************************
|
513 |
|
514 |
|
515 |
public JScrollPane getScrollTableSrc() { |
516 |
if(scrollPanelSrc == null) { |
517 |
scrollPanelSrc = new JScrollPane(); |
518 |
scrollPanelSrc.setViewportView(getFileListSrc()); |
519 |
} |
520 |
return scrollPanelSrc;
|
521 |
} |
522 |
|
523 |
public JTable getFileListSrc() { |
524 |
if(tableSrc == null) { |
525 |
tableSrc = new JTable(getModelSrc()); |
526 |
TableColumnModel columnModel = tableSrc.getColumnModel();
|
527 |
columnModel.getColumn(0).setMaxWidth(55); |
528 |
} |
529 |
return tableSrc;
|
530 |
} |
531 |
|
532 |
public DefaultTableModel getModelSrc() { |
533 |
if(modelSrc == null) |
534 |
modelSrc = new DefaultTableModel(columnNames, 0); |
535 |
return modelSrc;
|
536 |
} |
537 |
|
538 |
//******************************************************
|
539 |
|
540 |
public JPanel getIconsPanel() { |
541 |
if(arrowButtonsPanel == null) { |
542 |
FlowLayout fl = new FlowLayout(); |
543 |
fl.setAlignment(FlowLayout.CENTER);
|
544 |
arrowButtonsPanel = new JPanel(fl); |
545 |
//iconsPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
|
546 |
fl.setHgap(2);
|
547 |
arrowButtonsPanel.add(getUpArrowButton()); |
548 |
arrowButtonsPanel.add(getDownArrowButton()); |
549 |
arrowButtonsPanel.add(getAddAllButton()); |
550 |
arrowButtonsPanel.add(getRemoveAllButton()); |
551 |
} |
552 |
return arrowButtonsPanel;
|
553 |
} |
554 |
|
555 |
public JButton getUpArrowButton() { |
556 |
if(upArrowButton == null) { |
557 |
upArrowButton = new JButton(loadIcon("up-16x16-icon")); |
558 |
upArrowButton.addActionListener(this);
|
559 |
} |
560 |
return upArrowButton;
|
561 |
} |
562 |
|
563 |
public JButton getDownArrowButton() { |
564 |
if(downArrowButton == null) { |
565 |
downArrowButton = new JButton(loadIcon("down-16x16-icon")); |
566 |
downArrowButton.addActionListener(this);
|
567 |
} |
568 |
return downArrowButton;
|
569 |
} |
570 |
|
571 |
public JButton getAddAllButton() { |
572 |
if(addAllButton == null) { |
573 |
addAllButton = new JButton(loadIcon("downred-16x16-icon")); |
574 |
addAllButton.addActionListener(this);
|
575 |
} |
576 |
return addAllButton;
|
577 |
} |
578 |
|
579 |
public JButton getRemoveAllButton() { |
580 |
if(removeAllButton == null) { |
581 |
removeAllButton = new JButton(loadIcon("upred-16x16-icon")); |
582 |
removeAllButton.addActionListener(this);
|
583 |
} |
584 |
return removeAllButton;
|
585 |
} |
586 |
|
587 |
//******************************************************
|
588 |
|
589 |
private ImageIcon loadIcon(String iconName) { |
590 |
ImageIcon icon = null; |
591 |
try {
|
592 |
icon = IconThemeHelper.getImageIcon(iconName); |
593 |
} catch(NullPointerException e) {} |
594 |
String path = System.getProperty("user.dir") + pathToImagesForTest + iconName + ".png"; |
595 |
if(new File(path).exists()) |
596 |
icon = new ImageIcon(path, ""); |
597 |
if(icon == null) |
598 |
icon = new ImageIcon(System.getProperty("user.dir") + pathToImagesForTest + iconName + ".gif", ""); |
599 |
return icon;
|
600 |
} |
601 |
|
602 |
public void actionPerformed(ActionEvent e) { |
603 |
//Cambio del n?mero de bandas de las salida
|
604 |
if(e.getSource() == getNbandsJComboBox()) {
|
605 |
enableUIRGBOutput(); |
606 |
} |
607 |
|
608 |
//Activar/desactivar el check de RGB
|
609 |
if(e.getSource() == getRGBOutputCheckBox()) {
|
610 |
enableUIRGBOutput(); |
611 |
} |
612 |
|
613 |
//Eliminar todas de las capas de salida
|
614 |
if(e.getSource() == getRemoveAllButton()) {
|
615 |
for (int i = 0; i < entriesDst.size(); i++) { |
616 |
entriesSrc.add(entriesDst.get(i)); |
617 |
} |
618 |
entriesDst.clear(); |
619 |
updateUISrcTable(); |
620 |
updateUIDstTable(); |
621 |
} |
622 |
|
623 |
//A?adir todas de las capas de salida
|
624 |
if(e.getSource() == getAddAllButton()) {
|
625 |
for (int i = 0; i < entriesSrc.size(); i++) { |
626 |
entriesDst.add(entriesSrc.get(i)); |
627 |
} |
628 |
entriesSrc.clear(); |
629 |
updateUISrcTable(); |
630 |
updateUIDstTable(); |
631 |
} |
632 |
|
633 |
//A?adir la seleccionada a la salida
|
634 |
if(e.getSource() == getDownArrowButton()) {
|
635 |
int[] rows = getFileListSrc().getSelectedRows(); |
636 |
|
637 |
for (int i = 0; i < rows.length; i++) { |
638 |
TableEntry entry = entriesSrc.remove(rows[i]); |
639 |
entriesDst.add(entry); |
640 |
} |
641 |
|
642 |
updateUISrcTable(); |
643 |
updateUIDstTable(); |
644 |
} |
645 |
|
646 |
//Eliminar la seleccionada de la salida
|
647 |
if(e.getSource() == getUpArrowButton()) {
|
648 |
int[] rows = getFileListDst().getSelectedRows(); |
649 |
|
650 |
for (int i = rows.length - 1; i >= 0; i--) { |
651 |
TableEntry entry = entriesDst.remove(rows[i]); |
652 |
entriesSrc.add(entry); |
653 |
} |
654 |
|
655 |
updateUISrcTable(); |
656 |
updateUIDstTable(); |
657 |
} |
658 |
|
659 |
//A?ade ficheros desde disco
|
660 |
if(e.getSource() == getAddFilesButton()) {
|
661 |
if(listener != null) { |
662 |
JFileChooser fileChooser = createJFileChooser(false); |
663 |
int result = fileChooser.showOpenDialog(this); |
664 |
|
665 |
if (result == JFileChooser.APPROVE_OPTION) { |
666 |
File[] files = fileChooser.getSelectedFiles(); |
667 |
listener.actionAddFiles(new AddFilesEvent(getAddFilesButton(), files));
|
668 |
} |
669 |
} |
670 |
} |
671 |
|
672 |
//Elimina ficheros desde disco
|
673 |
if(e.getSource() == getAddDirButton()) {
|
674 |
if(listener != null) { |
675 |
JFileChooser fileChooser = createJFileChooser(true); |
676 |
int result = fileChooser.showOpenDialog(this); |
677 |
|
678 |
if (result == JFileChooser.APPROVE_OPTION) { |
679 |
File folder = fileChooser.getSelectedFile();
|
680 |
String[] list = folder.list(); |
681 |
File[] files = filterFileList(list, folder); |
682 |
listener.actionAddFolder(new AddFilesEvent(getAddFilesButton(), files));
|
683 |
} |
684 |
} |
685 |
} |
686 |
} |
687 |
|
688 |
private File[] filterFileList(String[] f, File folder) { |
689 |
List<File> list = new ArrayList<File>(); |
690 |
for (int i = 0; i < f.length; i++) { |
691 |
if(isInList(f[i]))
|
692 |
list.add(new File(folder.getAbsolutePath() + File.separator + f[i])); |
693 |
} |
694 |
return list.toArray(new File[list.size()]); |
695 |
} |
696 |
|
697 |
private boolean isInList(String name) { |
698 |
for (int i = 0; i < suffixList.size(); i++) { |
699 |
String suffix = suffixList.get(i);
|
700 |
if(name.endsWith("." + suffix)) |
701 |
return true; |
702 |
} |
703 |
return false; |
704 |
} |
705 |
|
706 |
protected JFileChooser createJFileChooser(boolean folder) { |
707 |
JFileChooser fileChooser = new JFileChooser(lastFolder, JFileChooser.getLastPath(lastFolder, null)); |
708 |
fileChooser.setMultiSelectionEnabled(true);
|
709 |
fileChooser.setAcceptAllFileFilterUsed(false);
|
710 |
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
|
711 |
if(folder) {
|
712 |
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
713 |
fileChooser.addChoosableFileFilter(new RasterFormatFileFilter());
|
714 |
} else {
|
715 |
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
716 |
fileChooser.addChoosableFileFilter(new RasterFormatFileFilter(suffixList));
|
717 |
} |
718 |
return fileChooser;
|
719 |
} |
720 |
|
721 |
private boolean cache = true; |
722 |
public Object getResult() { |
723 |
try {
|
724 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
725 |
DataServerExplorerParameters explParams = dataManager.createServerExplorerParameters(MosaicProvider.NAME); |
726 |
DataServerExplorer explorer = dataManager.openServerExplorer(MosaicProvider.NAME, explParams); |
727 |
MosaicDataParameters newParamsMosaic = (MosaicDataParameters)dataManager.createStoreParameters(explorer.getProviderName()); |
728 |
|
729 |
newParamsMosaic.setURI(folder + File.separator + file + MosaicRasterFormat.getSuffix());
|
730 |
newParamsMosaic.setPixelSize(getMinPixelSize()); |
731 |
|
732 |
for (int i = 0; i < entriesDst.size(); i++) { |
733 |
RasterDataStore store = (RasterDataStore)entriesDst.get(i).obj; |
734 |
RasterProvider prov = (RasterProvider)store.getProvider(); |
735 |
if(prov != null) |
736 |
newParamsMosaic.addProvider(prov); |
737 |
} |
738 |
|
739 |
if(cache) {
|
740 |
DataManager manager = DALLocator.getDataManager(); |
741 |
TileDataParameters tileParams = null;
|
742 |
try {
|
743 |
tileParams = (TileDataParameters) manager.createStoreParameters("Tile Store");
|
744 |
} catch (ProviderNotRegisteredException e) {
|
745 |
throw new InitializeException(e.getMessage(), e); |
746 |
} |
747 |
tileParams.setDataParameters(newParamsMosaic); |
748 |
|
749 |
CoverageStoreProvider provider = (CoverageStoreProvider)dataManager.createProvider(null, tileParams);
|
750 |
RasterDataStore store = RasterLocator.getManager().getProviderServices().open(provider, tileParams); |
751 |
return store;
|
752 |
|
753 |
} else {
|
754 |
MosaicProvider provider = (MosaicProvider)dataManager.createProvider(null, newParamsMosaic);
|
755 |
RasterDataStore store = RasterLocator.getManager().getProviderServices().open(provider, newParamsMosaic); |
756 |
return store;
|
757 |
} |
758 |
|
759 |
} catch(ValidateDataParametersException e) {
|
760 |
log.debug("Error validating parameters", e);
|
761 |
} catch (InitializeException e) {
|
762 |
log.debug("Error initializating Mosaic Store", e);
|
763 |
} catch (ProviderNotRegisteredException e) {
|
764 |
log.debug("Error looking for the provider", e);
|
765 |
} catch (RasterDriverException e) {
|
766 |
log.debug("Error creating the Store", e);
|
767 |
} catch (LocatorException e) {
|
768 |
log.debug("Error creating the Store", e);
|
769 |
} catch (NotSupportedExtensionException e) {
|
770 |
log.debug("Error creating the Store", e);
|
771 |
} |
772 |
|
773 |
return null; |
774 |
} |
775 |
|
776 |
private double getMinPixelSize() { |
777 |
double cellsize = Integer.MAX_VALUE; |
778 |
for (int i = 0; i < entriesDst.size(); i++) { |
779 |
if(entriesDst.get(i).cellsize < cellsize)
|
780 |
cellsize = entriesDst.get(i).cellsize; |
781 |
} |
782 |
return cellsize;
|
783 |
} |
784 |
|
785 |
} |