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