svn-gvsig-desktop / trunk / examples / exaExample1 / src / com / iver / example / tools / MyInfoListener.java @ 10626
History | View | Annotate | Download (3.57 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
5 |
*
|
6 |
*/
|
7 |
package com.iver.example.tools; |
8 |
|
9 |
import java.awt.Cursor; |
10 |
import java.awt.geom.Point2D; |
11 |
|
12 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
13 |
import com.hardcode.gdbms.engine.data.DataSource; |
14 |
import com.hardcode.gdbms.engine.values.Value; |
15 |
import com.iver.andami.PluginServices; |
16 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
17 |
import com.iver.cit.gvsig.fmap.MapControl; |
18 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
19 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
20 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
21 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
22 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
23 |
import com.iver.cit.gvsig.fmap.operations.strategies.QueryByPointVisitor; |
24 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
25 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
26 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
27 |
import com.iver.example.dialogs.MyInfoDlg; |
28 |
|
29 |
public class MyInfoListener implements PointListener { |
30 |
|
31 |
private MapControl mapCtrl;
|
32 |
private Cursor cur = java.awt.Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); |
33 |
|
34 |
|
35 |
public MyInfoListener(MapControl mc) {
|
36 |
this.mapCtrl = mc;
|
37 |
} |
38 |
|
39 |
|
40 |
/* (non-Javadoc)
|
41 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
42 |
* The PointEvent method bring you a point in pixel coordinates. You
|
43 |
* need to transform it to world coordinates. The class to do conversions
|
44 |
* is ViewPort, obtained thru the MapContext of mapCtrl.
|
45 |
*/
|
46 |
public void point(PointEvent event) throws BehaviorException { |
47 |
|
48 |
Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
|
49 |
|
50 |
MyInfoDlg dlg = new MyInfoDlg();
|
51 |
dlg = (MyInfoDlg) PluginServices.getMDIManager().addWindow(dlg); |
52 |
|
53 |
|
54 |
/* We will use a Visitor pattern to query the layer and
|
55 |
* to obtain a FBitSet (the selected items). Then, we iterate thru
|
56 |
* selection and extract the needed information from the dataSource.
|
57 |
*/
|
58 |
QueryByPointVisitor visitor = new QueryByPointVisitor();
|
59 |
FLayers lyrs = mapCtrl.getMapContext().getLayers(); |
60 |
FLayer lyrProvin = lyrs.getLayer("Provin.shp");
|
61 |
visitor.setLayer(lyrProvin); |
62 |
visitor.setQueriedPoint(pReal); |
63 |
visitor.setTolerance(5.0);
|
64 |
try {
|
65 |
((VectorialData) lyrProvin).process(visitor); |
66 |
FBitSet selection = visitor.getBitSet(); |
67 |
|
68 |
DataSource ds = ((AlphanumericData) lyrProvin).getRecordset();
|
69 |
ds.start(); |
70 |
int idField = ds.getFieldIndexByName("NOM_PROVIN"); |
71 |
int numReg = 0; |
72 |
Value strNomProvin = null;
|
73 |
|
74 |
while ((numReg = selection.nextSetBit(numReg)) > 0) |
75 |
{ |
76 |
strNomProvin = ds.getFieldValue(numReg, idField); |
77 |
numReg++; |
78 |
} |
79 |
ds.stop(); |
80 |
dlg.setProvince(strNomProvin.toString()); |
81 |
// dlg.setProvince("En un lugar de la Mancha");
|
82 |
} catch (ReadDriverException e) {
|
83 |
// TODO Auto-generated catch block
|
84 |
e.printStackTrace(); |
85 |
} catch (VisitorException e) {
|
86 |
// TODO Auto-generated catch block
|
87 |
e.printStackTrace(); |
88 |
} |
89 |
|
90 |
} |
91 |
|
92 |
public Cursor getCursor() { |
93 |
return cur;
|
94 |
} |
95 |
|
96 |
public boolean cancelDrawing() { |
97 |
return false; |
98 |
} |
99 |
|
100 |
|
101 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
102 |
// TODO Auto-generated method stub
|
103 |
|
104 |
} |
105 |
|
106 |
} |