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