Statistics
| Revision:

svn-gvsig-desktop / branches / v05 / extensions / extWMS / src / com / iver / cit / gvsig / gui / wizards / StylesTableModel.java @ 3855

History | View | Annotate | Download (7.39 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??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
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
/* CVS MESSAGES:
43
*
44
* $Id: StylesTableModel.java 3855 2006-01-31 16:25:24Z jaume $
45
* $Log$
46
* Revision 1.2.2.3  2006-01-31 16:25:24  jaume
47
* correcciones de bugs
48
*
49
* Revision 1.3  2006/01/26 16:07:14  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.2.2.1  2006/01/26 12:59:32  jaume
53
* 0.5
54
*
55
* Revision 1.2  2006/01/24 14:36:33  jaume
56
* This is the new version
57
*
58
* Revision 1.1.2.1  2005/12/27 10:47:33  jaume
59
* configured to restore previous downloads instead of download each time
60
*
61
* Revision 1.1.2.1  2005/12/26 16:51:40  jaume
62
* Handles STYLES, layer saving does nothing ??
63
*
64
*
65
*/
66
/**
67
 * 
68
 */
69
package com.iver.cit.gvsig.gui.wizards;
70

    
71
import java.util.ArrayList;
72
import java.util.Hashtable;
73
import java.util.Vector;
74

    
75
import javax.swing.event.TableModelListener;
76
import javax.swing.table.TableModel;
77

    
78
import com.iver.andami.PluginServices;
79
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
80
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode.FMapWMSStyle;
81

    
82

    
83
/**
84
 * @author jaume
85
 *
86
 */
87
public class StylesTableModel implements TableModel {
88
    private final int COLUMN_COUNT = 2;
89
    
90
    private final int LAYERS_COLUMN = 0;
91
    private final int STYLES_COLUMN = 1;
92
    private boolean editable = true;
93
    
94
    private final String[] COLUMN_NAMES =
95
        new String[] {
96
            PluginServices.getText(this, "capa"), 
97
            PluginServices.getText(this, "estilo")
98
        };
99

    
100
    /**
101
     * key: the layer, value: row index (as Integer)
102
     */
103
    private Hashtable indexTable = new Hashtable();
104
    /**
105
     * key: row index (as Integer), value: the layer
106
     */
107
    private Hashtable layers = new Hashtable();
108
    /**
109
     * key: row index (as Integer), value: the index of the selected style (as Integer)
110
     */
111
    private Hashtable selectedStyle = new Hashtable();
112
    
113
    private ArrayList listeners = new ArrayList();
114
    
115
    public int getColumnCount() {
116
        return COLUMN_COUNT;
117
    }
118

    
119
    public int getRowCount() {
120
        return layers.size();
121
    }
122

    
123
    /* (non-Javadoc)
124
     * @see javax.swing.table.TableModel#isCellEditable(int, int)
125
     */
126
    public boolean isCellEditable(int rowIndex, int columnIndex) {
127
        return (editable && columnIndex == STYLES_COLUMN);
128
    }
129

    
130
    /* (non-Javadoc)
131
     * @see javax.swing.table.TableModel#getColumnClass(int)
132
     */
133
    public Class getColumnClass(int columnIndex) {
134
        if (columnIndex == LAYERS_COLUMN) return WMSLayerNode.class;
135
        if (columnIndex == STYLES_COLUMN) return String.class;
136
        return null;
137
    }
138

    
139
    /* (non-Javadoc)
140
     * @see javax.swing.table.TableModel#getValueAt(int, int)
141
     */
142
    public Object getValueAt(int rowIndex, int columnIndex) {
143

    
144
        Integer index = new Integer(rowIndex);
145
        
146
        if (columnIndex == STYLES_COLUMN){
147
            if (layers.containsKey(index)){
148
                WMSLayerNode node = (WMSLayerNode) layers.get(new Integer(rowIndex));
149
                int i = ((Integer) selectedStyle.get(new Integer(rowIndex))).intValue();
150
                if (i == -1) {
151
                    // will take default style for the layer
152
                    return "<"+PluginServices.getText(this, "estilo_por_defecto")+">";
153
                }
154
                return node.getStyles().get(i);
155
            }
156
        } else if (columnIndex == LAYERS_COLUMN){
157
            return (WMSLayerNode) layers.get(new Integer(rowIndex));
158
        }
159
        return null;       
160
    }
161

    
162

    
163
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
164

    
165
        if (columnIndex == LAYERS_COLUMN){
166
            layers.put(new Integer(rowIndex), aValue);
167
            selectedStyle.put(new Integer(rowIndex), new Integer(-1));
168
            indexTable.put(aValue, new Integer(rowIndex));
169
        } else if (columnIndex == LAYERS_COLUMN){
170
        }
171
    }
172

    
173
    /* (non-Javadoc)
174
     * @see javax.swing.table.TableModel#getColumnName(int)
175
     */
176
    public String getColumnName(int columnIndex) {
177
        if (columnIndex > COLUMN_COUNT)
178
            return null;
179
        return COLUMN_NAMES[columnIndex];
180
    }
181

    
182
    /* (non-Javadoc)
183
     * @see javax.swing.table.TableModel#addTableModelListener(javax.swing.event.TableModelListener)
184
     */
185
    public void addTableModelListener(TableModelListener l) {
186
        listeners.add(l);
187
    }
188

    
189
    /* (non-Javadoc)
190
     * @see javax.swing.table.TableModel#removeTableModelListener(javax.swing.event.TableModelListener)
191
     */
192
    public void removeTableModelListener(TableModelListener l) {
193
        listeners.remove(l);
194
    }
195
    
196
    /**
197
     * While the table remains locked it cannot be edited at any of its cells.
198
     */
199
    public void lock(){
200
        this.editable = false;
201
    }
202

    
203
    /**
204
     * Unlocks the table. So, it can be edited.
205
     */
206
    public void unlock(){
207
        this.editable = true;
208
    }
209

    
210
    /**
211
     * Appends a new row to this table. The new row is situated at the end of the
212
     * table.
213
     * 
214
     * @param layer
215
     * @return
216
     */
217
    public int addRow(WMSLayerNode layer){
218
        int position     = layers.size();
219
        setValueAt(layer, position, LAYERS_COLUMN);
220
        return position;
221
    }
222

    
223
    /**
224
     * Removes any element on this table.
225
     */
226
    public void removeAll() {
227
        indexTable.clear();
228
        layers.clear();
229
        selectedStyle.clear();
230
    }
231
    
232
    public WMSLayerNode getLayerAt(int rowIndex){
233
        return (WMSLayerNode) layers.get(new Integer(rowIndex));
234
    }
235

    
236
    /**
237
     * Sets to selected the index of the style within the style list
238
     * defined by the layer.
239
     * @param myRow
240
     * @param selectedIndex
241
     */
242
    public void setSelectedStyle(int row, int selectedIndex) {
243
        selectedStyle.put(new Integer(row), new Integer(selectedIndex));
244
    }
245
    
246
    /**
247
     * Returns the selected styles for the layers. 
248
     * @return
249
     */
250
    public Vector getStyles(WMSLayerNode[] layers){
251
        Vector myStyles = new Vector();
252
        
253
        for (int i=0; i<layers.length; i++){
254
            WMSLayerNode node = layers[i]; //(WMSLayerNode) this.layers.get(new Integer(i));
255
            Integer idLayer = (Integer) indexTable.get(node);
256
            int idStyle = ((Integer) selectedStyle.get(idLayer)).intValue();
257
            if (idStyle == -1)
258
                myStyles.add("");
259
            else
260
                myStyles.add(((FMapWMSStyle)node.getStyles().get(idStyle)).name);
261
            
262
        }
263
        return myStyles;
264
    }
265
}