Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / wms / SRSListModel.java @ 1850

History | View | Annotate | Download (3.33 KB)

1 1103 fjp
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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 312 fernando
package com.iver.cit.gvsig.gui.wms;
42
43
import java.util.ArrayList;
44
import java.util.HashMap;
45
import java.util.HashSet;
46
import java.util.Iterator;
47
48
import javax.swing.AbstractListModel;
49
50
51
/**
52
 * DOCUMENT ME!
53
 *
54
 * @author Fernando Gonz?lez Cort?s
55
 */
56
public class SRSListModel extends AbstractListModel {
57
        ArrayList comunes = new ArrayList();
58
59
    private HashSet srsSet = new HashSet();
60
        private HashMap cuenta = new HashMap();
61
        private ArrayList nombresSRS = new ArrayList();
62
63
    /**
64
     * DOCUMENT ME!
65
     *
66
     * @param srs DOCUMENT ME!
67
     */
68
    public void add(String srs) {
69
            System.out.println("A?adiendo " + srs);
70
        if (!srsSet.add(srs)) {
71
            Integer i = (Integer) cuenta.get(srs);
72
            cuenta.put(srs, new Integer(i.intValue() + 1));
73
            System.out.println("Ya hab?a, llevamos " + i.intValue() + 1);
74
        } else {
75
                        nombresSRS.add(srs);
76
            cuenta.put(srs, new Integer(1));
77
                        fireContentsChanged(this, nombresSRS.size()-1,nombresSRS.size()-1);
78
        }
79
    }
80
81
    /**
82
     * DOCUMENT ME!
83
     *
84
     * @param srs DOCUMENT ME!
85
     */
86
    public void del(String srs) {
87
            System.out.println("Eliminando SRS: "+ srs);
88
        Integer i = (Integer) cuenta.get(srs);
89
90
        if (i == null) {
91
                System.out.println("Eliminando un elemento que no estaba");
92
            return;
93
        }
94
95
        int nuevo = i.intValue() - 1;
96
97
                System.out.println("quedan " + nuevo);
98
99
        if (nuevo == 0) {
100
            cuenta.remove(srs);
101
            srsSet.remove(srs);
102
            nombresSRS.remove(srs);
103
                        fireContentsChanged(this, 0,nombresSRS.size()-1);
104
        } else {
105
            cuenta.put(srs, new Integer(nuevo));
106
        }
107
    }
108
109
    /**
110
     * DOCUMENT ME!
111
     *
112
     * @return
113
     */
114
    public Iterator iterator() {
115
        return srsSet.iterator();
116
    }
117
118
    /**
119
     * DOCUMENT ME!
120
     *
121
     * @return
122
     */
123
    public int size() {
124
        return srsSet.size();
125
    }
126
127
        /**
128
         * @see javax.swing.ListModel#getSize()
129
         */
130
        public int getSize() {
131
                return nombresSRS.size();
132
        }
133
134
        /**
135
         * @see javax.swing.ListModel#getElementAt(int)
136
         */
137
        public Object getElementAt(int index) {
138
                return nombresSRS.get(index);
139
        }
140
}