Revision 45947
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/vectorial/FLyrVect.java | ||
---|---|---|
29 | 29 |
import java.awt.image.BufferedImage; |
30 | 30 |
import java.io.File; |
31 | 31 |
import java.util.Iterator; |
32 |
import java.util.List; |
|
32 | 33 |
import java.util.Set; |
33 | 34 |
import java.util.TreeSet; |
34 | 35 |
|
... | ... | |
42 | 43 |
import org.gvsig.fmap.dal.exception.DataException; |
43 | 44 |
import org.gvsig.fmap.dal.exception.InitializeException; |
44 | 45 |
import org.gvsig.fmap.dal.exception.ReadException; |
46 |
import org.gvsig.fmap.dal.feature.Feature; |
|
45 | 47 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
46 | 48 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
47 | 49 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
... | ... | |
903 | 905 |
} |
904 | 906 |
} |
905 | 907 |
|
908 |
public FeatureQuery createQueryByPoint(double x, double y, |
|
909 |
double tol, |
|
910 |
FeatureType featureType) throws DataException { |
|
911 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
912 |
org.gvsig.fmap.geom.primitive.Point center; |
|
913 |
try { |
|
914 |
center |
|
915 |
= (org.gvsig.fmap.geom.primitive.Point) manager.create(TYPES.POINT, |
|
916 |
SUBTYPES.GEOM2D); |
|
917 |
center.setX(x); |
|
918 |
center.setY(y); |
|
919 |
Circle circle |
|
920 |
= (Circle) manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
|
921 |
circle.setPoints(center, tol); |
|
922 |
return createQueryByGeometry(circle, featureType); |
|
923 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
|
924 |
throw new CreateGeometryException(TYPES.CIRCLE, SUBTYPES.GEOM2D, e); |
|
925 |
} |
|
926 |
} |
|
927 |
|
|
906 | 928 |
/** |
907 | 929 |
* Input geom must be in the CRS of the view. |
908 | 930 |
* |
... | ... | |
931 | 953 |
|
932 | 954 |
} |
933 | 955 |
|
956 |
public FeatureQuery createQueryByGeometry(Geometry geom, FeatureType featureType) throws DataException { |
|
957 |
FeatureQuery featureQuery = createFeatureQuery(); |
|
958 |
featureQuery.setFeatureType(featureType); |
|
959 |
|
|
960 |
Geometry query_geo = this.transformToSourceCRS(geom, true); |
|
961 |
IProjection query_proj = getMapContext().getProjection(); |
|
962 |
if (this.getCoordTrans() != null) { |
|
963 |
query_proj = this.getCoordTrans().getPOrig(); |
|
964 |
} |
|
965 |
Evaluator iee = SpatialEvaluatorsFactory.getInstance().intersects( |
|
966 |
query_geo, |
|
967 |
query_proj, |
|
968 |
featureStore |
|
969 |
); |
|
970 |
featureQuery.setFilter(iee); |
|
971 |
featureQuery.setAttributeNames(null); |
|
972 |
return featureQuery; |
|
973 |
|
|
974 |
} |
|
975 |
|
|
934 | 976 |
public FeatureSet queryByContainedInGeometry(Geometry geom, FeatureType featureType) throws DataException { |
935 | 977 |
FeatureQuery featureQuery = createFeatureQuery(); |
936 | 978 |
featureQuery.setFeatureType(featureType); |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/resources/org/gvsig/fmap/mapcontrol/i18n/text.properties | ||
---|---|---|
25 | 25 |
|
26 | 26 |
_Pixels=P\u00edxeles |
27 | 27 |
|
28 |
_Next=Siguiente |
|
29 |
_Previous=Anterior |
|
30 |
_Features_selector=Selector de features |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/resources/org/gvsig/fmap/mapcontrol/i18n/text_en.properties | ||
---|---|---|
23 | 23 |
_Show_as_text=Show as text |
24 | 24 |
|
25 | 25 |
_Pixels=Pixels |
26 |
|
|
27 |
_Next=Next |
|
28 |
_Previous=Previous |
|
29 |
_Features_selector=Features selector |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/PointSelectionListenerUniqueSelect.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.mapcontrol.tools; |
2 |
|
|
2 | 3 |
import com.jeta.open.i18n.I18NUtils; |
3 | 4 |
import com.jgoodies.forms.layout.CellConstraints; |
4 | 5 |
import com.jgoodies.forms.layout.FormLayout; |
... | ... | |
6 | 7 |
import java.awt.ComponentOrientation; |
7 | 8 |
import java.awt.Container; |
8 | 9 |
import java.awt.Dimension; |
9 |
import java.awt.event.WindowAdapter; |
|
10 |
import java.awt.event.WindowEvent; |
|
11 | 10 |
import javax.swing.Box; |
12 | 11 |
import javax.swing.ImageIcon; |
12 |
import javax.swing.JButton; |
|
13 | 13 |
import javax.swing.JFrame; |
14 |
import javax.swing.JLabel;
|
|
14 |
import javax.swing.JList;
|
|
15 | 15 |
import javax.swing.JPanel; |
16 | 16 |
import javax.swing.JScrollPane; |
17 | 17 |
import javax.swing.JTable; |
... | ... | |
19 | 19 |
|
20 | 20 |
public class PointSelectionListenerUniqueSelect extends JPanel |
21 | 21 |
{ |
22 |
JLabel lblSelect = new JLabel(); |
|
23 | 22 |
JTable tblSelection = new JTable(); |
23 |
JList lstLayers = new JList(); |
|
24 |
JButton btnPrevious = new JButton(); |
|
25 |
JButton btnNext = new JButton(); |
|
24 | 26 |
|
25 | 27 |
/** |
26 | 28 |
* Default constructor |
... | ... | |
31 | 33 |
} |
32 | 34 |
|
33 | 35 |
/** |
34 |
* Main method for panel |
|
35 |
*/ |
|
36 |
public static void main(String[] args) |
|
37 |
{ |
|
38 |
JFrame frame = new JFrame(); |
|
39 |
frame.setSize(600, 400); |
|
40 |
frame.setLocation(100, 100); |
|
41 |
frame.getContentPane().add(new PointSelectionListenerUniqueSelect()); |
|
42 |
frame.setVisible(true); |
|
43 |
|
|
44 |
frame.addWindowListener( new WindowAdapter() |
|
45 |
{ |
|
46 |
public void windowClosing( WindowEvent evt ) |
|
47 |
{ |
|
48 |
System.exit(0); |
|
49 |
} |
|
50 |
}); |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 | 36 |
* Adds fill components to empty cells in the first row and first column of the grid. |
55 | 37 |
* This ensures that the grid spacing will be the same as shown in the designer. |
56 | 38 |
* @param cols an array of column indices in the first row where fill components should be added. |
... | ... | |
132 | 114 |
public JPanel createPanel() |
133 | 115 |
{ |
134 | 116 |
JPanel jpanel1 = new JPanel(); |
135 |
FormLayout formlayout1 = new FormLayout("FILL:5PX:NONE,FILL:340PX:GROW(1.0),FILL:4PX:NONE","CENTER:4PX:NONE,CENTER:DEFAULT:NONE,CENTER:4PX:NONE,FILL:133PX:GROW(1.0),CENTER:5PX:NONE");
|
|
117 |
FormLayout formlayout1 = new FormLayout("FILL:5PX:NONE,FILL:MAX(200DLU;DEFAULT):NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4PX:NONE","CENTER:4PX:NONE,FILL:133PX:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:5PX:NONE");
|
|
136 | 118 |
CellConstraints cc = new CellConstraints(); |
137 | 119 |
jpanel1.setLayout(formlayout1); |
138 | 120 |
|
139 |
lblSelect.setName("lblSelect"); |
|
140 |
lblSelect.setText("_Choose_features_to_select"); |
|
141 |
jpanel1.add(lblSelect,cc.xy(2,2)); |
|
142 |
|
|
143 | 121 |
tblSelection.setName("tblSelection"); |
144 | 122 |
JScrollPane jscrollpane1 = new JScrollPane(); |
145 | 123 |
jscrollpane1.setViewportView(tblSelection); |
146 | 124 |
jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
147 | 125 |
jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
148 |
jpanel1.add(jscrollpane1,cc.xy(2,4));
|
|
126 |
jpanel1.add(jscrollpane1,cc.xy(4,2));
|
|
149 | 127 |
|
150 |
addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5 }); |
|
128 |
lstLayers.setName("lstLayers"); |
|
129 |
JScrollPane jscrollpane2 = new JScrollPane(); |
|
130 |
jscrollpane2.setViewportView(lstLayers); |
|
131 |
jscrollpane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
|
132 |
jscrollpane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
133 |
jpanel1.add(jscrollpane2,cc.xy(2,2)); |
|
134 |
|
|
135 |
jpanel1.add(createPanel1(),cc.xywh(2,4,3,1)); |
|
136 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5 }); |
|
151 | 137 |
return jpanel1; |
152 | 138 |
} |
153 | 139 |
|
140 |
public JPanel createPanel1() |
|
141 |
{ |
|
142 |
JPanel jpanel1 = new JPanel(); |
|
143 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE"); |
|
144 |
CellConstraints cc = new CellConstraints(); |
|
145 |
jpanel1.setLayout(formlayout1); |
|
146 |
|
|
147 |
btnPrevious.setActionCommand("_Previous"); |
|
148 |
btnPrevious.setName("btnPrevious"); |
|
149 |
btnPrevious.setText("_Previous"); |
|
150 |
jpanel1.add(btnPrevious,cc.xy(2,1)); |
|
151 |
|
|
152 |
btnNext.setActionCommand("_Next"); |
|
153 |
btnNext.setName("btnNext"); |
|
154 |
btnNext.setText("_Next"); |
|
155 |
jpanel1.add(btnNext,cc.xy(4,1)); |
|
156 |
|
|
157 |
addFillComponents(jpanel1,new int[]{ 1,3 },new int[]{ 1 }); |
|
158 |
return jpanel1; |
|
159 |
} |
|
160 |
|
|
154 | 161 |
/** |
155 | 162 |
* Initializer |
156 | 163 |
*/ |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/CompoundBehavior.java | ||
---|---|---|
27 | 27 |
import java.awt.event.MouseEvent; |
28 | 28 |
import java.awt.event.MouseWheelEvent; |
29 | 29 |
import java.util.ArrayList; |
30 |
import java.util.Iterator; |
|
31 |
import java.util.List; |
|
30 | 32 |
|
31 | 33 |
import org.slf4j.Logger; |
32 | 34 |
import org.slf4j.LoggerFactory; |
... | ... | |
46 | 48 |
* @author Fernando Gonz?lez Cort?s |
47 | 49 |
* @author Pablo Piqueras Bartolom? |
48 | 50 |
*/ |
49 |
public class CompoundBehavior extends Behavior { |
|
51 |
public class CompoundBehavior extends Behavior implements Iterable<Behavior> {
|
|
50 | 52 |
private static final Logger logger = LoggerFactory.getLogger(CompoundBehavior.class); |
51 | 53 |
/** |
52 | 54 |
* List of all behaviors that compound this one. |
53 | 55 |
*/ |
54 |
private ArrayList behaviors = new ArrayList(); //<Behavior>
|
|
56 |
private List<Behavior> behaviors = new ArrayList();
|
|
55 | 57 |
|
56 | 58 |
/** |
57 | 59 |
* List that determines which behaviors of this one will be real-time painted. |
58 | 60 |
*/ |
59 |
private ArrayList draws = new ArrayList(); //<Boolean>
|
|
61 |
private List<Boolean> draws = new ArrayList();
|
|
60 | 62 |
|
61 | 63 |
/** |
62 | 64 |
* Static <code>behavior</code> that will be used for any <code>MapControl</code>.</p> |
... | ... | |
382 | 384 |
public static Behavior getAllControlsBehavior() { |
383 | 385 |
return CompoundBehavior.behavior; |
384 | 386 |
} |
387 |
|
|
388 |
@Override |
|
389 |
public Iterator<Behavior> iterator() { |
|
390 |
return this.behaviors.iterator(); |
|
391 |
} |
|
385 | 392 |
} |
386 | 393 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/PointSelectionListener.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.awt.Image; |
27 | 27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ComponentAdapter; |
|
29 |
import java.awt.event.ComponentEvent; |
|
30 |
import java.awt.event.ComponentListener; |
|
28 | 31 |
import java.awt.geom.Point2D; |
32 |
import java.util.ArrayList; |
|
33 |
import java.util.Iterator; |
|
29 | 34 |
import java.util.List; |
35 |
import javax.swing.SwingUtilities; |
|
36 |
import org.apache.commons.lang3.tuple.ImmutablePair; |
|
37 |
import org.apache.commons.lang3.tuple.Pair; |
|
30 | 38 |
|
31 | 39 |
import org.gvsig.fmap.IconThemeHelper; |
32 | 40 |
import org.gvsig.fmap.dal.exception.DataException; |
33 | 41 |
import org.gvsig.fmap.dal.feature.Feature; |
42 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
34 | 43 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
35 | 44 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
46 |
import org.gvsig.fmap.geom.primitive.Point; |
|
36 | 47 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 | 48 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
38 | 49 |
import org.gvsig.fmap.mapcontrol.MapControl; |
... | ... | |
45 | 56 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
46 | 57 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
47 | 58 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
59 |
import org.gvsig.tools.util.UnmodifiableBasicList64; |
|
48 | 60 |
|
49 | 61 |
/** |
50 | 62 |
* <p> |
... | ... | |
56 | 68 |
*/ |
57 | 69 |
public class PointSelectionListener implements PointListener { |
58 | 70 |
|
71 |
public static int PIXEL_TOLERANCE_FOR_QUERY_BY_POINT = 3; |
|
59 | 72 |
/** |
60 | 73 |
* Reference to the <code>MapControl</code> object that uses. |
61 | 74 |
*/ |
62 | 75 |
protected MapControl mapCtrl; |
76 |
private PointSelectionListenerUniqueSelectPanel panel; |
|
63 | 77 |
|
64 | 78 |
/** |
65 | 79 |
* <p> |
... | ... | |
71 | 85 |
this.mapCtrl = mc; |
72 | 86 |
} |
73 | 87 |
|
88 |
List<Pair<FLyrVect, UnmodifiableBasicList64<Feature>>> getClickedFeatures(Point mapPoint) throws BehaviorException { |
|
89 |
List<Pair<FLyrVect, UnmodifiableBasicList64<Feature>>> clickedFeatures = new ArrayList(); |
|
90 |
|
|
91 |
// Tolerancia de 3 pixels |
|
92 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
93 |
double tol = mapCtrl.getViewPort().toMapDistance(PIXEL_TOLERANCE_FOR_QUERY_BY_POINT); |
|
94 |
FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives(); |
|
95 |
for (int i = 0; i < actives.length; i++) { |
|
96 |
if (actives[i] instanceof FLyrVect) { |
|
97 |
FLyrVect lyrVect = (FLyrVect) actives[i]; |
|
98 |
try { |
|
99 |
FeatureStore store = lyrVect.getFeatureStore(); |
|
100 |
FeatureQuery query = lyrVect.createQueryByPoint(mapPoint.getX(), mapPoint.getY(), tol, store.getDefaultFeatureType()); |
|
101 |
UnmodifiableBasicList64<Feature> features = (UnmodifiableBasicList64<Feature>) store.getFeatures(query); |
|
102 |
|
|
103 |
if (!features.isEmpty()) { |
|
104 |
Pair<FLyrVect, UnmodifiableBasicList64<Feature>> pair = new ImmutablePair( |
|
105 |
lyrVect, |
|
106 |
features |
|
107 |
); |
|
108 |
clickedFeatures.add(pair); |
|
109 |
} |
|
110 |
} catch (DataException e) { |
|
111 |
throw new BehaviorException("No se pudo hacer la selecci?n", e); |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
return clickedFeatures; |
|
116 |
} |
|
117 |
|
|
74 | 118 |
public void point(PointEvent event) throws BehaviorException { |
75 | 119 |
try { |
76 |
Point2D p = event.getPoint(); |
|
77 |
Point2D mapPoint = mapCtrl.getViewPort().toMapPoint((int) p.getX(), (int) p.getY()); |
|
120 |
if (this.panel != null && this.panel.isVisible()) { |
|
121 |
PointSelectionListenerUniqueSelectPanel myPanel = this.panel; |
|
122 |
this.panel = null; |
|
123 |
myPanel.setVisible(false); |
|
124 |
} |
|
125 |
Point mapPoint = event.getMapPoint(); |
|
78 | 126 |
|
79 |
// Tolerancia de 3 pixels |
|
80 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
81 |
double tol = mapCtrl.getViewPort().toMapDistance(3); |
|
82 |
FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives(); |
|
83 |
for (int i = 0; i < actives.length; i++) { |
|
84 |
if (actives[i] instanceof FLyrVect) { |
|
85 |
FLyrVect lyrVect = (FLyrVect) actives[i]; |
|
86 |
FeatureSet newSelection = null; |
|
87 |
try { |
|
88 |
newSelection = lyrVect.queryByPoint( |
|
89 |
mapPoint, tol, |
|
90 |
lyrVect.getFeatureStore().getDefaultFeatureType()); |
|
91 |
if (event.getEvent().isControlDown()) { |
|
92 |
FeatureSelection currentSelection = (FeatureSelection) lyrVect.getDataStore().getSelection(); |
|
93 |
DisposableIterator it = newSelection.fastIterator(); |
|
94 |
while (it.hasNext()) { |
|
95 |
Object obj = it.next(); |
|
96 |
if (obj instanceof Feature) { |
|
97 |
Feature feat = ((Feature) obj); |
|
98 |
if (currentSelection.isSelected(feat)) { |
|
99 |
currentSelection.deselect(feat); |
|
100 |
} else { |
|
101 |
currentSelection.select(feat); |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
} else { |
|
106 |
lyrVect.getFeatureStore() |
|
107 |
.setSelection(newSelection); |
|
108 |
} |
|
109 |
if (event.getEvent().isShiftDown()) { |
|
110 |
//select features in the feature selection in a table |
|
111 |
FeatureSelection actualSelection = lyrVect.getFeatureStore().getFeatureSelection(); |
|
112 |
if (actualSelection.getSize() > 1) { |
|
127 |
List<Pair<FLyrVect, UnmodifiableBasicList64<Feature>>> clickedFeatures = getClickedFeatures(mapPoint); |
|
128 |
int countFeatures = 0; |
|
113 | 129 |
|
114 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
115 |
PointSelectionListenerUniqueSelectPanel panel = new PointSelectionListenerUniqueSelectPanel(); |
|
116 |
panel.put(lyrVect.getFeatureStore(), actualSelection); |
|
117 |
final Dialog dialog = winmanager.createDialog( |
|
118 |
panel.asJComponent(), |
|
119 |
i18n.getTranslation("_Features_selector"), |
|
120 |
null, |
|
121 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
122 |
); |
|
123 |
dialog.addActionListener((ActionEvent e) -> { |
|
124 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) { |
|
125 |
List<Feature> selectedFeatures = panel.getSelectedFeatures(); |
|
126 |
FeatureSelection newFeatureSelection = null; |
|
127 |
try { |
|
128 |
newFeatureSelection = lyrVect.getFeatureStore().createFeatureSelection(); |
|
129 |
if (newFeatureSelection!=null) { |
|
130 |
for (Feature selectedFeature : selectedFeatures) { |
|
131 |
newFeatureSelection.select(selectedFeature.getReference()); |
|
132 |
} |
|
133 |
} |
|
134 |
lyrVect.getFeatureStore().setSelection(newFeatureSelection); |
|
135 |
} catch (DataException ex) { |
|
136 |
|
|
137 |
} finally { |
|
130 |
for (Pair<FLyrVect, UnmodifiableBasicList64<Feature>> pair : clickedFeatures) { |
|
131 |
countFeatures += pair.getRight().size64(); |
|
132 |
} |
|
138 | 133 |
|
139 |
} |
|
140 |
} |
|
141 |
}); |
|
142 |
dialog.show(WindowManager.MODE.DIALOG); |
|
143 |
} |
|
134 |
if (event.getEvent().isShiftDown() && countFeatures > 1) { |
|
135 |
if (!event.getEvent().isControlDown()) { |
|
136 |
FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives(); |
|
137 |
for (int i = 0; i < actives.length; i++) { |
|
138 |
if (actives[i] instanceof FLyrVect) { |
|
139 |
FLyrVect lyrVect = (FLyrVect) actives[i]; |
|
140 |
FeatureStore store = lyrVect.getFeatureStore(); |
|
141 |
store.getFeatureSelection().deselectAll(); |
|
144 | 142 |
} |
145 |
} finally { |
|
146 |
if (newSelection != null) { |
|
147 |
newSelection.dispose(); |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
this.panel = new PointSelectionListenerUniqueSelectPanel(this.mapCtrl, event.getEvent().isControlDown()); |
|
147 |
this.panel.addComponentListener(new ComponentAdapter() { |
|
148 |
@Override |
|
149 |
public void componentHidden(ComponentEvent e) { |
|
150 |
if (e.getSource() == panel) { |
|
151 |
panel = null; |
|
148 | 152 |
} |
149 | 153 |
} |
150 |
mapCtrl.drawMap(false); // FIXME Esto deber?a sobrar (la capa deber?a de ser observada) |
|
154 |
}); |
|
155 |
final WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
156 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
157 |
|
|
158 |
panel.put(clickedFeatures); |
|
159 |
// SwingUtilities.invokeLater(() -> { |
|
160 |
winManager.showWindow( |
|
161 |
panel.asJComponent(), |
|
162 |
i18n.getTranslation("_Features_selector"), |
|
163 |
WindowManager.MODE.TOOL |
|
164 |
); |
|
165 |
// }); |
|
166 |
|
|
167 |
} else if (event.getEvent().isControlDown()) { |
|
168 |
for (Pair<FLyrVect, UnmodifiableBasicList64<Feature>> pair : clickedFeatures) { |
|
169 |
FLyrVect layer = pair.getLeft(); |
|
170 |
FeatureStore store = layer.getFeatureStore(); |
|
171 |
FeatureSelection selection = store.getFeatureSelection(); |
|
172 |
UnmodifiableBasicList64<Feature> features = pair.getRight(); |
|
173 |
for (Feature feature : features) { |
|
174 |
if (selection.isSelected(feature)) { |
|
175 |
selection.deselect(feature); |
|
176 |
} else { |
|
177 |
selection.select(feature); |
|
178 |
} |
|
179 |
} |
|
151 | 180 |
} |
181 |
} else { |
|
182 |
FLayer[] actives = mapCtrl.getMapContext().getLayers().getActives(); |
|
183 |
for (int i = 0; i < actives.length; i++) { |
|
184 |
if (actives[i] instanceof FLyrVect) { |
|
185 |
FLyrVect lyrVect = (FLyrVect) actives[i]; |
|
186 |
FeatureStore store = lyrVect.getFeatureStore(); |
|
187 |
store.getFeatureSelection().deselectAll(); |
|
188 |
} |
|
189 |
} |
|
190 |
for (Pair<FLyrVect, UnmodifiableBasicList64<Feature>> pair : clickedFeatures) { |
|
191 |
FLyrVect layer = pair.getLeft(); |
|
192 |
FeatureStore store = layer.getFeatureStore(); |
|
193 |
FeatureSelection selection = store.getFeatureSelection(); |
|
194 |
UnmodifiableBasicList64<Feature> features = pair.getRight(); |
|
195 |
for (Feature feature : features) { |
|
196 |
selection.select(feature); |
|
197 |
} |
|
198 |
} |
|
152 | 199 |
} |
153 | 200 |
|
154 | 201 |
} catch (DataException e) { |
155 |
throw new BehaviorException("No se pudo hacer la selecci?n", e);
|
|
202 |
throw new BehaviorException("Can't do the selection", e);
|
|
156 | 203 |
} |
157 | 204 |
} |
158 | 205 |
|
206 |
@Override |
|
159 | 207 |
public Image getImageCursor() { |
160 | 208 |
return IconThemeHelper.getImage("cursor-select-by-point"); |
161 | 209 |
} |
162 | 210 |
|
211 |
@Override |
|
163 | 212 |
public boolean cancelDrawing() { |
164 | 213 |
return false; |
165 | 214 |
} |
166 | 215 |
|
216 |
@Override |
|
167 | 217 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
168 | 218 |
|
169 | 219 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/PointSelectionListenerUniqueSelect.xml | ||
---|---|---|
24 | 24 |
</at> |
25 | 25 |
<at name="componentclass">com.jeta.forms.gui.form.FormComponent</at> |
26 | 26 |
</super> |
27 |
<at name="id">/home/omartinez/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/PointSelectionListenerUniqueSelect.xml</at>
|
|
28 |
<at name="rowspecs">CENTER:4PX:NONE,CENTER:DEFAULT:NONE,CENTER:4PX:NONE,FILL:133PX:GROW(1.0),CENTER:5PX:NONE</at>
|
|
29 |
<at name="colspecs">FILL:5PX:NONE,FILL:340PX:GROW(1.0),FILL:4PX:NONE</at>
|
|
27 |
<at name="id">/home/fdiaz/projects/gvSIG/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/PointSelectionListenerUniqueSelect.xml</at>
|
|
28 |
<at name="rowspecs">CENTER:4PX:NONE,FILL:133PX:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:5PX:NONE</at>
|
|
29 |
<at name="colspecs">FILL:5PX:NONE,FILL:MAX(200DLU;DEFAULT):NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4PX:NONE</at>
|
|
30 | 30 |
<at name="components"> |
31 | 31 |
<object classname="java.util.LinkedList"> |
32 | 32 |
<item > |
... | ... | |
35 | 35 |
<super classname="com.jeta.forms.store.memento.ComponentMemento"> |
36 | 36 |
<at name="cellconstraints"> |
37 | 37 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
38 |
<at name="column">2</at>
|
|
38 |
<at name="column">4</at>
|
|
39 | 39 |
<at name="row">2</at> |
40 | 40 |
<at name="colspan">1</at> |
41 | 41 |
<at name="rowspan">1</at> |
... | ... | |
47 | 47 |
<at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at> |
48 | 48 |
</super> |
49 | 49 |
<at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at> |
50 |
<at name="beanclass">com.jeta.forms.components.label.JETALabel</at>
|
|
50 |
<at name="beanclass">javax.swing.JTable</at>
|
|
51 | 51 |
<at name="beanproperties"> |
52 | 52 |
<object classname="com.jeta.forms.store.memento.PropertiesMemento"> |
53 |
<at name="classname">com.jeta.forms.components.label.JETALabel</at>
|
|
53 |
<at name="classname">javax.swing.JTable</at>
|
|
54 | 54 |
<at name="properties"> |
55 | 55 |
<object classname="com.jeta.forms.store.support.PropertyMap"> |
56 | 56 |
<at name="border"> |
... | ... | |
73 | 73 |
</at> |
74 | 74 |
</object> |
75 | 75 |
</at> |
76 |
<at name="name">lblSelect</at> |
|
77 |
<at name="width">1174</at> |
|
78 |
<at name="text">_Choose_features_to_select</at> |
|
79 |
<at name="fill"> |
|
80 |
<object classname="com.jeta.forms.store.properties.effects.PaintProperty"> |
|
81 |
<at name="name">fill</at> |
|
76 |
<at name="name">tblSelection</at> |
|
77 |
<at name="width">929</at> |
|
78 |
<at name="scollBars"> |
|
79 |
<object classname="com.jeta.forms.store.properties.ScrollBarsProperty"> |
|
80 |
<at name="name">scollBars</at> |
|
81 |
<at name="verticalpolicy">20</at> |
|
82 |
<at name="horizontalpolicy">30</at> |
|
83 |
<at name="border"> |
|
84 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
85 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
86 |
<at name="name">border</at> |
|
87 |
</super> |
|
88 |
<at name="borders"> |
|
89 |
<object classname="java.util.LinkedList"> |
|
90 |
<item > |
|
91 |
<at name="value"> |
|
92 |
<object classname="com.jeta.forms.store.properties.DefaultBorderProperty"> |
|
93 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
94 |
<at name="name">border</at> |
|
95 |
</super> |
|
96 |
</object> |
|
97 |
</at> |
|
98 |
</item> |
|
99 |
</object> |
|
100 |
</at> |
|
101 |
</object> |
|
102 |
</at> |
|
82 | 103 |
</object> |
83 | 104 |
</at> |
84 |
<at name="height">14</at>
|
|
105 |
<at name="height">32</at>
|
|
85 | 106 |
</object> |
86 | 107 |
</at> |
87 | 108 |
</object> |
... | ... | |
96 | 117 |
<at name="cellconstraints"> |
97 | 118 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
98 | 119 |
<at name="column">2</at> |
99 |
<at name="row">4</at>
|
|
120 |
<at name="row">2</at>
|
|
100 | 121 |
<at name="colspan">1</at> |
101 | 122 |
<at name="rowspan">1</at> |
102 | 123 |
<at name="halign">default</at> |
... | ... | |
107 | 128 |
<at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at> |
108 | 129 |
</super> |
109 | 130 |
<at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at> |
110 |
<at name="beanclass">javax.swing.JTable</at>
|
|
131 |
<at name="beanclass">javax.swing.JList</at>
|
|
111 | 132 |
<at name="beanproperties"> |
112 | 133 |
<object classname="com.jeta.forms.store.memento.PropertiesMemento"> |
113 |
<at name="classname">javax.swing.JTable</at>
|
|
134 |
<at name="classname">javax.swing.JList</at>
|
|
114 | 135 |
<at name="properties"> |
115 | 136 |
<object classname="com.jeta.forms.store.support.PropertyMap"> |
116 | 137 |
<at name="border"> |
... | ... | |
133 | 154 |
</at> |
134 | 155 |
</object> |
135 | 156 |
</at> |
136 |
<at name="name">tblSelection</at> |
|
137 |
<at name="width">1172</at> |
|
157 |
<at name="scrollableTracksViewportHeight">true</at> |
|
158 |
<at name="scrollableTracksViewportWidth">true</at> |
|
159 |
<at name="name">lstLayers</at> |
|
160 |
<at name="width">344</at> |
|
161 |
<at name="items"> |
|
162 |
<object classname="com.jeta.forms.store.properties.ItemsProperty"> |
|
163 |
<at name="name">items</at> |
|
164 |
</object> |
|
165 |
</at> |
|
138 | 166 |
<at name="scollBars"> |
139 | 167 |
<object classname="com.jeta.forms.store.properties.ScrollBarsProperty"> |
140 | 168 |
<at name="name">scollBars</at> |
141 | 169 |
<at name="verticalpolicy">20</at> |
142 | 170 |
<at name="horizontalpolicy">30</at> |
143 |
<at name="border"> |
|
144 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
145 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
146 |
<at name="name">border</at> |
|
147 |
</super> |
|
148 |
<at name="borders"> |
|
149 |
<object classname="java.util.LinkedList"> |
|
150 |
<item > |
|
151 |
<at name="value"> |
|
152 |
<object classname="com.jeta.forms.store.properties.DefaultBorderProperty"> |
|
153 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
154 |
<at name="name">border</at> |
|
155 |
</super> |
|
171 |
</object> |
|
172 |
</at> |
|
173 |
<at name="height">677</at> |
|
174 |
</object> |
|
175 |
</at> |
|
176 |
</object> |
|
177 |
</at> |
|
178 |
</object> |
|
179 |
</at> |
|
180 |
</item> |
|
181 |
<item > |
|
182 |
<at name="value"> |
|
183 |
<object classname="com.jeta.forms.store.memento.FormMemento"> |
|
184 |
<super classname="com.jeta.forms.store.memento.ComponentMemento"> |
|
185 |
<at name="cellconstraints"> |
|
186 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
|
187 |
<at name="column">2</at> |
|
188 |
<at name="row">4</at> |
|
189 |
<at name="colspan">3</at> |
|
190 |
<at name="rowspan">1</at> |
|
191 |
<at name="halign">default</at> |
|
192 |
<at name="valign">default</at> |
|
193 |
<at name="insets" object="insets">0,0,0,0</at> |
|
194 |
</object> |
|
195 |
</at> |
|
196 |
<at name="componentclass">com.jeta.forms.gui.form.FormComponent</at> |
|
197 |
</super> |
|
198 |
<at name="id">embedded.A21dde949I17c78b35a5fKR7ffb</at> |
|
199 |
<at name="rowspecs">CENTER:DEFAULT:NONE</at> |
|
200 |
<at name="colspecs">FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE</at> |
|
201 |
<at name="components"> |
|
202 |
<object classname="java.util.LinkedList"> |
|
203 |
<item > |
|
204 |
<at name="value"> |
|
205 |
<object classname="com.jeta.forms.store.memento.BeanMemento"> |
|
206 |
<super classname="com.jeta.forms.store.memento.ComponentMemento"> |
|
207 |
<at name="cellconstraints"> |
|
208 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
|
209 |
<at name="column">2</at> |
|
210 |
<at name="row">1</at> |
|
211 |
<at name="colspan">1</at> |
|
212 |
<at name="rowspan">1</at> |
|
213 |
<at name="halign">default</at> |
|
214 |
<at name="valign">default</at> |
|
215 |
<at name="insets" object="insets">0,0,0,0</at> |
|
216 |
</object> |
|
217 |
</at> |
|
218 |
<at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at> |
|
219 |
</super> |
|
220 |
<at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at> |
|
221 |
<at name="beanclass">javax.swing.JButton</at> |
|
222 |
<at name="beanproperties"> |
|
223 |
<object classname="com.jeta.forms.store.memento.PropertiesMemento"> |
|
224 |
<at name="classname">javax.swing.JButton</at> |
|
225 |
<at name="properties"> |
|
226 |
<object classname="com.jeta.forms.store.support.PropertyMap"> |
|
227 |
<at name="border"> |
|
228 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
229 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
230 |
<at name="name">border</at> |
|
231 |
</super> |
|
232 |
<at name="borders"> |
|
233 |
<object classname="java.util.LinkedList"> |
|
234 |
<item > |
|
235 |
<at name="value"> |
|
236 |
<object classname="com.jeta.forms.store.properties.DefaultBorderProperty"> |
|
237 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
238 |
<at name="name">border</at> |
|
239 |
</super> |
|
240 |
</object> |
|
241 |
</at> |
|
242 |
</item> |
|
156 | 243 |
</object> |
157 | 244 |
</at> |
158 |
</item> |
|
159 |
</object> |
|
160 |
</at> |
|
245 |
</object> |
|
246 |
</at> |
|
247 |
<at name="actionCommand">_Previous</at> |
|
248 |
<at name="name">btnPrevious</at> |
|
249 |
<at name="width">87</at> |
|
250 |
<at name="text">_Previous</at> |
|
251 |
<at name="height">22</at> |
|
252 |
</object> |
|
253 |
</at> |
|
254 |
</object> |
|
255 |
</at> |
|
256 |
</object> |
|
257 |
</at> |
|
258 |
</item> |
|
259 |
<item > |
|
260 |
<at name="value"> |
|
261 |
<object classname="com.jeta.forms.store.memento.BeanMemento"> |
|
262 |
<super classname="com.jeta.forms.store.memento.ComponentMemento"> |
|
263 |
<at name="cellconstraints"> |
|
264 |
<object classname="com.jeta.forms.store.memento.CellConstraintsMemento"> |
|
265 |
<at name="column">4</at> |
|
266 |
<at name="row">1</at> |
|
267 |
<at name="colspan">1</at> |
|
268 |
<at name="rowspan">1</at> |
|
269 |
<at name="halign">default</at> |
|
270 |
<at name="valign">default</at> |
|
271 |
<at name="insets" object="insets">0,0,0,0</at> |
|
161 | 272 |
</object> |
162 | 273 |
</at> |
274 |
<at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at> |
|
275 |
</super> |
|
276 |
<at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at> |
|
277 |
<at name="beanclass">javax.swing.JButton</at> |
|
278 |
<at name="beanproperties"> |
|
279 |
<object classname="com.jeta.forms.store.memento.PropertiesMemento"> |
|
280 |
<at name="classname">javax.swing.JButton</at> |
|
281 |
<at name="properties"> |
|
282 |
<object classname="com.jeta.forms.store.support.PropertyMap"> |
|
283 |
<at name="border"> |
|
284 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
285 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
286 |
<at name="name">border</at> |
|
287 |
</super> |
|
288 |
<at name="borders"> |
|
289 |
<object classname="java.util.LinkedList"> |
|
290 |
<item > |
|
291 |
<at name="value"> |
|
292 |
<object classname="com.jeta.forms.store.properties.DefaultBorderProperty"> |
|
293 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
294 |
<at name="name">border</at> |
|
295 |
</super> |
|
296 |
</object> |
|
297 |
</at> |
|
298 |
</item> |
|
299 |
</object> |
|
300 |
</at> |
|
301 |
</object> |
|
302 |
</at> |
|
303 |
<at name="actionCommand">_Next</at> |
|
304 |
<at name="name">btnNext</at> |
|
305 |
<at name="width">63</at> |
|
306 |
<at name="text">_Next</at> |
|
307 |
<at name="height">22</at> |
|
308 |
</object> |
|
309 |
</at> |
|
310 |
</object> |
|
311 |
</at> |
|
312 |
</object> |
|
313 |
</at> |
|
314 |
</item> |
|
315 |
</object> |
|
316 |
</at> |
|
317 |
<at name="properties"> |
|
318 |
<object classname="com.jeta.forms.store.memento.PropertiesMemento"> |
|
319 |
<at name="classname">com.jeta.forms.gui.form.GridView</at> |
|
320 |
<at name="properties"> |
|
321 |
<object classname="com.jeta.forms.store.support.PropertyMap"> |
|
322 |
<at name="border"> |
|
323 |
<object classname="com.jeta.forms.store.properties.CompoundBorderProperty"> |
|
324 |
<super classname="com.jeta.forms.store.properties.BorderProperty"> |
|
325 |
<at name="name">border</at> |
|
326 |
</super> |
|
327 |
<at name="borders"> |
|
328 |
<object classname="java.util.LinkedList"/> |
|
329 |
</at> |
|
163 | 330 |
</object> |
164 | 331 |
</at> |
165 |
<at name="height">32</at> |
|
332 |
<at name="name"></at> |
|
333 |
<at name="fill"> |
|
334 |
<object classname="com.jeta.forms.store.properties.effects.PaintProperty"> |
|
335 |
<at name="name">fill</at> |
|
336 |
</object> |
|
337 |
</at> |
|
338 |
<at name="scollBars"> |
|
339 |
<object classname="com.jeta.forms.store.properties.ScrollBarsProperty"> |
|
340 |
<at name="name">scollBars</at> |
|
341 |
<at name="verticalpolicy">21</at> |
|
342 |
<at name="horizontalpolicy">31</at> |
|
343 |
</object> |
|
344 |
</at> |
|
166 | 345 |
</object> |
167 | 346 |
</at> |
168 | 347 |
</object> |
169 | 348 |
</at> |
349 |
<at name="cellpainters"> |
|
350 |
<object classname="com.jeta.forms.store.support.Matrix"> |
|
351 |
<at name="rows"> |
|
352 |
<object classname="[Ljava.lang.Object;" size="1"> |
|
353 |
<at name="item" index="0"> |
|
354 |
<object classname="[Ljava.lang.Object;" size="4"/> |
|
355 |
</at> |
|
356 |
</object> |
|
357 |
</at> |
|
358 |
</object> |
|
359 |
</at> |
|
360 |
<at name="rowgroups"> |
|
361 |
<object classname="com.jeta.forms.store.memento.FormGroupSet"> |
|
362 |
<at name="groups"> |
|
363 |
<object classname="java.util.HashMap"/> |
|
364 |
</at> |
|
365 |
</object> |
|
366 |
</at> |
|
367 |
<at name="colgroups"> |
|
368 |
<object classname="com.jeta.forms.store.memento.FormGroupSet"> |
|
369 |
<at name="groups"> |
|
370 |
<object classname="java.util.HashMap"/> |
|
371 |
</at> |
|
372 |
</object> |
|
373 |
</at> |
|
170 | 374 |
</object> |
171 | 375 |
</at> |
172 | 376 |
</item> |
... | ... | |
187 | 391 |
</at> |
188 | 392 |
</object> |
189 | 393 |
</at> |
190 |
<at name="name"></at>
|
|
394 |
<at name="name"/>
|
|
191 | 395 |
<at name="fill"> |
192 | 396 |
<object classname="com.jeta.forms.store.properties.effects.PaintProperty"> |
193 | 397 |
<at name="name">fill</at> |
... | ... | |
229 | 433 |
<at name="rows"> |
230 | 434 |
<object classname="[Ljava.lang.Object;" size="5"> |
231 | 435 |
<at name="item" index="0"> |
232 |
<object classname="[Ljava.lang.Object;" size="3"/>
|
|
436 |
<object classname="[Ljava.lang.Object;" size="5"/>
|
|
233 | 437 |
</at> |
234 | 438 |
<at name="item" index="1"> |
235 |
<object classname="[Ljava.lang.Object;" size="3"/>
|
|
439 |
<object classname="[Ljava.lang.Object;" size="5"/>
|
|
236 | 440 |
</at> |
237 | 441 |
<at name="item" index="2"> |
238 |
<object classname="[Ljava.lang.Object;" size="3"/>
|
|
442 |
<object classname="[Ljava.lang.Object;" size="5"/>
|
|
239 | 443 |
</at> |
240 | 444 |
<at name="item" index="3"> |
241 |
<object classname="[Ljava.lang.Object;" size="3"/>
|
|
445 |
<object classname="[Ljava.lang.Object;" size="5"/>
|
|
242 | 446 |
</at> |
243 | 447 |
<at name="item" index="4"> |
244 |
<object classname="[Ljava.lang.Object;" size="3"/>
|
|
448 |
<object classname="[Ljava.lang.Object;" size="5"/>
|
|
245 | 449 |
</at> |
246 | 450 |
</object> |
247 | 451 |
</at> |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/PointSelectionListenerUniqueSelectPanel.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.mapcontrol.tools; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
3 |
import java.awt.event.ActionEvent; |
|
4 |
import java.awt.event.ActionListener; |
|
5 |
import java.awt.event.ComponentAdapter; |
|
6 |
import java.awt.event.ComponentEvent; |
|
7 |
import java.awt.event.ComponentListener; |
|
8 |
import java.awt.event.KeyAdapter; |
|
9 |
import java.awt.event.KeyEvent; |
|
4 | 10 |
import java.util.List; |
11 |
import java.util.logging.Level; |
|
12 |
import javax.swing.DefaultListModel; |
|
5 | 13 |
import javax.swing.JComponent; |
14 |
import javax.swing.ListModel; |
|
15 |
import javax.swing.ListSelectionModel; |
|
16 |
import javax.swing.event.ChangeEvent; |
|
17 |
import javax.swing.event.ChangeListener; |
|
18 |
import javax.swing.event.ListSelectionEvent; |
|
19 |
import javax.swing.event.ListSelectionListener; |
|
20 |
import org.apache.commons.lang3.tuple.Pair; |
|
6 | 21 |
import org.gvsig.fmap.dal.exception.DataException; |
7 | 22 |
import org.gvsig.fmap.dal.feature.Feature; |
8 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
|
|
9 |
import org.gvsig.fmap.dal.feature.FeatureSet;
|
|
23 |
import org.gvsig.fmap.dal.feature.FeatureReference;
|
|
24 |
import org.gvsig.fmap.dal.feature.FeatureSelection;
|
|
10 | 25 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
12 | 26 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
13 | 27 |
import org.gvsig.fmap.dal.swing.featuretable.SimpleFeaturesTableModel; |
14 |
import org.gvsig.tools.ToolsLocator; |
|
15 |
import org.gvsig.tools.i18n.I18nManager; |
|
28 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
29 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
30 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
31 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
|
16 | 32 |
import org.gvsig.tools.swing.api.Component; |
17 | 33 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
18 | 34 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
35 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
|
36 |
import org.gvsig.tools.util.UnmodifiableBasicList64; |
|
37 |
import org.slf4j.Logger; |
|
38 |
import org.slf4j.LoggerFactory; |
|
19 | 39 |
/** |
20 | 40 |
* |
21 | 41 |
* @author omartinez |
22 | 42 |
*/ |
23 | 43 |
public class PointSelectionListenerUniqueSelectPanel extends PointSelectionListenerUniqueSelect implements Component { |
24 | 44 |
|
45 |
private static final Logger LOGGER = LoggerFactory.getLogger(PointSelectionListenerUniqueSelectPanel.class); |
|
25 | 46 |
SimpleFeaturesTableModel simpleTableModel; |
47 |
ListModel layersModel; |
|
48 |
List<Pair<FLyrVect, UnmodifiableBasicList64<Feature>>> clickedFeatures; |
|
49 |
private FeatureReference lastFeature; |
|
50 |
private FeatureStore lastStore; |
|
51 |
private final boolean toggle; |
|
52 |
private final MapControl mapControl; |
|
53 |
private final ChangeListener mapControlListener; |
|
26 | 54 |
|
27 |
public PointSelectionListenerUniqueSelectPanel() { |
|
55 |
public PointSelectionListenerUniqueSelectPanel(MapControl mapControl, boolean toggle) { |
|
56 |
this.mapControl = mapControl; |
|
57 |
this.toggle = toggle; |
|
58 |
this.mapControlListener = (ChangeEvent e) -> { |
|
59 |
Behavior currentMapTool = mapControl.getCurrentMapTool(); |
|
60 |
boolean found = false; |
|
61 |
if(currentMapTool instanceof CompoundBehavior){ |
|
62 |
CompoundBehavior behaviors = (CompoundBehavior)currentMapTool; |
|
63 |
for (Behavior behavior : behaviors) { |
|
64 |
if(behavior.getListener() instanceof PointSelectionListener) { |
|
65 |
found = true; |
|
66 |
break; |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
} else if(currentMapTool.getListener() instanceof PointSelectionListener) { |
|
71 |
found = true; |
|
72 |
} |
|
73 |
if(!found){ |
|
74 |
this.setVisible(false); |
|
75 |
} |
|
76 |
}; |
|
28 | 77 |
this.translate(); |
78 |
initComponents(); |
|
29 | 79 |
} |
30 | 80 |
|
31 | 81 |
protected void translate() { |
32 |
I18nManager i18m = ToolsLocator.getI18nManager(); |
|
33 |
this.lblSelect.setText(i18m.getTranslation("_Choose_features_from_selection")); |
|
82 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
|
83 |
swingManager.translate(this.btnPrevious); |
|
84 |
swingManager.translate(this.btnNext); |
|
34 | 85 |
} |
35 | 86 |
@Override |
36 | 87 |
public JComponent asJComponent() { |
37 | 88 |
return this; |
38 | 89 |
} |
90 |
|
|
91 |
private void initComponents() { |
|
92 |
this.btnPrevious.addActionListener(new ActionListener() { |
|
93 |
@Override |
|
94 |
public void actionPerformed(ActionEvent e) { |
|
95 |
doPrevious(); |
|
96 |
} |
|
97 |
}); |
|
98 |
this.btnNext.addActionListener(new ActionListener() { |
|
99 |
@Override |
|
100 |
public void actionPerformed(ActionEvent e) { |
|
101 |
doNext(); |
|
102 |
} |
|
103 |
}); |
|
104 |
this.lstLayers.addListSelectionListener(new ListSelectionListener() { |
|
105 |
@Override |
|
106 |
public void valueChanged(ListSelectionEvent e) { |
|
107 |
doSelectLayer(); |
|
108 |
} |
|
109 |
}); |
|
110 |
this.tblSelection.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
111 |
this.tblSelection.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
|
112 |
@Override |
|
113 |
public void valueChanged(ListSelectionEvent e) { |
|
114 |
if(e.getValueIsAdjusting()){ |
|
115 |
return; |
|
116 |
} |
|
117 |
doSelectFeature(); |
|
118 |
} |
|
119 |
}); |
|
120 |
this.tblSelection.addKeyListener(new KeyAdapter() { |
|
121 |
@Override |
|
122 |
public void keyPressed(KeyEvent e) { |
|
123 |
super.keyPressed(e); |
|
124 |
if(e.getKeyCode() == KeyEvent.VK_UP){ |
|
125 |
doPrevious(); |
|
126 |
e.consume(); |
|
127 |
} else if(e.getKeyCode() == KeyEvent.VK_DOWN){ |
|
128 |
doNext(); |
|
129 |
e.consume(); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
}); |
|
134 |
this.mapControl.addChangeToolListener(this.mapControlListener); |
|
135 |
this.addComponentListener(new ComponentAdapter() { |
|
136 |
@Override |
|
137 |
public void componentHidden(ComponentEvent e) { |
|
138 |
mapControl.removeChangeToolListener(mapControlListener); |
|
139 |
} |
|
140 |
}); |
|
141 |
|
|
142 |
ToolsSwingUtils.ensureRowsCols(this, 12, 50, 20, 100); |
|
143 |
|
|
144 |
} |
|
145 |
|
|
146 |
public void put(List<Pair<FLyrVect, UnmodifiableBasicList64<Feature>>> clickedFeatures) { |
|
147 |
this.clickedFeatures = clickedFeatures; |
|
148 |
layersModel = new DefaultListModel(); |
|
149 |
for (Pair<FLyrVect, UnmodifiableBasicList64<Feature>> pair : clickedFeatures) { |
|
150 |
FLyrVect layer = pair.getLeft(); |
|
151 |
((DefaultListModel)layersModel).addElement(layer); |
|
152 |
if(!toggle){ |
|
153 |
try { |
|
154 |
layer.getFeatureStore().getFeatureSelection().deselectAll(); |
|
155 |
} catch (DataException ex) { |
|
156 |
LOGGER.warn("Can't deselect all", ex); |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
this.lstLayers.setModel(layersModel); |
|
161 |
this.lstLayers.setSelectedIndex(0);//.getSelectionModel().setSelectionInterval(0, 0); |
|
162 |
doSelectLayer(); |
|
163 |
this.tblSelection.getSelectionModel().setSelectionInterval(0, 0); |
|
164 |
|
|
165 |
} |
|
166 |
|
|
167 |
private void doPrevious() { |
|
168 |
if (this.simpleTableModel != null) { |
|
169 |
int selectedRow = this.tblSelection.getSelectedRow(); |
|
170 |
if (selectedRow <= 0) { |
|
171 |
int selectedLayerIndex = this.lstLayers.getSelectedIndex(); |
|
172 |
if (selectedLayerIndex <= 0) { |
|
173 |
selectedLayerIndex = this.lstLayers.getModel().getSize()-1; |
|
174 |
} else { |
|
175 |
selectedLayerIndex--; |
|
176 |
} |
|
177 |
this.lstLayers.getSelectionModel().setSelectionInterval( |
|
178 |
selectedLayerIndex, |
|
179 |
selectedLayerIndex |
|
180 |
); |
|
181 |
doSelectLayer(); |
|
182 |
selectedRow = this.tblSelection.getModel().getRowCount()-1; |
|
183 |
} else { |
|
184 |
selectedRow--; |
|
185 |
} |
|
186 |
this.tblSelection.getSelectionModel().setSelectionInterval( |
|
187 |
selectedRow, |
|
188 |
selectedRow |
|
189 |
); |
|
190 |
this.tblSelection.scrollRectToVisible(this.tblSelection.getCellRect(selectedRow,0, true)); |
|
191 |
} |
|
192 |
} |
|
39 | 193 |
|
40 |
void put(FeatureStore store, FeatureSet posibleSelection) { |
|
41 |
FeatureType featureType; |
|
42 |
try { |
|
43 |
featureType = store.getDefaultFeatureType(); |
|
44 |
} catch (DataException ex) { |
|
45 |
return; |
|
194 |
private void doNext() { |
|
195 |
if (this.simpleTableModel != null) { |
|
196 |
int selectedRow = this.tblSelection.getSelectedRow(); |
|
197 |
if (selectedRow >= this.tblSelection.getRowCount()-1) { |
|
198 |
int selectedLayerIndex = this.lstLayers.getSelectedIndex(); |
|
199 |
if (selectedLayerIndex >= this.lstLayers.getModel().getSize()-1) { |
|
200 |
selectedLayerIndex = 0; |
|
201 |
} else { |
|
202 |
selectedLayerIndex++; |
|
203 |
} |
|
204 |
this.lstLayers.getSelectionModel().setSelectionInterval(selectedLayerIndex, selectedLayerIndex); |
|
205 |
doSelectLayer(); |
|
206 |
selectedRow = 0; |
|
207 |
} else { |
|
208 |
selectedRow++; |
|
209 |
} |
|
210 |
this.tblSelection.getSelectionModel().setSelectionInterval(selectedRow, selectedRow); |
|
211 |
this.tblSelection.scrollRectToVisible(this.tblSelection.getCellRect(selectedRow,0, true)); |
|
46 | 212 |
} |
47 |
FeatureAttributeDescriptor[] descriptors = featureType.getAttributeDescriptors(); |
|
48 |
List<String> columnNames = new ArrayList<>(); |
|
49 |
for (FeatureAttributeDescriptor descriptor : descriptors) { |
|
50 |
columnNames.add(descriptor.getName()); |
|
213 |
} |
|
214 |
|
|
215 |
private void doSelectLayer() { |
|
216 |
FLyrVect layer = (FLyrVect) lstLayers.getSelectedValue(); |
|
217 |
if (layer != null) { |
|
218 |
|
|
219 |
this.simpleTableModel = (SimpleFeaturesTableModel) DALSwingLocator.getDataSwingManager().createSimpleFeaturesTableModel( |
|
220 |
layer.getFeatureStore().getDefaultFeatureTypeQuietly(), |
|
221 |
null, |
|
222 |
getFeatures(layer).toList()); |
|
223 |
this.simpleTableModel.setCellRenderers(this.tblSelection); |
|
224 |
this.tblSelection.setModel(simpleTableModel); |
|
225 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
|
226 |
swingManager.createTableColumnAdjuster(tblSelection); |
|
227 |
|
|
51 | 228 |
} |
229 |
} |
|
52 | 230 |
|
53 |
List<Feature> posibleListSelection = new ArrayList<>(); |
|
54 |
for (Feature feature : posibleSelection) { |
|
55 |
posibleListSelection.add(feature); |
|
231 |
private void doSelectFeature() { |
|
232 |
FLyrVect layer = (FLyrVect) lstLayers.getSelectedValue(); |
|
233 |
if(layer == null){ |
|
234 |
return; |
|
56 | 235 |
} |
236 |
int n = this.tblSelection.getSelectedRow(); |
|
237 |
if(n<0){ |
|
238 |
return; |
|
239 |
} |
|
57 | 240 |
|
58 |
this.simpleTableModel = (SimpleFeaturesTableModel) DALSwingLocator.getDataSwingManager().createSimpleFeaturesTableModel(featureType, columnNames, posibleListSelection); |
|
59 |
|
|
60 |
this.tblSelection.setModel(simpleTableModel); |
|
61 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
|
62 |
swingManager.createTableColumnAdjuster(tblSelection); |
|
241 |
try { |
|
242 |
if(this.toggle){ |
|
243 |
if(lastFeature != null){ |
|
244 |
FeatureSelection selection = lastStore.getFeatureSelection(); |
|
245 |
if(selection.isSelected(lastFeature)){ |
|
246 |
selection.deselect(lastFeature); |
|
247 |
} else { |
|
248 |
selection.select(lastFeature); |
|
249 |
} |
|
250 |
} |
|
251 |
FeatureStore store = layer.getFeatureStore(); |
|
252 |
Feature f = simpleTableModel.getFeatureAt(n); |
|
253 |
FeatureSelection selection = store.getFeatureSelection(); |
|
254 |
if(selection.isSelected(f)){ |
|
255 |
selection.deselect(f); |
|
256 |
} else { |
|
257 |
selection.select(f); |
|
258 |
} |
|
259 |
this.lastFeature = f.getReference(); |
|
260 |
this.lastStore = store; |
|
261 |
|
|
262 |
} else { |
|
263 |
if(lastFeature != null){ |
|
264 |
lastStore.getFeatureSelection().deselect(lastFeature); |
|
265 |
} |
|
266 |
FeatureStore store = layer.getFeatureStore(); |
|
267 |
Feature f = simpleTableModel.getFeatureAt(n); |
|
268 |
store.getFeatureSelection().select(f); |
|
269 |
this.lastFeature = f.getReference(); |
|
270 |
this.lastStore = store; |
|
271 |
} |
|
272 |
} catch (DataException ex) { |
|
273 |
LOGGER.warn("Can't select feature.", ex); |
|
274 |
} |
|
63 | 275 |
} |
64 | 276 |
|
65 |
public List<Feature> getSelectedFeatures() { |
|
66 |
if (this.simpleTableModel!=null) { |
|
67 |
int[] selectedRows = this.tblSelection.getSelectedRows(); |
|
68 |
List<Feature> selectedFeatures = new ArrayList<>(); |
|
69 |
for (int selectedRow : selectedRows) { |
|
70 |
Feature feature = this.simpleTableModel.get(selectedRow); |
|
71 |
selectedFeatures.add(feature); |
|
277 |
private UnmodifiableBasicList64<Feature> getFeatures(FLayer layer) { |
|
278 |
if (clickedFeatures != null) { |
|
279 |
for (Pair<FLyrVect, UnmodifiableBasicList64<Feature>> pair : clickedFeatures) { |
|
280 |
if (pair.getLeft() == layer) { |
|
281 |
return pair.getRight(); |
|
282 |
} |
|
72 | 283 |
} |
73 |
return selectedFeatures; |
|
74 | 284 |
} |
75 | 285 |
return null; |
76 | 286 |
} |
287 |
|
|
288 |
// void put(FeatureStore store, FeatureSet posibleSelection) { |
|
289 |
// FeatureType featureType; |
|
290 |
// try { |
|
291 |
// featureType = store.getDefaultFeatureType(); |
|
292 |
// } catch (DataException ex) { |
|
293 |
// return; |
|
294 |
// } |
|
295 |
// FeatureAttributeDescriptor[] descriptors = featureType.getAttributeDescriptors(); |
|
296 |
// List<String> columnNames = new ArrayList<>(); |
|
297 |
// for (FeatureAttributeDescriptor descriptor : descriptors) { |
|
298 |
// columnNames.add(descriptor.getName()); |
|
299 |
// } |
|
300 |
// |
|
301 |
// List<Feature> posibleListSelection = new ArrayList<>(); |
|
302 |
// for (Feature feature : posibleSelection) { |
|
303 |
// posibleListSelection.add(feature); |
|
304 |
// } |
|
305 |
// |
|
306 |
// this.simpleTableModel = (SimpleFeaturesTableModel) DALSwingLocator.getDataSwingManager().createSimpleFeaturesTableModel(featureType, columnNames, posibleListSelection); |
|
307 |
// |
|
308 |
// this.tblSelection.setModel(simpleTableModel); |
|
309 |
// ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
|
310 |
// swingManager.createTableColumnAdjuster(tblSelection); |
|
311 |
// } |
|
77 | 312 |
|
313 |
public Feature getSelectedFeature() { |
|
314 |
if (this.simpleTableModel!=null) { |
|
315 |
int selectedRow = this.tblSelection.getSelectedRow(); |
|
316 |
Feature feature = this.simpleTableModel.get(selectedRow); |
|
317 |
return feature; |
|
318 |
} |
|
319 |
return null; |
|
320 |
} |
|
78 | 321 |
|
322 |
|
|
79 | 323 |
|
80 | 324 |
} |
Also available in: Unified diff