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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26