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