Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.fmap.mapcontext.raster.swing / org.gvsig.fmap.mapcontext.raster.swing.impl / src / main / java / org / gvsig / fmap / mapcontext / raster / swing / impl / bands / ColorInterpretationCellEditor.java @ 6701

History | View | Annotate | Download (3.18 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2017 gvSIG Association
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.mapcontext.raster.swing.impl.bands;
24

    
25
import java.awt.Component;
26
import java.util.List;
27

    
28
import javax.swing.AbstractCellEditor;
29
import javax.swing.JComboBox;
30
import javax.swing.JTable;
31
import javax.swing.table.TableCellEditor;
32

    
33
import org.gvsig.raster.lib.legend.api.ColorInterpretation;
34
import org.gvsig.tools.ToolsLocator;
35

    
36

    
37
/**
38
 * @author fdiaz
39
 *
40
 */
41
public class ColorInterpretationCellEditor extends AbstractCellEditor implements TableCellEditor {
42

    
43
    /**
44
     *
45
     */
46
    private static final long serialVersionUID = 8964406967059115883L;
47
    private List<String> colorSpace;
48
    private JComboBox<ItemColor> comboBox;
49
    /**
50
     * @param colorSpace
51
     */
52
    public ColorInterpretationCellEditor(List<String> colorSpace) {
53
        this.colorSpace = colorSpace;
54
    }
55

    
56
    @Override
57
    public Object getCellEditorValue() {
58
        return ((ItemColor)comboBox.getSelectedItem()).key;
59
    }
60

    
61
    @Override
62
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
63

    
64
        comboBox = new JComboBox<ItemColor>();
65
        int i=0;
66
        int selected=i;
67
        comboBox.addItem(new ItemColor(ColorInterpretation.UNDEFINED_BAND));
68
        if(ColorInterpretation.UNDEFINED_BAND.equalsIgnoreCase((String)value)){
69
            selected=i;
70
        };
71
        i++;
72
        for (String string : colorSpace) {
73
            comboBox.addItem(new ItemColor(string));
74
            if(string.equalsIgnoreCase((String)value)){
75
                selected=i;
76
            };
77
            i++;
78
        }
79
        comboBox.addItem(new ItemColor(ColorInterpretation.GRAY_BAND));
80
        if(ColorInterpretation.GRAY_BAND.equalsIgnoreCase((String)value)){
81
            selected=i;
82
        };
83
        i++;
84
        comboBox.addItem(new ItemColor(ColorInterpretation.PALETTE_BAND));
85
        if(ColorInterpretation.PALETTE_BAND.equalsIgnoreCase((String)value)){
86
            selected=i;
87
        };
88
        i++;
89

    
90
        comboBox.setSelectedItem(selected);
91
        return comboBox;
92
    }
93

    
94
    class ItemColor {
95
        private String key;
96

    
97
        public ItemColor(String key){
98
            this.key = key;
99
        }
100

    
101
        public String toString() {
102
            return ToolsLocator.getI18nManager().getTranslation(key);
103
        }
104

    
105
    }
106

    
107
}