Revision 16560
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/colortable/ui/ColorTablePanel.java | ||
---|---|---|
33 | 33 |
import javax.swing.JButton; |
34 | 34 |
import javax.swing.JCheckBox; |
35 | 35 |
import javax.swing.JComponent; |
36 |
import javax.swing.JFileChooser; |
|
36 | 37 |
import javax.swing.JOptionPane; |
37 | 38 |
import javax.swing.JPanel; |
38 | 39 |
import javax.swing.JScrollPane; |
39 | 40 |
import javax.swing.JSplitPane; |
40 | 41 |
import javax.swing.JTabbedPane; |
42 |
import javax.swing.border.Border; |
|
41 | 43 |
import javax.swing.event.ChangeEvent; |
42 | 44 |
import javax.swing.event.ChangeListener; |
45 |
import javax.swing.plaf.basic.BasicSplitPaneDivider; |
|
46 |
import javax.swing.plaf.basic.BasicSplitPaneUI; |
|
43 | 47 |
|
44 | 48 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
45 | 49 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
... | ... | |
54 | 58 |
import org.gvsig.raster.datastruct.ColorItem; |
55 | 59 |
import org.gvsig.raster.datastruct.ColorTable; |
56 | 60 |
import org.gvsig.raster.datastruct.Extent; |
61 |
import org.gvsig.raster.datastruct.io.RasterLegendIO; |
|
62 |
import org.gvsig.raster.datastruct.io.exceptions.RasterLegendIONotFound; |
|
57 | 63 |
import org.gvsig.raster.datastruct.serializer.ColorTableLibraryPersistence; |
58 | 64 |
import org.gvsig.raster.datastruct.serializer.ColorTableRmfSerializer; |
59 | 65 |
import org.gvsig.raster.grid.GridPalette; |
... | ... | |
61 | 67 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
62 | 68 |
import org.gvsig.raster.grid.filter.bands.ColorTableFilter; |
63 | 69 |
import org.gvsig.raster.grid.render.Rendering; |
70 |
import org.gvsig.raster.util.ExtendedFileFilter; |
|
64 | 71 |
import org.gvsig.raster.util.RasterToolsUtil; |
65 | 72 |
import org.gvsig.raster.util.RasterUtilities; |
66 | 73 |
import org.gvsig.rastertools.colortable.ColorTableListener; |
... | ... | |
107 | 114 |
private JButton buttonAdd = null; |
108 | 115 |
private JButton buttonDel = null; |
109 | 116 |
private JButton buttonCopy = null; |
117 |
private JButton buttonImport = null; |
|
118 |
private JButton buttonExport = null; |
|
110 | 119 |
private ColorTableDialog colorTableDialog = null; |
111 | 120 |
//[end] |
112 | 121 |
|
... | ... | |
149 | 158 |
jSplitPane1.setLeftComponent(panelLeft); |
150 | 159 |
jSplitPane1.setRightComponent(getPanelRight()); |
151 | 160 |
jSplitPane1.setResizeWeight(1.0); |
152 |
jSplitPane1.setOneTouchExpandable(true); |
|
153 | 161 |
jSplitPane1.setContinuousLayout(true); |
162 |
jSplitPane1.setUI(new BasicSplitPaneUI() { |
|
163 |
public BasicSplitPaneDivider createDefaultDivider() { |
|
164 |
return new BasicSplitPaneDivider(this) { |
|
165 |
public void setBorder(Border b) { |
|
166 |
} |
|
167 |
}; |
|
168 |
} |
|
169 |
}); |
|
154 | 170 |
jSplitPane1.setBorder(null); |
155 | 171 |
|
172 |
|
|
156 | 173 |
add(jSplitPane1, BorderLayout.CENTER); |
157 | 174 |
|
158 | 175 |
ArrayList fileList = ColorTableLibraryPersistence.getPaletteFileList(palettesPath); |
... | ... | |
267 | 284 |
if (jPanelRight == null) { |
268 | 285 |
jPanelRight = new JSplitPane(); |
269 | 286 |
jPanelRight.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); |
270 |
jPanelRight.setOneTouchExpandable(true); |
|
271 | 287 |
jPanelRight.setContinuousLayout(true); |
272 |
jPanelRight.setBorder(null); |
|
273 | 288 |
jPanelRight.setResizeWeight(0.0); |
274 | 289 |
jPanelRight.setPreferredSize(new Dimension(220, 0)); |
275 | 290 |
jPanelRight.setMinimumSize(new Dimension(220, 0)); |
276 | 291 |
|
277 | 292 |
jPanelRight.setTopComponent(getPanelPreview()); |
278 | 293 |
jPanelRight.setBottomComponent(getPanelListView()); |
294 |
jPanelRight.setUI(new BasicSplitPaneUI() { |
|
295 |
public BasicSplitPaneDivider createDefaultDivider() { |
|
296 |
return new BasicSplitPaneDivider(this) { |
|
297 |
public void setBorder(Border b) { |
|
298 |
} |
|
299 |
}; |
|
300 |
} |
|
301 |
}); |
|
302 |
jPanelRight.setBorder(null); |
|
279 | 303 |
} |
280 | 304 |
return jPanelRight; |
281 | 305 |
} |
... | ... | |
326 | 350 |
panelButtons.setLayout(flowLayout5); |
327 | 351 |
|
328 | 352 |
panelButtons.add(getButtonAdd(), null); |
353 |
panelButtons.add(getButtonExport(), null); |
|
354 |
panelButtons.add(getButtonImport(), null); |
|
329 | 355 |
panelButtons.add(getButtonDel(), null); |
330 |
panelButtons.add(getButtonCopy(), null); |
|
331 | 356 |
} |
332 | 357 |
return panelButtons; |
333 | 358 |
} |
... | ... | |
377 | 402 |
* Devuelve el jButtonDel |
378 | 403 |
* @return |
379 | 404 |
*/ |
380 |
private JButton getButtonCopy() {
|
|
381 |
if (buttonCopy == null) {
|
|
405 |
private JButton getButtonImport() {
|
|
406 |
if (buttonImport == null) {
|
|
382 | 407 |
ImageIcon icon = null; |
383 | 408 |
try { |
384 |
icon = PluginServices.getIconTheme().get("duplicate-icon");
|
|
409 |
icon = PluginServices.getIconTheme().get("import-icon");
|
|
385 | 410 |
} catch (NullPointerException n) { |
386 | 411 |
// No ha encontrado el icono, no lo muestra. |
387 | 412 |
} |
388 |
buttonCopy = new JButton(icon);
|
|
389 |
buttonCopy.setPreferredSize(new Dimension(22, 19));
|
|
390 |
buttonCopy.addActionListener(this);
|
|
391 |
buttonCopy.setToolTipText(PluginServices.getText(this, "duplicar_libreria"));
|
|
413 |
buttonImport = new JButton(icon);
|
|
414 |
buttonImport.setPreferredSize(new Dimension(22, 19));
|
|
415 |
buttonImport.addActionListener(this);
|
|
416 |
buttonImport.setToolTipText(PluginServices.getText(this, "import_libreria"));
|
|
392 | 417 |
} |
393 |
return buttonCopy;
|
|
418 |
return buttonImport;
|
|
394 | 419 |
} |
420 |
|
|
421 |
/** |
|
422 |
* Devuelve el jButtonDel |
|
423 |
* @return |
|
424 |
*/ |
|
425 |
private JButton getButtonExport() { |
|
426 |
if (buttonExport == null) { |
|
427 |
ImageIcon icon = null; |
|
428 |
try { |
|
429 |
icon = PluginServices.getIconTheme().get("export-icon"); |
|
430 |
} catch (NullPointerException n) { |
|
431 |
// No ha encontrado el icono, no lo muestra. |
|
432 |
} |
|
433 |
buttonExport = new JButton(icon); |
|
434 |
buttonExport.setPreferredSize(new Dimension(22, 19)); |
|
435 |
buttonExport.addActionListener(this); |
|
436 |
buttonExport.setToolTipText(PluginServices.getText(this, "export_libreria")); |
|
437 |
} |
|
438 |
return buttonExport; |
|
439 |
} |
|
395 | 440 |
//[end] |
396 | 441 |
|
397 | 442 |
/** |
... | ... | |
773 | 818 |
} |
774 | 819 |
} |
775 | 820 |
|
776 |
if (e.getSource() == getButtonCopy()) { |
|
777 |
ColorTable colorTable = (ColorTable) getColorTableData().getColorTable().clone(); |
|
778 |
colorTable.setName(PluginServices.getText(this, "nueva_libreria")); |
|
779 |
colorTable.setInterpolated(true); |
|
821 |
if (e.getSource() == getButtonExport()) { |
|
822 |
JFileChooser chooser = new JFileChooser(); |
|
823 |
chooser.setAcceptAllFileFilterUsed(false); |
|
780 | 824 |
|
781 |
ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), PluginServices.getText(this, "nueva_libreria"));
|
|
782 |
item.setTag(item.getName() + ".xml");
|
|
783 |
getListViewComponent().addItem(item);
|
|
784 |
getListViewComponent().setSelectedIndex(getListViewComponent().getItems().size() - 1);
|
|
785 |
reloadColorTableFromListViewComponent();
|
|
786 |
((ColorTableIconPainter) item.getIcon()).getColorTable().setName(item.getName());
|
|
787 |
getColorTableData().getColorTable().setName(((ColorTableIconPainter) item.getIcon()).getColorTable().getName());
|
|
825 |
String[] formats = RasterLegendIO.getFormats();
|
|
826 |
ExtendedFileFilter fileFilter = null;
|
|
827 |
for (int i = 0; i < formats.length; i++) {
|
|
828 |
fileFilter = new ExtendedFileFilter();
|
|
829 |
fileFilter.addExtension(formats[i]);
|
|
830 |
chooser.addChoosableFileFilter(fileFilter);
|
|
831 |
}
|
|
788 | 832 |
|
789 |
ColorTableLibraryPersistence.save_to_1_1(palettesPath, getColorTableData().getColorTable()); |
|
833 |
int returnVal = chooser.showSaveDialog(this); |
|
834 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
|
835 |
try { |
|
836 |
ColorTable colorTable = (ColorTable) getColorTableData().getColorTable().clone(); |
|
837 |
|
|
838 |
fileFilter = null; |
|
839 |
for (int i = 0; i < formats.length; i++) { |
|
840 |
fileFilter = new ExtendedFileFilter(); |
|
841 |
fileFilter.addExtension(formats[i]); |
|
842 |
if (fileFilter.accept(chooser.getSelectedFile())) { |
|
843 |
RasterLegendIO.getRasterLegendIO(formats[i]).write(colorTable, chooser.getSelectedFile()); |
|
844 |
break; |
|
845 |
} |
|
846 |
} |
|
847 |
} catch (IOException e1) { |
|
848 |
e1.printStackTrace(); |
|
849 |
} catch (RasterLegendIONotFound e1) { |
|
850 |
e1.printStackTrace(); |
|
851 |
} |
|
852 |
} |
|
790 | 853 |
} |
791 | 854 |
|
855 |
if (e.getSource() == getButtonImport()) { |
|
856 |
JFileChooser chooser = new JFileChooser(); |
|
857 |
chooser.setAcceptAllFileFilterUsed(false); |
|
858 |
|
|
859 |
String[] formats = RasterLegendIO.getFormats(); |
|
860 |
ExtendedFileFilter allFilters = new ExtendedFileFilter(); |
|
861 |
ExtendedFileFilter fileFilter = null; |
|
862 |
for (int i = 0; i < formats.length; i++) { |
|
863 |
fileFilter = new ExtendedFileFilter(); |
|
864 |
fileFilter.addExtension(formats[i]); |
|
865 |
allFilters.addExtension(formats[i]); |
|
866 |
|
|
867 |
chooser.addChoosableFileFilter(fileFilter); |
|
868 |
} |
|
869 |
allFilters.setDescription(PluginServices.getText(this, "todos_soportados")); |
|
870 |
chooser.addChoosableFileFilter(allFilters); |
|
871 |
chooser.setFileFilter(allFilters); |
|
872 |
|
|
873 |
int returnVal = chooser.showOpenDialog(this); |
|
874 |
|
|
875 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
|
876 |
try { |
|
877 |
fileFilter = null; |
|
878 |
for (int i = 0; i < formats.length; i++) { |
|
879 |
fileFilter = new ExtendedFileFilter(); |
|
880 |
fileFilter.addExtension(formats[i]); |
|
881 |
if (fileFilter.accept(chooser.getSelectedFile())) { |
|
882 |
ColorTable colorTable = RasterLegendIO.getRasterLegendIO(formats[i]).read(chooser.getSelectedFile()); |
|
883 |
|
|
884 |
colorTable.setInterpolated(true); |
|
885 |
|
|
886 |
ListViewItem item = new ListViewItem(new ColorTableIconPainter(colorTable), colorTable.getName()); |
|
887 |
item.setTag(item.getName() + ".xml"); |
|
888 |
getListViewComponent().addItem(item); |
|
889 |
getListViewComponent().setSelectedIndex(getListViewComponent().getItems().size() - 1); |
|
890 |
reloadColorTableFromListViewComponent(); |
|
891 |
((ColorTableIconPainter) item.getIcon()).getColorTable().setName(item.getName()); |
|
892 |
getColorTableData().getColorTable().setName(((ColorTableIconPainter) item.getIcon()).getColorTable().getName()); |
|
893 |
|
|
894 |
ColorTableLibraryPersistence.save_to_1_1(palettesPath, getColorTableData().getColorTable()); |
|
895 |
break; |
|
896 |
} |
|
897 |
} |
|
898 |
} catch (IOException e1) { |
|
899 |
e1.printStackTrace(); |
|
900 |
} catch (RasterLegendIONotFound e1) { |
|
901 |
e1.printStackTrace(); |
|
902 |
} |
|
903 |
} |
|
904 |
} |
|
905 |
|
|
792 | 906 |
if (e.getSource() == getButtonDel()) { |
793 | 907 |
if (getListViewComponent().getSelectedIndices().length > 0) { |
794 | 908 |
if (RasterToolsUtil.messageBoxYesOrNot("desea_borrar_librerias", this)) { |
Also available in: Unified diff