Revision 41175
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/PointSelectionListener.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
import org.gvsig.fmap.IconThemeHelper; |
30 | 30 |
import org.gvsig.fmap.dal.exception.DataException; |
31 |
import org.gvsig.fmap.dal.feature.Feature; |
|
31 | 32 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
32 | 33 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
33 | 34 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
... | ... | |
35 | 36 |
import org.gvsig.fmap.mapcontrol.MapControl; |
36 | 37 |
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
37 | 38 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener; |
39 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
38 | 40 |
|
39 | 41 |
/** |
40 | 42 |
* <p>Listener that selects all features of the active, and vector layers of the associated <code>MapControl</code> |
... | ... | |
44 | 46 |
*/ |
45 | 47 |
public class PointSelectionListener implements PointListener { |
46 | 48 |
/** |
47 |
* The image to display when the cursor is active. |
|
48 |
*/ |
|
49 |
// private final Image img = PluginServices.getIconTheme().get("cursor-select-by-point").getImage(); |
|
50 |
|
|
51 |
/** |
|
52 | 49 |
* Reference to the <code>MapControl</code> object that uses. |
53 | 50 |
*/ |
54 | 51 |
protected MapControl mapCtrl; |
... | ... | |
62 | 59 |
this.mapCtrl = mc; |
63 | 60 |
} |
64 | 61 |
|
65 |
/* |
|
66 |
* (non-Javadoc) |
|
67 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent) |
|
68 |
*/ |
|
69 | 62 |
public void point(PointEvent event) throws BehaviorException { |
70 | 63 |
try { |
71 |
// mapCtrl.getMapContext().selectByPoint(event.getPoint(), 1); |
|
72 | 64 |
Point2D p = event.getPoint(); |
73 | 65 |
Point2D mapPoint = mapCtrl.getViewPort().toMapPoint((int) p.getX(), (int) p.getY()); |
74 | 66 |
|
75 | 67 |
// Tolerancia de 3 pixels |
76 | 68 |
double tol = mapCtrl.getViewPort().toMapDistance(3); |
77 |
FLayer[] actives = mapCtrl.getMapContext() |
|
78 |
.getLayers().getActives(); |
|
79 |
for (int i=0; i < actives.length; i++) |
|
80 |
{ |
|
69 |
FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives(); |
|
70 |
for (int i = 0; i < actives.length; i++) { |
|
81 | 71 |
if (actives[i] instanceof FLyrVect) { |
82 | 72 |
FLyrVect lyrVect = (FLyrVect) actives[i]; |
83 | 73 |
FeatureSet newSelection = null; |
84 | 74 |
try { |
85 |
newSelection = |
|
86 |
lyrVect.queryByPoint(mapPoint, tol, |
|
87 |
lyrVect.getFeatureStore() |
|
88 |
.getDefaultFeatureType()); |
|
75 |
newSelection = lyrVect.queryByPoint( |
|
76 |
mapPoint, tol, |
|
77 |
lyrVect.getFeatureStore().getDefaultFeatureType()); |
|
89 | 78 |
if (event.getEvent().isControlDown()) { |
90 |
((FeatureSelection) lyrVect.getDataStore() |
|
91 |
.getSelection()).select(newSelection); |
|
79 |
FeatureSelection currentSelection = |
|
80 |
((FeatureSelection) lyrVect.getDataStore().getSelection()); |
|
81 |
if(isAlreadySelected(currentSelection, newSelection)) { |
|
82 |
currentSelection.deselect(newSelection); |
|
83 |
} else { |
|
84 |
currentSelection.select(newSelection); |
|
85 |
} |
|
92 | 86 |
} else { |
93 | 87 |
lyrVect.getFeatureStore() |
94 | 88 |
.setSelection(newSelection); |
... | ... | |
98 | 92 |
newSelection.dispose(); |
99 | 93 |
} |
100 | 94 |
} |
101 |
|
|
102 |
|
|
103 | 95 |
mapCtrl.drawMap(false); // FIXME Esto deber?a sobrar (la capa deber?a de ser observada) |
104 | 96 |
} |
105 | 97 |
} |
... | ... | |
108 | 100 |
throw new BehaviorException("No se pudo hacer la selecci?n", e); |
109 | 101 |
} |
110 | 102 |
} |
103 |
|
|
104 |
private boolean isAlreadySelected(FeatureSelection currentSelection, FeatureSet newSelection) throws DataException { |
|
105 |
DisposableIterator it = newSelection.fastIterator(); |
|
106 |
while(it.hasNext()) { |
|
107 |
Object obj = it.next(); |
|
108 |
if(obj instanceof Feature) { |
|
109 |
Feature feat = ((Feature)obj); |
|
110 |
if(currentSelection.isSelected(feat)) |
|
111 |
return true; |
|
112 |
} |
|
113 |
} |
|
114 |
return false; |
|
115 |
} |
|
111 | 116 |
|
112 |
/* |
|
113 |
* (non-Javadoc) |
|
114 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor() |
|
115 |
*/ |
|
116 | 117 |
public Image getImageCursor() { |
117 | 118 |
return IconThemeHelper.getImage("cursor-select-by-point"); |
118 | 119 |
} |
119 | 120 |
|
120 |
/* |
|
121 |
* (non-Javadoc) |
|
122 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing() |
|
123 |
*/ |
|
124 | 121 |
public boolean cancelDrawing() { |
125 | 122 |
return false; |
126 | 123 |
} |
127 | 124 |
|
128 |
/* |
|
129 |
* (non-Javadoc) |
|
130 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#pointDoubleClick(com.iver.cit.gvsig.fmap.tools.Events.PointEvent) |
|
131 |
*/ |
|
132 | 125 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
133 | 126 |
|
134 | 127 |
} |
135 |
|
|
136 |
|
|
137 | 128 |
} |
Also available in: Unified diff