/[schmitzm]/branches/2.1/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
ViewVC logotype

Diff of /branches/2.1/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 151 by alfonx, Fri Jun 19 16:22:29 2009 UTC revision 224 by alfonx, Tue Jul 14 15:57:19 2009 UTC
# Line 17  import java.beans.PropertyChangeEvent; Line 17  import java.beans.PropertyChangeEvent;
17  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
18  import java.util.Arrays;  import java.util.Arrays;
19  import java.util.Collection;  import java.util.Collection;
20    import java.util.HashSet;
21    import java.util.Set;
22  import java.util.Vector;  import java.util.Vector;
23    
24  import javax.swing.JTable;  import javax.swing.JTable;
# Line 27  import org.geotools.feature.Feature; Line 29  import org.geotools.feature.Feature;
29  import org.geotools.map.MapLayer;  import org.geotools.map.MapLayer;
30  import org.geotools.styling.FeatureTypeStyle;  import org.geotools.styling.FeatureTypeStyle;
31  import org.geotools.styling.Style;  import org.geotools.styling.Style;
32  import org.opengis.filter.Filter;  import org.opengis.filter.identity.FeatureId;
 import org.opengis.filter.FilterVisitor;  
33    
34    import schmitzm.geotools.FilterUtil;
35  import schmitzm.geotools.gui.JMapPane;  import schmitzm.geotools.gui.JMapPane;
36  import schmitzm.geotools.map.event.FeatureSelectedEvent;  import schmitzm.geotools.map.event.FeatureSelectedEvent;
37  import schmitzm.geotools.map.event.JMapPaneEvent;  import schmitzm.geotools.map.event.JMapPaneEvent;
# Line 37  import schmitzm.geotools.map.event.JMapP Line 39  import schmitzm.geotools.map.event.JMapP
39  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
40  import schmitzm.lang.LangUtil;  import schmitzm.lang.LangUtil;
41  import skrueger.geotools.MapPaneToolBar;  import skrueger.geotools.MapPaneToolBar;
42  import skrueger.geotools.StyledMapInterface;  import skrueger.geotools.StyledLayerInterface;
43    
44  /**  /**
45   * This class keeps the selection of a (feature) {@link JTable} synchronized   * This class keeps the selection of a (feature) {@link JTable} synchronized
# Line 66  public class FeatureMapLayerSelectionSyn Line 68  public class FeatureMapLayerSelectionSyn
68           * model.           * model.
69           */           */
70          protected final MapLayer mapLayer;          protected final MapLayer mapLayer;
71          protected final StyledMapInterface<?> styledMapLayer;          protected final StyledLayerInterface<?> styledLayer;
72          protected final JMapPane mapPane;          protected final JMapPane mapPane;
73          private final MapPaneToolBar toolBar;          private final MapPaneToolBar toolBar;
74    
# Line 82  public class FeatureMapLayerSelectionSyn Line 84  public class FeatureMapLayerSelectionSyn
84           */           */
85          public FeatureMapLayerSelectionSynchronizer(          public FeatureMapLayerSelectionSynchronizer(
86                          StyledFeatureLayerSelectionModel layerSelModel,                          StyledFeatureLayerSelectionModel layerSelModel,
87                          StyledMapInterface<?> styledMapLayer, MapLayer mapLayer,                          StyledLayerInterface<?> styledLayer, MapLayer mapLayer,
88                          JMapPane mapPane, MapPaneToolBar toolBar) {                          JMapPane mapPane, MapPaneToolBar toolBar) {
89    
90                  super(layerSelModel);                  super(layerSelModel);
91                  this.styledMapLayer = styledMapLayer;                  this.styledLayer = styledLayer;
92    
93                  this.mapLayer = mapLayer;                  this.mapLayer = mapLayer;
94                  this.mapPane = mapPane;                  this.mapPane = mapPane;
# Line 143  public class FeatureMapLayerSelectionSyn Line 145  public class FeatureMapLayerSelectionSyn
145                  try {                  try {
146                          if (newSelection.isEmpty()) {                          if (newSelection.isEmpty()) {
147    
148                                  selectionMapStyle = styledMapLayer.getStyle();                                  selectionMapStyle = styledLayer.getStyle();
149                                  // LOGGER.debug("NO SELECTION .. set to original style directly");                                  // LOGGER.debug("NO SELECTION .. set to original style directly");
150    
151                          } else {                          } else {
152                                  LOGGER.debug("SELECTION .. change style");                                  LOGGER.debug("SELECTION .. change style");
153    
154                                  // We take Style from the MapLayer that is displayed at the                                  // We take Style from the MapLayer that is displayed at the
155                                  // moment. We do not use the styledMapLayer.getStyle, because in                                  // moment. We do not use the styledLayer.getStyle, because in
156                                  // the atlas, this always return the default style, but                                  // the atlas, this always return the default style, but
157                                  // additionaly styles might be selected.                                  // additional styles might be selected.
158                                  // Taking the style from the mapLayer indicated, that we have to                                  // Taking the style from the mapLayer indicated, that we have to
159                                  // remove any selection rules first.                                  // remove any selection rules first.
160                                  Style originalStyle = mapLayer.getStyle();                                  Style originalStyle = mapLayer.getStyle();
# Line 160  public class FeatureMapLayerSelectionSyn Line 162  public class FeatureMapLayerSelectionSyn
162                                  // TODO The default style is not good here. We need                                  // TODO The default style is not good here. We need
163                                  // .createSelectionStyle(normalStyle, geoObj);                                  // .createSelectionStyle(normalStyle, geoObj);
164                                  selectionMapStyle = StylingUtil                                  selectionMapStyle = StylingUtil
165                                                  .createSelectionStyle(styledMapLayer.getGeoObject());                                                  .createSelectionStyle(styledLayer.getGeoObject());
166                                  // selectionMapStyle = StylingUtil                                  // selectionMapStyle = StylingUtil
167                                  // .createDefaultStyle(styledMapLayer.getGeoObject());                                  // .createDefaultStyle(styledLayer.getGeoObject());
168    
169                                  selectionMapStyle.getFeatureTypeStyles()[0]                                  selectionMapStyle.getFeatureTypeStyles()[0]
170                                                  .setName(SELECTION_STYLING);                                                  .setName(SELECTION_STYLING);
171    
172                                  // Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule();                                  /**
173                                  selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0]                                   *
174                                                  .setFilter(new Filter() {                                   * Add a Filter to the selectionMapStyle, so that it is only
175                                     * used on objects that are selected. <br/>
176                                                          @Override                                   *
177                                                          public Object accept(FilterVisitor visitor,                                   * Note 1:<br/>
178                                                                          Object extraData) {                                   * It is NEVER allowed to GeoTools extend Filter () { .. } (and write
179                                                                  return null;                                   * tests into the evaluate block). Especially for the
180                                                          }                                   * ShapeFileRenderer, we may only use a geotools Filter.<br/>
181                                     *
182                                                          @Override                                   * Note 2:<br/>
183                                                          public boolean evaluate(Object obj) {                                   * The FilterUtil.FILTER_FAC2.id(fids) wants a set of FeatureId-Objects!
184                                                                  if (obj instanceof Feature) {                                   */
185                                                                          Feature f = (Feature) obj;  
186                                                                          // TODO BAD CODE! says Martin.. i am fine                                  Set<FeatureId> fids = new HashSet<FeatureId>();
187                                                                          // with it.. well.. not great...                                  for (String fid : newSelection) {
188                                                                          for (String ffID : newSelection) {                                          fids.add(FilterUtil.FILTER_FAC2.featureId(fid));
189                                                                                  if (ffID.equals(f.getID()))                                  }
                                                                                         return true;  
                                                                         }  
                                                                         return false;  
   
                                                                 }  
                                                                 return false;  
                                                         }  
190    
191                                                  });                                  selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0]
192                                                    .setFilter(FilterUtil.FILTER_FAC2.id(fids));
193    
194                                  FeatureTypeStyle[] originalFeatureTypeStyles = originalStyle                                  FeatureTypeStyle[] originalFeatureTypeStyles = originalStyle
195                                                  .getFeatureTypeStyles();                                                  .getFeatureTypeStyles();
# Line 258  public class FeatureMapLayerSelectionSyn Line 254  public class FeatureMapLayerSelectionSyn
254                  FeatureSelectedEvent fse = (FeatureSelectedEvent) e;                  FeatureSelectedEvent fse = (FeatureSelectedEvent) e;
255    
256                  /**                  /**
257                   * Checking, that the FeatureSelectedEvent actually contains features from this layer                   * Checking, that the FeatureSelectedEvent actually contains features
258                     * from this layer
259                   */                   */
260                  final String sourceID = fse.getSourceLayer().getTitle();                  final String sourceID = fse.getSourceLayer().getTitle();
261                  final String syncForID = mapLayer.getTitle();                  final String syncForID = mapLayer.getTitle();
262                  if (sourceID != null && syncForID != null                  if (sourceID != null && syncForID != null
263                                  && !sourceID.equals(syncForID)){                                  && !sourceID.equals(syncForID)) {
264                          LOGGER.debug("Ignoring a FeatureSelectedEvent from "+sourceID);                          LOGGER.debug("Ignoring a FeatureSelectedEvent from " + sourceID);
265                          return;                          return;
266                  }                  }
                   
267    
268                  LOGGER.debug("do event " + fse);                  LOGGER.debug("do event " + fse);
269    

Legend:
Removed from v.151  
changed lines
  Added in v.224

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26