root / trunk / extensions / extRasterTools-SE / src-test-ui / org / gvsig / rastertools / colortable / combobox / TestComboBoxColorTable.java @ 13120
History | View | Annotate | Download (3.12 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.rastertools.colortable.combobox; |
20 |
|
21 |
import java.awt.Component; |
22 |
import java.io.File; |
23 |
import java.util.ArrayList; |
24 |
|
25 |
import javax.swing.JComboBox; |
26 |
import javax.swing.JFrame; |
27 |
import javax.swing.JList; |
28 |
import javax.swing.ListCellRenderer; |
29 |
|
30 |
import org.gvsig.raster.datastruct.ColorTable; |
31 |
import org.gvsig.raster.datastruct.serializer.ColorTableLibraryPersistence; |
32 |
import org.gvsig.rastertools.colortable.ui.ColorTablePaint; |
33 |
/**
|
34 |
*
|
35 |
* @version 17/04/2007
|
36 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
37 |
*/
|
38 |
public class TestComboBoxColorTable { |
39 |
private JFrame frame = new JFrame(); |
40 |
private JComboBox jComboBox = null; |
41 |
|
42 |
private String palettesPath = System.getProperty("user.home") + |
43 |
File.separator +
|
44 |
"gvSIG" + // PluginServices.getArguments()[0] + |
45 |
File.separator + "colortable"; |
46 |
|
47 |
public TestComboBoxColorTable() {
|
48 |
super();
|
49 |
initialize(); |
50 |
} |
51 |
|
52 |
public static void main(String[] args){ |
53 |
new TestComboBoxColorTable();
|
54 |
} |
55 |
|
56 |
private void initialize() { |
57 |
jComboBox = new JComboBox(); |
58 |
|
59 |
ArrayList fileList = ColorTableLibraryPersistence.getPaletteFileList(palettesPath);
|
60 |
|
61 |
for (int i = 0; i < fileList.size(); i++) { |
62 |
ArrayList paletteItems = new ArrayList(); |
63 |
String paletteName = ColorTableLibraryPersistence.loadPalette(palettesPath, (String) fileList.get(i), paletteItems); |
64 |
|
65 |
if (paletteItems.size() <= 0) |
66 |
continue;
|
67 |
|
68 |
ColorTable colorTable = new ColorTable();
|
69 |
colorTable.setName(paletteName); |
70 |
colorTable.createPaletteFromColorItems(paletteItems, true);
|
71 |
colorTable.setInterpolated(true);
|
72 |
|
73 |
ArrayList array = new ArrayList(); |
74 |
array.add(paletteName); |
75 |
array.add(new ColorTablePaint(colorTable));
|
76 |
|
77 |
jComboBox.addItem(array); |
78 |
} |
79 |
|
80 |
frame.setContentPane(jComboBox); |
81 |
frame.setSize(new java.awt.Dimension(400, 60)); |
82 |
frame.setResizable(true);
|
83 |
frame.setTitle("Tablas de color");
|
84 |
frame.setVisible(true);
|
85 |
frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
86 |
|
87 |
jComboBox.setRenderer(new ListCellRenderer() { |
88 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
89 |
ArrayList array = (ArrayList) value; |
90 |
|
91 |
|
92 |
PaintItem paintItem = new PaintItem((String) array.get(0), (ColorTablePaint) array.get(1), isSelected); |
93 |
return paintItem;
|
94 |
} |
95 |
}); |
96 |
} |
97 |
} |