svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVectLinkProperties.java @ 20701
History | View | Annotate | Download (4.96 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
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.BitSet; |
8 |
|
9 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
10 |
import com.hardcode.gdbms.engine.data.DataSource; |
11 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
12 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
13 |
|
14 |
/**
|
15 |
* This class extends AbstractLinkProperties and implements the method to get an array of URI
|
16 |
* using a point2D and a tolerance. This class extends AstractLinkProperties to add HyperLink
|
17 |
* to Vectorial Layer(FLyrVect)
|
18 |
*/
|
19 |
|
20 |
public class FLyrVectLinkProperties extends AbstractLinkProperties{ |
21 |
|
22 |
/**
|
23 |
* Default Constructor. Costructs a LinkProperties with the necessary information
|
24 |
*
|
25 |
*/
|
26 |
public FLyrVectLinkProperties(){
|
27 |
setType(0);
|
28 |
setField(null);
|
29 |
setExt(null);
|
30 |
} |
31 |
|
32 |
/**
|
33 |
* Constructor. Constructs a LinkProperties with the information that receives
|
34 |
* @param tipo
|
35 |
* @param fieldName
|
36 |
* @param extension
|
37 |
*/
|
38 |
public FLyrVectLinkProperties(int tipo, String fieldName, String extension){ |
39 |
setType(tipo); |
40 |
setField(fieldName); |
41 |
setExt(extension); |
42 |
} |
43 |
|
44 |
/**
|
45 |
* Creates an array of URI. With the point and the tolerance makes a query to the layer
|
46 |
* and gets the geometries that contains the point with a certain error (tolerance).
|
47 |
* For each one of this geometries creates one URI and adds it to the array
|
48 |
* @param layer
|
49 |
* @param point
|
50 |
* @param tolerance
|
51 |
* @return Array of URI
|
52 |
*/
|
53 |
public URI[] getLink(FLayer layer, Point2D point, double tolerance) { |
54 |
//Sacado de la clase LinkListener
|
55 |
FLyrVect lyrVect = (FLyrVect) layer; |
56 |
FBitSet newBitSet; |
57 |
BitSet bitset;
|
58 |
URI uri[]=null; |
59 |
|
60 |
//Construimos el BitSet (V?ctor con componentes BOOLEAN) con la consulta que
|
61 |
//hacemos a la capa.
|
62 |
try {
|
63 |
newBitSet = lyrVect.queryByPoint(point, tolerance); |
64 |
bitset = newBitSet; |
65 |
} catch (ReadDriverException e) {
|
66 |
return null; |
67 |
} catch (VisitorException e) {
|
68 |
return null; |
69 |
} |
70 |
|
71 |
//Si el bitset creado no est? vac?o creamos el vector de URLS correspondientes
|
72 |
//a la consulta que hemos hecho.
|
73 |
|
74 |
if (bitset!=null){ |
75 |
try {
|
76 |
if (layer instanceof AlphanumericData) { |
77 |
|
78 |
DataSource ds = ((AlphanumericData) layer).getRecordset();
|
79 |
ds.start(); |
80 |
//boolean exist=false;
|
81 |
int idField;
|
82 |
//Creo el vector de URL?s con la misma longitud que el bitset
|
83 |
uri = new URI[bitset.length()]; |
84 |
|
85 |
//Consigo el identificador del campo pasandole como par?metro el
|
86 |
//nombre del campo del ?nlace
|
87 |
idField = ds.getFieldIndexByName(this.getField());
|
88 |
if (idField != -1){ |
89 |
//Recorremos el BitSet siguiendo el ejmplo de la clase que se
|
90 |
//proporciona en la API
|
91 |
for (int j = bitset.nextSetBit(0); j >= 0; |
92 |
j = bitset.nextSetBit(j + 1)){
|
93 |
//TODO
|
94 |
//Sacado de la clase LinkPanel, decidir como pintar la URL le
|
95 |
//corresponde a LinkPanel, aqu? solo creamos el vector de URL?s
|
96 |
String auxext=""; |
97 |
if (!super.getExt().equals("")){ |
98 |
auxext="."+this.getExt(); |
99 |
} |
100 |
// ds.start();
|
101 |
//Creamos el fichero con el nombre del campo y la extensi?n.
|
102 |
String auxField=ds.getFieldValue(j, idField).toString();
|
103 |
if(auxField.startsWith("http:/")){ |
104 |
try {
|
105 |
uri[j]=new URI(auxField); |
106 |
} catch (URISyntaxException e) { |
107 |
// TODO Auto-generated catch block
|
108 |
e.printStackTrace(); |
109 |
} |
110 |
} |
111 |
else{
|
112 |
|
113 |
File file =new File(ds.getFieldValue(j, idField).toString()+auxext); |
114 |
uri[j]= file.toURI(); |
115 |
} |
116 |
System.out.println(uri[j].toString());
|
117 |
//System.out.println(uri[j]);
|
118 |
|
119 |
|
120 |
} |
121 |
return uri;
|
122 |
} |
123 |
|
124 |
ds.stop(); |
125 |
}else {
|
126 |
//Posible error
|
127 |
System.out.println("Error"); |
128 |
} |
129 |
|
130 |
} catch (ReadDriverException e) {
|
131 |
//Posible error
|
132 |
System.out.println("Error"); |
133 |
} |
134 |
|
135 |
|
136 |
} |
137 |
return null; |
138 |
} |
139 |
|
140 |
public String getClassName() { |
141 |
// TODO Auto-generated method stub
|
142 |
return null; |
143 |
} |
144 |
|
145 |
|
146 |
} |