/[schmitzm]/branches/2.0-RC1/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
ViewVC logotype

Diff of /branches/2.0-RC1/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 454 by alfonx, Mon Oct 5 13:33:45 2009 UTC revision 455 by alfonx, Sun Oct 11 21:41:53 2009 UTC
# Line 55  import javax.swing.JTable; Line 55  import javax.swing.JTable;
55  import javax.swing.ListSelectionModel;  import javax.swing.ListSelectionModel;
56  import javax.swing.event.ListSelectionListener;  import javax.swing.event.ListSelectionListener;
57    
58    import org.geotools.feature.FeatureCollection;
59  import org.geotools.map.MapLayer;  import org.geotools.map.MapLayer;
60  import org.geotools.renderer.GTRenderer;  import org.geotools.renderer.GTRenderer;
61  import org.geotools.renderer.label.LabelCacheImpl;  import org.geotools.renderer.label.LabelCacheImpl;
# Line 63  import org.geotools.styling.FeatureTypeS Line 64  import org.geotools.styling.FeatureTypeS
64  import org.geotools.styling.Style;  import org.geotools.styling.Style;
65  import org.geotools.styling.visitor.DuplicatingStyleVisitor;  import org.geotools.styling.visitor.DuplicatingStyleVisitor;
66  import org.opengis.feature.simple.SimpleFeature;  import org.opengis.feature.simple.SimpleFeature;
67    import org.opengis.feature.simple.SimpleFeatureType;
68  import org.opengis.filter.identity.FeatureId;  import org.opengis.filter.identity.FeatureId;
69    
70  import schmitzm.geotools.FilterUtil;  import schmitzm.geotools.FilterUtil;
# Line 120  public class FeatureMapLayerSelectionSyn Line 122  public class FeatureMapLayerSelectionSyn
122          public FeatureMapLayerSelectionSynchronizer(          public FeatureMapLayerSelectionSynchronizer(
123                          StyledFeatureLayerSelectionModel layerSelModel,                          StyledFeatureLayerSelectionModel layerSelModel,
124                          StyledLayerInterface<?> styledLayer, MapLayer mapLayer,                          StyledLayerInterface<?> styledLayer, MapLayer mapLayer,
125                          JMapPane mapPane, MapPaneToolBar toolBar, HashMap<Object, Object> defaultGTRenderingHints) {                          JMapPane mapPane, MapPaneToolBar toolBar,
126                            HashMap<Object, Object> defaultGTRenderingHints) {
127    
128                  super(layerSelModel);                  super(layerSelModel);
129                  this.styledLayer = styledLayer;                  this.styledLayer = styledLayer;
# Line 130  public class FeatureMapLayerSelectionSyn Line 133  public class FeatureMapLayerSelectionSyn
133                  this.toolBar = toolBar;                  this.toolBar = toolBar;
134                  if (defaultGTRenderingHints != null)                  if (defaultGTRenderingHints != null)
135                          this.defaultGTRenderingHints = defaultGTRenderingHints;                          this.defaultGTRenderingHints = defaultGTRenderingHints;
136                  else                  else
137                          this.defaultGTRenderingHints = new HashMap<Object, Object>();                          this.defaultGTRenderingHints = new HashMap<Object, Object>();
138          }          }
139    
# Line 181  public class FeatureMapLayerSelectionSyn Line 184  public class FeatureMapLayerSelectionSyn
184           */           */
185          private void changeLayerStyle(final Vector<String> newSelection) {          private void changeLayerStyle(final Vector<String> newSelection) {
186                  try {                  try {
187                            
188                          Style originalStyle = mapLayer.getStyle();                          Style originalStyle = mapLayer.getStyle();
189                          if (newSelection.isEmpty()) {                          if (newSelection.isEmpty()) {
190    
191                                  // Check if the Style contains a SELECTION FTS                                  // Check if the Style contains a SELECTION FTS
192                                    
193                                  FeatureTypeStyle[] clone = originalStyle.featureTypeStyles().toArray( new FeatureTypeStyle[] {} ).clone();                                  FeatureTypeStyle[] clone = originalStyle.featureTypeStyles()
194                                                                                    .toArray(new FeatureTypeStyle[] {}).clone();
195    
196                                  for (FeatureTypeStyle fts : clone) {                                  for (FeatureTypeStyle fts : clone) {
197                                          if (fts.getName() != null                                          if (fts.getName() != null
198                                                          && fts.getName().equals(SELECTION_STYLING)) {                                                          && fts.getName().equals(SELECTION_STYLING)) {
199                                                  originalStyle.featureTypeStyles().remove(fts);                                                  originalStyle.featureTypeStyles().remove(fts);
200                                                    
201                                                  replaceRenderer();                                                  replaceRenderer();
202  //                                              mapPane.refresh();                                                  // mapPane.refresh();
                                                   
203    
204                                                  return;                                                  return;
205                                          }                                          }
# Line 255  public class FeatureMapLayerSelectionSyn Line 258  public class FeatureMapLayerSelectionSyn
258                                  if (!foundAndReplaced) {                                  if (!foundAndReplaced) {
259                                          originalStyle.featureTypeStyles().add(selectionFTStyle);                                          originalStyle.featureTypeStyles().add(selectionFTStyle);
260                                  }                                  }
                                   
                                   
261    
262                                  // Refresh the map                                  // Refresh the map
263  //                              mapPane.refresh();                                  // mapPane.refresh();
264                                    
265                                  DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();                                  DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();
266                                  dsv.visit(originalStyle);                                  dsv.visit(originalStyle);
267                                  Style newStyle = (Style)dsv.getCopy();                                  Style newStyle = (Style) dsv.getCopy();
268                                    
269  //                              Style newStyle = StylingUtil.STYLE_BUILDER.createStyle();                                  // Style newStyle = StylingUtil.STYLE_BUILDER.createStyle();
270  //                              newStyle.featureTypeStyles().addAll(originalStyle.featureTypeStyles());                                  // newStyle.featureTypeStyles().addAll(originalStyle.featureTypeStyles());
271                                  mapLayer.setStyle(newStyle);                                  mapLayer.setStyle(newStyle);
272                                    
273                                  replaceRenderer();                                  replaceRenderer();
274                          }                          }
275    
# Line 278  public class FeatureMapLayerSelectionSyn Line 279  public class FeatureMapLayerSelectionSyn
279          }          }
280    
281          private void replaceRenderer() {          private void replaceRenderer() {
282  //                  //
283  //              // Has to be done before we apply the new Renderer                  // // Has to be done before we apply the new Renderer
284  //              mapLayer.setStyle(style);                  // mapLayer.setStyle(style);
285    
286                  GTRenderer oldRenderer = mapPane.getRenderer();                  GTRenderer oldRenderer = mapPane.getRenderer();
287    
# Line 301  public class FeatureMapLayerSelectionSyn Line 302  public class FeatureMapLayerSelectionSyn
302                  mapPane.setRenderer(newRenderer);                  mapPane.setRenderer(newRenderer);
303    
304                  if (oldRenderer != null) {                  if (oldRenderer != null) {
305                            
306                          RenderingHints java2DHints = oldRenderer.getJava2DHints();                          RenderingHints java2DHints = oldRenderer.getJava2DHints();
307                          if (java2DHints != null) {                          if (java2DHints != null) {
308                                  newRenderer.setJava2DHints(java2DHints);                                  newRenderer.setJava2DHints(java2DHints);
309                          }                          }
310                            
311                          oldRenderer.setContext(null);                          oldRenderer.setContext(null);
312                          oldRenderer = null;                          oldRenderer = null;
313                  }                  }
314                    
315                  mapPane.refresh();                  mapPane.refresh();
316    
317          }          }
# Line 366  public class FeatureMapLayerSelectionSyn Line 367  public class FeatureMapLayerSelectionSyn
367                  // Avoid event circles in propertyChange(..)                  // Avoid event circles in propertyChange(..)
368                  selectionChangeCausedByMe = true;                  selectionChangeCausedByMe = true;
369    
370                  Iterator<SimpleFeature> fi = fse.getSelectionResult().iterator();                  final FeatureCollection<SimpleFeatureType, SimpleFeature> selectionResult = fse
371                                    .getSelectionResult();
372                    Iterator<SimpleFeature> fi = selectionResult.iterator();
373                    try {
374    
375                  // reset the selection of the DpLayerSelectionModel                          // reset the selection of the DpLayerSelectionModel
376                  // layerSelModel.setValueIsAdjusting(true);                          // layerSelModel.setValueIsAdjusting(true);
377    
378                  if (selectedTool == MapPaneToolBar.TOOL_SELECTION_ADD) {                          if (selectedTool == MapPaneToolBar.TOOL_SELECTION_ADD) {
379                          layerSelModel.setValueIsAdjusting(true);                                  layerSelModel.setValueIsAdjusting(true);
380    
381                          for (int fIdx = 0; fi.hasNext(); fIdx++) {                                  for (int fIdx = 0; fi.hasNext(); fIdx++) {
382                                  SimpleFeature f = fi.next();                                          SimpleFeature f = fi.next();
383                                  layerSelModel.addSelection(f.getID());                                          layerSelModel.addSelection(f.getID());
384                          }                                  }
385                          layerSelModel.setValueIsAdjusting(false);                                  layerSelModel.setValueIsAdjusting(false);
386                  } else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_SET) {                          } else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_SET) {
387                          layerSelModel.setValueIsAdjusting(true);                                  layerSelModel.setValueIsAdjusting(true);
388                          layerSelModel.clearSelection();                                  layerSelModel.clearSelection();
389    
390                          for (int fIdx = 0; fi.hasNext(); fIdx++) {                                  for (int fIdx = 0; fi.hasNext(); fIdx++) {
391                                  SimpleFeature f = fi.next();                                          SimpleFeature f = fi.next();
392                                  layerSelModel.addSelection(f.getID());                                          layerSelModel.addSelection(f.getID());
393                          }                                  }
394    
395                          // LOGGER.debug("Setting selection to " + fi.());                                  // LOGGER.debug("Setting selection to " + fi.());
396    
397                          layerSelModel.setValueIsAdjusting(false);                                  layerSelModel.setValueIsAdjusting(false);
398                  } else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_REMOVE) {                          } else if (selectedTool == MapPaneToolBar.TOOL_SELECTION_REMOVE) {
399                          layerSelModel.setValueIsAdjusting(true);                                  layerSelModel.setValueIsAdjusting(true);
400                          for (int fIdx = 0; fi.hasNext(); fIdx++) {                                  for (int fIdx = 0; fi.hasNext(); fIdx++) {
401                                  SimpleFeature f = fi.next();                                          SimpleFeature f = fi.next();
402                                  layerSelModel.removeSelection(f.getID());                                          layerSelModel.removeSelection(f.getID());
403                                    }
404                                    layerSelModel.setValueIsAdjusting(false);
405                          }                          }
406                          layerSelModel.setValueIsAdjusting(false);  
407                    } finally {
408                            selectionResult.close(fi);
409                  }                  }
410    
411                  // Show selected features in the map, which is not automatically done by                  // Show selected features in the map, which is not automatically done by

Legend:
Removed from v.454  
changed lines
  Added in v.455

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26