svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SymbolSelectorListModel.java @ 8311
History | View | Annotate | Download (4.41 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: SymbolSelectorListModel.java 8311 2006-10-24 22:26:18Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2006-10-24 22:26:18 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1 2006/10/24 16:31:12 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
*
|
53 |
*/
|
54 |
package com.iver.cit.gvsig.gui.styling; |
55 |
|
56 |
import java.io.File; |
57 |
import java.io.FileFilter; |
58 |
import java.io.FileNotFoundException; |
59 |
import java.io.FileReader; |
60 |
import java.util.ArrayList; |
61 |
import java.util.Vector; |
62 |
|
63 |
import javax.swing.event.ListDataListener; |
64 |
|
65 |
import org.exolab.castor.xml.MarshalException; |
66 |
import org.exolab.castor.xml.ValidationException; |
67 |
|
68 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
69 |
import com.iver.utiles.XMLEntity; |
70 |
import com.iver.utiles.listManager.ListModel; |
71 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
72 |
|
73 |
public class SymbolSelectorListModel implements ListModel { |
74 |
public static final File SYMBOL_DIRECTORY = new File(SymbolSelectorListModel.class. |
75 |
getClassLoader().getResource("symbols").getFile());
|
76 |
private static final String SYMBOL_FILE_EXTENSION = ".sym"; |
77 |
|
78 |
private static final FileFilter filter = new FileFilter() { |
79 |
public boolean accept(File pathname) { |
80 |
return pathname.getAbsolutePath().toLowerCase().endsWith(SYMBOL_FILE_EXTENSION);
|
81 |
} |
82 |
}; |
83 |
|
84 |
private Vector symbols; |
85 |
private ArrayList listeners; |
86 |
public Object remove(int i) throws ArrayIndexOutOfBoundsException { |
87 |
return symbols.remove(i);
|
88 |
} |
89 |
|
90 |
public void insertAt(int i, Object o) { |
91 |
getObjects().insertElementAt(o, i); |
92 |
} |
93 |
|
94 |
public void add(Object o) { |
95 |
getObjects().add(o); |
96 |
} |
97 |
|
98 |
public Vector getObjects() { |
99 |
if (symbols == null) { |
100 |
symbols = new Vector(); |
101 |
|
102 |
File[] ff = SYMBOL_DIRECTORY.listFiles(filter); |
103 |
for (int i = 0; i < ff.length; i++) { |
104 |
|
105 |
XMLEntity xml; |
106 |
try {
|
107 |
xml = new XMLEntity((XmlTag) XmlTag.unmarshal(new FileReader(ff[i]))); |
108 |
symbols.add(SymbolFactory.createFromXML(xml)); |
109 |
} catch (MarshalException e) { |
110 |
// TODO Auto-generated catch block
|
111 |
e.printStackTrace(); |
112 |
} catch (ValidationException e) {
|
113 |
// TODO Auto-generated catch block
|
114 |
e.printStackTrace(); |
115 |
} catch (FileNotFoundException e) { |
116 |
// TODO Auto-generated catch block
|
117 |
e.printStackTrace(); |
118 |
} |
119 |
|
120 |
} |
121 |
} |
122 |
return symbols;
|
123 |
} |
124 |
|
125 |
public int getSize() { |
126 |
return getObjects().size();
|
127 |
} |
128 |
|
129 |
public Object getElementAt(int index) { |
130 |
return getObjects().get(index);
|
131 |
} |
132 |
|
133 |
public void addListDataListener(ListDataListener l) { |
134 |
if (listeners == null) |
135 |
listeners = new ArrayList(); |
136 |
listeners.add(l); |
137 |
} |
138 |
|
139 |
public void removeListDataListener(ListDataListener l) { |
140 |
if (listeners!=null) |
141 |
listeners.remove(l); |
142 |
} |
143 |
|
144 |
} |
145 |
|
146 |
class SymbolFactory { |
147 |
|
148 |
public static ISymbol createFromXML(XMLEntity xml) { |
149 |
int propCount = xml.getPropertyCount();
|
150 |
ArrayList props = new ArrayList(xml.getPropertyCount()); |
151 |
for (int i = 0; i < propCount; i++) { |
152 |
props.add(xml.getPropertyName(i)); |
153 |
} |
154 |
|
155 |
Class clazz;
|
156 |
ISymbol sym = null;
|
157 |
|
158 |
try {
|
159 |
clazz = Class.forName(xml.getStringProperty("className")); |
160 |
sym = (ISymbol) clazz.newInstance(); |
161 |
sym.setXMLEntity(xml); |
162 |
} catch (InstantiationException e) { |
163 |
// TODO Auto-generated catch block
|
164 |
e.printStackTrace(); |
165 |
} catch (IllegalAccessException e) { |
166 |
// TODO Auto-generated catch block
|
167 |
e.printStackTrace(); |
168 |
} catch (ClassNotFoundException e) { |
169 |
// TODO Auto-generated catch block
|
170 |
e.printStackTrace(); |
171 |
} |
172 |
return sym;
|
173 |
} |
174 |
} |