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 @ 2300
History | View | Annotate | Download (24.3 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.coverage.RasterLocator; |
34 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
35 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
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 |
NoData nodata = null;
|
136 |
|
137 |
public TableEntry(String text, Object obj, int bandCount, int dataType, double cellsize, NoData 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, NoData 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, NoData 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 |
//**********************GUI*****************************
|
336 |
|
337 |
protected void initialize() { |
338 |
enableUIRGBOutput(); |
339 |
setLayout(new GridBagLayout()); |
340 |
|
341 |
GridBagConstraints gbc = new GridBagConstraints(); |
342 |
gbc.insets = new Insets(2, 2, 2, 2); |
343 |
gbc.fill = GridBagConstraints.BOTH;
|
344 |
gbc.weightx = 1.0;
|
345 |
gbc.weighty = 1.0;
|
346 |
gbc.gridwidth = 2;
|
347 |
add(getScrollTableSrc(), gbc); |
348 |
|
349 |
gbc.gridy = 2;
|
350 |
add(getScrollTableDst(), gbc); |
351 |
|
352 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
353 |
gbc.weighty = 0.0;
|
354 |
|
355 |
gbc.gridy = 1;
|
356 |
add(getIconsPanel(), gbc); |
357 |
|
358 |
gbc.gridy = 3;
|
359 |
add(getButtonsPanel(), gbc); |
360 |
|
361 |
gbc.gridwidth = 1;
|
362 |
gbc.gridx = 0;
|
363 |
gbc.gridy = 4;
|
364 |
add(new JPanel(), gbc); |
365 |
|
366 |
gbc.fill = GridBagConstraints.NONE;
|
367 |
gbc.weightx = 0.0;
|
368 |
gbc.gridx = 1;
|
369 |
gbc.gridy = 4;
|
370 |
add(getOptionsPanel(), gbc); |
371 |
} |
372 |
|
373 |
//******************************************************
|
374 |
|
375 |
public JPanel getOptionsPanel() { |
376 |
if(optionsPanel == null) { |
377 |
optionsPanel = new JPanel(new GridBagLayout()); |
378 |
//optionsPanel.setBorder(BorderFactory.createLineBorder(Color.red));
|
379 |
JLabel l1 = new JLabel(Messages.getText("n_output_bands")); |
380 |
JLabel l2 = new JLabel(Messages.getText("output_datatype")); |
381 |
|
382 |
GridBagConstraints gbc = new GridBagConstraints(); |
383 |
gbc.insets = new Insets(0, 0, 2, 20); |
384 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
385 |
|
386 |
gbc.gridx = 0;
|
387 |
gbc.gridy = 0;
|
388 |
optionsPanel.add(l1, gbc); |
389 |
|
390 |
gbc.gridx = 1;
|
391 |
gbc.gridy = 0;
|
392 |
optionsPanel.add(getNbandsJComboBox(), gbc); |
393 |
|
394 |
gbc.gridx = 0;
|
395 |
gbc.gridy = 1;
|
396 |
optionsPanel.add(l2, gbc); |
397 |
|
398 |
gbc.gridx = 1;
|
399 |
gbc.gridy = 1;
|
400 |
optionsPanel.add(getDatatypeJTextField(), gbc); |
401 |
|
402 |
gbc.gridx = 0;
|
403 |
gbc.gridy = 2;
|
404 |
optionsPanel.add(getRGBOutputCheckBox(), gbc); |
405 |
|
406 |
gbc.gridx = 1;
|
407 |
gbc.gridy = 2;
|
408 |
optionsPanel.add(getRGBTypeComboBox(), gbc); |
409 |
} |
410 |
return optionsPanel;
|
411 |
} |
412 |
|
413 |
public JComboBox getNbandsJComboBox() { |
414 |
if(nbandsCombo == null) { |
415 |
nbandsCombo = new JComboBox(); |
416 |
nbandsCombo.addItem("0");
|
417 |
nbandsCombo.addActionListener(this);
|
418 |
} |
419 |
return nbandsCombo;
|
420 |
} |
421 |
|
422 |
public JTextField getDatatypeJTextField() { |
423 |
if(datatypeTextField == null) { |
424 |
datatypeTextField = new JTextField(); |
425 |
datatypeTextField.setEditable(false);
|
426 |
datatypeTextField.setPreferredSize(new Dimension(30, 30)); |
427 |
} |
428 |
return datatypeTextField;
|
429 |
} |
430 |
|
431 |
public JComboBox getRGBTypeComboBox() { |
432 |
if(rgbTypeCombo == null) { |
433 |
rgbTypeCombo = new JComboBox(); |
434 |
rgbTypeCombo.addItem("------");
|
435 |
rgbTypeCombo.addItem("ARGB");
|
436 |
rgbTypeCombo.addItem("RGB");
|
437 |
rgbTypeCombo.addItem("BGR IR");
|
438 |
} |
439 |
return rgbTypeCombo;
|
440 |
} |
441 |
|
442 |
public JCheckBox getRGBOutputCheckBox() { |
443 |
if(rgbCheckBox == null) { |
444 |
rgbCheckBox = new JCheckBox(Messages.getText("rgb_output")); |
445 |
rgbCheckBox.addActionListener(this);
|
446 |
} |
447 |
return rgbCheckBox;
|
448 |
} |
449 |
|
450 |
//******************************************************
|
451 |
|
452 |
public JPanel getButtonsPanel() { |
453 |
if(buttonsPanel == null) { |
454 |
FlowLayout fl = new FlowLayout(); |
455 |
fl.setAlignment(FlowLayout.LEFT);
|
456 |
buttonsPanel = new JPanel(fl); |
457 |
//iconsPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
|
458 |
buttonsPanel.add(getAddDirButton()); |
459 |
buttonsPanel.add(getAddFilesButton()); |
460 |
buttonsPanel.add(getOptionsButton()); |
461 |
} |
462 |
return buttonsPanel;
|
463 |
} |
464 |
|
465 |
public JButton getAddDirButton() { |
466 |
if(addDirButton == null) { |
467 |
addDirButton = new JButton(Messages.getText("add_dir")); |
468 |
addDirButton.addActionListener(this);
|
469 |
} |
470 |
return addDirButton;
|
471 |
} |
472 |
|
473 |
public JButton getAddFilesButton() { |
474 |
if(addFilesButton == null) { |
475 |
addFilesButton = new JButton(Messages.getText("add_files")); |
476 |
addFilesButton.addActionListener(this);
|
477 |
} |
478 |
return addFilesButton;
|
479 |
} |
480 |
|
481 |
public JButton getOptionsButton() { |
482 |
if(optionsButton == null) { |
483 |
optionsButton = new JButton(Messages.getText("options")); |
484 |
} |
485 |
return optionsButton;
|
486 |
} |
487 |
|
488 |
//******************************************************
|
489 |
|
490 |
public JScrollPane getScrollTableDst() { |
491 |
if(scrollPanelDst == null) { |
492 |
scrollPanelDst = new JScrollPane(); |
493 |
scrollPanelDst.setViewportView(getFileListDst()); |
494 |
} |
495 |
return scrollPanelDst;
|
496 |
} |
497 |
|
498 |
public JTable getFileListDst() { |
499 |
if(tableDst == null) { |
500 |
tableDst = new JTable(getModelDst()); |
501 |
TableColumnModel columnModel = tableDst.getColumnModel();
|
502 |
columnModel.getColumn(0).setMaxWidth(55); |
503 |
} |
504 |
return tableDst;
|
505 |
} |
506 |
|
507 |
public DefaultTableModel getModelDst() { |
508 |
if(modelDst == null) |
509 |
modelDst = new DefaultTableModel(columnNames, 0); |
510 |
return modelDst;
|
511 |
} |
512 |
|
513 |
|
514 |
//******************************************************
|
515 |
|
516 |
|
517 |
public JScrollPane getScrollTableSrc() { |
518 |
if(scrollPanelSrc == null) { |
519 |
scrollPanelSrc = new JScrollPane(); |
520 |
scrollPanelSrc.setViewportView(getFileListSrc()); |
521 |
} |
522 |
return scrollPanelSrc;
|
523 |
} |
524 |
|
525 |
public JTable getFileListSrc() { |
526 |
if(tableSrc == null) { |
527 |
tableSrc = new JTable(getModelSrc()); |
528 |
TableColumnModel columnModel = tableSrc.getColumnModel();
|
529 |
columnModel.getColumn(0).setMaxWidth(55); |
530 |
} |
531 |
return tableSrc;
|
532 |
} |
533 |
|
534 |
public DefaultTableModel getModelSrc() { |
535 |
if(modelSrc == null) |
536 |
modelSrc = new DefaultTableModel(columnNames, 0); |
537 |
return modelSrc;
|
538 |
} |
539 |
|
540 |
//******************************************************
|
541 |
|
542 |
public JPanel getIconsPanel() { |
543 |
if(arrowButtonsPanel == null) { |
544 |
FlowLayout fl = new FlowLayout(); |
545 |
fl.setAlignment(FlowLayout.CENTER);
|
546 |
arrowButtonsPanel = new JPanel(fl); |
547 |
//iconsPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
|
548 |
fl.setHgap(2);
|
549 |
arrowButtonsPanel.add(getUpArrowButton()); |
550 |
arrowButtonsPanel.add(getDownArrowButton()); |
551 |
arrowButtonsPanel.add(getAddAllButton()); |
552 |
arrowButtonsPanel.add(getRemoveAllButton()); |
553 |
} |
554 |
return arrowButtonsPanel;
|
555 |
} |
556 |
|
557 |
public JButton getUpArrowButton() { |
558 |
if(upArrowButton == null) { |
559 |
upArrowButton = new JButton(loadIcon("up-16x16-icon")); |
560 |
upArrowButton.addActionListener(this);
|
561 |
} |
562 |
return upArrowButton;
|
563 |
} |
564 |
|
565 |
public JButton getDownArrowButton() { |
566 |
if(downArrowButton == null) { |
567 |
downArrowButton = new JButton(loadIcon("down-16x16-icon")); |
568 |
downArrowButton.addActionListener(this);
|
569 |
} |
570 |
return downArrowButton;
|
571 |
} |
572 |
|
573 |
public JButton getAddAllButton() { |
574 |
if(addAllButton == null) { |
575 |
addAllButton = new JButton(loadIcon("downred-16x16-icon")); |
576 |
addAllButton.addActionListener(this);
|
577 |
} |
578 |
return addAllButton;
|
579 |
} |
580 |
|
581 |
public JButton getRemoveAllButton() { |
582 |
if(removeAllButton == null) { |
583 |
removeAllButton = new JButton(loadIcon("upred-16x16-icon")); |
584 |
removeAllButton.addActionListener(this);
|
585 |
} |
586 |
return removeAllButton;
|
587 |
} |
588 |
|
589 |
//******************************************************
|
590 |
|
591 |
private ImageIcon loadIcon(String iconName) { |
592 |
ImageIcon icon = null; |
593 |
try {
|
594 |
icon = IconThemeHelper.getImageIcon(iconName); |
595 |
} catch(NullPointerException e) {} |
596 |
String path = System.getProperty("user.dir") + pathToImagesForTest + iconName + ".png"; |
597 |
if(new File(path).exists()) |
598 |
icon = new ImageIcon(path, ""); |
599 |
if(icon == null) |
600 |
icon = new ImageIcon(System.getProperty("user.dir") + pathToImagesForTest + iconName + ".gif", ""); |
601 |
return icon;
|
602 |
} |
603 |
|
604 |
public void actionPerformed(ActionEvent e) { |
605 |
//Cambio del n?mero de bandas de las salida
|
606 |
if(e.getSource() == getNbandsJComboBox()) {
|
607 |
enableUIRGBOutput(); |
608 |
} |
609 |
|
610 |
//Activar/desactivar el check de RGB
|
611 |
if(e.getSource() == getRGBOutputCheckBox()) {
|
612 |
enableUIRGBOutput(); |
613 |
} |
614 |
|
615 |
//Eliminar todas las capas de la de salida
|
616 |
if(e.getSource() == getRemoveAllButton()) {
|
617 |
for (int i = 0; i < entriesDst.size(); i++) { |
618 |
entriesSrc.add(entriesDst.get(i)); |
619 |
} |
620 |
entriesDst.clear(); |
621 |
updateUISrcTable(); |
622 |
updateUIDstTable(); |
623 |
} |
624 |
|
625 |
//A?adir todas las capas a la de salida
|
626 |
if(e.getSource() == getAddAllButton()) {
|
627 |
for (int i = 0; i < entriesSrc.size(); i++) { |
628 |
entriesDst.add(entriesSrc.get(i)); |
629 |
} |
630 |
entriesSrc.clear(); |
631 |
updateUISrcTable(); |
632 |
updateUIDstTable(); |
633 |
} |
634 |
|
635 |
//A?adir la capa seleccionada a la capa de salida
|
636 |
if(e.getSource() == getDownArrowButton()) {
|
637 |
int[] rows = getFileListSrc().getSelectedRows(); |
638 |
|
639 |
for (int i = 0; i < rows.length; i++) { |
640 |
TableEntry entry = entriesSrc.remove(rows[i]); |
641 |
entriesDst.add(entry); |
642 |
} |
643 |
|
644 |
updateUISrcTable(); |
645 |
updateUIDstTable(); |
646 |
} |
647 |
|
648 |
//Eliminar la capa seleccionada de la capa de salida
|
649 |
if(e.getSource() == getUpArrowButton()) {
|
650 |
int[] rows = getFileListDst().getSelectedRows(); |
651 |
|
652 |
for (int i = rows.length - 1; i >= 0; i--) { |
653 |
TableEntry entry = entriesDst.remove(rows[i]); |
654 |
entriesSrc.add(entry); |
655 |
} |
656 |
|
657 |
updateUISrcTable(); |
658 |
updateUIDstTable(); |
659 |
} |
660 |
|
661 |
//A?ade ficheros desde disco
|
662 |
if(e.getSource() == getAddFilesButton()) {
|
663 |
if(listener != null) { |
664 |
JFileChooser fileChooser = createJFileChooser(false); |
665 |
int result = fileChooser.showOpenDialog(this); |
666 |
|
667 |
if (result == JFileChooser.APPROVE_OPTION) { |
668 |
File[] files = fileChooser.getSelectedFiles(); |
669 |
listener.actionAddFiles(new AddFilesEvent(getAddFilesButton(), files));
|
670 |
} |
671 |
} |
672 |
} |
673 |
|
674 |
//Elimina ficheros desde disco
|
675 |
if(e.getSource() == getAddDirButton()) {
|
676 |
if(listener != null) { |
677 |
JFileChooser fileChooser = createJFileChooser(true); |
678 |
int result = fileChooser.showOpenDialog(this); |
679 |
|
680 |
if (result == JFileChooser.APPROVE_OPTION) { |
681 |
File folder = fileChooser.getSelectedFile();
|
682 |
String[] list = folder.list(); |
683 |
File[] files = filterFileList(list, folder); |
684 |
listener.actionAddFolder(new AddFilesEvent(getAddFilesButton(), files));
|
685 |
} |
686 |
} |
687 |
} |
688 |
} |
689 |
|
690 |
private File[] filterFileList(String[] f, File folder) { |
691 |
List<File> list = new ArrayList<File>(); |
692 |
for (int i = 0; i < f.length; i++) { |
693 |
if(isInList(f[i]))
|
694 |
list.add(new File(folder.getAbsolutePath() + File.separator + f[i])); |
695 |
} |
696 |
return list.toArray(new File[list.size()]); |
697 |
} |
698 |
|
699 |
private boolean isInList(String name) { |
700 |
for (int i = 0; i < suffixList.size(); i++) { |
701 |
String suffix = suffixList.get(i);
|
702 |
if(name.endsWith("." + suffix)) |
703 |
return true; |
704 |
} |
705 |
return false; |
706 |
} |
707 |
|
708 |
protected JFileChooser createJFileChooser(boolean folder) { |
709 |
JFileChooser fileChooser = new JFileChooser(lastFolder, JFileChooser.getLastPath(lastFolder, null)); |
710 |
fileChooser.setMultiSelectionEnabled(true);
|
711 |
fileChooser.setAcceptAllFileFilterUsed(false);
|
712 |
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
|
713 |
if(folder) {
|
714 |
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
715 |
fileChooser.addChoosableFileFilter(new RasterFormatFileFilter());
|
716 |
} else {
|
717 |
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
718 |
fileChooser.addChoosableFileFilter(new RasterFormatFileFilter(suffixList));
|
719 |
} |
720 |
return fileChooser;
|
721 |
} |
722 |
|
723 |
public RasterDataStore getResult(boolean tiled) { |
724 |
try {
|
725 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
726 |
DataServerExplorerParameters explParams = dataManager.createServerExplorerParameters(MosaicProvider.NAME); |
727 |
DataServerExplorer explorer = dataManager.openServerExplorer(MosaicProvider.NAME, explParams); |
728 |
MosaicDataParameters newParamsMosaic = (MosaicDataParameters)dataManager.createStoreParameters(explorer.getProviderName()); |
729 |
|
730 |
newParamsMosaic.setURI(folder + File.separator + file + MosaicRasterFormat.getSuffix());
|
731 |
newParamsMosaic.setPixelSize(getMinPixelSize()); |
732 |
|
733 |
for (int i = 0; i < entriesDst.size(); i++) { |
734 |
RasterDataStore store = (RasterDataStore)entriesDst.get(i).obj; |
735 |
RasterProvider prov = (RasterProvider)store.getProvider(); |
736 |
if(prov != null) |
737 |
newParamsMosaic.addProvider(prov); |
738 |
} |
739 |
|
740 |
if(tiled) {
|
741 |
DataManager manager = DALLocator.getDataManager(); |
742 |
TileDataParameters tileParams = null;
|
743 |
try {
|
744 |
tileParams = (TileDataParameters) manager.createStoreParameters("Tile Store");
|
745 |
} catch (ProviderNotRegisteredException e) {
|
746 |
throw new InitializeException(e.getMessage(), e); |
747 |
} |
748 |
tileParams.setDataParameters(newParamsMosaic); |
749 |
|
750 |
CoverageStoreProvider provider = (CoverageStoreProvider)dataManager.createProvider(null, tileParams);
|
751 |
RasterDataStore store = RasterLocator.getManager().getProviderServices().open(provider, tileParams); |
752 |
return store;
|
753 |
|
754 |
} else {
|
755 |
MosaicProvider provider = (MosaicProvider)dataManager.createProvider(null, newParamsMosaic);
|
756 |
RasterDataStore store = RasterLocator.getManager().getProviderServices().open(provider, newParamsMosaic); |
757 |
return store;
|
758 |
} |
759 |
|
760 |
} catch(ValidateDataParametersException e) {
|
761 |
log.debug("Error validating parameters", e);
|
762 |
} catch (InitializeException e) {
|
763 |
log.debug("Error initializating Mosaic Store", e);
|
764 |
} catch (ProviderNotRegisteredException e) {
|
765 |
log.debug("Error looking for the provider", e);
|
766 |
} catch (RasterDriverException e) {
|
767 |
log.debug("Error creating the Store", e);
|
768 |
} catch (LocatorException e) {
|
769 |
log.debug("Error creating the Store", e);
|
770 |
} catch (NotSupportedExtensionException e) {
|
771 |
log.debug("Error creating the Store", e);
|
772 |
} |
773 |
|
774 |
return null; |
775 |
} |
776 |
|
777 |
private double getMinPixelSize() { |
778 |
double cellsize = Integer.MAX_VALUE; |
779 |
for (int i = 0; i < entriesDst.size(); i++) { |
780 |
if(entriesDst.get(i).cellsize < cellsize)
|
781 |
cellsize = entriesDst.get(i).cellsize; |
782 |
} |
783 |
return cellsize;
|
784 |
} |
785 |
|
786 |
} |