Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / colortable / panels / ColorTTable.java @ 12514

History | View | Annotate | Download (3.03 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.panels;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.Color;
23
import java.util.ArrayList;
24

    
25
import javax.swing.JPanel;
26
import javax.swing.JTable;
27
import javax.swing.event.TableModelEvent;
28
import javax.swing.event.TableModelListener;
29

    
30
import org.gvsig.gui.beans.table.TableContainer;
31
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
32
import org.gvsig.gui.beans.table.models.TableButtonModel;
33
import org.gvsig.raster.datastruct.ColorItem;
34

    
35
import com.iver.andami.PluginServices;
36
/**
37
 *
38
 * @version 27/06/2007
39
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
40
 */
41
public class ColorTTable extends JPanel {
42
        private static final long serialVersionUID = -6971866166164473789L;
43
        private TableContainer tableContainer = null;
44

    
45
        public ColorTTable() {
46
                initialize();
47
        }
48

    
49
        private void initialize() {
50
                setLayout(new BorderLayout());
51
                add(getTableContainer(), BorderLayout.CENTER);
52
        }
53

    
54
        /**
55
         * Borra todas las filas de la tabla.
56
         */
57
        public void clearTable() {
58
                try {
59
                        getTableContainer().removeAllRows();
60
                } catch (NotInitializeException e) {
61
                        e.printStackTrace();
62
                }
63
        }
64

    
65
        private String getColorString(Color c) {
66
                return c.getRed() + ", " + c.getGreen() + ", " + c.getBlue();
67
        }
68

    
69
        /**
70
         * A?ade una fila a la tabla asignando el color por par?metro. Este
71
         * color asignado ser? el que aparezca en el bot?n y en el texto RGB
72
         * @param color
73
         */
74
        public void addRowToTable(Color color, String name, Double fromRange, Double toRange, String alpha){
75
                try {
76
                        getTableContainer().addRow(new Object[] { color, name, getColorString(color), fromRange, toRange, alpha });
77
                } catch (NotInitializeException e1) {
78
                        return;
79
                }
80
        }
81

    
82
        public TableContainer getTableContainer() {
83
                if (tableContainer == null) {
84
                        String[] columnNames = {PluginServices.getText(this, "selec"), PluginServices.getText(this, "clase"), "RGB", PluginServices.getText(this, "valor"), PluginServices.getText(this, "hasta"), PluginServices.getText(this, "alpha")};
85
                        int[] columnWidths = {50, 90, 94, 95, 95, 65};
86
                        tableContainer = new TableContainer(columnNames, columnWidths);
87
                        tableContainer.setModel("TableColorModel");
88
                        tableContainer.initialize();
89
                }
90
                return tableContainer;
91
        }
92
}