Statistics
| Revision:

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

History | View | Annotate | Download (2.79 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

    
24
import javax.swing.JPanel;
25

    
26
import org.gvsig.gui.beans.table.TableContainer;
27
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
28

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

    
39
        public ColorTTable() {
40
                initialize();
41
        }
42

    
43
        private void initialize() {
44
                setLayout(new BorderLayout());
45
                add(getTableContainer(), BorderLayout.CENTER);
46
        }
47

    
48
        /**
49
         * Borra todas las filas de la tabla.
50
         */
51
        public void clearTable() {
52
                try {
53
                        getTableContainer().removeAllRows();
54
                } catch (NotInitializeException e) {
55
                        e.printStackTrace();
56
                }
57
        }
58

    
59
        private String getColorString(Color c) {
60
                return c.getRed() + ", " + c.getGreen() + ", " + c.getBlue();
61
        }
62

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

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