Revision 30327 branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/MapControl.java
MapControl.java | ||
---|---|---|
61 | 61 |
import java.awt.image.BufferedImage; |
62 | 62 |
import java.awt.image.MemoryImageSource; |
63 | 63 |
import java.util.ArrayList; |
64 |
import java.util.Comparator; |
|
64 | 65 |
import java.util.HashMap; |
65 | 66 |
import java.util.Set; |
67 |
import java.util.TreeMap; |
|
66 | 68 |
import java.util.prefs.Preferences; |
67 | 69 |
|
68 | 70 |
import javax.swing.JComponent; |
... | ... | |
104 | 106 |
import org.gvsig.utils.exceptionHandling.ExceptionListener; |
105 | 107 |
import org.slf4j.Logger; |
106 | 108 |
import org.slf4j.LoggerFactory; |
107 |
import java.util.TreeMap; |
|
108 |
import java.util.Comparator; |
|
109 | 109 |
|
110 | 110 |
|
111 |
|
|
111 | 112 |
/** |
112 | 113 |
* <p>A component that includes a {@link MapContext MapContext} with support for use it as a particular {@link Behavior Behavior}.</p> |
113 | 114 |
* |
... | ... | |
152 | 153 |
* <ul> |
153 | 154 |
* <li>Register each tool as: |
154 | 155 |
* <ul> |
155 |
* <li>A single behavior: {@link #addMapTool(String, Behavior) #addMapTool(String, Behavior)}.</li>
|
|
156 |
* <li>Or, a compound behavior: {@link #addMapTool(String, Behavior) #addMapTool(String, Behavior)}.</li>
|
|
156 |
* <li>A single behavior: {@link #addBehavior(String, Behavior) #addMapTool(String, Behavior)}.</li>
|
|
157 |
* <li>Or, a compound behavior: {@link #addBehavior(String, Behavior) #addMapTool(String, Behavior)}.</li>
|
|
157 | 158 |
* </ul> |
158 | 159 |
* </li> |
159 | 160 |
* <li>Get the current active tool: {@link #getCurrentMapTool() #getCurrentMapTool()}.</li> |
... | ... | |
198 | 199 |
* </p> |
199 | 200 |
* |
200 | 201 |
* @see CancelDraw |
201 |
* @see Drawer2
|
|
202 |
* @see Drawer |
|
202 | 203 |
* @see MapContextListener |
203 | 204 |
* @see MapToolListener |
204 | 205 |
* |
... | ... | |
206 | 207 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
207 | 208 |
*/ |
208 | 209 |
public class MapControl extends JComponent implements ComponentListener, Observer { |
209 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
|
210 |
private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class);
|
|
210 |
protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
|
211 |
protected static final Logger logger = LoggerFactory.getLogger(GeometryManager.class);
|
|
211 | 212 |
|
212 | 213 |
/** |
213 | 214 |
* <p>One of the possible status of <code>MapControl</code>. Determines that all visible information has been |
... | ... | |
227 | 228 |
*/ |
228 | 229 |
public static final int ONLY_GRAPHICS = 2; |
229 | 230 |
|
230 |
|
|
231 |
|
|
232 | 231 |
/** |
233 | 232 |
* <p>Determines if the drawer can update this <code>MapControl</code> instance when the timer launches an event.</p> |
234 | 233 |
*/ |
235 | 234 |
private static boolean drawAnimationEnabled = true; |
236 | 235 |
|
237 |
// public static final int FAST_PAINT = 3; |
|
238 |
//private static Logger logger = Logger.getLogger(MapControl.class.getName()); |
|
239 |
|
|
240 | 236 |
/** |
241 | 237 |
* <p>Inner model with the layers, event support for drawing them, and the <code>ViewPort</code> |
242 | 238 |
* with information to adapt to the bounds available in <i>image coordinates</i>.</p> |
... | ... | |
246 | 242 |
*/ |
247 | 243 |
private MapContext mapContext = null; |
248 | 244 |
|
249 |
//private boolean drawerAlive = false; |
|
250 |
|
|
251 |
|
|
252 |
/** |
|
245 |
/** |
|
253 | 246 |
* <p>All registered <code>Behavior</code> that can define a way to work with this <code>MapControl</code>.</p> |
254 | 247 |
* |
255 | 248 |
* <p>Only one of them can be active at a given moment.</p> |
256 | 249 |
* |
257 |
* @see #addMapTool(String, Behavior)
|
|
258 |
* @see #addMapTool(String, Behavior[])
|
|
250 |
* @see #addBehavior(String, Behavior)
|
|
251 |
* @see #addBehavior(String, Behavior[])
|
|
259 | 252 |
* @see #getMapTool(String) |
260 | 253 |
* @see #getMapToolsKeySet() |
261 | 254 |
* @see #getNamesMapTools() |
... | ... | |
342 | 335 |
*/ |
343 | 336 |
protected ViewPort vp; |
344 | 337 |
|
345 |
//private Drawer drawer; |
|
346 |
|
|
347 | 338 |
/** |
348 | 339 |
* <p>Manager of all <code>MapControl</code> painting requests.</p> |
349 | 340 |
*/ |
350 |
private Drawer2 drawer2;
|
|
341 |
private Drawer drawer;
|
|
351 | 342 |
|
352 |
// private boolean firstDraw = true; |
|
353 |
|
|
354 | 343 |
/** |
355 | 344 |
* <p>Listener of all kind of mouse events produced in this component.</p> |
356 | 345 |
* |
357 | 346 |
* <p>Delegates each mouse event to the current map tool.</p> |
358 | 347 |
* |
359 |
* @see #addMapTool(String, Behavior)
|
|
360 |
* @see #addMapTool(String, Behavior[])
|
|
348 |
* @see #addBehavior(String, Behavior)
|
|
349 |
* @see #addBehavior(String, Behavior[])
|
|
361 | 350 |
* @see #getMapTool(String) |
362 | 351 |
* @see #getMapToolsKeySet() |
363 | 352 |
* @see #getNamesMapTools() |
... | ... | |
388 | 377 |
* <p>Tool that will be used combined with the current tool of this <code>MapControl</code>.</p> |
389 | 378 |
*/ |
390 | 379 |
private Behavior combinedTool = null; |
391 |
|
|
380 |
|
|
392 | 381 |
/** |
393 |
* We need this to avoid not wanted refresh. REMEMBER TO SET TO TRUE!! |
|
394 |
*/ |
|
395 |
// private boolean paintEnabled = false; |
|
396 |
/** |
|
397 |
* Edition preferences. |
|
398 |
*/ |
|
399 |
private static Preferences prefs = Preferences.userRoot().node( "cadtooladapter" ); |
|
400 |
/** |
|
401 | 382 |
* Optional grid that could be applied on the <code>MapControl</code>'s view port. |
402 | 383 |
* |
403 | 384 |
* @see #getGrid() |
... | ... | |
418 | 399 |
* defined in the preferences.</p> |
419 | 400 |
*/ |
420 | 401 |
private boolean bForceCoord = false; |
402 |
|
|
421 | 403 |
/** |
422 | 404 |
* Kind of geometry drawn to identify the kind of control point selected by the cursor's mouse. |
423 | 405 |
*/ |
424 | 406 |
private ISnapper usedSnap = null; |
425 |
/** |
|
426 |
* A light yellow color for the tool tip text box associated to the point indicated by the mouse's cursor. |
|
427 |
*/ |
|
428 |
private Color theTipColor = new Color(255, 255, 155); |
|
429 | 407 |
|
430 | 408 |
/** |
431 | 409 |
* Determines if the snap tools are enabled or disabled. |
... | ... | |
440 | 418 |
*/ |
441 | 419 |
private double[] previousPoint = null; |
442 | 420 |
|
421 |
protected static MapControlManager mapControlManager = MapControlLocator.getMapControlManager(); |
|
422 |
|
|
443 | 423 |
private static TreeMap selected = new TreeMap(new Comparator(){ |
444 | 424 |
|
445 | 425 |
public int compare(Object o1, Object o2) { |
... | ... | |
453 | 433 |
|
454 | 434 |
}); |
455 | 435 |
|
456 |
public static int tolerance=4; |
|
457 | 436 |
/** |
458 | 437 |
* Represents the cursor's point selected in <i>map coordinates</i>. |
459 | 438 |
* |
... | ... | |
462 | 441 |
private Point2D mapAdjustedPoint; |
463 | 442 |
|
464 | 443 |
/** |
444 |
* Renderer used to draw the layers. |
|
445 |
*/ |
|
446 |
private MapControlDrawer mapControlDrawer = null; |
|
447 |
|
|
448 |
/** |
|
465 | 449 |
* <p>Creates a new <code>MapControl</code> instance with the following characteristics: |
466 | 450 |
* <ul> |
467 | 451 |
* <li><i>Name</i>: MapControl .</li> |
... | ... | |
500 | 484 |
this.addMouseMotionListener(mapToolListener); |
501 | 485 |
this.addMouseWheelListener(mapToolListener); |
502 | 486 |
|
503 |
this.drawer2 = new Drawer2();
|
|
487 |
this.drawer = new Drawer();
|
|
504 | 488 |
//Timer para mostrar el redibujado mientras se dibuja |
505 | 489 |
timer = new Timer(1000/MapContext.getDrawFrameRate(), |
506 | 490 |
new ActionListener() { |
... | ... | |
544 | 528 |
} else { |
545 | 529 |
vp = mapContext.getViewPort(); |
546 | 530 |
cadgrid.setViewPort(vp); |
547 |
// vp.setImageSize(new Dimension(getWidth(), getHeight())); |
|
548 |
//System.err.println("Viewport en setMapContext:" + vp); |
|
549 |
} |
|
550 |
|
|
531 |
} |
|
532 |
|
|
551 | 533 |
mapContext.addAtomicEventListener(mapContextListener); |
552 |
|
|
534 |
|
|
553 | 535 |
status = DESACTUALIZADO; |
554 | 536 |
} |
555 | 537 |
|
556 | 538 |
/** |
539 |
* @return the mapControlDrawer |
|
540 |
*/ |
|
541 |
public MapControlDrawer getMapControlDrawer() { |
|
542 |
return mapControlDrawer; |
|
543 |
} |
|
544 |
|
|
545 |
/** |
|
546 |
* @param mapControlDrawer the mapControlDrawer to set |
|
547 |
*/ |
|
548 |
public void setMapControlDrawer(MapControlDrawer mapControlDrawer) { |
|
549 |
this.mapControlDrawer = mapControlDrawer; |
|
550 |
this.mapControlDrawer.setViewPort(vp); |
|
551 |
} |
|
552 |
|
|
553 |
/** |
|
557 | 554 |
* <p>Gets this component's {@link MapContext MapContext} projection.</p> |
558 | 555 |
* |
559 | 556 |
* @return this component's {@link MapContext MapContext} projection |
... | ... | |
603 | 600 |
* @param name name to identify the behavior to add |
604 | 601 |
* @param tool the behavior to add |
605 | 602 |
* |
606 |
* @see #addMapTool(String, Behavior[])
|
|
603 |
* @see #addBehavior(String, Behavior[])
|
|
607 | 604 |
* @see #getNamesMapTools() |
608 | 605 |
* @see #getMapToolsKeySet() |
609 | 606 |
* @see #hasTool(String) |
610 | 607 |
*/ |
611 |
public void addMapTool(String name, Behavior tool) {
|
|
608 |
public void addBehavior(String name, Behavior tool) {
|
|
612 | 609 |
namesMapTools.put(name, tool); |
613 | 610 |
tool.setMapControl(this); |
614 | 611 |
} |
... | ... | |
623 | 620 |
* @param name name to identify the compound behavior to add |
624 | 621 |
* @param tools the compound behavior to add |
625 | 622 |
* |
626 |
* @see #addMapTool(String, Behavior)
|
|
623 |
* @see #addBehavior(String, Behavior)
|
|
627 | 624 |
* @see #getNamesMapTools() |
628 | 625 |
* @see #getMapToolsKeySet() |
629 | 626 |
* @see #hasTool(String) |
630 | 627 |
*/ |
631 |
public void addMapTool(String name, Behavior[] tools){
|
|
628 |
public void addBehavior(String name, Behavior[] tools){
|
|
632 | 629 |
CompoundBehavior tool = new CompoundBehavior(tools); |
633 |
addMapTool(name, tool);
|
|
630 |
addBehavior(name, tool);
|
|
634 | 631 |
} |
635 | 632 |
|
636 | 633 |
/** |
... | ... | |
642 | 639 |
* @return tool the registered behavior in this component as <code>name</code>, or <code>null</code> if |
643 | 640 |
* no one has that identifier |
644 | 641 |
* |
645 |
* @see #addMapTool(String, Behavior)
|
|
646 |
* @see #addMapTool(String, Behavior[])
|
|
642 |
* @see #addBehavior(String, Behavior)
|
|
643 |
* @see #addBehavior(String, Behavior[])
|
|
647 | 644 |
* @see #hasTool(String) |
648 | 645 |
*/ |
649 | 646 |
public Behavior getMapTool(String name) { |
... | ... | |
659 | 656 |
* @see HashMap#keySet() |
660 | 657 |
* |
661 | 658 |
* @see #getNamesMapTools() |
662 |
* @see #addMapTool(String, Behavior)
|
|
663 |
* @see #addMapTool(String, Behavior[])
|
|
659 |
* @see #addBehavior(String, Behavior)
|
|
660 |
* @see #addBehavior(String, Behavior[])
|
|
664 | 661 |
*/ |
665 | 662 |
public Set getMapToolsKeySet() { |
666 | 663 |
return namesMapTools.keySet(); |
... | ... | |
673 | 670 |
* |
674 | 671 |
* @return <code>true</code> if this component contains a tool identified by <code>toolName</code>; otherwise <code>false</code> |
675 | 672 |
* |
676 |
* @see #addMapTool(String, Behavior)
|
|
677 |
* @see #addMapTool(String, Behavior[])
|
|
673 |
* @see #addBehavior(String, Behavior)
|
|
674 |
* @see #addBehavior(String, Behavior[])
|
|
678 | 675 |
*/ |
679 | 676 |
public boolean hasTool(String toolName) { |
680 | 677 |
return namesMapTools.containsKey(toolName); |
... | ... | |
835 | 832 |
* @see Drawer2 |
836 | 833 |
*/ |
837 | 834 |
protected void paintComponent(Graphics g) { |
838 |
adaptToImageSize(); |
|
839 |
/* if (status == FAST_PAINT) { |
|
840 |
System.out.println("FAST_PAINT"); |
|
841 |
g.drawImage(image,0,0,null); |
|
842 |
status = ACTUALIZADO; |
|
843 |
return; |
|
844 |
} */ |
|
845 |
// System.out.println("PINTANDO MAPCONTROL" + this); |
|
835 |
adaptToImageSize(); |
|
836 |
|
|
837 |
mapControlDrawer.setGraphics(g); |
|
838 |
mapControlDrawer.setViewPort(getMapContext().getViewPort()); |
|
839 |
|
|
846 | 840 |
if (status == ACTUALIZADO) { |
847 |
// LWS logger.debug("Dibujando la imagen obtenida"); |
|
848 |
|
|
849 | 841 |
/* |
850 | 842 |
* Si hay un behaviour y la imagen es distinta de null se delega el dibujado |
851 | 843 |
* en dicho behaviour |
852 | 844 |
*/ |
853 |
if (image != null)
|
|
854 |
{
|
|
855 |
if (currentMapTool != null) {
|
|
856 |
currentMapTool.paintComponent(g);
|
|
845 |
if (image != null)
|
|
846 |
{
|
|
847 |
if (currentMapTool != null) {
|
|
848 |
currentMapTool.paintComponent(mapControlDrawer);
|
|
857 | 849 |
} else { |
858 |
g.drawImage(image,0,0,null); |
|
859 |
} |
|
860 |
|
|
861 |
// System.out.println("Pinto ACTUALIZADO"); |
|
850 |
mapControlDrawer.drawImage(image,0,0); |
|
851 |
} |
|
862 | 852 |
} |
863 | 853 |
} else if ((status == DESACTUALIZADO) |
864 |
|| (status == ONLY_GRAPHICS)) { |
|
865 |
// LWS System.out.println("DESACTUALIZADO: Obteniendo la imagen de la cartograf?a"); |
|
866 |
/* if (isOpaque()) |
|
867 |
{ |
|
868 |
if (image==null) |
|
869 |
{ |
|
870 |
g.setColor(vp.getBackColor()); |
|
871 |
g.fillRect(0,0,getWidth(), getHeight()); |
|
872 |
} |
|
873 |
// else g.drawImage(image,0,0,null); |
|
874 |
} */ |
|
875 |
// cancelDrawing(); |
|
876 |
//Se crea la imagen con el color de fonde deseado |
|
877 |
/* if (image == null) |
|
878 |
{ |
|
879 |
image = new BufferedImage(this.getWidth(), this.getHeight(), |
|
880 |
BufferedImage.TYPE_INT_ARGB); |
|
881 |
vp.setImageSize(new Dimension(getWidth(), getHeight())); |
|
882 |
Graphics gTemp = image.createGraphics(); |
|
883 |
Color theBackColor = vp.getBackColor(); |
|
884 |
if (theBackColor == null) |
|
885 |
gTemp.setColor(Color.WHITE); |
|
886 |
else |
|
887 |
gTemp.setColor(theBackColor); |
|
854 |
|| (status == ONLY_GRAPHICS)) { |
|
855 |
|
|
856 |
mapControlDrawer.drawImage(image,0,0); |
|
888 | 857 |
|
889 |
gTemp.fillRect(0,0,getWidth(), getHeight()); |
|
890 |
gTemp.dispose(); |
|
891 |
// g.drawImage(image,0,0,null); |
|
892 |
System.out.println("Imagen con null en DESACTUALIZADO. Width = " + this.getWidth()); |
|
893 |
} */ |
|
894 |
// else |
|
895 |
// { |
|
896 |
|
|
897 |
|
|
898 |
// if (image != null) |
|
899 |
// { |
|
900 |
g.drawImage(image,0,0,null); |
|
901 |
|
|
902 |
drawer2.put(new PaintingRequest()); |
|
903 |
timer.start(); |
|
904 |
/* } |
|
905 |
else |
|
906 |
return; */ |
|
907 |
// } |
|
908 |
|
|
909 |
/* if (drawerAlive == false) |
|
910 |
{ |
|
911 |
drawer = new Drawer(image, canceldraw); |
|
912 |
drawer.start(); |
|
913 |
//Se lanza el tread de dibujado |
|
914 |
} */ |
|
915 |
|
|
916 |
// status = ACTUALIZADO; |
|
858 |
drawer.put(new PaintingRequest()); |
|
859 |
timer.start(); |
|
917 | 860 |
} |
918 | 861 |
cadgrid.drawGrid(g); |
919 | 862 |
drawCursor(g); |
... | ... | |
1187 | 1130 |
* |
1188 | 1131 |
* @author fjp |
1189 | 1132 |
*/ |
1190 |
public class Drawer2
|
|
1133 |
public class Drawer |
|
1191 | 1134 |
{ |
1192 | 1135 |
// Una mini cola de 2. No acumulamos peticiones de dibujado |
1193 | 1136 |
// dibujamos solo lo ?ltimo que nos han pedido. |
... | ... | |
1247 | 1190 |
* </ul> |
1248 | 1191 |
* </p> |
1249 | 1192 |
*/ |
1250 |
public Drawer2()
|
|
1193 |
public Drawer() |
|
1251 | 1194 |
{ |
1252 | 1195 |
paintingRequest = null; |
1253 | 1196 |
waitingRequest = null; |
... | ... | |
1339 | 1282 |
} |
1340 | 1283 |
} |
1341 | 1284 |
} |
1342 |
|
|
1285 |
|
|
1343 | 1286 |
/** |
1344 |
* <p><code>Drawer</code> is implemented for drawing the layers of a <code>MapControl</code>'s <i>MapContext</i> instance |
|
1345 |
* as a <i>thread</i> of execution.</p> |
|
1346 |
* |
|
1347 |
* <p>Draws <code>MapControl</code> according its <i>status</i>: |
|
1348 |
* <ul> |
|
1349 |
* <li><code><i>ONLY_GRAPHICS</i></code>: refreshes only the graphical layer, changing the status to <code><i>UPDATED</i></code>, via |
|
1350 |
* {@linkplain MapContext#drawGraphics(BufferedImage, Graphics2D, Cancellable, double) MapContext#drawGraphics(BufferedImage, Graphics2D, Cancellable, double)}.</li> |
|
1351 |
* <li><code><i>OUTDATED</i></code>: refreshes all layers, changing the status to <code><i>UPDATED</i></code>, via |
|
1352 |
* {@linkplain MapContext#draw(BufferedImage, Graphics2D, Cancellable, double) MapContext#draw(BufferedImage, Graphics2D, Cancellable, double)}.</li> |
|
1353 |
* <ul> |
|
1354 |
* </p> |
|
1355 |
* |
|
1356 |
* <p>This drawing process is accelerated by a <code>BufferedImage</code>, and can be canceled.</p> |
|
1357 |
* |
|
1358 |
* <p>Once the drawing process has finished, the timer stops and this component gets repainted.</p> |
|
1359 |
* |
|
1360 |
* @deprecated |
|
1361 |
* @author Vicente Caballero Navarro |
|
1362 |
*/ |
|
1363 |
public class Drawer extends Thread { |
|
1364 |
//private Graphics g; |
|
1365 |
|
|
1366 |
/** |
|
1367 |
* <p>Image with a buffer to accelerate the draw the changes of the graphical items in this component.</p> |
|
1368 |
* |
|
1369 |
* <p>Firstly, information will be drawn in the buffer, and, when is outright drawn, that information will be displayed. |
|
1370 |
* Meanwhile, the previous image can be kept showed.</p> |
|
1371 |
* |
|
1372 |
* @see BufferedImage |
|
1373 |
*/ |
|
1374 |
private BufferedImage image = null; |
|
1375 |
|
|
1376 |
/** |
|
1377 |
* <p>Object to store the flag that notifies the drawing must be canceled or can continue with the process.</p> |
|
1378 |
* |
|
1379 |
* <p>At last resort, the particular implementation of each layer in a <code>MapControl</code>'s <code>MapContrext</code> |
|
1380 |
* will be which will draw the graphical information, and, if supports, which could cancel its drawing subprocess.</p> |
|
1381 |
*/ |
|
1382 |
private CancelDraw cancel; |
|
1383 |
//private boolean threadCancel = false; |
|
1384 |
|
|
1385 |
/** |
|
1386 |
* <p>Creates a new <code>Drawer</code> instance.</p> |
|
1387 |
*/ |
|
1388 |
public Drawer(BufferedImage image, CancelDraw cancel) |
|
1389 |
{ |
|
1390 |
this.image = image; |
|
1391 |
this.cancel = cancel; |
|
1392 |
// drawerAlive = true; |
|
1393 |
} |
|
1394 |
|
|
1395 |
/** |
|
1396 |
* @see java.lang.Runnable#run() |
|
1397 |
* @see MapContext#draw(BufferedImage, Graphics2D, Cancellable, double) |
|
1398 |
* @see MapContext#drawGraphics(BufferedImage, Graphics2D, Cancellable, double) |
|
1399 |
*/ |
|
1400 |
public void run() { |
|
1401 |
try { |
|
1402 |
// synchronized (Drawer.class) { |
|
1403 |
Graphics2D g = image.createGraphics(); |
|
1404 |
|
|
1405 |
ViewPort viewPort = mapContext.getViewPort(); |
|
1406 |
if (status == DESACTUALIZADO) |
|
1407 |
{ |
|
1408 |
Color theBackColor = viewPort.getBackColor(); |
|
1409 |
if (theBackColor == null) { |
|
1410 |
g.setColor(Color.WHITE); |
|
1411 |
} else { |
|
1412 |
g.setColor(theBackColor); |
|
1413 |
} |
|
1414 |
g.fillRect(0, 0, viewPort.getImageWidth(), viewPort.getImageHeight()); |
|
1415 |
status = ACTUALIZADO; |
|
1416 |
mapContext.draw(image, g, cancel,mapContext.getScaleView()); |
|
1417 |
} |
|
1418 |
else if (status == ONLY_GRAPHICS) |
|
1419 |
{ |
|
1420 |
status = ACTUALIZADO; |
|
1421 |
mapContext.drawGraphics(image, g, cancel,mapContext.getScaleView()); |
|
1422 |
} |
|
1423 |
|
|
1424 |
timer.stop(); |
|
1425 |
// status = FAST_PAINT; |
|
1426 |
// drawerAlive = false; |
|
1427 |
repaint(); |
|
1428 |
|
|
1429 |
|
|
1430 |
|
|
1431 |
// } |
|
1432 |
} catch (Throwable e) { |
|
1433 |
timer.stop(); |
|
1434 |
//isCancelled = true; |
|
1435 |
e.printStackTrace(); |
|
1436 |
throwException(e); |
|
1437 |
} finally { |
|
1438 |
} |
|
1439 |
} |
|
1440 |
} |
|
1441 |
|
|
1442 |
/** |
|
1443 | 1287 |
* <p>An instance of <code>CancelDraw</code> will be shared by all this <code>MapControl</code>'s <code>MapContext</code> layers, |
1444 | 1288 |
* allowing receive a notification that, when they're been drawn, to be cancelled.</p> |
1445 | 1289 |
* |
... | ... | |
1529 | 1373 |
* @see Behavior#mouseEntered(MouseEvent) |
1530 | 1374 |
*/ |
1531 | 1375 |
public void mouseEntered(MouseEvent e) { |
1532 |
clearMouseImage();
|
|
1376 |
setToolMouse();
|
|
1533 | 1377 |
try { |
1534 | 1378 |
if (currentMapTool != null) { |
1535 | 1379 |
currentMapTool.mouseEntered(e); |
... | ... | |
1551 | 1395 |
} catch (BehaviorException t) { |
1552 | 1396 |
throwException(t); |
1553 | 1397 |
} |
1398 |
//Remove the snapping image if exist |
|
1399 |
usedSnap = null; |
|
1400 |
repaint(); |
|
1554 | 1401 |
} |
1555 | 1402 |
|
1556 | 1403 |
/** |
... | ... | |
1780 | 1627 |
* |
1781 | 1628 |
* @return registered <code>Behavior</code> to this <code>MapControl</code> |
1782 | 1629 |
* |
1783 |
* @see #addMapTool(String, Behavior)
|
|
1784 |
* @see #addMapTool(String, Behavior[])
|
|
1630 |
* @see #addBehavior(String, Behavior)
|
|
1631 |
* @see #addBehavior(String, Behavior[])
|
|
1785 | 1632 |
* @see #getMapToolsKeySet() |
1786 | 1633 |
* @see #hasTool(String) |
1787 | 1634 |
*/ |
... | ... | |
1810 | 1657 |
* |
1811 | 1658 |
* <p>Exchanges the previous tool with the current one.</p> |
1812 | 1659 |
* |
1813 |
* @see #addMapTool(String, Behavior)
|
|
1814 |
* @see #addMapTool(String, Behavior[])
|
|
1660 |
* @see #addBehavior(String, Behavior)
|
|
1661 |
* @see #addBehavior(String, Behavior[])
|
|
1815 | 1662 |
* @see #setTool(String) |
1816 | 1663 |
*/ |
1817 | 1664 |
public void setPrevTool() { |
... | ... | |
1886 | 1733 |
* @see #getCurrentTool() |
1887 | 1734 |
* @see #setTool(String) |
1888 | 1735 |
* @see #setPrevTool() |
1889 |
* @see #addMapTool(String, Behavior)
|
|
1890 |
* @see #addMapTool(String, Behavior[])
|
|
1736 |
* @see #addBehavior(String, Behavior)
|
|
1737 |
* @see #addBehavior(String, Behavior[])
|
|
1891 | 1738 |
*/ |
1892 | 1739 |
public void setCurrentMapTool(Behavior mapTool ){ |
1893 | 1740 |
currentMapTool = mapTool; |
... | ... | |
1975 | 1822 |
* |
1976 | 1823 |
* @param tool a new tool to be used combined with the current tool |
1977 | 1824 |
*/ |
1978 |
public void addCombinedTool(Behavior tool) {
|
|
1825 |
public void addCombinedBehavior(Behavior tool) {
|
|
1979 | 1826 |
if (combinedTool == null) { |
1980 | 1827 |
combinedTool = tool; |
1981 | 1828 |
} |
... | ... | |
2044 | 1891 |
* </p> |
2045 | 1892 |
*/ |
2046 | 1893 |
public void initializeGrid(){ |
1894 |
Preferences prefs = mapControlManager.getEditionPreferences(); |
|
2047 | 1895 |
boolean showGrid = prefs.getBoolean("grid.showgrid",cadgrid.isShowGrid()); |
2048 | 1896 |
boolean adjustGrid = prefs.getBoolean("grid.adjustgrid",cadgrid.isAdjustGrid()); |
2049 | 1897 |
|
... | ... | |
2065 | 1913 |
cadgrid.setViewPort(getViewPort()); |
2066 | 1914 |
this.repaint(); |
2067 | 1915 |
} |
1916 |
|
|
2068 | 1917 |
/** |
1918 |
* Uses like a mouse pointer the image that provides the |
|
1919 |
* selected tool. |
|
1920 |
*/ |
|
1921 |
private void setToolMouse(){ |
|
1922 |
Image cursor=getCurrentMapTool().getImageCursor(); |
|
1923 |
Toolkit toolkit = Toolkit.getDefaultToolkit(); |
|
1924 |
Cursor c = toolkit.createCustomCursor(cursor , |
|
1925 |
new Point(16, 16), "img"); |
|
1926 |
setCursor (c); |
|
1927 |
} |
|
1928 |
|
|
1929 |
/** |
|
1930 |
* Makes the mouse pointer transparent. |
|
1931 |
*/ |
|
1932 |
private void setTransparentMouse(){ |
|
1933 |
Image cursor=getCurrentMapTool().getImageCursor(); |
|
1934 |
Toolkit toolkit = Toolkit.getDefaultToolkit(); |
|
1935 |
Cursor transparentCursor = Toolkit.getDefaultToolkit() |
|
1936 |
.createCustomCursor(Toolkit.getDefaultToolkit().createImage(new MemoryImageSource( |
|
1937 |
16, 16, new int[16 * 16], 0, 16)), |
|
1938 |
new Point(0, 0), "invisiblecursor"); |
|
1939 |
setCursor (transparentCursor); |
|
1940 |
} |
|
1941 |
|
|
1942 |
/** |
|
2069 | 1943 |
* <p>Draws a 31x31 pixels cross round the mouse's cursor with an small geometry centered: |
2070 | 1944 |
* <ul> |
2071 | 1945 |
* <li><i>an square centered</i>: if isn't over a <i>control point</i>. |
... | ... | |
2078 | 1952 |
* @param g <code>MapControl</code>'s graphics where the data will be drawn |
2079 | 1953 |
*/ |
2080 | 1954 |
private void drawCursor(Graphics g) { |
2081 |
Image cursor=getCurrentMapTool().getImageCursor(); |
|
2082 |
|
|
2083 |
|
|
2084 |
|
|
2085 |
g.setColor(Color.black); |
|
2086 |
Point2D p = adjustedPoint; |
|
2087 |
|
|
2088 |
if (p == null) { |
|
2089 |
cadgrid.setViewPort(vp); |
|
1955 |
if (adjustedPoint == null){ |
|
2090 | 1956 |
return; |
2091 | 1957 |
} |
2092 |
g.drawImage(cursor, (int)p.getX()-16, (int)p.getY()-16, this); |
|
2093 |
// int size1 = 15; |
|
2094 |
// int size2 = 3; |
|
2095 |
// g.drawLine((int) (p.getX() - size1), (int) (p.getY()), |
|
2096 |
// (int) (p.getX() + size1), (int) (p.getY())); |
|
2097 |
// g.drawLine((int) (p.getX()), (int) (p.getY() - size1), |
|
2098 |
// (int) (p.getX()), (int) (p.getY() + size1)); |
|
2099 |
// |
|
2100 |
// // getMapControl().setToolTipText(null); |
|
2101 |
// if (adjustedPoint != null) { |
|
2102 |
// if (bForceCoord) { |
|
2103 |
// /* g.setColor(Color.ORANGE); |
|
2104 |
// g.drawRect((int) (adjustedPoint.getX() - 6), |
|
2105 |
// (int) (adjustedPoint.getY() - 6), 12, 12); |
|
2106 |
// g.drawRect((int) (adjustedPoint.getX() - 3), |
|
2107 |
// (int) (adjustedPoint.getY() - 3), 6, 6); |
|
2108 |
// g.setColor(Color.MAGENTA); |
|
2109 |
// g.drawRect((int) (adjustedPoint.getX() - 4), |
|
2110 |
// (int) (adjustedPoint.getY() - 4), 8, 8); */ |
|
2111 |
// if (usedSnap != null) |
|
2112 |
// { |
|
2113 |
// usedSnap.draw(g, adjustedPoint); |
|
2114 |
// |
|
2115 |
// Graphics2D g2 = (Graphics2D) g; |
|
2116 |
// FontMetrics metrics = g2.getFontMetrics(); |
|
2117 |
// int w = metrics.stringWidth(usedSnap.getToolTipText()) + 5; |
|
2118 |
// int h = metrics.getMaxAscent() + 5; |
|
2119 |
// int x = (int)p.getX()+9; |
|
2120 |
// int y = (int)p.getY()- 7; |
|
2121 |
// |
|
2122 |
// g2.setColor(theTipColor ); |
|
2123 |
// g2.fillRect(x, y-h, w, h); |
|
2124 |
// g2.setColor(Color.BLACK); |
|
2125 |
// g2.drawRect(x, y-h, w, h); |
|
2126 |
// g2.drawString(usedSnap.getToolTipText(), x+3, y-3); |
|
2127 |
// |
|
2128 |
// |
|
2129 |
// // getMapControl().setToolTipText(usedSnap.getToolTipText()); |
|
2130 |
// } |
|
2131 |
// |
|
2132 |
// bForceCoord = false; |
|
2133 |
// } else { |
|
2134 |
// g.drawRect((int) (p.getX() - size2), (int) (p.getY() - size2), |
|
2135 |
// (int) (size2 * 2), (int) (size2 * 2)); |
|
2136 |
// } |
|
2137 |
// } |
|
2138 |
// repaint(); |
|
1958 |
|
|
1959 |
if (usedSnap != null){ |
|
1960 |
usedSnap.draw(g, adjustedPoint); |
|
1961 |
setTransparentMouse(); |
|
1962 |
}else{ |
|
1963 |
setToolMouse(); |
|
1964 |
} |
|
2139 | 1965 |
} |
1966 |
|
|
2140 | 1967 |
/** |
2141 |
* Hides the mouse's cursor. |
|
2142 |
*/ |
|
2143 |
private void clearMouseImage() { |
|
2144 |
int[] pixels = new int[16 * 16]; |
|
2145 |
Image image = Toolkit.getDefaultToolkit().createImage( |
|
2146 |
new MemoryImageSource(16, 16, pixels, 0, 16)); |
|
2147 |
Cursor transparentCursor = Toolkit.getDefaultToolkit() |
|
2148 |
.createCustomCursor(image, new Point(0, 0), "invisiblecursor"); |
|
2149 |
|
|
2150 |
setCursor(transparentCursor); |
|
2151 |
} |
|
2152 |
/** |
|
2153 | 1968 |
* <p>Adjusts the <code>point</code> to the grid if its enabled, and |
2154 | 1969 |
* sets <code>mapHandlerAdjustedPoint</code> with that new value.</p> |
2155 | 1970 |
* |
... | ... | |
2170 | 1985 |
if (!isRefentEnabled()) |
2171 | 1986 |
return Double.MAX_VALUE; |
2172 | 1987 |
|
2173 |
ArrayList snappers=new ArrayList(selected.keySet()); |
|
2174 | 1988 |
ArrayList layersToSnap = getMapContext().getLayersToSnap(); |
2175 | 1989 |
|
2176 |
double mapTolerance = vp.toMapDistance(MapControl.tolerance);
|
|
1990 |
double mapTolerance = vp.toMapDistance(mapControlManager.getTolerance());
|
|
2177 | 1991 |
double minDist = mapTolerance; |
2178 | 1992 |
double middleTol=mapTolerance * 0.5; |
2179 | 1993 |
Point2D mapPoint = point; |
... | ... | |
2208 | 2022 |
java.util.List geoms = cache.query(e); |
2209 | 2023 |
for (int n=0; n < geoms.size(); n++) { |
2210 | 2024 |
Geometry geom = (Geometry) geoms.get(n); |
2211 |
for (int i = 0; i < snappers.size(); i++)
|
|
2025 |
for (int i = 0; i < mapControlManager.getSnapperCount(); i++)
|
|
2212 | 2026 |
{ |
2213 |
ISnapper theSnapper = (ISnapper) snappers.get(i);
|
|
2027 |
ISnapper theSnapper = mapControlManager.getSnapperAt(i);
|
|
2214 | 2028 |
|
2215 | 2029 |
if (usedSnap != null) |
2216 | 2030 |
{ |
... | ... | |
2260 | 2074 |
{ |
2261 | 2075 |
return bRefent; |
2262 | 2076 |
} |
2263 |
public void initializeSnapping() { |
|
2264 |
ArrayList snappers=getMapContext().getSnappers(); |
|
2265 |
for (int n = 0; n < snappers.size(); n++) { |
|
2266 |
ISnapper snp = (ISnapper) snappers.get(n); |
|
2267 |
String nameClass=snp.getClass().getName(); |
|
2268 |
nameClass=nameClass.substring(nameClass.lastIndexOf('.')); |
|
2269 |
boolean select = prefs.getBoolean("snapper_activated" + nameClass, false); |
|
2270 |
if (select) { |
|
2271 |
selected.put(snp, new Boolean(select)); |
|
2272 |
} |
|
2273 |
int priority = prefs.getInt("snapper_priority" + nameClass,3); |
|
2274 |
snp.setPriority(priority); |
|
2275 |
} |
|
2276 |
// applySnappers = prefs.getBoolean("apply-snappers",true); |
|
2277 |
// snapConfig.setApplySnappers(applySnappers); |
|
2278 |
// snapConfig.selectSnappers(selected); |
|
2279 |
|
|
2280 |
} |
|
2077 |
|
|
2281 | 2078 |
/** |
2079 |
* Enables the snapping. |
|
2080 |
*/ |
|
2081 |
public void enableSnapping() { |
|
2082 |
mapControlManager.disableSnapping(); |
|
2083 |
} |
|
2084 |
|
|
2085 |
/** |
|
2086 |
* Disables the snapping. |
|
2087 |
*/ |
|
2088 |
public void disableSnapping(){ |
|
2089 |
mapControlManager.clearSnappers(); |
|
2090 |
} |
|
2091 |
|
|
2092 |
/** |
|
2282 | 2093 |
* <p>Tries to find the nearest geometry or grid control point by the position of the current snap tool.</p> |
2283 | 2094 |
* |
2284 | 2095 |
* <p>Prioritizes the grid control points than the geometries ones.</p> |
... | ... | |
2288 | 2099 |
* |
2289 | 2100 |
* @param point current mouse 2D position |
2290 | 2101 |
*/ |
2291 |
public Point2D calculateSnapPoint(Point point) {
|
|
2102 |
public void calculateSnapPoint(Point point) {
|
|
2292 | 2103 |
// Se comprueba el ajuste a rejilla |
2293 | 2104 |
|
2294 | 2105 |
Point2D gridAdjustedPoint = vp.toMapPoint( |
... | ... | |
2335 | 2146 |
if (minDistance == Double.MAX_VALUE) { |
2336 | 2147 |
adjustedPoint = point; |
2337 | 2148 |
mapAdjustedPoint = null; |
2338 |
} |
|
2339 |
return mapAdjustedPoint; |
|
2149 |
} |
|
2340 | 2150 |
} |
2151 |
|
|
2341 | 2152 |
/** |
2342 | 2153 |
* Sets the snap tools enabled or disabled. |
2343 | 2154 |
* |
... | ... | |
2353 | 2164 |
return cadgrid; |
2354 | 2165 |
} |
2355 | 2166 |
|
2356 |
public static TreeMap getSelectedSnapppers() { |
|
2357 |
return selected; |
|
2358 |
} |
|
2359 |
|
|
2360 | 2167 |
public void update(Observable observable, Object notification) { |
2361 | 2168 |
DataStoreNotification ddsn=(DataStoreNotification)notification; |
2362 | 2169 |
String type=ddsn.getType(); |
... | ... | |
2364 | 2171 |
type.equals(FeatureStoreNotification.AFTER_REDO)){ |
2365 | 2172 |
repaint(); |
2366 | 2173 |
} |
2174 |
} |
|
2175 |
|
|
2176 |
/** |
|
2177 |
* @return the adjustedPoint |
|
2178 |
*/ |
|
2179 |
public Point2D getAdjustedPoint() { |
|
2180 |
return adjustedPoint; |
|
2367 | 2181 |
} |
2182 |
|
|
2183 |
/** |
|
2184 |
* @return the mapAdjustedPoint |
|
2185 |
*/ |
|
2186 |
public Point2D getMapAdjustedPoint() { |
|
2187 |
return mapAdjustedPoint; |
|
2188 |
} |
|
2189 |
|
|
2190 |
/** |
|
2191 |
* Gets the selected point. If the snapping is enabled |
|
2192 |
* it returns the selected point. |
|
2193 |
* @return |
|
2194 |
* The selected point |
|
2195 |
*/ |
|
2196 |
public Point2D getPoint(){ |
|
2197 |
if (mapAdjustedPoint != null) { |
|
2198 |
return mapAdjustedPoint; |
|
2199 |
} else { |
|
2200 |
return getViewPort().toMapPoint(adjustedPoint); |
|
2201 |
} |
|
2202 |
} |
|
2368 | 2203 |
} |
Also available in: Unified diff