gvsig-raster / org.gvsig.raster.wms / trunk / org.gvsig.raster.wms / org.gvsig.raster.wms.app.wmsclient / src / main / java / org / gvsig / raster / wms / app / wmsclient / gui / wizard / SRSListModel.java @ 2484
History | View | Annotate | Download (3.69 KB)
1 | 2484 | nbrodin | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | |||
23 | package org.gvsig.raster.wms.app.wmsclient.gui.wizard; |
||
24 | |||
25 | import java.util.ArrayList; |
||
26 | import java.util.Collection; |
||
27 | import java.util.TreeSet; |
||
28 | |||
29 | import javax.swing.AbstractListModel; |
||
30 | |||
31 | |||
32 | /**
|
||
33 | * DOCUMENT ME!
|
||
34 | *
|
||
35 | * @author Fernando Gonz?lez Cort?s
|
||
36 | */
|
||
37 | public class SRSListModel extends AbstractListModel { |
||
38 | ArrayList srs = new ArrayList(); |
||
39 | |||
40 | public int getSize() { |
||
41 | return srs.size();
|
||
42 | } |
||
43 | |||
44 | public Object getElementAt(int index) { |
||
45 | return srs.get(index);
|
||
46 | } |
||
47 | |||
48 | public void setAll(Collection c) { |
||
49 | |||
50 | srs.clear(); |
||
51 | srs.addAll(c); |
||
52 | } |
||
53 | |||
54 | public Collection intersect(Collection c) { |
||
55 | TreeSet resul = new TreeSet(); |
||
56 | for (int i = 0; i < srs.size(); i++) { |
||
57 | if (c.contains(srs.get(i)))
|
||
58 | resul.add(srs.get(i)); |
||
59 | } |
||
60 | return resul;
|
||
61 | } |
||
62 | /*ArrayList comunes = new ArrayList();
|
||
63 | |||
64 | private HashSet srsSet = new HashSet();
|
||
65 | private HashMap cuenta = new HashMap();
|
||
66 | private ArrayList nombresSRS = new ArrayList();
|
||
67 | |||
68 | /**
|
||
69 | * DOCUMENT ME!
|
||
70 | *
|
||
71 | * @param srs DOCUMENT ME!
|
||
72 | * /
|
||
73 | public void add(String srs) {
|
||
74 | System.out.println("A?adiendo " + srs);
|
||
75 | if (!srsSet.add(srs)) {
|
||
76 | Integer i = (Integer) cuenta.get(srs);
|
||
77 | cuenta.put(srs, new Integer(i.intValue() + 1));
|
||
78 | System.out.println("Ya hab?a, llevamos " + i.intValue() + 1);
|
||
79 | } else {
|
||
80 | nombresSRS.add(srs);
|
||
81 | cuenta.put(srs, new Integer(1));
|
||
82 | fireContentsChanged(this, nombresSRS.size()-1,nombresSRS.size()-1);
|
||
83 | }
|
||
84 | }
|
||
85 | |||
86 | /**
|
||
87 | * DOCUMENT ME!
|
||
88 | *
|
||
89 | * @param srs DOCUMENT ME!
|
||
90 | * /
|
||
91 | public void del(String srs) {
|
||
92 | System.out.println("Eliminando SRS: "+ srs);
|
||
93 | Integer i = (Integer) cuenta.get(srs);
|
||
94 | |||
95 | if (i == null) {
|
||
96 | System.out.println("Eliminando un elemento que no estaba");
|
||
97 | return;
|
||
98 | }
|
||
99 | |||
100 | int nuevo = i.intValue() - 1;
|
||
101 | |||
102 | System.out.println("quedan " + nuevo);
|
||
103 | |||
104 | if (nuevo == 0) {
|
||
105 | cuenta.remove(srs);
|
||
106 | srsSet.remove(srs);
|
||
107 | nombresSRS.remove(srs);
|
||
108 | fireContentsChanged(this, 0,nombresSRS.size()-1);
|
||
109 | } else {
|
||
110 | cuenta.put(srs, new Integer(nuevo));
|
||
111 | }
|
||
112 | }
|
||
113 | |||
114 | /**
|
||
115 | * DOCUMENT ME!
|
||
116 | *
|
||
117 | * @return
|
||
118 | * /
|
||
119 | public Iterator iterator() {
|
||
120 | return srsSet.iterator();
|
||
121 | }
|
||
122 | |||
123 | /**
|
||
124 | * DOCUMENT ME!
|
||
125 | *
|
||
126 | * @return
|
||
127 | * /
|
||
128 | public int size() {
|
||
129 | return srsSet.size();
|
||
130 | }
|
||
131 | |||
132 | /**
|
||
133 | * @see javax.swing.ListModel#getSize()
|
||
134 | * /
|
||
135 | public int getSize() {
|
||
136 | return nombresSRS.size();
|
||
137 | }
|
||
138 | |||
139 | /**
|
||
140 | * @see javax.swing.ListModel#getElementAt(int)
|
||
141 | * /
|
||
142 | public Object getElementAt(int index) {
|
||
143 | return nombresSRS.get(index);
|
||
144 | }
|
||
145 | |||
146 | public ArrayList intersect(Collection col) {
|
||
147 | ArrayList resul = new ArrayList();
|
||
148 | for (int i = 0; i < nombresSRS.size(); i++) {
|
||
149 | if (col.contains(nombresSRS.get(i)))
|
||
150 | resul.add(nombresSRS.get(i));
|
||
151 | }
|
||
152 | return resul;
|
||
153 | }
|
||
154 | */
|
||
155 | } |