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