Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVectLinkProperties.java @ 22945

History | View | Annotate | Download (4.6 KB)

1
package org.gvsig.fmap.mapcontext.layers.vectorial;
2

    
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
import java.util.Iterator;
9

    
10
import org.gvsig.fmap.data.ReadException;
11
import org.gvsig.fmap.data.feature.Feature;
12
import org.gvsig.fmap.data.feature.FeatureCollection;
13
import org.gvsig.fmap.data.feature.FeatureStore;
14
import org.gvsig.fmap.mapcontext.layers.AbstractLinkProperties;
15
import org.gvsig.fmap.mapcontext.layers.FLayer;
16

    
17

    
18
/**
19
 * This class extends AbstractLinkProperties and implements the method to get an array of URI
20
 * using a point2D and a tolerance. This class extends AstractLinkProperties to add HyperLink
21
 * to Vectorial Layer(FLyrVect)
22
 */
23

    
24
public class FLyrVectLinkProperties extends AbstractLinkProperties{
25

    
26
    /**
27
     * Default Constructor. Costructs a LinkProperties with the necessary information
28
     *
29
     */
30
    public FLyrVectLinkProperties(){
31
        setType(0);
32
        setField(null);
33
        setExt(null);
34
    }
35

    
36
    /**
37
     * Constructor. Constructs a LinkProperties with the information that receives
38
     * @param tipo
39
     * @param fieldName
40
     * @param extension
41
     */
42
    public FLyrVectLinkProperties(int tipo, String fieldName, String extension){
43
        setType(tipo);
44
        setField(fieldName);
45
        setExt(extension);
46
    }
47

    
48
    /**
49
     * Creates an array of URI. With the point and the tolerance makes a query to the layer
50
     * and gets the geometries that contains the point with a certain error (tolerance).
51
     * For each one of this geometries creates one URI and adds it to the array
52
     * @param layer
53
     * @param point
54
     * @param tolerance
55
     * @return Array of URI
56
     * @throws ReadException
57
     */
58
    public URI[] getLink(FLayer layer, Point2D point, double tolerance) throws ReadException{
59
            //Sacado de la clase LinkListener
60
                FLyrVect lyrVect = (FLyrVect) layer;
61
                FeatureStore fStore = null;
62
                FeatureCollection fCollection=null;
63

    
64
            try {
65
                    fStore = lyrVect.getFeatureStore();
66
                    URI uri[]=null;
67

    
68
                    //Construimos el BitSet (V?ctor con componentes BOOLEAN) con la consulta que
69
                    //hacemos a la capa.
70
                    String filter = "true = false"; //FIXME: Funcion!!!
71
                    try {
72
                            fCollection = (FeatureCollection)fStore.getDataCollection(fStore.getDefaultFeatureType(), filter, null);
73
                    } catch (ReadException e) {
74
                            return null;
75
                    }
76

    
77
                    Iterator iter = null;
78
                    //Si el bitset creado no est? vac?o creamos el vector de URLS correspondientes
79
                    //a la consulta que hemos hecho.
80

    
81
                    ArrayList tmpUris=new ArrayList();
82
                    String auxext="";
83
                    int idField = fStore.getDefaultFeatureType().getFieldIndex(this.getField());
84

    
85

    
86

    
87

    
88
                    //Consigo el identificador del campo pasandole como par?metro el
89
                    //nombre del campo del ?nlace
90
                    if (idField == -1){
91
                        throw new ReadException(lyrVect.getName()+": '"+this.getField()+"' not found",new Exception());
92
                    }
93
                    //Recorremos el BitSet siguiendo el ejmplo de la clase que se
94
                    //proporciona en la API
95
                    iter = fCollection.iterator();
96
                    while (iter.hasNext()){
97
                            //TODO
98
                            //Sacado de la clase LinkPanel, decidir como pintar la URL le
99
                            //corresponde a LinkPanel, aqu? solo creamos el vector de URL?s
100
                            if (!super.getExt().equals("")){
101
                                    auxext="."+this.getExt();
102
                            }
103
//                          ds.start();
104
                            //Creamos el fichero con el nombre del campo y la extensi?n.
105
                            Feature feature = (Feature) iter.next();
106
                            String auxField=feature.getString(idField);
107
                            URI tmpUri = null;
108
                            if(auxField.startsWith("http:/")){
109
                                    tmpUri= new URI(auxField);
110
                            }else{
111
                                    File file =new File(feature.getString(idField)+auxext);
112
                                    tmpUri = file.toURI();
113
                            }
114
                            tmpUris.add(tmpUri);
115
                            System.out.println(tmpUri.toString());
116
                            //System.out.println(uri[j]);
117

    
118

    
119
                    }
120

    
121
                    if (tmpUris.size()==0){
122
                            return null;
123
                    }
124

    
125
                    //Creo el vector de URL?s con la misma longitud que el bitset
126
                    uri = new URI[tmpUris.size()];
127
                    iter = tmpUris.iterator();
128
                    int i=0;
129
                    while (iter.hasNext()){
130
                            uri[i]=(URI) iter.next();
131
                            i++;
132
                    }
133

    
134
                    return uri;
135

    
136
            } catch (ReadException e) {
137
                    throw new ReadException(lyrVect.getName(),e);
138
            } catch (URISyntaxException e) {
139
                    throw new ReadException(lyrVect.getName(),e);
140
                }finally{
141
                        fCollection.dispose();
142
                }
143

    
144
    }
145

    
146
        public String getClassName() {
147
                // TODO Auto-generated method stub
148
                return null;
149
        }
150

    
151

    
152
}