/[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 101 by alfonx, Fri May 8 13:17:02 2009 UTC revision 106 by alfonx, Fri May 8 15:13:49 2009 UTC
# Line 30  import org.geotools.styling.Rule; Line 30  import org.geotools.styling.Rule;
30  import org.geotools.styling.RuleImpl;  import org.geotools.styling.RuleImpl;
31  import org.geotools.styling.Style;  import org.geotools.styling.Style;
32  import org.geotools.styling.StyleImpl;  import org.geotools.styling.StyleImpl;
33    import org.geotools.styling.Symbolizer;
34  import org.opengis.filter.Filter;  import org.opengis.filter.Filter;
35  import org.opengis.filter.FilterVisitor;  import org.opengis.filter.FilterVisitor;
36  import org.opengis.layer.StyleURL;  import org.opengis.layer.StyleURL;
# Line 40  import schmitzm.geotools.map.event.Featu Line 41  import schmitzm.geotools.map.event.Featu
41  import schmitzm.geotools.map.event.JMapPaneEvent;  import schmitzm.geotools.map.event.JMapPaneEvent;
42  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
43  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
44    import schmitzm.lang.LangUtil;
45  import skrueger.geotools.StyledFeatureCollectionInterface;  import skrueger.geotools.StyledFeatureCollectionInterface;
46  import skrueger.geotools.StyledMapInterface;  import skrueger.geotools.StyledMapInterface;
47  import skrueger.geotools.selection.StyledFeatureLayerSelectionModel;  import skrueger.geotools.selection.StyledFeatureLayerSelectionModel;
# Line 65  import skrueger.geotools.selection.Style Line 67  import skrueger.geotools.selection.Style
67   *         (University of Bonn/Germany)   *         (University of Bonn/Germany)
68   */   */
69  public class FeatureMapLayerSelectionSynchronizer extends  public class FeatureMapLayerSelectionSynchronizer extends
70                  StyledLayerSelectionModelSynchronizer<Feature> implements                  StyledLayerSelectionModelSynchronizer<StyledFeatureLayerSelectionModel>
71                  JMapPaneListener {                  implements JMapPaneListener {
72          /**          /**
73           * Holds the {@link MapLayer} to keep synchronized with the layer selection           * Holds the {@link MapLayer} to keep synchronized with the layer selection
74           * model.           * model.
# Line 131  public class FeatureMapLayerSelectionSyn Line 133  public class FeatureMapLayerSelectionSyn
133                  selectionChangeCausedByMe = false;                  selectionChangeCausedByMe = false;
134          }          }
135    
136          private void changeLayerStyle(Vector<Feature> newSelection) {          private void changeLayerStyle(final Vector<Feature> newSelection) {
137                  Style selectionMapStyle = null;                  Style selectionMapStyle = null;
138                  try {                  try {
139                          if (newSelection.isEmpty()) {                          if (newSelection.isEmpty()) {
140    
141                                  selectionMapStyle = styledMapLayer.getStyle();                                  selectionMapStyle = styledMapLayer.getStyle();
142                                  LOGGER.debug("NO SELECTION .. reset original style");                                  LOGGER.debug("NO SELECTION .. reset original style");
143                                    
144                          } else {                          } else {
145                                  LOGGER.debug("SELECTION .. change style");                                  LOGGER.debug("SELECTION .. change style");
146                                    
147                                  Style originalStyle = styledMapLayer.getStyle();                                  Style originalStyle = styledMapLayer.getStyle();
148                                    
149                                  // TODO This clone is a deep clone and it is slow..                                  // TODO This clone is a deep clone and it is slow..
150                                  selectionMapStyle =  StylingUtil.clone(originalStyle);                                  selectionMapStyle = StylingUtil.clone(originalStyle);
151                                    
152                                  Rule[] rules = selectionMapStyle.getFeatureTypeStyles()[0].getRules();                                  // TODO BAD CODE
153                                                                    Style defaultStyle = StylingUtil
154                                  Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule();                                                  .createDefaultStyle(styledMapLayer.getGeoObject());
155                                  selectedRule.setFilter(new Filter() {  
156                                    // Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule();
157                                          @Override                                  defaultStyle.getFeatureTypeStyles()[0].getRules()[0]
158                                          public Object accept(FilterVisitor visitor, Object extraData) {                                                  .setFilter(new Filter() {
159                                                  return null;  
160                                          }                                                          @Override
161                                                            public Object accept(FilterVisitor visitor,
162                                          @Override                                                                          Object extraData) {
163                                          public boolean evaluate(Object obj) {                                                                  return null;
164                                                                                                            }
165                                                  return false;  
166                                          }                                                          @Override
167                                                                                                    public boolean evaluate(Object obj) {
168                                  });                                                                  if (obj instanceof Feature) {
169                                                                                                            Feature f = (Feature) obj;
170                                                                                                            // TODO BAD CODE
171  //                              selectionMapStyle.setFeatureTypeStyles(originalStyle.getF)                                                                          for (Feature ff : newSelection) {
172                                                                                                                    if (ff.getID().equals(f.getID()))
173                                                                                            return true;
174                                                                            }
175                                                                            return false;
176    
177                                                                    }
178                                                                    return false;
179                                                            }
180    
181                                                    });
182    
183                                    selectionMapStyle.setFeatureTypeStyles(LangUtil.extendArray(
184                                                    selectionMapStyle.getFeatureTypeStyles(), defaultStyle
185                                                                    .getFeatureTypeStyles()[0]));
186    
187                                    // selectionMapStyle.setFeatureTypeStyles(originalStyle.getF)
188    
189                                  // Flat copy the style                                  // Flat copy the style
190                                    
191                                                                    // selectionMapStyle =
192                                                                    // StylingUtil.createDefaultStyle(styledMapLayer.getGeoObject());
193                                    
194                          }                          }
195    
196                          mapLayer.setStyle(selectionMapStyle);                          mapLayer.setStyle(selectionMapStyle);
# Line 198  public class FeatureMapLayerSelectionSyn Line 216  public class FeatureMapLayerSelectionSyn
216    
217          @Override          @Override
218          public void performMapPaneEvent(JMapPaneEvent e) {          public void performMapPaneEvent(JMapPaneEvent e) {
219                  if (!(e instanceof FeatureSelectedEvent))  
220                    if (!(e instanceof FeatureSelectedEvent)) {
221    //                      LOGGER.debug("Ignoring event " + e);
222                          return;                          return;
223                    }
224    
225                  FeatureSelectedEvent fse = (FeatureSelectedEvent) e;                  FeatureSelectedEvent fse = (FeatureSelectedEvent) e;
226    //              LOGGER.debug("Do event " + fse);
227    //              LOGGER.debug("Do event " + fse.getSelectionResult());
228    
229                  // ignore event if it is caused by the DpLayerVectorSelectionModel                  // ignore event if it is caused by the DpLayerVectorSelectionModel
230                  if (selectionChangeCausedByMe)                  if (selectionChangeCausedByMe)
# Line 229  public class FeatureMapLayerSelectionSyn Line 252  public class FeatureMapLayerSelectionSyn
252                  // Show selected feature in the map, which is not automatically done by                  // Show selected feature in the map, which is not automatically done by
253                  // the FeatureSelectedEvent                  // the FeatureSelectedEvent
254                  changeLayerStyle(layerSelModel.getSelection());                  changeLayerStyle(layerSelModel.getSelection());
255                    
256                  // Danger of event circles in propertyChange(..) banned                  // Danger of event circles in propertyChange(..) banned
257                  selectionChangeCausedByMe = false;                  selectionChangeCausedByMe = false;
258          }          }

Legend:
Removed from v.101  
changed lines
  Added in v.106

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26