svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVectLinkProperties.java @ 42488
History | View | Annotate | Download (6.17 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 |
package org.gvsig.fmap.mapcontext.layers.vectorial; |
25 |
|
26 |
import java.awt.geom.Point2D; |
27 |
import java.io.File; |
28 |
import java.net.URI; |
29 |
import java.net.URISyntaxException; |
30 |
import java.util.ArrayList; |
31 |
|
32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 |
import org.gvsig.fmap.dal.exception.ReadException; |
34 |
import org.gvsig.fmap.dal.feature.Feature; |
35 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
36 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
37 |
import org.gvsig.fmap.mapcontext.layers.AbstractLinkProperties; |
38 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
39 |
import org.gvsig.tools.ToolsLocator; |
40 |
import org.gvsig.tools.dispose.DisposableIterator; |
41 |
import org.gvsig.tools.dynobject.DynStruct; |
42 |
import org.gvsig.tools.persistence.PersistenceManager; |
43 |
|
44 |
|
45 |
/**
|
46 |
* This class extends AbstractLinkProperties and implements the method to get an array of URI
|
47 |
* using a point2D and a tolerance. This class extends AstractLinkProperties to add HyperLink
|
48 |
* to Vectorial Layer(FLyrVect)
|
49 |
*
|
50 |
* @deprecated this functionality has extracted of the core form gvSIG 2.0
|
51 |
*/
|
52 |
|
53 |
public class FLyrVectLinkProperties extends AbstractLinkProperties { |
54 |
|
55 |
/**
|
56 |
* Default Constructor. Costructs a LinkProperties with the necessary information
|
57 |
*
|
58 |
*/
|
59 |
public FLyrVectLinkProperties(){
|
60 |
setType(0);
|
61 |
setField(null);
|
62 |
setExt(null);
|
63 |
} |
64 |
|
65 |
/**
|
66 |
* Constructor. Constructs a LinkProperties with the information that receives
|
67 |
* @param tipo
|
68 |
* @param fieldName
|
69 |
* @param extension
|
70 |
*/
|
71 |
public FLyrVectLinkProperties(int tipo, String fieldName, String extension){ |
72 |
setType(tipo); |
73 |
setField(fieldName); |
74 |
setExt(extension); |
75 |
} |
76 |
|
77 |
/**
|
78 |
* Creates an array of URI. With the point and the tolerance makes a query to the layer
|
79 |
* and gets the geometries that contains the point with a certain error (tolerance).
|
80 |
* For each one of this geometries creates one URI and adds it to the array
|
81 |
* @param layer
|
82 |
* @param point
|
83 |
* @param tolerance
|
84 |
* @return Array of URI
|
85 |
* @throws ReadException
|
86 |
*/
|
87 |
public URI[] getLink(FLayer layer, Point2D point, double tolerance) throws ReadException{ |
88 |
//Sacado de la clase LinkListener
|
89 |
FLyrVect lyrVect = (FLyrVect) layer; |
90 |
FeatureStore fStore = null;
|
91 |
FeatureSet fSet=null;
|
92 |
DisposableIterator iter = null;
|
93 |
|
94 |
try {
|
95 |
fStore = lyrVect.getFeatureStore(); |
96 |
//URI uri[]=null;
|
97 |
|
98 |
//Construimos el BitSet (V?ctor con componentes BOOLEAN) con la consulta que
|
99 |
try {
|
100 |
fSet = lyrVect.queryByPoint(point, tolerance, fStore.getDefaultFeatureType());//fStore.getFeatureSet(featureQuery);
|
101 |
} catch (ReadException e) {
|
102 |
return null; |
103 |
} catch (DataException e) {
|
104 |
return null; |
105 |
} |
106 |
|
107 |
//Si el bitset creado no est? vac?o creamos el vector de URLS correspondientes
|
108 |
//a la consulta que hemos hecho.
|
109 |
|
110 |
ArrayList tmpUris=new ArrayList(); |
111 |
String auxext=""; |
112 |
int idField = fStore.getDefaultFeatureType().getIndex(this.getField()); |
113 |
|
114 |
|
115 |
|
116 |
|
117 |
//Consigo el identificador del campo pasandole como par?metro el
|
118 |
//nombre del campo del ?nlace
|
119 |
if (idField == -1){ |
120 |
throw new ReadException(lyrVect.getName()+": '"+this.getField()+"' not found",new Exception()); |
121 |
} |
122 |
//Recorremos el BitSet siguiendo el ejmplo de la clase que se
|
123 |
//proporciona en la API
|
124 |
iter = fSet.fastIterator(); |
125 |
while (iter.hasNext()){
|
126 |
//TODO
|
127 |
//Sacado de la clase LinkPanel, decidir como pintar la URL le
|
128 |
//corresponde a LinkPanel, aqu? solo creamos el vector de URL?s
|
129 |
if (!super.getExt().equals("")){ |
130 |
auxext="."+this.getExt(); |
131 |
} |
132 |
//Creamos el fichero con el nombre del campo y la extensi?n.
|
133 |
Feature feature = (Feature) iter.next(); |
134 |
String auxField=feature.getString(idField);
|
135 |
URI tmpUri = null; |
136 |
if(auxField.startsWith("http:/")){ |
137 |
tmpUri= new URI(auxField); |
138 |
}else{
|
139 |
File file =new File(feature.getString(idField)+auxext); |
140 |
tmpUri = file.toURI(); |
141 |
} |
142 |
tmpUris.add(tmpUri); |
143 |
System.out.println(tmpUri.toString());
|
144 |
|
145 |
|
146 |
} |
147 |
|
148 |
if (tmpUris.size()==0){ |
149 |
return null; |
150 |
} |
151 |
|
152 |
// Creo el vector de URL?s con la misma longitud que el bitset
|
153 |
|
154 |
return (URI[]) tmpUris.toArray(new URI[0]); |
155 |
|
156 |
} catch (ReadException e) {
|
157 |
throw new ReadException(lyrVect.getName(),e); |
158 |
} catch (URISyntaxException e) { |
159 |
throw new ReadException(lyrVect.getName(),e); |
160 |
} catch (DataException e) {
|
161 |
throw new ReadException(lyrVect.getName(),e); |
162 |
}finally{
|
163 |
if (iter != null) { |
164 |
iter.dispose(); |
165 |
} |
166 |
if (fSet != null) { |
167 |
fSet.dispose(); |
168 |
} |
169 |
} |
170 |
|
171 |
} |
172 |
|
173 |
public static void registerPersistent() { |
174 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
175 |
DynStruct definition = manager.addDefinition( |
176 |
FLyrVectLinkProperties.class, |
177 |
"FLyrVectLinkProperties",
|
178 |
"FLyrVectLinkProperties Persistence definition",
|
179 |
null,
|
180 |
null
|
181 |
); |
182 |
definition.addDynFieldInt("typeLink").setMandatory(true); |
183 |
definition.addDynFieldString("fieldName").setMandatory(true); |
184 |
definition.addDynFieldString("extName").setMandatory(true); |
185 |
} |
186 |
|
187 |
|
188 |
} |