/[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 101 by alfonx, Fri May 8 13:17:02 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;
33  import org.geotools.styling.StyleImpl;  import org.geotools.styling.StyleImpl;
34    import org.geotools.styling.Symbolizer;
35  import org.opengis.filter.Filter;  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;
43  import schmitzm.geotools.map.event.JMapPaneEvent;  import schmitzm.geotools.map.event.JMapPaneEvent;
44  import schmitzm.geotools.map.event.JMapPaneListener;  import schmitzm.geotools.map.event.JMapPaneListener;
45  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
46    import schmitzm.lang.LangUtil;
47  import skrueger.geotools.StyledFeatureCollectionInterface;  import skrueger.geotools.StyledFeatureCollectionInterface;
48  import skrueger.geotools.StyledMapInterface;  import skrueger.geotools.StyledMapInterface;
49  import skrueger.geotools.selection.StyledFeatureLayerSelectionModel;  import skrueger.geotools.selection.StyledFeatureLayerSelectionModel;
# Line 65  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<Feature> 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 131  public class FeatureMapLayerSelectionSyn Line 135  public class FeatureMapLayerSelectionSyn
135                  selectionChangeCausedByMe = false;                  selectionChangeCausedByMe = false;
136          }          }
137    
138          private void changeLayerStyle(Vector<Feature> newSelection) {          private void changeLayerStyle(final Vector<Feature> newSelection) {
139                  Style selectionMapStyle = null;                  Style selectionMapStyle = null;
140                  try {                  try {
141                          if (newSelection.isEmpty()) {                          if (newSelection.isEmpty()) {
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                                                    //                                      ps.getFill().setOpacity( FilterUtil.FILTER_FAC.literal(0.5));
159                                                  return false;  //                              }
160                                          }  
161                                                                            // Rule selectedRule = StylingUtil.STYLE_FACTORY.createRule();
162                                  });                                  selectionMapStyle.getFeatureTypeStyles()[0].getRules()[0]
163                                                                                    .setFilter(new Filter() {
164                                    
165  //                              selectionMapStyle.setFeatureTypeStyles(originalStyle.getF)                                                          @Override
166                                                                                            public Object accept(FilterVisitor visitor,
167                                                                            Object extraData) {
168                                                                    return null;
169                                                            }
170    
171                                                            @Override
172                                                            public boolean evaluate(Object obj) {
173                                                                    if (obj instanceof Feature) {
174                                                                            Feature f = (Feature) obj;
175                                                                            // TODO BAD CODE
176                                                                            for (Feature ff : newSelection) {
177                                                                                    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 198  public class FeatureMapLayerSelectionSyn Line 221  public class FeatureMapLayerSelectionSyn
221    
222          @Override          @Override
223          public void performMapPaneEvent(JMapPaneEvent e) {          public void performMapPaneEvent(JMapPaneEvent e) {
224                  if (!(e instanceof FeatureSelectedEvent))  
225                    if (!(e instanceof FeatureSelectedEvent)) {
226    //                      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);
232    //              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 229  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.101  
changed lines
  Added in v.107

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26