Revision 20100 branches/v10/extensions/extDwg/src/com/iver/cit/gvsig/drivers/dwg/debug/DwgEntityListener.java
DwgEntityListener.java | ||
---|---|---|
89 | 89 |
import com.iver.cit.jdwglib.dwg.DwgHandleReference; |
90 | 90 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
91 | 91 |
|
92 |
/** |
|
93 |
* <p>Listens events produced by the selection of a <i>control point</i> of any graphical geometry |
|
94 |
* in layers of the associated {@link MapControl MapControl} object.</p> |
|
95 |
* |
|
96 |
* <p>Listens a single or double click of any mouse's button, and also the events produced when |
|
97 |
* the position of the cursor has changed on the associated <code>MapControl</code> object.</p> |
|
98 |
* |
|
99 |
* <p>Uses {@link Cursor#CROSSHAIR_CURSOR Cursor#CROSSHAIR_CURSOR} as mouse's cursor image.</p> |
|
100 |
*/ |
|
92 | 101 |
public class DwgEntityListener implements PointListener{ |
93 |
|
|
102 |
/** |
|
103 |
* Used to calculate the pixel at the associated <code>MapControl</code> down the |
|
104 |
* position of the mouse. |
|
105 |
*/ |
|
106 |
public static int pixelTolerance = 3; |
|
94 | 107 |
|
95 |
|
|
96 |
|
|
97 |
public static int pixelTolerance = 3; |
|
98 |
private MapControl mapCtrl; |
|
99 |
private Cursor cur = java.awt.Cursor. |
|
108 |
/** |
|
109 |
* Reference to the <code>MapControl</code> object that uses. |
|
110 |
*/ |
|
111 |
private MapControl mapCtrl; |
|
112 |
|
|
113 |
/** |
|
114 |
* The cursor used to work with this tool listener. |
|
115 |
* |
|
116 |
* @see #getCursor() |
|
117 |
*/ |
|
118 |
private Cursor cur = java.awt.Cursor. |
|
100 | 119 |
getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); |
101 | 120 |
|
102 |
public DwgEntityListener(MapControl mc) { |
|
121 |
|
|
122 |
/** |
|
123 |
* <p>Creates a new <code>DwgEntityListener</code> object.</p> |
|
124 |
* |
|
125 |
* @param mc the <code>MapControl</code> where will be applied the changes |
|
126 |
*/ |
|
127 |
public DwgEntityListener(MapControl mc) { |
|
103 | 128 |
this.mapCtrl = mc; |
104 | 129 |
} |
105 | 130 |
|
106 |
public void point(PointEvent event) throws BehaviorException { |
|
107 |
|
|
108 |
Point2D pReal = mapCtrl. |
|
109 |
getMapContext(). |
|
110 |
getViewPort(). |
|
111 |
toMapPoint(event.getPoint()); |
|
112 |
|
|
113 |
SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers()); |
|
114 |
while (it.hasNext()) |
|
115 |
{ |
|
116 |
FLayer aux = it.next(); |
|
117 |
if (!aux.isActive()) |
|
118 |
continue; |
|
119 |
if(! (aux instanceof FLyrVect)) |
|
120 |
return; |
|
121 |
|
|
122 |
FLyrVect vectLyr = (FLyrVect) aux; |
|
123 |
VectorialDriver driver = vectLyr.getSource().getDriver(); |
|
124 |
|
|
131 |
/* |
|
132 |
* (non-Javadoc) |
|
133 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent) |
|
134 |
*/ |
|
135 |
public void point(PointEvent event) throws BehaviorException { |
|
136 |
|
|
137 |
Point2D pReal = mapCtrl. |
|
138 |
getMapContext(). |
|
139 |
getViewPort(). |
|
140 |
toMapPoint(event.getPoint()); |
|
141 |
|
|
142 |
SingleLayerIterator it = new SingleLayerIterator(mapCtrl.getMapContext().getLayers()); |
|
143 |
while (it.hasNext()) |
|
144 |
{ |
|
145 |
FLayer aux = it.next(); |
|
146 |
if (!aux.isActive()) |
|
147 |
continue; |
|
148 |
if(! (aux instanceof FLyrVect)) |
|
149 |
return; |
|
150 |
|
|
151 |
FLyrVect vectLyr = (FLyrVect) aux; |
|
152 |
VectorialDriver driver = vectLyr.getSource().getDriver(); |
|
153 |
|
|
125 | 154 |
// Class dwgMemoryDriverClass = LayerFactory.getDM().getDriverClassByName("gvSIG DWG Memory Driver"); |
126 | 155 |
// if(dwgMemoryDriverClass == null){ |
127 | 156 |
// System.out.println("Driver dwg no disponible???"); |
... | ... | |
136 | 165 |
// } catch (ClassNotFoundException e1) { |
137 | 166 |
// return; |
138 | 167 |
// } |
139 |
|
|
140 |
if(!(driver instanceof com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)) |
|
141 |
return; |
|
142 |
/* |
|
143 |
* Comentarizar el if completo para que funcione en el libFMap del HEAD. |
|
144 |
*/ |
|
145 |
if(!(driver instanceof DwgMemoryDriver)){ |
|
146 |
JOptionPane.showConfirmDialog(null, |
|
147 |
"Esta herramienta s?lo funciona con libFMap del HEAD.\nVer comentarios en el codigo de esta clase." |
|
148 |
); |
|
168 |
|
|
169 |
if(!(driver instanceof com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)) |
|
149 | 170 |
return; |
150 |
} |
|
171 |
/* |
|
172 |
* Comentarizar el if completo para que funcione en el libFMap del HEAD. |
|
173 |
*/ |
|
174 |
if(!(driver instanceof DwgMemoryDriver)){ |
|
175 |
JOptionPane.showConfirmDialog(null, |
|
176 |
"Esta herramienta s?lo funciona con libFMap del HEAD.\nVer comentarios en el codigo de esta clase." |
|
177 |
); |
|
178 |
return; |
|
179 |
} |
|
151 | 180 |
|
152 |
final com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver dwgDriver = (com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)driver;
|
|
153 |
double realTol = mapCtrl.getViewPort().toMapDistance(pixelTolerance);
|
|
154 |
|
|
155 |
Rectangle2D recPoint = new Rectangle2D.Double(pReal.getX() - (realTol / 2),
|
|
156 |
pReal.getY() - (realTol / 2), realTol, realTol);
|
|
157 |
|
|
158 |
try {
|
|
159 |
vectLyr.process(new FeatureVisitor(){
|
|
160 |
public void visit(IGeometry g, int index) throws VisitException {
|
|
161 |
/*
|
|
162 |
* Cambiar la comentarizacion de las dos lineas de abajo
|
|
163 |
* para funcione la herramienta en libFMap del HEAD.
|
|
164 |
* No funciona en la v10 porque AbstractCadMemoryDriver
|
|
165 |
* no declara el metodo getCadSource.
|
|
166 |
* Quitar tambi?n el if que muestra el mensaje de arriba.
|
|
167 |
*/
|
|
181 |
final com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver dwgDriver = (com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver)driver; |
|
182 |
double realTol = mapCtrl.getViewPort().toMapDistance(pixelTolerance); |
|
183 |
|
|
184 |
Rectangle2D recPoint = new Rectangle2D.Double(pReal.getX() - (realTol / 2), |
|
185 |
pReal.getY() - (realTol / 2), realTol, realTol); |
|
186 |
|
|
187 |
try { |
|
188 |
vectLyr.process(new FeatureVisitor(){ |
|
189 |
public void visit(IGeometry g, int index) throws VisitException { |
|
190 |
/* |
|
191 |
* Cambiar la comentarizacion de las dos lineas de abajo |
|
192 |
* para funcione la herramienta en libFMap del HEAD. |
|
193 |
* No funciona en la v10 porque AbstractCadMemoryDriver |
|
194 |
* no declara el metodo getCadSource. |
|
195 |
* Quitar tambi?n el if que muestra el mensaje de arriba. |
|
196 |
*/ |
|
168 | 197 |
|
169 | 198 |
// DwgObject dwgObj = (DwgObject) dwgDriver.getCadSource(index); |
170 |
DwgObject dwgObj = (DwgObject) ((DwgMemoryDriver)dwgDriver).getCadSource(index);
|
|
199 |
DwgObject dwgObj = (DwgObject) ((DwgMemoryDriver)dwgDriver).getCadSource(index); |
|
171 | 200 |
|
172 |
DwgHandleReference handle = dwgObj.getLayerHandle();
|
|
173 |
int lyrHdlCode = handle.getCode();
|
|
174 |
int lyrHdl = handle.getOffset();
|
|
175 |
JOptionPane.showConfirmDialog(null,
|
|
176 |
"hdlCode="+lyrHdlCode+",hdl="+lyrHdl+"entity="+dwgObj.getClass().getName());
|
|
177 |
}
|
|
201 |
DwgHandleReference handle = dwgObj.getLayerHandle(); |
|
202 |
int lyrHdlCode = handle.getCode(); |
|
203 |
int lyrHdl = handle.getOffset(); |
|
204 |
JOptionPane.showConfirmDialog(null, |
|
205 |
"hdlCode="+lyrHdlCode+",hdl="+lyrHdl+"entity="+dwgObj.getClass().getName()); |
|
206 |
} |
|
178 | 207 |
|
179 |
public String getProcessDescription() {
|
|
180 |
return "";
|
|
181 |
}
|
|
208 |
public String getProcessDescription() { |
|
209 |
return ""; |
|
210 |
} |
|
182 | 211 |
|
183 |
public void stop(FLayer layer) {
|
|
184 |
}
|
|
212 |
public void stop(FLayer layer) { |
|
213 |
} |
|
185 | 214 |
|
186 |
public boolean start(FLayer layer) {
|
|
187 |
return true;
|
|
188 |
}}, recPoint);
|
|
189 |
} catch (VisitException e) {
|
|
190 |
// TODO Auto-generated catch block
|
|
191 |
e.printStackTrace();
|
|
192 |
} catch (DriverException e) {
|
|
193 |
// TODO Auto-generated catch block
|
|
194 |
e.printStackTrace();
|
|
195 |
}//try
|
|
196 |
}//while
|
|
197 |
}
|
|
215 |
public boolean start(FLayer layer) { |
|
216 |
return true; |
|
217 |
}}, recPoint); |
|
218 |
} catch (VisitException e) { |
|
219 |
// TODO Auto-generated catch block |
|
220 |
e.printStackTrace(); |
|
221 |
} catch (DriverException e) { |
|
222 |
// TODO Auto-generated catch block |
|
223 |
e.printStackTrace(); |
|
224 |
}//try |
|
225 |
}//while |
|
226 |
} |
|
198 | 227 |
|
199 |
public Cursor getCursor() { |
|
200 |
return cur; |
|
201 |
} |
|
228 |
/* |
|
229 |
* (non-Javadoc) |
|
230 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor() |
|
231 |
*/ |
|
232 |
public Cursor getCursor() { |
|
233 |
return cur; |
|
234 |
} |
|
202 | 235 |
|
203 |
public boolean cancelDrawing() { |
|
204 |
return false; |
|
205 |
} |
|
236 |
/* |
|
237 |
* (non-Javadoc) |
|
238 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing() |
|
239 |
*/ |
|
240 |
public boolean cancelDrawing() { |
|
241 |
return false; |
|
242 |
} |
|
206 | 243 |
|
207 |
|
|
208 |
public void pointDoubleClick(PointEvent event) throws BehaviorException {
|
|
209 |
point(event);
|
|
210 |
}
|
|
211 |
|
|
212 |
|
|
244 |
/* |
|
245 |
* (non-Javadoc)
|
|
246 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
|
|
247 |
*/
|
|
248 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
|
249 |
point(event); |
|
213 | 250 |
} |
251 |
} |
|
214 | 252 |
|
215 | 253 |
|
216 | 254 |
|
Also available in: Unified diff