/[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 491 by alfonx, Fri Oct 23 12:57:15 2009 UTC revision 500 by alfonx, Sun Oct 25 16:56:21 2009 UTC
# Line 58  import javax.swing.event.ListSelectionLi Line 58  import javax.swing.event.ListSelectionLi
58    
59  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
60  import org.geotools.feature.FeatureIterator;  import org.geotools.feature.FeatureIterator;
61    import org.geotools.filter.FidFilterImpl;
62  import org.geotools.map.MapLayer;  import org.geotools.map.MapLayer;
63  import org.geotools.renderer.GTRenderer;  import org.geotools.renderer.GTRenderer;
64  import org.geotools.renderer.label.LabelCacheImpl;  import org.geotools.renderer.label.LabelCacheImpl;
# Line 67  import org.geotools.styling.Style; Line 68  import org.geotools.styling.Style;
68  import org.geotools.styling.visitor.DuplicatingStyleVisitor;  import org.geotools.styling.visitor.DuplicatingStyleVisitor;
69  import org.opengis.feature.simple.SimpleFeature;  import org.opengis.feature.simple.SimpleFeature;
70  import org.opengis.feature.simple.SimpleFeatureType;  import org.opengis.feature.simple.SimpleFeatureType;
71    import org.opengis.filter.Filter;
72    import org.opengis.filter.Not;
73  import org.opengis.filter.identity.FeatureId;  import org.opengis.filter.identity.FeatureId;
74    
75  import schmitzm.geotools.FilterUtil;  import schmitzm.geotools.FilterUtil;
# Line 78  import schmitzm.geotools.map.event.JMapP Line 81  import schmitzm.geotools.map.event.JMapP
81  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
82  import skrueger.geotools.MapPaneToolBar;  import skrueger.geotools.MapPaneToolBar;
83  import skrueger.geotools.StyledFeaturesInterface;  import skrueger.geotools.StyledFeaturesInterface;
 import skrueger.geotools.StyledLayerInterface;  
84    
85  /**  /**
86   * This class keeps the selection of a (feature) {@link JTable} synchronized   * This class keeps the selection of a (feature) {@link JTable} synchronized
# Line 189  public class FeatureMapLayerSelectionSyn Line 191  public class FeatureMapLayerSelectionSyn
191                  try {                  try {
192    
193                          Style originalStyle = mapLayer.getStyle();                          Style originalStyle = mapLayer.getStyle();
194    
195                          if (newSelection.isEmpty()) {                          if (newSelection.isEmpty()) {
196    
197                                  // Check if the Style contains a SELECTION FTS                                  // Check if the Style contains a SELECTION FTS
# Line 209  public class FeatureMapLayerSelectionSyn Line 212  public class FeatureMapLayerSelectionSyn
212                                  }                                  }
213    
214                          } else {                          } else {
215    
216                                  LOGGER.debug("SELECTION .. change style");                                  LOGGER.debug("SELECTION .. change style");
217    
218                                    // Saving a repaint if the selection didn't change
219                                    if (!selectionChanged(newSelection, originalStyle)) {
220                                            return;
221                                    }
222    
223                                  // We take Style from the MapLayer that is displayed at the                                  // We take Style from the MapLayer that is displayed at the
224                                  // moment. We do not use the styledLayer.getStyle, because in                                  // moment. We do not use the styledLayer.getStyle, because in
225                                  // the atlas, this always return the default style, but                                  // the atlas, this always return the default style, but
# Line 232  public class FeatureMapLayerSelectionSyn Line 241  public class FeatureMapLayerSelectionSyn
241                                   * inverted to be shorter.                                   * inverted to be shorter.
242                                   *                                   *
243                                   */                                   */
   
244                                  final FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollectionFiltered = styledLayer                                  final FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollectionFiltered = styledLayer
245                                                  .getFeatureCollectionFiltered();                                                  .getFeatureCollectionFiltered();
246                                  if (newSelection.size() > featureCollectionFiltered.size() / 2) {                                  if (newSelection.size() > featureCollectionFiltered.size() / 2) {
# Line 287  public class FeatureMapLayerSelectionSyn Line 295  public class FeatureMapLayerSelectionSyn
295                                  DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();                                  DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();
296                                  dsv.visit(originalStyle);                                  dsv.visit(originalStyle);
297                                  Style newStyle = (Style) dsv.getCopy();                                  Style newStyle = (Style) dsv.getCopy();
298  //  
299  //                              try {                                  // SK-Debug
300  ////                                                                      try {
301  ////                            StylingUtil.saveStyleToSLD(newStyle, new File(                                          //
302  ////                                            "/home/stefan/Desktop/selection.sld"));                                          StylingUtil.saveStyleToSLD(newStyle, new File(
303  //                              } catch (Exception e) {                                                          "/home/stefan/Desktop/selection.sld"));
304  //                              }                                  } catch (Exception e) {
305  //                                  }
306  //                              // DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();  
307                                    // DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();
308                                  // dsv.visit(originalStyle);                                  // dsv.visit(originalStyle);
309                                  // Style newStyle = originalStyle;                                  // Style newStyle = originalStyle;
310    
# Line 311  public class FeatureMapLayerSelectionSyn Line 320  public class FeatureMapLayerSelectionSyn
320                  }                  }
321          }          }
322    
323            /**
324             * Analyses whether the selection has changed in comparison to the selection
325             * stored in the mapLayer.Style
326             *
327             * @param newSelection
328             * @param originalStyle
329             * @return
330             */
331            private boolean selectionChanged(Vector<String> newSelection,
332                            Style originalStyle) {
333    
334                    boolean SELECTION_STYLING_foundInMapStyle = false;
335    
336                    /**
337                     * testing, whether the selection really changed. If not, we can save
338                     * one paint!
339                     */
340                    for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
341    
342                            if (fts.getName() != null
343                                            && fts.getName().equals(SELECTION_STYLING)) {
344    
345                                    SELECTION_STYLING_foundInMapStyle = true;
346    
347                                    Filter filter = fts.rules().get(0).getFilter();
348                                    if (filter instanceof Not) {
349                                            FidFilterImpl antiOrigFidsFilter = (FidFilterImpl) ((Not) filter)
350                                                            .getFilter();
351    
352                                            // Check one way
353                                            final Set<String> antiFids = antiOrigFidsFilter
354                                                            .getFidsSet();
355    
356                                            if (antiFids.isEmpty() && !newSelection.isEmpty())
357                                                    return true;
358    
359                                            for (String fid : antiFids) {
360                                                    if (newSelection.contains(fid)) {
361                                                            return true;
362                                                    }
363                                            }
364    
365                                            // Check the other way
366                                            for (String fid : newSelection) {
367                                                    if (antiFids.contains(fid)) {
368                                                            return true;
369                                                    }
370                                            }
371    
372                                    } else {
373                                            FidFilterImpl origFidsFilter = (FidFilterImpl) filter;
374    
375                                            // Check one way
376                                            final Set<String> fids = origFidsFilter.getFidsSet();
377    
378                                            if (fids.isEmpty() && newSelection.isEmpty())
379                                                    return false;
380                                            if (fids.size() != newSelection.size())
381                                                    return true;
382    
383                                            for (String fid : fids) {
384                                                    if (!newSelection.contains(fid)) {
385                                                            return true;
386                                                    }
387                                            }
388    
389                                            // Check the other way
390                                            for (String fid : newSelection) {
391                                                    if (!fids.contains(fid)) {
392                                                            return true;
393                                                    }
394                                            }
395    
396                                    }
397    
398                                    break;
399                            }
400                    }
401    
402                    if (!SELECTION_STYLING_foundInMapStyle && !newSelection.isEmpty())
403                            return true;
404    
405                    return false;
406            }
407    
408          private void replaceRenderer() {          private void replaceRenderer() {
409                  //                  //
410                  // // Has to be done before we apply the new Renderer                  // // Has to be done before we apply the new Renderer
# Line 381  public class FeatureMapLayerSelectionSyn Line 475  public class FeatureMapLayerSelectionSyn
475                  if (e.getSourceObject() != this.mapPane)                  if (e.getSourceObject() != this.mapPane)
476                          return;                          return;
477    
                 FeatureSelectedEvent fse = (FeatureSelectedEvent) e;  
   
478                  /**                  /**
479                   * Checking, that the FeatureSelectedEvent actually contains features                   * Checking, that the FeatureSelectedEvent actually contains features
480                   * from this layer                   * from this layer
481                   */                   */
482                    FeatureSelectedEvent fse = (FeatureSelectedEvent) e;
483                  final String sourceID = fse.getSourceLayer().getTitle();                  final String sourceID = fse.getSourceLayer().getTitle();
484                  final String syncForID = mapLayer.getTitle();                  final String syncForID = mapLayer.getTitle();
485                  if (sourceID != null && syncForID != null                  if (sourceID != null && syncForID != null

Legend:
Removed from v.491  
changed lines
  Added in v.500

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26