/[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 500 by alfonx, Sun Oct 25 16:56:21 2009 UTC revision 560 by alfonx, Tue Nov 24 14:57:05 2009 UTC
# Line 74  import org.opengis.filter.identity.Featu Line 74  import org.opengis.filter.identity.Featu
74    
75  import schmitzm.geotools.FilterUtil;  import schmitzm.geotools.FilterUtil;
76  import schmitzm.geotools.GTUtil;  import schmitzm.geotools.GTUtil;
77  import schmitzm.geotools.gui.JMapPane;  import schmitzm.geotools.gui.SelectableXMapPane;
78  import schmitzm.geotools.map.event.FeatureSelectedEvent;  import schmitzm.geotools.map.event.FeatureSelectedEvent;
 import schmitzm.geotools.map.event.JMapPaneEvent;  
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 103  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.
117           */           */
118          protected final MapLayer mapLayer;          protected final MapLayer mapLayer;
119          protected final StyledFeaturesInterface<?> styledLayer;          protected final StyledFeaturesInterface<?> styledLayer;
120          protected final JMapPane mapPane;          protected final SelectableXMapPane mapPane;
121          private final MapPaneToolBar toolBar;          private final MapPaneToolBar toolBar;
         private final HashMap<Object, Object> defaultGTRenderingHints;  
122    
123          /**          /**
124           * Creates a new synchronizer           * Creates a new synchronizer
# Line 127  public class FeatureMapLayerSelectionSyn Line 133  public class FeatureMapLayerSelectionSyn
133          public FeatureMapLayerSelectionSynchronizer(          public FeatureMapLayerSelectionSynchronizer(
134                          StyledFeatureLayerSelectionModel layerSelModel,                          StyledFeatureLayerSelectionModel layerSelModel,
135                          StyledFeaturesInterface<?> styledLayer, MapLayer mapLayer,                          StyledFeaturesInterface<?> styledLayer, MapLayer mapLayer,
136                          JMapPane mapPane, MapPaneToolBar toolBar,                          SelectableXMapPane mapPane, MapPaneToolBar toolBar) {
                         HashMap<Object, Object> defaultGTRenderingHints) {  
137    
138                  super(layerSelModel);                  super(layerSelModel);
139                  this.styledLayer = styledLayer;                  this.styledLayer = styledLayer;
# Line 136  public class FeatureMapLayerSelectionSyn Line 141  public class FeatureMapLayerSelectionSyn
141                  this.mapLayer = mapLayer;                  this.mapLayer = mapLayer;
142                  this.mapPane = mapPane;                  this.mapPane = mapPane;
143                  this.toolBar = toolBar;                  this.toolBar = toolBar;
                 if (defaultGTRenderingHints != null)  
                         this.defaultGTRenderingHints = defaultGTRenderingHints;  
                 else  
                         this.defaultGTRenderingHints = new HashMap<Object, Object>();  
144          }          }
145    
146          /**          /**
# Line 201  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 230  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 278  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 321  public class FeatureMapLayerSelectionSyn Line 323  public class FeatureMapLayerSelectionSyn
323          }          }
324    
325          /**          /**
326           * Analyses whether the selection has changed in comparison to the selection           * Analyzes whether the selection has changed in comparison to the selection
327           * stored in the mapLayer.Style           * stored in the mapLayer.Style
328           *           *
329           * @param newSelection           * @param newSelection a List<String> of all newly selected FIDs
330           * @param originalStyle           * @param originalStyle the original {@link Style} that has an earlier selection coded into the {@link Style}
331           * @return           * @return <code>true</code> if changed.
332           */           */
333          private boolean selectionChanged(Vector<String> newSelection,          private boolean selectionChanged(Vector<String> newSelection,
334                          Style originalStyle) {                          Style originalStyle) {
# Line 335  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 369  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 405  public class FeatureMapLayerSelectionSyn Line 411  public class FeatureMapLayerSelectionSyn
411                  return false;                  return false;
412          }          }
413    
414            /**
415             * 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.getRenderer();  
   
                 /**  
                  * 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.setRenderer(newRenderer);  
   
                 if (oldRenderer != null) {  
   
                         RenderingHints java2DHints = oldRenderer.getJava2DHints();  
                         if (java2DHints != null) {  
                                 newRenderer.setJava2DHints(java2DHints);  
                         }  
   
                         oldRenderer.setContext(null);  
                         oldRenderer = null;  
                 }  
   
                 mapPane.refresh();  
   
418          }          }
419    
420          /**          /**
# Line 448  public class FeatureMapLayerSelectionSyn Line 422  public class FeatureMapLayerSelectionSyn
422           * {@link StyledFeatureLayerSelectionModel}           * {@link StyledFeatureLayerSelectionModel}
423           */           */
424          @Override          @Override
425          public void performMapPaneEvent(JMapPaneEvent e) {          public void performMapPaneEvent(MapPaneEvent e) {
426    
427                  // Ignore event if it is caused by us or the synchronizer is disabled.                  // Ignore event if it is caused by us or the synchronizer is disabled.
428                  if (!isEnabled() || selectionChangeCausedByMe)                  if (!isEnabled() || selectionChangeCausedByMe)

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26