/[schmitzm]/branches/2.0-RC2/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
ViewVC logotype

Diff of /branches/2.0-RC2/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 415 by alfonx, Thu Sep 24 17:58:32 2009 UTC revision 438 by alfonx, Mon Oct 5 13:04:01 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.util.HashMap;
49  import java.util.HashSet;  import java.util.HashSet;
50  import java.util.Iterator;  import java.util.Iterator;
51  import java.util.Set;  import java.util.Set;
# Line 54  import javax.swing.ListSelectionModel; Line 56  import javax.swing.ListSelectionModel;
56  import javax.swing.event.ListSelectionListener;  import javax.swing.event.ListSelectionListener;
57    
58  import org.geotools.map.MapLayer;  import org.geotools.map.MapLayer;
59    import org.geotools.renderer.GTRenderer;
60    import org.geotools.renderer.label.LabelCacheImpl;
61    import org.geotools.renderer.lite.StreamingRenderer;
62    import org.geotools.renderer.shape.ShapefileRenderer;
63  import org.geotools.styling.FeatureTypeStyle;  import org.geotools.styling.FeatureTypeStyle;
64  import org.geotools.styling.Style;  import org.geotools.styling.Style;
65    import org.geotools.styling.visitor.DuplicatingStyleVisitor;
66  import org.opengis.feature.simple.SimpleFeature;  import org.opengis.feature.simple.SimpleFeature;
67  import org.opengis.filter.identity.FeatureId;  import org.opengis.filter.identity.FeatureId;
68    
69  import schmitzm.geotools.FilterUtil;  import schmitzm.geotools.FilterUtil;
70    import schmitzm.geotools.GTUtil;
71  import schmitzm.geotools.gui.JMapPane;  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.JMapPaneEvent;
# Line 98  public class FeatureMapLayerSelectionSyn Line 106  public class FeatureMapLayerSelectionSyn
106          protected final StyledLayerInterface<?> styledLayer;          protected final StyledLayerInterface<?> styledLayer;
107          protected final JMapPane mapPane;          protected final JMapPane mapPane;
108          private final MapPaneToolBar toolBar;          private final MapPaneToolBar toolBar;
109            private final HashMap<Object, Object> defaultGTRenderingHints;
110    
111          /**          /**
112           * Creates a new synchronizer           * Creates a new synchronizer
# Line 112  public class FeatureMapLayerSelectionSyn Line 121  public class FeatureMapLayerSelectionSyn
121          public FeatureMapLayerSelectionSynchronizer(          public FeatureMapLayerSelectionSynchronizer(
122                          StyledFeatureLayerSelectionModel layerSelModel,                          StyledFeatureLayerSelectionModel layerSelModel,
123                          StyledLayerInterface<?> styledLayer, MapLayer mapLayer,                          StyledLayerInterface<?> styledLayer, MapLayer mapLayer,
124                          JMapPane mapPane, MapPaneToolBar toolBar) {                          JMapPane mapPane, MapPaneToolBar toolBar, HashMap<Object, Object> defaultGTRenderingHints) {
125    
126                  super(layerSelModel);                  super(layerSelModel);
127                  this.styledLayer = styledLayer;                  this.styledLayer = styledLayer;
# Line 120  public class FeatureMapLayerSelectionSyn Line 129  public class FeatureMapLayerSelectionSyn
129                  this.mapLayer = mapLayer;                  this.mapLayer = mapLayer;
130                  this.mapPane = mapPane;                  this.mapPane = mapPane;
131                  this.toolBar = toolBar;                  this.toolBar = toolBar;
132                    if (defaultGTRenderingHints != null)
133                            this.defaultGTRenderingHints = defaultGTRenderingHints;
134                    else
135                            this.defaultGTRenderingHints = new HashMap<Object, Object>();
136          }          }
137    
138          /**          /**
# Line 169  public class FeatureMapLayerSelectionSyn Line 182  public class FeatureMapLayerSelectionSyn
182           */           */
183          private void changeLayerStyle(final Vector<String> newSelection) {          private void changeLayerStyle(final Vector<String> newSelection) {
184                  try {                  try {
 //                      GTRenderer r = mapPane.getRenderer();  
 //                      if (r instanceof ShapefileRenderer) {  
 //                              ShapefileRenderer sfr = (ShapefileRenderer)r;  
 //                              sfr.setCaching(false);  
 //                      }  
 //                        
185                                                    
186                          Style originalStyle = mapLayer.getStyle();                          Style originalStyle = mapLayer.getStyle();
187                          if (newSelection.isEmpty()) {                          if (newSelection.isEmpty()) {
# Line 188  public class FeatureMapLayerSelectionSyn Line 195  public class FeatureMapLayerSelectionSyn
195                                                          && fts.getName().equals(SELECTION_STYLING)) {                                                          && fts.getName().equals(SELECTION_STYLING)) {
196                                                  originalStyle.featureTypeStyles().remove(fts);                                                  originalStyle.featureTypeStyles().remove(fts);
197                                                                                                    
198                                                  mapPane.refresh();                                                  replaceRenderer();
199    //                                              mapPane.refresh();
200                                                    
201    
202                                                  return;                                                  return;
203                                          }                                          }
# Line 247  public class FeatureMapLayerSelectionSyn Line 256  public class FeatureMapLayerSelectionSyn
256                                  if (!foundAndReplaced) {                                  if (!foundAndReplaced) {
257                                          originalStyle.featureTypeStyles().add(selectionFTStyle);                                          originalStyle.featureTypeStyles().add(selectionFTStyle);
258                                  }                                  }
259                                    
260                                    
261    
262                                  // Refresh the map                                  // Refresh the map
263                                  mapPane.refresh();  //                              mapPane.refresh();
264                                    
265                                    DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();
266                                    dsv.visit(originalStyle);
267                                    Style newStyle = (Style)dsv.getCopy();
268                                    
269    //                              Style newStyle = StylingUtil.STYLE_BUILDER.createStyle();
270    //                              newStyle.featureTypeStyles().addAll(originalStyle.featureTypeStyles());
271                                    mapLayer.setStyle(newStyle);
272                                    
273                                    replaceRenderer();
274                          }                          }
 //                        
 //                      if (r instanceof ShapefileRenderer) {  
 //                              ShapefileRenderer sfr = (ShapefileRenderer)r;  
 //                              sfr.setCaching(true);  
 //                      }  
   
275    
276                  } catch (Exception e) {                  } catch (Exception e) {
277                          LOGGER.error("Error while trying to create a selection style", e);                          LOGGER.error("Error while trying to create a selection style", e);
278                  }                  }
279          }          }
280    
281            private void replaceRenderer() {
282    //
283    //              // Has to be done before we apply the new Renderer
284    //              mapLayer.setStyle(style);
285    
286                    GTRenderer oldRenderer = mapPane.getRenderer();
287    
288                    /**
289                     * Explicitly putting a new instance of LabelCacheDefault into the
290                     * renderer instance, so JMapPane doesn't reuse the old one. This is
291                     * very useful when changing the TextSymbolizer with AtlasStyler<br/>
292                     * SK 9.7.09: It's not enought to user LabelCache.clear(). We can not
293                     * reuse the old Renderer - better to create a new one!
294                     */
295                    final GTRenderer newRenderer = GTUtil.createGTRenderer(oldRenderer.getContext());
296    
297                    final HashMap<Object, Object> rendererHints = defaultGTRenderingHints;
298                    rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY,
299                                    new LabelCacheImpl());
300    
301                    newRenderer.setRendererHints(rendererHints);
302                    mapPane.setRenderer(newRenderer);
303    
304                    if (oldRenderer != null) {
305                            
306                            RenderingHints java2DHints = oldRenderer.getJava2DHints();
307                            if (java2DHints != null) {
308                                    newRenderer.setJava2DHints(java2DHints);
309                            }
310                            
311                            oldRenderer.setContext(null);
312                            oldRenderer = null;
313                    }
314                    
315                    mapPane.refresh();
316    
317            }
318    
319          /**          /**
320           * Used to synchronize {@link FeatureSelectedEvent}s with the           * Used to synchronize {@link FeatureSelectedEvent}s with the
321           * {@link StyledFeatureLayerSelectionModel}           * {@link StyledFeatureLayerSelectionModel}

Legend:
Removed from v.415  
changed lines
  Added in v.438

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26