Revision 784
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/InfoListener.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.gui; |
|
2 |
|
|
3 |
import java.awt.Cursor; |
|
4 |
import java.awt.Image; |
|
5 |
import java.awt.Point; |
|
6 |
import java.awt.Toolkit; |
|
7 |
import java.awt.geom.Point2D; |
|
8 |
import java.util.BitSet; |
|
9 |
|
|
10 |
import javax.swing.ImageIcon; |
|
11 |
import javax.swing.JDialog; |
|
12 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
13 |
import javax.swing.tree.DefaultTreeModel; |
|
14 |
import javax.swing.tree.TreePath; |
|
15 |
|
|
16 |
import org.apache.log4j.Logger; |
|
17 |
import org.xml.sax.ContentHandler; |
|
18 |
import org.xml.sax.SAXException; |
|
19 |
import org.xml.sax.helpers.AttributesImpl; |
|
20 |
|
|
21 |
import com.hardcode.gdbms.engine.data.DataSource; |
|
22 |
import com.iver.andami.PluginServices; |
|
23 |
import com.iver.andami.messages.NotificationManager; |
|
24 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
25 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
|
26 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
27 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
28 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
|
29 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
|
30 |
import com.iver.cit.gvsig.fmap.operations.QueriedPoint; |
|
31 |
import com.iver.cit.gvsig.fmap.operations.strategies.QueryByPointVisitor; |
|
32 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
|
33 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
|
34 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
|
35 |
import com.iver.cit.gvsig.gui.Dialogs.FInfoDialogXML; |
|
36 |
import com.iver.utiles.xmlViewer.XMLContent; |
|
37 |
|
|
38 |
|
|
39 |
/** |
|
40 |
* DOCUMENT ME! |
|
41 |
* |
|
42 |
* @author Vicente Caballero Navarro |
|
43 |
*/ |
|
44 |
public class InfoListener implements PointListener { |
|
45 |
// private final Image img = new ImageIcon(NewMapControl.class.getResource( |
|
46 |
//"images/InfoCursor.png")).getImage(); |
|
47 |
private static Logger logger = Logger.getLogger(InfoListener.class.getName()); |
|
48 |
private final Image img = new ImageIcon(NewMapControl.class.getResource( |
|
49 |
"images/InfoCursor.gif")).getImage(); |
|
50 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img, |
|
51 |
new Point(16, 16), ""); |
|
52 |
private NewMapControl mapCtrl; |
|
53 |
private BitSet[] bitset; |
|
54 |
private FLayer[] layers; |
|
55 |
|
|
56 |
/** |
|
57 |
* Crea un nuevo AreaListenerImpl. |
|
58 |
* |
|
59 |
* @param mc DOCUMENT ME! |
|
60 |
*/ |
|
61 |
public InfoListener(NewMapControl mc) { |
|
62 |
this.mapCtrl = mc; |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* DOCUMENT ME! |
|
67 |
* |
|
68 |
* @param event DOCUMENT ME! |
|
69 |
* |
|
70 |
* @throws DriverIOException |
|
71 |
* |
|
72 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent) |
|
73 |
*/ |
|
74 |
public void point(PointEvent event) throws BehaviorException { |
|
75 |
Point2D pReal = mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint()); |
|
76 |
|
|
77 |
// Dentro de queryByPoint tenemos que separar los registros que vienen asociados a una |
|
78 |
// capa o a otra. Supongo que lo correcto ser?a que montaramos un XML y usar el visor |
|
79 |
// de XML que ha empezado Fernando. |
|
80 |
// String strResul = m_MapControl.queryByPoint(pScreen,m_MapControl.toMapDistance(3),""); |
|
81 |
//FInfoDialog dlg = new FInfoDialog(); |
|
82 |
// dlg.clearAll(); |
|
83 |
// dlg.setViewModel((ProjectView) proj); |
|
84 |
FInfoDialogXML dlgXML = new FInfoDialogXML(); |
|
85 |
|
|
86 |
//MultipleXMLContent xmlModel = new MultipleXMLContent(); |
|
87 |
|
|
88 |
FLayer[] sel = mapCtrl.getMapContext().getLayers().getActives(); |
|
89 |
|
|
90 |
bitset = new BitSet[sel.length]; |
|
91 |
layers = new FLayer[sel.length]; |
|
92 |
|
|
93 |
for (int i = 0; i < sel.length; i++) { |
|
94 |
FLayer laCapa = (FLayer) sel[i]; |
|
95 |
|
|
96 |
if ((laCapa instanceof VectorialData) && |
|
97 |
(laCapa instanceof AlphanumericData)){ |
|
98 |
QueryByPointVisitor visitor = new QueryByPointVisitor(); |
|
99 |
visitor.setLayer(laCapa); |
|
100 |
visitor.setQueriedPoint(new QueriedPoint( |
|
101 |
pReal.getX(), pReal.getY())); |
|
102 |
visitor.setTolerance(mapCtrl.getMapContext().getViewPort().toMapDistance(3)); |
|
103 |
try { |
|
104 |
((VectorialData) laCapa).process(visitor); |
|
105 |
} catch (DriverException e) { |
|
106 |
throw new BehaviorException("No se pudo procesar la capa", e); |
|
107 |
} |
|
108 |
bitset[i] = visitor.getBitSet(); |
|
109 |
layers[i] = laCapa; |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
113 |
if (bitset != null) { |
|
114 |
try { |
|
115 |
if (PluginServices.getMainFrame() == null) |
|
116 |
{ |
|
117 |
JDialog dialog = new JDialog(); |
|
118 |
dlgXML.setPreferredSize(dlgXML.getSize()); |
|
119 |
dialog.getContentPane().add(dlgXML); |
|
120 |
dialog.setModal(false); |
|
121 |
dialog.pack(); |
|
122 |
dialog.show(); |
|
123 |
|
|
124 |
} |
|
125 |
else |
|
126 |
dlgXML = (FInfoDialogXML) PluginServices.getMDIManager().addView(dlgXML); |
|
127 |
|
|
128 |
dlgXML.setModel(new XMLContent() { |
|
129 |
private ContentHandler handler; |
|
130 |
|
|
131 |
public void setContentHandler(ContentHandler arg0) { |
|
132 |
handler = arg0; |
|
133 |
} |
|
134 |
|
|
135 |
public void parse() throws SAXException { |
|
136 |
handler.startDocument(); |
|
137 |
|
|
138 |
for (int i = 0; i < bitset.length; i++) { |
|
139 |
AttributesImpl aii = new AttributesImpl(); |
|
140 |
handler.startElement("", "", |
|
141 |
((FLayer) layers[i]).getName(), aii); |
|
142 |
|
|
143 |
try { |
|
144 |
DataSource ds = ((AlphanumericData) layers[i]).getRecordset(); |
|
145 |
ds.start(); |
|
146 |
|
|
147 |
for (int j = bitset[i].nextSetBit(0); |
|
148 |
j >= 0; |
|
149 |
j = bitset[i].nextSetBit(j + 1)) { |
|
150 |
// for (int j = 0; j < bitset[i].length(); |
|
151 |
// j++) { |
|
152 |
//if (bitset[i].get(j)) { |
|
153 |
AttributesImpl ai = new AttributesImpl(); |
|
154 |
|
|
155 |
for (int k = 0; k < ds.getFieldCount(); |
|
156 |
k++) { |
|
157 |
ai.addAttribute("", |
|
158 |
ds.getFieldName(k), "", |
|
159 |
"xs:string", |
|
160 |
ds.getFieldValue(j, k).toString()); |
|
161 |
} |
|
162 |
|
|
163 |
handler.startElement("", "", |
|
164 |
String.valueOf(j), ai); |
|
165 |
|
|
166 |
handler.endElement("", "", |
|
167 |
String.valueOf(j)); |
|
168 |
|
|
169 |
} |
|
170 |
|
|
171 |
logger.debug("ds.stop()"); |
|
172 |
ds.stop(); |
|
173 |
} catch (com.hardcode.gdbms.engine.data.DriverException e) { |
|
174 |
throw new SAXException(e); |
|
175 |
} catch (DriverException e) { |
|
176 |
throw new SAXException(e); |
|
177 |
} |
|
178 |
|
|
179 |
handler.endElement("", "", |
|
180 |
((FLayer) layers[i]).getName()); |
|
181 |
} |
|
182 |
|
|
183 |
handler.endDocument(); |
|
184 |
} |
|
185 |
}); |
|
186 |
dlgXML.getXmlTree().setRootVisible(false); |
|
187 |
DefaultTreeModel treeModel = (DefaultTreeModel) dlgXML.getXmlTree().getModel(); |
|
188 |
DefaultMutableTreeNode n; |
|
189 |
DefaultMutableTreeNode root = (DefaultMutableTreeNode) dlgXML.getXmlTree().getModel().getRoot(); |
|
190 |
n = root.getFirstLeaf(); |
|
191 |
TreePath path = new TreePath(treeModel.getPathToRoot(n)); |
|
192 |
dlgXML.getXmlTree().expandPath(path); |
|
193 |
|
|
194 |
dlgXML.getXmlTree().setSelectionPath(path); |
|
195 |
|
|
196 |
} catch (SAXException e) { |
|
197 |
NotificationManager.addError("Error formateando los resultados", e); |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor() |
|
205 |
*/ |
|
206 |
public Cursor getCursor() { |
|
207 |
return cur; |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing() |
|
212 |
*/ |
|
213 |
public boolean cancelDrawing() { |
|
214 |
return false; |
|
215 |
} |
|
216 |
} |
Also available in: Unified diff