/[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

branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java revision 509 by alfonx, Thu Nov 5 08:51:33 2009 UTC trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java revision 685 by alfonx, Wed Feb 10 15:04:02 2010 UTC
# Line 70  import org.opengis.filter.identity.Featu Line 70  import org.opengis.filter.identity.Featu
70  import schmitzm.geotools.FilterUtil;  import schmitzm.geotools.FilterUtil;
71  import schmitzm.geotools.gui.SelectableXMapPane;  import schmitzm.geotools.gui.SelectableXMapPane;
72  import schmitzm.geotools.map.event.FeatureSelectedEvent;  import schmitzm.geotools.map.event.FeatureSelectedEvent;
 import schmitzm.geotools.map.event.MapPaneEvent;  
73  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
74    import schmitzm.geotools.map.event.MapPaneEvent;
75  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
76  import skrueger.geotools.MapPaneToolBar;  import skrueger.geotools.MapPaneToolBar;
77  import skrueger.geotools.StyledFeaturesInterface;  import skrueger.geotools.StyledFeaturesInterface;
# Line 97  import skrueger.geotools.StyledFeaturesI Line 97  import skrueger.geotools.StyledFeaturesI
97  public class FeatureMapLayerSelectionSynchronizer extends  public class FeatureMapLayerSelectionSynchronizer extends
98                  StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>                  StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
99                  implements JMapPaneListener {                  implements JMapPaneListener {
100          public static final String SELECTION_STYLING = "SELECTION";  
101            /**
102             * This constant is set as the {@link FeatureTypeStyle#getName()} attribute
103             * in the {@link FeatureTypeStyle}s that only exist to present the selected
104             * features
105             **/
106            public static final String SELECTION_STYLING_FTS_NAME = "SELECTION";
107    
108          /**          /**
109           * Holds the {@link MapLayer} to keep synchronized with the layer selection           * Holds the {@link MapLayer} to keep synchronized with the layer selection
110           * model.           * model.
# Line 189  public class FeatureMapLayerSelectionSyn Line 196  public class FeatureMapLayerSelectionSyn
196    
197                                  for (FeatureTypeStyle fts : clone) {                                  for (FeatureTypeStyle fts : clone) {
198                                          if (fts.getName() != null                                          if (fts.getName() != null
199                                                          && fts.getName().equals(SELECTION_STYLING)) {                                                          && fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
200                                                  originalStyle.featureTypeStyles().remove(fts);                                                  originalStyle.featureTypeStyles().remove(fts);
201    
202                                                  replaceRenderer();                                                  mapLayer.setStyle(originalStyle);
203                                                  // mapPane.refresh();                                                  // replaceRenderer();
204                                                    // // mapPane.refresh();
205    
206                                                  return;                                                  return;
207                                          }                                          }
# Line 218  public class FeatureMapLayerSelectionSyn Line 226  public class FeatureMapLayerSelectionSyn
226                                  FeatureTypeStyle selectionFTStyle = StylingUtil                                  FeatureTypeStyle selectionFTStyle = StylingUtil
227                                                  .createSelectionStyle(styledLayer.getGeoObject());                                                  .createSelectionStyle(styledLayer.getGeoObject());
228    
229                                  selectionFTStyle.setName(SELECTION_STYLING);                                  selectionFTStyle.setName(SELECTION_STYLING_FTS_NAME);
230    
231                                  /**                                  /**
232                                   *                                   *
# Line 254  public class FeatureMapLayerSelectionSyn Line 262  public class FeatureMapLayerSelectionSyn
262                                  } else {                                  } else {
263                                          Set<FeatureId> fids = new HashSet<FeatureId>();                                          Set<FeatureId> fids = new HashSet<FeatureId>();
264                                          for (String fid : newSelection) {                                          for (String fid : newSelection) {
265                                                  fids.add(FilterUtil.FILTER_FAC2.featureId(fid));                                                  if (fid != null)
266                                                            fids.add(FilterUtil.FILTER_FAC2.featureId(fid));
267                                          }                                          }
268    
269                                          selectionFTStyle.rules().get(0).setFilter(                                          selectionFTStyle.rules().get(0).setFilter(
# Line 266  public class FeatureMapLayerSelectionSyn Line 275  public class FeatureMapLayerSelectionSyn
275                                  boolean foundAndReplaced = false;                                  boolean foundAndReplaced = false;
276                                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {                                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
277                                          if (fts.getName() != null                                          if (fts.getName() != null
278                                                          && fts.getName().equals(SELECTION_STYLING)) {                                                          && fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
279                                                  foundAndReplaced = true;                                                  foundAndReplaced = true;
280                                                  fts.rules().clear();                                                  fts.rules().clear();
281                                                  fts.rules().addAll(selectionFTStyle.rules());                                                  fts.rules().addAll(selectionFTStyle.rules());
# Line 309  public class FeatureMapLayerSelectionSyn Line 318  public class FeatureMapLayerSelectionSyn
318          }          }
319    
320          /**          /**
321           * Analyses whether the selection has changed in comparison to the selection           * Analyzes whether the selection has changed in comparison to the selection
322           * stored in the mapLayer.Style           * stored in the mapLayer.Style
323           *           *
324           * @param newSelection           * @param newSelection a List<String> of all newly selected FIDs
325           * @param originalStyle           * @param originalStyle the original {@link Style} that has an earlier selection coded into the {@link Style}
326           * @return           * @return <code>true</code> if changed.
327           */           */
328          private boolean selectionChanged(Vector<String> newSelection,          private boolean selectionChanged(Vector<String> newSelection,
329                          Style originalStyle) {                          Style originalStyle) {
# Line 323  public class FeatureMapLayerSelectionSyn Line 332  public class FeatureMapLayerSelectionSyn
332    
333                  /**                  /**
334                   * testing, whether the selection really changed. If not, we can save                   * testing, whether the selection really changed. If not, we can save
335                   * one paint!                   * one rendering!
336                   */                   */
337                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
338    
339                          if (fts.getName() != null                          if (fts.getName() != null
340                                          && fts.getName().equals(SELECTION_STYLING)) {                                          && fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
341    
342                                  SELECTION_STYLING_foundInMapStyle = true;                                  SELECTION_STYLING_foundInMapStyle = true;
343    
# Line 357  public class FeatureMapLayerSelectionSyn Line 366  public class FeatureMapLayerSelectionSyn
366                                                  }                                                  }
367                                          }                                          }
368    
369                                            if (antiFids.size() + newSelection.size() != styledLayer
370                                                            .getFeatureCollectionFiltered().size())
371                                                    return true;
372    
373                                  } else {                                  } else {
374                                          FidFilterImpl origFidsFilter = (FidFilterImpl) filter;                                          FidFilterImpl origFidsFilter = (FidFilterImpl) filter;
375    
# Line 394  public class FeatureMapLayerSelectionSyn Line 407  public class FeatureMapLayerSelectionSyn
407          }          }
408    
409          /**          /**
410           * Replaces the local renderer           * Replaces the local renderer
411           */           */
412          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();  
   
413          }          }
414    
415          /**          /**

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26