Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / principalcomponents / gui / BandTableFormat.java @ 22067

History | View | Annotate | Download (6.04 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
         *
3
         * Copyright (C) 2006 Instituto de Desarrollo Regional 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
         * For more information, contact:
20
         *
21
         *  Generalitat Valenciana
22
         *   Conselleria d'Infraestructures i Transport
23
         *   Av. Blasco Iba?ez, 50
24
         *   46010 VALENCIA
25
         *   SPAIN
26
         *
27
         *      +34 963862235
28
         *   gvsig@gva.es
29
         *      www.gvsig.gva.es
30
         *
31
         *    or
32
         *
33
         *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
         *   Campus Universitario s/n
35
         *   02071 Alabacete
36
         *   Spain
37
         *
38
         *   +34 967 599 200
39
         */
40

    
41
package org.gvsig.remotesensing.principalcomponents.gui;
42

    
43
import javax.swing.SwingUtilities;
44
import javax.swing.table.AbstractTableModel;
45

    
46
import com.iver.andami.PluginServices;
47

    
48
/**
49
 *  Clase que define el modelo de tabla contenida PrincipalComponentPanel.
50
 *  La tabla contiene dos columnas una con el identificador de la banda y otra
51
 *  con el check box para su seleccion
52
 *  
53
 * @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
54
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es) 
55
 * @version 22/10/2007  
56
 */
57
public class BandTableFormat extends AbstractTableModel {
58
   
59
        private static final long serialVersionUID = 1L;
60
        private boolean DEBUG=true;
61
        private boolean multipleSelection= true;
62

    
63
        final String[] columnNames = {PluginServices.getText(this,"banda"), ""};
64
        Object[][] data = new Object[0][0];
65
        
66
        
67
         /**
68
     * @return numero de columnas
69
     */
70
        public int getColumnCount() {
71
        return columnNames.length;
72
    }
73
    
74
         /**
75
     * @return numero de filas
76
     */
77
    public int getRowCount() {
78
        return data.length;
79
    }
80

    
81
    /**
82
     * @param  numero de columna 
83
     * @return nombre de la columna correspondiente al indice que se pasa como par?metro  
84
     */
85
    public String getColumnName(int col) {
86
        return columnNames[col];
87
    }
88
    
89
    /**
90
     * @param colum
91
     * @param row        
92
     * @return valor de la celda de la tabla
93
     */
94
    public Object getValueAt(int row, int col) {
95
        return data[row][col];
96
    }
97

    
98
    
99
    /**
100
     * @return clase de la columna cuyo indice se pasa como parametro
101
     */
102
    public Class getColumnClass(int c) {
103
        return getValueAt(0, c).getClass();
104
    }
105

    
106
    /**
107
     * @return  true si los elementos de la columna son editables
108
     */
109
    public boolean isCellEditable(int row, int col) {
110
        if (col < 1) { 
111
            return false;
112
        } else {
113
            return true;
114
        }
115
    }
116
    
117

    
118
    /**
119
     * Asina el valor a la celda
120
     * @param value valor a asignar
121
     * @param row 
122
     * @param col
123
     */
124
    public void setValueAt(Object value, int row, int col) {
125
            if (DEBUG) {
126
           // Nothing
127
        }
128
            if(multipleSelection==false){
129
                    for (int i=0; i<data.length;i++)
130
                                data[i][1]=new Boolean(false);
131
                    fireTableDataChanged();
132
            }
133
                    
134
  
135
        if (data[0][col] instanceof Integer) {
136
            try {
137
                data[row][col] = new Integer((String)value);
138
            } catch (NumberFormatException e) {
139
                if (SwingUtilities.isEventDispatchThread()) {
140
                } else {
141
                    System.err.println("User attempted to enter non-integer"
142
                                   + " value (" + value 
143
                                   + ") into an integer-only column.");
144
                }
145
            }
146
        } else {
147
            data[row][col] = value;
148
        }
149

    
150
       
151
    }
152

    
153
  
154
    /**
155
     * A?ade un elemento a la tabla
156
     * @param indetificador de la banda
157
     */
158
    public void addRow(String band, boolean active){
159
            Object[][] dataux=new Object [data.length+1][];
160
            // Objeto a a?adir
161
            Object [] newRow= {band, new Boolean(active)};
162
            for (int i=0; i<data.length; i++)
163
                    dataux[i]=data[i];
164
            dataux[data.length]=newRow;
165
            data=dataux;
166
    }
167
      
168
    
169
    /**
170
     * @return array con bandas seleccionadas a true
171
     */
172
    public boolean[] getSeleccionadas(){
173
            boolean a[]=new boolean[data.length];
174
            for (int i=0; i<data.length;i++)
175
                    if(data[i][1].equals(new Boolean(true)))
176
                            a[i]=true;
177
            return a;
178
    }
179
    
180
   
181
    /**
182
     * @return numero de bandas seleccionadas
183
     */
184
    public int getNumSelected(){
185
            int cont =0;
186
            for (int i=0;i<data.length;i++)
187
                     if(data[i][1].equals(new Boolean(true)))
188
                            cont++;
189
            return cont;
190
    }
191
    
192

    
193
    /**
194
     * Seleccion de todas las bandas de la tabla
195
     */
196
    public void seleccionarTodas(){
197
            for (int i=0;i<data.length;i++)
198
                            setValueAt(new Boolean(true), i, 1);         
199
    }
200
    
201
  
202
    /**
203
     *  No selecciona ninguna banda de la tabla
204
     */
205
    public void seleccionarNinguna(){
206
            for (int i=0;i<data.length;i++)
207
                            setValueAt(new Boolean(false), i, 1);
208
    }
209
    
210

    
211
    /**
212
     * Inicializaci?n de la tabla 
213
     */
214
    public void LimpiarLista(){
215
            data=new Object[0][0];        
216
    }
217
  
218
    
219
    /**
220
     * Asigna el titulo de la columna
221
     * */
222
    public void setColumnName(String newName){
223
            columnNames[0]= newName;
224
    }
225

    
226
    
227
    public void setMultipleSelection(boolean multipleSeleccion){
228
            this.multipleSelection=multipleSeleccion;
229
    }
230

    
231
    
232
    /**
233
     * @return indice de la primera fila seleccionada
234
     */
235
    public int getFirstSelected(){
236
            for (int i=0; i<data.length;i++)
237
                    if(data[i][1].equals(new Boolean(true)))
238
                            return i;
239
            return -1;
240
   
241
    }
242
    
243
}