/[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 105 by alfonx, Fri May 8 15:02:28 2009 UTC revision 107 by alfonx, Mon May 11 13:14:20 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 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                                                          // TODO BAD CODE                                  // Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule();
162                                                          for (Feature ff : newSelection){                                  selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0]
163                                                                  if (ff.getID().equals(f.getID())) return true;                                                  .setFilter(new Filter() {
164    
165                                                            @Override
166                                                            public Object accept(FilterVisitor visitor,
167                                                                            Object extraData) {
168                                                                    return null;
169                                                          }                                                          }
170                                                          return false;  
171                                                                                                                    @Override
172                                                  }                                                          public boolean evaluate(Object obj) {
173                                                  LOGGER.info("kein treffer");                                                                  if (obj instanceof Feature) {
174                                                  return false;                                                                          Feature f = (Feature) obj;
175                                          }                                                                          // TODO BAD CODE
176                                                                                                                    for (Feature ff : newSelection) {
177                                  });                                                                                  if (ff.getID().equals(f.getID()))
178                                                                                                                            return true;
179                                  Style defaultStyle = StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject());                                                                          }
180                                  selectedRule.setSymbolizers(new Symbolizer[] {defaultStyle.getFeatureTypeStyles()[0].getRules()[0].getSymbolizers()[0]} );                                                                          return false;
181                                    
182                                  Rule[] rules = selectionMapStyle.getFeatureTypeStyles()[0].getRules();                                                                  }
183                                  rules = LangUtil.extendArray(rules, selectedRule);                                                                  return false;
184                                                                                            }
185                                  selectionMapStyle.getFeatureTypeStyles()[0].setRules(rules);  
186                                                                                    });
187  //                              selectionMapStyle.setFeatureTypeStyles(originalStyle.getF)  
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 = StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject());                                  // selectionMapStyle =
197                                                                    // StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject());
198                                    
199                          }                          }
200    
201                          mapLayer.setStyle(selectionMapStyle);                          mapLayer.setStyle(selectionMapStyle);
# Line 216  public class FeatureMapLayerSelectionSyn Line 221  public class FeatureMapLayerSelectionSyn
221    
222          @Override          @Override
223          public void performMapPaneEvent(JMapPaneEvent e) {          public void performMapPaneEvent(JMapPaneEvent e) {
224                    
225                  if (!(e instanceof FeatureSelectedEvent)) {                  if (!(e instanceof FeatureSelectedEvent)) {
226                          LOGGER.debug("Ignoring event "+e);  //                      LOGGER.debug("Ignoring event " + e);
227                          return;                          return;
228                  }                  }
229    
230                  FeatureSelectedEvent fse = (FeatureSelectedEvent) e;                  FeatureSelectedEvent fse = (FeatureSelectedEvent) e;
231                  LOGGER.debug("Do event "+fse);  //              LOGGER.debug("Do event " + fse);
232                  LOGGER.debug("Do event "+fse.getSelectionResult());  //              LOGGER.debug("Do event " + fse.getSelectionResult());
233    
234                  // ignore event if it is caused by the DpLayerVectorSelectionModel                  // ignore event if it is caused by the DpLayerVectorSelectionModel
235                  if (selectionChangeCausedByMe)                  if (selectionChangeCausedByMe)
# Line 252  public class FeatureMapLayerSelectionSyn Line 257  public class FeatureMapLayerSelectionSyn
257                  // Show selected feature in the map, which is not automatically done by                  // Show selected feature in the map, which is not automatically done by
258                  // the FeatureSelectedEvent                  // the FeatureSelectedEvent
259                  changeLayerStyle(layerSelModel.getSelection());                  changeLayerStyle(layerSelModel.getSelection());
260                    
261                  // Danger of event circles in propertyChange(..) banned                  // Danger of event circles in propertyChange(..) banned
262                  selectionChangeCausedByMe = false;                  selectionChangeCausedByMe = false;
263          }          }

Legend:
Removed from v.105  
changed lines
  Added in v.107

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26