root / trunk / extensions / extRasterTools-SE / src-test-ui / org / gvsig / rastertools / colortableJaume / TestComboBoxColorTable.java @ 12838
History | View | Annotate | Download (3.11 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.colortableJaume; |
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 |
|
33 |
import com.iver.cit.gvsig.gui.styling.ColorTablePaint; |
34 |
/**
|
35 |
*
|
36 |
* @version 17/04/2007
|
37 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
38 |
*/
|
39 |
public class TestComboBoxColorTable { |
40 |
private JFrame frame = new JFrame(); |
41 |
private JComboBox jComboBox = null; |
42 |
|
43 |
private String palettesPath = System.getProperty("user.home") + |
44 |
File.separator +
|
45 |
"gvSIG" + // PluginServices.getArguments()[0] + |
46 |
File.separator + "colortable"; |
47 |
|
48 |
public TestComboBoxColorTable() {
|
49 |
super();
|
50 |
initialize(); |
51 |
} |
52 |
|
53 |
public static void main(String[] args){ |
54 |
new TestComboBoxColorTable();
|
55 |
} |
56 |
|
57 |
private void initialize() { |
58 |
jComboBox = new JComboBox(); |
59 |
|
60 |
ArrayList fileList = ColorTableLibraryPersistence.getPaletteFileList(palettesPath);
|
61 |
|
62 |
for (int i = 0; i < fileList.size(); i++) { |
63 |
ArrayList paletteItems = new ArrayList(); |
64 |
String paletteName = ColorTableLibraryPersistence.loadPalette(palettesPath, (String) fileList.get(i), paletteItems); |
65 |
|
66 |
if (paletteItems.size() <= 0) |
67 |
continue;
|
68 |
|
69 |
ColorTable colorTable = new ColorTable();
|
70 |
colorTable.setName(paletteName); |
71 |
colorTable.createPaletteFromColorItems(paletteItems, true);
|
72 |
colorTable.setInterpolated(true);
|
73 |
|
74 |
ArrayList array = new ArrayList(); |
75 |
array.add(paletteName); |
76 |
array.add(new ColorTablePaint(colorTable));
|
77 |
|
78 |
jComboBox.addItem(array); |
79 |
} |
80 |
|
81 |
frame.setContentPane(jComboBox); |
82 |
frame.setSize(new java.awt.Dimension(400, 60)); |
83 |
frame.setResizable(true);
|
84 |
frame.setTitle("Tablas de color");
|
85 |
frame.setVisible(true);
|
86 |
frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
87 |
|
88 |
jComboBox.setRenderer(new ListCellRenderer() { |
89 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
90 |
ArrayList array = (ArrayList) value; |
91 |
|
92 |
|
93 |
PaintItem paintItem = new PaintItem((String) array.get(0), (ColorTablePaint) array.get(1), isSelected); |
94 |
return paintItem;
|
95 |
} |
96 |
}); |
97 |
} |
98 |
} |