/[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 516 by alfonx, Wed Nov 11 21:17:33 2009 UTC
# Line 42  Line 42 
42   **/   **/
43  package skrueger.geotools.selection;  package skrueger.geotools.selection;
44    
 import java.awt.RenderingHints;  
45  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
46  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
47  import java.io.File;  import java.io.File;
 import java.util.HashMap;  
48  import java.util.HashSet;  import java.util.HashSet;
49  import java.util.Iterator;  import java.util.Iterator;
50  import java.util.Set;  import java.util.Set;
# Line 60  import org.geotools.feature.FeatureColle Line 58  import org.geotools.feature.FeatureColle
58  import org.geotools.feature.FeatureIterator;  import org.geotools.feature.FeatureIterator;
59  import org.geotools.filter.FidFilterImpl;  import org.geotools.filter.FidFilterImpl;
60  import org.geotools.map.MapLayer;  import org.geotools.map.MapLayer;
 import org.geotools.renderer.GTRenderer;  
 import org.geotools.renderer.label.LabelCacheImpl;  
 import org.geotools.renderer.lite.StreamingRenderer;  
61  import org.geotools.styling.FeatureTypeStyle;  import org.geotools.styling.FeatureTypeStyle;
62  import org.geotools.styling.Style;  import org.geotools.styling.Style;
63  import org.geotools.styling.visitor.DuplicatingStyleVisitor;  import org.geotools.styling.visitor.DuplicatingStyleVisitor;
# Line 73  import org.opengis.filter.Not; Line 68  import org.opengis.filter.Not;
68  import org.opengis.filter.identity.FeatureId;  import org.opengis.filter.identity.FeatureId;
69    
70  import schmitzm.geotools.FilterUtil;  import schmitzm.geotools.FilterUtil;
71  import schmitzm.geotools.GTUtil;  import schmitzm.geotools.gui.SelectableXMapPane;
 import schmitzm.geotools.gui.JMapPane;  
72  import schmitzm.geotools.map.event.FeatureSelectedEvent;  import schmitzm.geotools.map.event.FeatureSelectedEvent;
73  import schmitzm.geotools.map.event.JMapPaneEvent;  import schmitzm.geotools.map.event.MapPaneEvent;
74  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
75  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
76  import skrueger.geotools.MapPaneToolBar;  import skrueger.geotools.MapPaneToolBar;
# Line 103  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.
111           */           */
112          protected final MapLayer mapLayer;          protected final MapLayer mapLayer;
113          protected final StyledFeaturesInterface<?> styledLayer;          protected final StyledFeaturesInterface<?> styledLayer;
114          protected final JMapPane mapPane;          protected final SelectableXMapPane mapPane;
115          private final MapPaneToolBar toolBar;          private final MapPaneToolBar toolBar;
         private final HashMap<Object, Object> defaultGTRenderingHints;  
116    
117          /**          /**
118           * Creates a new synchronizer           * Creates a new synchronizer
# Line 127  public class FeatureMapLayerSelectionSyn Line 127  public class FeatureMapLayerSelectionSyn
127          public FeatureMapLayerSelectionSynchronizer(          public FeatureMapLayerSelectionSynchronizer(
128                          StyledFeatureLayerSelectionModel layerSelModel,                          StyledFeatureLayerSelectionModel layerSelModel,
129                          StyledFeaturesInterface<?> styledLayer, MapLayer mapLayer,                          StyledFeaturesInterface<?> styledLayer, MapLayer mapLayer,
130                          JMapPane mapPane, MapPaneToolBar toolBar,                          SelectableXMapPane mapPane, MapPaneToolBar toolBar) {
                         HashMap<Object, Object> defaultGTRenderingHints) {  
131    
132                  super(layerSelModel);                  super(layerSelModel);
133                  this.styledLayer = styledLayer;                  this.styledLayer = styledLayer;
# Line 136  public class FeatureMapLayerSelectionSyn Line 135  public class FeatureMapLayerSelectionSyn
135                  this.mapLayer = mapLayer;                  this.mapLayer = mapLayer;
136                  this.mapPane = mapPane;                  this.mapPane = mapPane;
137                  this.toolBar = toolBar;                  this.toolBar = toolBar;
                 if (defaultGTRenderingHints != null)  
                         this.defaultGTRenderingHints = defaultGTRenderingHints;  
                 else  
                         this.defaultGTRenderingHints = new HashMap<Object, Object>();  
138          }          }
139    
140          /**          /**
# Line 201  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();                                                  replaceRenderer();
# Line 230  public class FeatureMapLayerSelectionSyn Line 225  public class FeatureMapLayerSelectionSyn
225                                  FeatureTypeStyle selectionFTStyle = StylingUtil                                  FeatureTypeStyle selectionFTStyle = StylingUtil
226                                                  .createSelectionStyle(styledLayer.getGeoObject());                                                  .createSelectionStyle(styledLayer.getGeoObject());
227    
228                                  selectionFTStyle.setName(SELECTION_STYLING);                                  selectionFTStyle.setName(SELECTION_STYLING_FTS_NAME);
229    
230                                  /**                                  /**
231                                   *                                   *
# Line 278  public class FeatureMapLayerSelectionSyn Line 273  public class FeatureMapLayerSelectionSyn
273                                  boolean foundAndReplaced = false;                                  boolean foundAndReplaced = false;
274                                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {                                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
275                                          if (fts.getName() != null                                          if (fts.getName() != null
276                                                          && fts.getName().equals(SELECTION_STYLING)) {                                                          && fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
277                                                  foundAndReplaced = true;                                                  foundAndReplaced = true;
278                                                  fts.rules().clear();                                                  fts.rules().clear();
279                                                  fts.rules().addAll(selectionFTStyle.rules());                                                  fts.rules().addAll(selectionFTStyle.rules());
# Line 340  public class FeatureMapLayerSelectionSyn Line 335  public class FeatureMapLayerSelectionSyn
335                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {                  for (FeatureTypeStyle fts : originalStyle.featureTypeStyles()) {
336    
337                          if (fts.getName() != null                          if (fts.getName() != null
338                                          && fts.getName().equals(SELECTION_STYLING)) {                                          && fts.getName().equals(SELECTION_STYLING_FTS_NAME)) {
339    
340                                  SELECTION_STYLING_foundInMapStyle = true;                                  SELECTION_STYLING_foundInMapStyle = true;
341    
# Line 405  public class FeatureMapLayerSelectionSyn Line 400  public class FeatureMapLayerSelectionSyn
400                  return false;                  return false;
401          }          }
402    
403            /**
404             * Replaces the local renderer
405             */
406          private void replaceRenderer() {          private void replaceRenderer() {
407                    // //
408                    // // // Has to be done before we apply the new Renderer
409                    // // mapLayer.setStyle(style);
410                  //                  //
411                  // // Has to be done before we apply the new Renderer                  // GTRenderer oldRenderer = mapPane.getLocalRenderer();
412                  // mapLayer.setStyle(style);                  //
413                    // /**
414                  GTRenderer oldRenderer = mapPane.getRenderer();                  // * Explicitly putting a new instance of LabelCacheDefault into the
415                    // * renderer instance, so JMapPane doesn't reuse the old one. This is
416                  /**                  // * very useful when changing the TextSymbolizer with AtlasStyler<br/>
417                   * Explicitly putting a new instance of LabelCacheDefault into the                  // * SK 9.7.09: It's not enought to user LabelCache.clear(). We can not
418                   * renderer instance, so JMapPane doesn't reuse the old one. This is                  // * reuse the old Renderer - better to create a new one!
419                   * very useful when changing the TextSymbolizer with AtlasStyler<br/>                  // */
420                   * SK 9.7.09: It's not enought to user LabelCache.clear(). We can not                  // final GTRenderer newRenderer = GTUtil.createGTRenderer();
421                   * reuse the old Renderer - better to create a new one!                  //
422                   */                  // final HashMap<Object, Object> rendererHints =
423                  final GTRenderer newRenderer = GTUtil.createGTRenderer();                  // defaultGTRenderingHints;
424                    // rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY,
425                  final HashMap<Object, Object> rendererHints = defaultGTRenderingHints;                  // new LabelCacheImpl());
426                  rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY,                  //
427                                  new LabelCacheImpl());                  // newRenderer.setRendererHints(rendererHints);
428                    // mapPane.setLocalRenderer(newRenderer);
429                  newRenderer.setRendererHints(rendererHints);                  //
430                  mapPane.setRenderer(newRenderer);                  // if (oldRenderer != null) {
431                    //
432                  if (oldRenderer != null) {                  // RenderingHints java2DHints = oldRenderer.getJava2DHints();
433                    // if (java2DHints != null) {
434                          RenderingHints java2DHints = oldRenderer.getJava2DHints();                  // newRenderer.setJava2DHints(java2DHints);
435                          if (java2DHints != null) {                  // }
436                                  newRenderer.setJava2DHints(java2DHints);                  //
437                          }                  // oldRenderer.setContext(null);
438                    // oldRenderer = null;
439                          oldRenderer.setContext(null);                  // }
                         oldRenderer = null;  
                 }  
440    
441                  mapPane.refresh();                  mapPane.refresh();
442    
# Line 448  public class FeatureMapLayerSelectionSyn Line 447  public class FeatureMapLayerSelectionSyn
447           * {@link StyledFeatureLayerSelectionModel}           * {@link StyledFeatureLayerSelectionModel}
448           */           */
449          @Override          @Override
450          public void performMapPaneEvent(JMapPaneEvent e) {          public void performMapPaneEvent(MapPaneEvent e) {
451    
452                  // 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.
453                  if (!isEnabled() || selectionChangeCausedByMe)                  if (!isEnabled() || selectionChangeCausedByMe)

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26