/[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 509 by alfonx, Thu Nov 5 08:51:33 2009 UTC revision 559 by alfonx, Tue Nov 24 14:12:41 2009 UTC
# Line 42  Line 42 
42   **/   **/
43  package skrueger.geotools.selection;  package skrueger.geotools.selection;
44    
45    import java.awt.RenderingHints;
46  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
47  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
48  import java.io.File;  import java.io.File;
49    import java.util.HashMap;
50  import java.util.HashSet;  import java.util.HashSet;
51  import java.util.Iterator;  import java.util.Iterator;
52  import java.util.Set;  import java.util.Set;
# Line 58  import org.geotools.feature.FeatureColle Line 60  import org.geotools.feature.FeatureColle
60  import org.geotools.feature.FeatureIterator;  import org.geotools.feature.FeatureIterator;
61  import org.geotools.filter.FidFilterImpl;  import org.geotools.filter.FidFilterImpl;
62  import org.geotools.map.MapLayer;  import org.geotools.map.MapLayer;
63    import org.geotools.renderer.GTRenderer;
64    import org.geotools.renderer.label.LabelCacheImpl;
65    import org.geotools.renderer.lite.StreamingRenderer;
66  import org.geotools.styling.FeatureTypeStyle;  import org.geotools.styling.FeatureTypeStyle;
67  import org.geotools.styling.Style;  import org.geotools.styling.Style;
68  import org.geotools.styling.visitor.DuplicatingStyleVisitor;  import org.geotools.styling.visitor.DuplicatingStyleVisitor;
# Line 68  import org.opengis.filter.Not; Line 73  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;
76    import schmitzm.geotools.GTUtil;
77  import schmitzm.geotools.gui.SelectableXMapPane;  import schmitzm.geotools.gui.SelectableXMapPane;
78  import schmitzm.geotools.map.event.FeatureSelectedEvent;  import schmitzm.geotools.map.event.FeatureSelectedEvent;
 import schmitzm.geotools.map.event.MapPaneEvent;  
79  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
80    import schmitzm.geotools.map.event.MapPaneEvent;
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;
# Line 97  import skrueger.geotools.StyledFeaturesI Line 103  import skrueger.geotools.StyledFeaturesI
103  public class FeatureMapLayerSelectionSynchronizer extends  public class FeatureMapLayerSelectionSynchronizer extends
104                  StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>                  StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
105                  implements JMapPaneListener {                  implements JMapPaneListener {
106          public static final String SELECTION_STYLING = "SELECTION";  
107            /**
108             * This constant is set as the {@link FeatureTypeStyle#getName()} attribute
109             * in the {@link FeatureTypeStyle}s that only exist to present the selected
110             * features
111             **/
112            public static final String SELECTION_STYLING_FTS_NAME = "SELECTION";
113    
114          /**          /**
115           * Holds the {@link MapLayer} to keep synchronized with the layer selection           * Holds the {@link MapLayer} to keep synchronized with the layer selection
116           * model.           * model.
# Line 189  public class FeatureMapLayerSelectionSyn Line 202  public class FeatureMapLayerSelectionSyn
202    
203                                  for (FeatureTypeStyle fts : clone) {                                  for (FeatureTypeStyle fts : clone) {
204                                          if (fts.getName() != null                                          if (fts.getName() != null
205                                                          && fts.getName().equals(SELECTION_STYLING)) {                                                          && fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
206                                                  originalStyle.featureTypeStyles().remove(fts);                                                  originalStyle.featureTypeStyles().remove(fts);
207    
208                                                  replaceRenderer();                                                  mapLayer.setStyle(originalStyle);
209                                                  // mapPane.refresh();                                                  // replaceRenderer();
210                                                    // // mapPane.refresh();
211    
212                                                  return;                                                  return;
213                                          }                                          }
# Line 218  public class FeatureMapLayerSelectionSyn Line 232  public class FeatureMapLayerSelectionSyn
232                                  FeatureTypeStyle selectionFTStyle = StylingUtil                                  FeatureTypeStyle selectionFTStyle = StylingUtil
233                                                  .createSelectionStyle(styledLayer.getGeoObject());                                                  .createSelectionStyle(styledLayer.getGeoObject());
234    
235                                  selectionFTStyle.setName(SELECTION_STYLING);                                  selectionFTStyle.setName(SELECTION_STYLING_FTS_NAME);
236    
237                                  /**                                  /**
238                                   *                                   *
# Line 266  public class FeatureMapLayerSelectionSyn Line 280  public class FeatureMapLayerSelectionSyn
280                                  boolean foundAndReplaced = false;                                  boolean foundAndReplaced = false;
281                                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {                                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
282                                          if (fts.getName() != null                                          if (fts.getName() != null
283                                                          && fts.getName().equals(SELECTION_STYLING)) {                                                          && fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
284                                                  foundAndReplaced = true;                                                  foundAndReplaced = true;
285                                                  fts.rules().clear();                                                  fts.rules().clear();
286                                                  fts.rules().addAll(selectionFTStyle.rules());                                                  fts.rules().addAll(selectionFTStyle.rules());
# Line 323  public class FeatureMapLayerSelectionSyn Line 337  public class FeatureMapLayerSelectionSyn
337    
338                  /**                  /**
339                   * testing, whether the selection really changed. If not, we can save                   * testing, whether the selection really changed. If not, we can save
340                   * one paint!                   * one rendering!
341                   */                   */
342                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
343    
344                          if (fts.getName() != null                          if (fts.getName() != null
345                                          && fts.getName().equals(SELECTION_STYLING)) {                                          && fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
346    
347                                  SELECTION_STYLING_foundInMapStyle = true;                                  SELECTION_STYLING_foundInMapStyle = true;
348    
# Line 357  public class FeatureMapLayerSelectionSyn Line 371  public class FeatureMapLayerSelectionSyn
371                                                  }                                                  }
372                                          }                                          }
373    
374                                            if (antiFids.size() + newSelection.size() != styledLayer
375                                                            .getFeatureCollectionFiltered().size())
376                                                    return true;
377    
378                                  } else {                                  } else {
379                                          FidFilterImpl origFidsFilter = (FidFilterImpl) filter;                                          FidFilterImpl origFidsFilter = (FidFilterImpl) filter;
380    
# Line 394  public class FeatureMapLayerSelectionSyn Line 412  public class FeatureMapLayerSelectionSyn
412          }          }
413    
414          /**          /**
415           * Replaces the local renderer           * Replaces the local renderer
416           */           */
417          private void replaceRenderer() {          private void replaceRenderer() {
 //              //  
 //              // // Has to be done before we apply the new Renderer  
 //              // mapLayer.setStyle(style);  
 //  
 //              GTRenderer oldRenderer = mapPane.getLocalRenderer();  
 //  
 //              /**  
 //               * Explicitly putting a new instance of LabelCacheDefault into the  
 //               * renderer instance, so JMapPane doesn't reuse the old one. This is  
 //               * very useful when changing the TextSymbolizer with AtlasStyler<br/>  
 //               * SK 9.7.09: It's not enought to user LabelCache.clear(). We can not  
 //               * reuse the old Renderer - better to create a new one!  
 //               */  
 //              final GTRenderer newRenderer = GTUtil.createGTRenderer();  
 //  
 //              final HashMap<Object, Object> rendererHints = defaultGTRenderingHints;  
 //              rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY,  
 //                              new LabelCacheImpl());  
 //  
 //              newRenderer.setRendererHints(rendererHints);  
 //              mapPane.setLocalRenderer(newRenderer);  
 //  
 //              if (oldRenderer != null) {  
 //  
 //                      RenderingHints java2DHints = oldRenderer.getJava2DHints();  
 //                      if (java2DHints != null) {  
 //                              newRenderer.setJava2DHints(java2DHints);  
 //                      }  
 //  
 //                      oldRenderer.setContext(null);  
 //                      oldRenderer = null;  
 //              }  
   
                 mapPane.refresh();  
   
418          }          }
419    
420          /**          /**

Legend:
Removed from v.509  
changed lines
  Added in v.559

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26