/[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 104 by alfonx, Fri May 8 13:49:34 2009 UTC revision 109 by mojays, Tue May 12 13:14:26 2009 UTC
# Line 26  import javax.swing.text.Utilities; Line 26  import javax.swing.text.Utilities;
26    
27  import org.geotools.feature.Feature;  import org.geotools.feature.Feature;
28  import org.geotools.map.MapLayer;  import org.geotools.map.MapLayer;
29    import org.geotools.styling.PolygonSymbolizer;
30  import org.geotools.styling.Rule;  import org.geotools.styling.Rule;
31  import org.geotools.styling.RuleImpl;  import org.geotools.styling.RuleImpl;
32  import org.geotools.styling.Style;  import org.geotools.styling.Style;
# Line 35  import org.opengis.filter.Filter; Line 36  import org.opengis.filter.Filter;
36  import org.opengis.filter.FilterVisitor;  import org.opengis.filter.FilterVisitor;
37  import org.opengis.layer.StyleURL;  import org.opengis.layer.StyleURL;
38    
39    import schmitzm.geotools.FilterUtil;
40  import schmitzm.geotools.gui.FeatureCollectionTableModel;  import schmitzm.geotools.gui.FeatureCollectionTableModel;
41  import schmitzm.geotools.gui.JMapPane;  import schmitzm.geotools.gui.JMapPane;
42  import schmitzm.geotools.map.event.FeatureSelectedEvent;  import schmitzm.geotools.map.event.FeatureSelectedEvent;
# Line 67  import skrueger.geotools.selection.Style Line 69  import skrueger.geotools.selection.Style
69   *         (University of Bonn/Germany)   *         (University of Bonn/Germany)
70   */   */
71  public class FeatureMapLayerSelectionSynchronizer extends  public class FeatureMapLayerSelectionSynchronizer extends
72                  StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel> implements                  StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
73                  JMapPaneListener {                  implements JMapPaneListener {
74          /**          /**
75           * Holds the {@link MapLayer} to keep synchronized with the layer selection           * Holds the {@link MapLayer} to keep synchronized with the layer selection
76           * model.           * model.
# Line 140  public class FeatureMapLayerSelectionSyn Line 142  public class FeatureMapLayerSelectionSyn
142    
143                                  selectionMapStyle = styledMapLayer.getStyle();                                  selectionMapStyle = styledMapLayer.getStyle();
144                                  LOGGER.debug("NO SELECTION .. reset original style");                                  LOGGER.debug("NO SELECTION .. reset original style");
145                                    
146                          } else {                          } else {
147                                  LOGGER.debug("SELECTION .. change style");                                  LOGGER.debug("SELECTION .. change style");
148                                    
149                                  Style originalStyle = styledMapLayer.getStyle();                                  Style originalStyle = styledMapLayer.getStyle();
                                   
                                 // TODO This clone is a deep clone and it is slow..  
                                 selectionMapStyle =  StylingUtil.clone(originalStyle);  
                                   
                                 Rule[] rules = selectionMapStyle.getFeatureTypeStyles()[0].getRules();  
                                   
                                 Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule();  
                                 selectedRule.setFilter(new Filter() {  
150    
151                                          @Override                                  // TODO This clone is a deep clone and it is slow..
152                                          public Object accept(FilterVisitor visitor, Object extraData) {                                  selectionMapStyle = StylingUtil
153                                                  return null;                                                  .createDefaultStyle(styledMapLayer.getGeoObject());
154                                          }                                  
155    //                              Symbolizer sss = selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0].getSymbolizers()[0];
156                                          @Override  //                              if (sss instanceof PolygonSymbolizer) {
157                                          public boolean evaluate(Object obj) {  //                                      PolygonSymbolizer ps = (PolygonSymbolizer) sss;
158                                                  if (obj instanceof Feature) {  //                                      ps.getFill().setOpacity( FilterUtil.FILTER_FAC.literal(0.5));
159                                                          Feature f = (Feature)obj;  //                              }
160                                                          LOGGER.info("treffer");  
161                                                          return newSelection.contains(f);                                  // Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule();
162                                                                                            selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0]
163                                                  }                                                  .setFilter(new Filter() {
164                                                  LOGGER.info("kein treffer");  
165                                                  return false;                                                          @Override
166                                          }                                                          public Object accept(FilterVisitor visitor,
167                                                                                                                    Object extraData) {
168                                  });                                                                  return null;
169                                                                                            }
170                                  Symbolizer[] symbolizers = selectedRule.getSymbolizers();  
171                                  Style selectedStyle = StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject());                                                          @Override
172                                  LangUtil.extendArray(symbolizers, selectedStyle);                                                          public boolean evaluate(Object obj) {
173                                  selectedRule.setSymbolizers(symbolizers);                                                                  if (obj instanceof Feature) {
174                                                                                                            Feature f = (Feature) obj;
175                                  LangUtil.extendArray(rules, selectedRule);                                                                          // TODO BAD CODE
176                                                                                                            for (Feature ff : newSelection) {
177  //                              selectionMapStyle.setFeatureTypeStyles(originalStyle.getF)                                                                                  if (ff.getID().equals(f.getID()))
178                                                                                                                            return true;
179                                                                            }
180                                                                            return false;
181    
182                                                                    }
183                                                                    return false;
184                                                            }
185    
186                                                    });
187    
188                                    selectionMapStyle.setFeatureTypeStyles(LangUtil.extendArray(
189                                                    originalStyle
190                                                                    .getFeatureTypeStyles(), selectionMapStyle.getFeatureTypeStyles()));
191    
192                                    // selectionMapStyle.setFeatureTypeStyles(originalStyle.getF)
193    
194                                  // Flat copy the style                                  // Flat copy the style
195                                    
196                                                                    // selectionMapStyle =
197                                                                    // StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject());
198                                    
199                          }                          }
200    
201                          mapLayer.setStyle(selectionMapStyle);                          mapLayer.setStyle(selectionMapStyle);
# Line 212  public class FeatureMapLayerSelectionSyn Line 221  public class FeatureMapLayerSelectionSyn
221    
222          @Override          @Override
223          public void performMapPaneEvent(JMapPaneEvent e) {          public void performMapPaneEvent(JMapPaneEvent e) {
                 if (!(e instanceof FeatureSelectedEvent))  
                         return;  
224    
225                    if (!(e instanceof FeatureSelectedEvent)) {
226    //                      LOGGER.debug("Ignoring event " + e);
227                            return;
228                    }
229                    // only listen to events directly coming from JMapPane
230                    // selection (ignore selections from FilterDialog)
231                    if ( e.getSourceObject() != this.mapPane )
232                      return;
233                    
234                  FeatureSelectedEvent fse = (FeatureSelectedEvent) e;                  FeatureSelectedEvent fse = (FeatureSelectedEvent) e;
235    //              LOGGER.debug("Do event " + fse);
236    //              LOGGER.debug("Do event " + fse.getSelectionResult());
237    
238                  // ignore event if it is caused by the DpLayerVectorSelectionModel                  // ignore event if it is caused by the DpLayerVectorSelectionModel
239                  if (selectionChangeCausedByMe)                  if (selectionChangeCausedByMe)
# Line 243  public class FeatureMapLayerSelectionSyn Line 261  public class FeatureMapLayerSelectionSyn
261                  // Show selected feature in the map, which is not automatically done by                  // Show selected feature in the map, which is not automatically done by
262                  // the FeatureSelectedEvent                  // the FeatureSelectedEvent
263                  changeLayerStyle(layerSelModel.getSelection());                  changeLayerStyle(layerSelModel.getSelection());
264                    
265                  // Danger of event circles in propertyChange(..) banned                  // Danger of event circles in propertyChange(..) banned
266                  selectionChangeCausedByMe = false;                  selectionChangeCausedByMe = false;
267          }          }

Legend:
Removed from v.104  
changed lines
  Added in v.109

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26