svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / StyleSelectorListModel.java @ 34294
History | View | Annotate | Download (5.74 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: StyleSelectorListModel.java 30011 2009-07-17 11:07:14Z cordinyana $
|
45 |
* $Log$
|
46 |
* Revision 1.5 2007-08-14 11:10:20 jvidal
|
47 |
* javadoc updated
|
48 |
*
|
49 |
* Revision 1.4 2007/08/07 11:21:42 jvidal
|
50 |
* javadoc
|
51 |
*
|
52 |
* Revision 1.3 2007/05/08 15:44:07 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.2 2007/04/04 16:01:14 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.2 2007/03/09 11:25:00 jaume
|
59 |
* Advanced symbology (start committing)
|
60 |
*
|
61 |
* Revision 1.1.2.4 2007/02/21 07:35:14 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.1.2.3 2007/02/08 15:43:04 jaume
|
65 |
* some bug fixes in the editor and removed unnecessary imports
|
66 |
*
|
67 |
* Revision 1.1.2.2 2007/01/30 18:10:10 jaume
|
68 |
* start commiting labeling stuff
|
69 |
*
|
70 |
* Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
*
|
74 |
*/
|
75 |
package org.gvsig.app.gui.styling; |
76 |
|
77 |
import java.io.File; |
78 |
import java.io.FileNotFoundException; |
79 |
import java.io.FileReader; |
80 |
import java.util.Comparator; |
81 |
import java.util.TreeSet; |
82 |
import java.util.Vector; |
83 |
|
84 |
import org.exolab.castor.xml.MarshalException; |
85 |
import org.exolab.castor.xml.ValidationException; |
86 |
import org.gvsig.andami.messages.NotificationManager; |
87 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.IStyle; |
88 |
import org.gvsig.utils.XMLEntity; |
89 |
import org.gvsig.utils.xmlEntity.generate.XmlTag; |
90 |
|
91 |
|
92 |
/**
|
93 |
* Implements a list to select styles.This list
|
94 |
* has the property that allows the user to stablish a filter to accept or reject
|
95 |
* elements for it from a directory which is also specified when the StyleSelectorModel
|
96 |
* is created.
|
97 |
*
|
98 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
99 |
*
|
100 |
*/
|
101 |
public class StyleSelectorListModel extends SymbolSelectorListModel { |
102 |
|
103 |
public static final String STYLE_FILE_EXTENSION = ".style"; |
104 |
|
105 |
/**
|
106 |
* <p>
|
107 |
* Creates a new instance of the model for the list in the Style Selector window
|
108 |
* where the styles are stored in the <b>dir</b> (root directory) param.<br>
|
109 |
* </p>
|
110 |
* <p>The <b>currentElement</b> defines which element is pre-selected.<br></p>
|
111 |
* <p>The <b>filter</b> is a user defined filter used to know which elements in
|
112 |
* the folder are accepted or rejected for this list and it is used to avoid
|
113 |
* mixing marker styles for polygons for example.<br></p>
|
114 |
* <p><b>fileExtension</b> param defines the extension of the file to be parsed. This
|
115 |
* is like that to enable inheritance of this class to other file selector such
|
116 |
* as StyleSelector.
|
117 |
*
|
118 |
* @param dir, the root dir where styles are located.
|
119 |
* @param currentElemet, the element to be pre-selected.
|
120 |
* @param filter, the filter used to show or hide some elements.
|
121 |
* @param fileExtension, file extension used for the files to be parsed.
|
122 |
*/
|
123 |
public StyleSelectorListModel(File dir, SelectorFilter filter, String fileExtension) { |
124 |
super(dir, filter, fileExtension);
|
125 |
// TODO Auto-generated constructor stub
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* TODO: use the new Persistence API.
|
130 |
*/
|
131 |
public Vector getObjects() { |
132 |
return null; |
133 |
// if (elements == null) {
|
134 |
// elements = new Vector();
|
135 |
//
|
136 |
// File[] ff = dir.listFiles(ffilter);
|
137 |
// for (int i = 0; i < ff.length; i++) {
|
138 |
//
|
139 |
// XMLEntity xml;
|
140 |
// try {
|
141 |
// xml = new XMLEntity((XmlTag) XmlTag.unmarshal(new FileReader(ff[i])));
|
142 |
// IStyle sty = SymbologyFactory.createStyleFromXML(xml, ff[i].getName());
|
143 |
// if (sfilter.accepts(sty))
|
144 |
// add(sty);
|
145 |
// } catch (MarshalException e) {
|
146 |
// NotificationManager.
|
147 |
// addWarning("Error in file ["+ff[i].getAbsolutePath()+"]. " +
|
148 |
// "File corrupted! Skiping it...", e);
|
149 |
// } catch (ValidationException e) {
|
150 |
// NotificationManager.
|
151 |
// addWarning("Error validating style file ["+ff[i].getAbsolutePath()+"].", e);
|
152 |
// } catch (FileNotFoundException e) {
|
153 |
// // unreachable code, but anyway...
|
154 |
// NotificationManager.
|
155 |
// addWarning("File not found: "+ ff[i].getAbsolutePath(), e);
|
156 |
// }
|
157 |
//
|
158 |
// }
|
159 |
// }
|
160 |
// return elements;
|
161 |
} |
162 |
|
163 |
|
164 |
public void add(Object o) { |
165 |
TreeSet map = new TreeSet(new Comparator() { |
166 |
|
167 |
public int compare(Object o1, Object o2) { |
168 |
|
169 |
IStyle sym1 = (IStyle) o1; |
170 |
IStyle sym2 = (IStyle) o2; |
171 |
if (sym1.getDescription() == null && sym2.getDescription() != null) return -1; |
172 |
if (sym1.getDescription() != null && sym2.getDescription() == null) return 1; |
173 |
if (sym1.getDescription() == null && sym2.getDescription() == null) return 1; |
174 |
|
175 |
int result = sym1.getDescription().compareTo(sym2.getDescription());
|
176 |
return (result!=0) ? result: 1; /* this will allow adding symbols with |
177 |
the same value for description than
|
178 |
a previous one. */
|
179 |
} |
180 |
|
181 |
}); |
182 |
|
183 |
map.addAll(elements); |
184 |
map.add(o); |
185 |
elements = new Vector(map); |
186 |
|
187 |
} |
188 |
} |