[Schmitzm-commits] r100 - trunk/src/skrueger/geotools/selection

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri May 8 14:29:46 CEST 2009


Author: alfonx
Date: 2009-05-08 14:29:45 +0200 (Fri, 08 May 2009)
New Revision: 100

Modified:
   trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
   trunk/src/skrueger/geotools/selection/TableSelectionSynchronizer.java
Log:
(Hacking Session in action - atomic commits can't be ensured)
- Remodeling the SelectionModels

Modified: trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-05-08 12:21:42 UTC (rev 99)
+++ trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-05-08 12:29:45 UTC (rev 100)
@@ -22,6 +22,7 @@
 import javax.swing.ListSelectionModel;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
+import javax.swing.text.Utilities;
 
 import org.geotools.feature.Feature;
 import org.geotools.map.MapLayer;
@@ -129,12 +130,16 @@
 		try {
 			if (newSelection.isEmpty()) {
 
-				LOGGER.debug("NO SELECTION");
 				selectionMapStyle = styledMapLayer.getStyle();
+				LOGGER.debug("NO SELECTION .. reset original style");
+				
 			} else {
-				LOGGER.debug("SELECTION EXISTEnT");
+				LOGGER.debug("SELECTION .. change style");
 				selectionMapStyle = StylingUtil
 						.createDefaultStyle(styledMapLayer.getGeoObject());
+				
+				selectionMapStyle = styledMapLayer.getStyle();
+				
 			}
 
 			mapLayer.setStyle(selectionMapStyle);

Modified: trunk/src/skrueger/geotools/selection/TableSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/TableSelectionSynchronizer.java	2009-05-08 12:21:42 UTC (rev 99)
+++ trunk/src/skrueger/geotools/selection/TableSelectionSynchronizer.java	2009-05-08 12:29:45 UTC (rev 100)
@@ -21,37 +21,46 @@
 import javax.swing.ListSelectionModel;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
+import javax.swing.table.TableModel;
 
 import org.geotools.feature.Feature;
 
 import schmitzm.geotools.gui.FeatureCollectionTableModel;
+import schmitzm.swing.table.PipedTableModel;
+import schmitzm.swing.table.SelectionTableModel;
 import skrueger.geotools.selection.StyledFeatureLayerSelectionModel;
 import skrueger.geotools.selection.StyledLayerSelectionEvent;
 import skrueger.geotools.selection.StyledLayerSelectionModel;
 
 /**
  * This class keeps the selection of a (feature) {@link JTable} synchronized
- * with the {@link StyledLayerSelectionModel} of a layer.
- * This is done by implementing:
+ * with the {@link StyledLayerSelectionModel} of a layer. This is done by
+ * implementing:
  * <ul>
- *   <li>a {@link PropertyChangeListener} which listens to the
- *       {@link StyledLayerSelectionModel} and accordingly changes the {@link JTable}
- *       selection</li>
- *   <li>a {@link ListSelectionListener} which listens to the {@link JTable}
- *       and accordingly changes the {@link StyledLayerSelectionModel} selection</li>
+ * <li>a {@link PropertyChangeListener} which listens to the
+ * {@link StyledLayerSelectionModel} and accordingly changes the {@link JTable}
+ * selection</li>
+ * <li>a {@link ListSelectionListener} which listens to the {@link JTable} and
+ * accordingly changes the {@link StyledLayerSelectionModel} selection</li>
  * </ul>
- * After creating, the instance of this synchronizer must be added as listener to
- * both, the {@link StyledLayerSelectionModel} and the table's {@link ListSelectionModel}.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * After creating, the instance of this synchronizer must be added as listener
+ * to both, the {@link StyledLayerSelectionModel} and the table's
+ * {@link ListSelectionModel}.
+ * 
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ *         (University of Bonn/Germany)
  */
-public class TableSelectionSynchronizer extends StyledLayerSelectionModelSynchronizer<Feature> implements ListSelectionListener {
-  /** Holds the table to keep synchronized with the layer selection
-   *  model. */
-  protected JTable featureTable = null;
-  /** Holds the table's data. */
-  protected FeatureCollectionTableModel featureTableModel = null;
-  
-  /**
+public class TableSelectionSynchronizer extends
+		StyledLayerSelectionModelSynchronizer<Feature> implements
+		ListSelectionListener {
+	/**
+	 * Holds the table to keep synchronized with the layer selection model.
+	 */
+	protected JTable featureTable = null;
+	/** Holds the table's data. */
+	protected FeatureCollectionTableModel featureTableModel = null;
+
+	/**
 	 * Creates a new synchronizer
 	 * 
 	 * @param layerSelModel
@@ -62,90 +71,97 @@
 	 */
 	public TableSelectionSynchronizer(
 			StyledFeatureLayerSelectionModel layerSelModel, JTable table) {
-		
+
 		super(layerSelModel);
 
-		if (!(table.getModel() instanceof FeatureCollectionTableModel)) {
+		TableModel model = table.getModel();
+		if (model instanceof PipedTableModel)
+			model = ((PipedTableModel) table.getModel()).getPipedModel();
+
+		if (!(model instanceof FeatureCollectionTableModel))
 			throw new IllegalArgumentException(
 					"Table must have a model instance of FeatureCollectionTableModel");
-		}
 
+		this.featureTableModel = (FeatureCollectionTableModel) model;
 		this.featureTable = table;
-		this.featureTableModel = (FeatureCollectionTableModel) table.getModel();
 	}
-  
-  /**
-   * Called by {@link StyledLayerSelectionModel} when a the selection on other
-   * selection components (map, chart, ...) has changed. When calling
-   * this method changes the table selection according to the
-   * {@link StyledLayerSelectionModel} selection.
-   * @param evt an event
-   */
-  @Override
-  public void propertyChange(PropertyChangeEvent evt) {
-    if ( !(evt instanceof StyledLayerSelectionEvent) )
-      return;
-    StyledLayerSelectionEvent selEvt = (StyledLayerSelectionEvent)evt;
-    // Only react on own layer and ignore events invoked by
-    // this component itself
-    if ( selEvt.getEmitter() != layerSelModel ||
-         selectionChangeCausedByMe )
-      return;
-    // Apply new selection on table (except this event is one of
-    // some more events)
-    Vector<Feature> newSelection = layerSelModel.getSelection();
-    if ( newSelection == null )
-      return;
 
-    // Avoid event circles in valueChanged(..)
-    selectionChangeCausedByMe = true;
+	/**
+	 * Called by {@link StyledLayerSelectionModel} when a the selection on other
+	 * selection components (map, chart, ...) has changed. When calling this
+	 * method changes the table selection according to the
+	 * {@link StyledLayerSelectionModel} selection.
+	 * 
+	 * @param evt
+	 *            an event
+	 */
+	@Override
+	public void propertyChange(PropertyChangeEvent evt) {
+		if (!(evt instanceof StyledLayerSelectionEvent))
+			return;
+		StyledLayerSelectionEvent selEvt = (StyledLayerSelectionEvent) evt;
+		// Only react on own layer and ignore events invoked by
+		// this component itself
+		if (selEvt.getEmitter() != layerSelModel || selectionChangeCausedByMe)
+			return;
+		// Apply new selection on table (except this event is one of
+		// some more events)
+		Vector<Feature> newSelection = layerSelModel.getSelection();
+		if (newSelection == null)
+			return;
 
-    ListSelectionModel tableSelModel = featureTable.getSelectionModel();
-    tableSelModel.setValueIsAdjusting(true);
-    tableSelModel.clearSelection();
-    for (Feature f : newSelection) {
-      int modelIdx = featureTableModel.findFeature(f);
-      if ( modelIdx >= 0 ) {
-        int tableIdx = featureTable.convertRowIndexToView(modelIdx);
-        tableSelModel.addSelectionInterval(tableIdx, tableIdx);
-      }
-    }
-    tableSelModel.setValueIsAdjusting(false); // event is fired autmatically!
+		// Avoid event circles in valueChanged(..)
+		selectionChangeCausedByMe = true;
 
-    // Danger of event circles in valueChanged(..) banned
-    selectionChangeCausedByMe = false;
-  }
-  
-  /**
-   * Called when the table selection is changed by the user.
-   * When calling this method changes the selection of the
-   * {@link StyledLayerSelectionModel}.
-   * @param evt an event
-   */
-  @Override
-  public void valueChanged(ListSelectionEvent evt) {
-    // ignore event if it is part of multiple events
-    if ( evt != null && evt.getValueIsAdjusting() )
-      return;
-    // ignore event if it is caused by the DpLayerVectorSelectionModel
-    if ( selectionChangeCausedByMe )
-      return;
+		ListSelectionModel tableSelModel = featureTable.getSelectionModel();
+		tableSelModel.setValueIsAdjusting(true);
+		tableSelModel.clearSelection();
+		for (Feature f : newSelection) {
+			int modelIdx = featureTableModel.findFeature(f);
+			if (modelIdx >= 0) {
+				int tableIdx = featureTable.convertRowIndexToView(modelIdx);
+				tableSelModel.addSelectionInterval(tableIdx, tableIdx);
+			}
+		}
+		tableSelModel.setValueIsAdjusting(false); // event is fired
+		// autmatically!
 
-    // Avoid event circles in propertyChange(..)
-    selectionChangeCausedByMe = true;
-    
-    // reset the selection of the DpLayerSelectionModel
-    layerSelModel.setValueIsAdjusting(true);
-    for (int i=evt.getFirstIndex(); i<=evt.getLastIndex(); i++) {
-      Feature changedFeature = featureTableModel.getFeature( featureTable.convertRowIndexToModel(i) ); 
-      if ( featureTable.isRowSelected(i) )
-        layerSelModel.addSelection(changedFeature);
-      else
-        layerSelModel.removeSelection(changedFeature);
-    }
-    layerSelModel.setValueIsAdjusting(false);
+		// Danger of event circles in valueChanged(..) banned
+		selectionChangeCausedByMe = false;
+	}
 
-    // Danger of event circles in propertyChange(..) banned
-    selectionChangeCausedByMe = false;
-  }
+	/**
+	 * Called when the table selection is changed by the user. When calling this
+	 * method changes the selection of the {@link StyledLayerSelectionModel}.
+	 * 
+	 * @param evt
+	 *            an event
+	 */
+	@Override
+	public void valueChanged(ListSelectionEvent evt) {
+		// ignore event if it is part of multiple events
+		if (evt != null && evt.getValueIsAdjusting())
+			return;
+		// ignore event if it is caused by the DpLayerVectorSelectionModel
+		if (selectionChangeCausedByMe)
+			return;
+
+		// Avoid event circles in propertyChange(..)
+		selectionChangeCausedByMe = true;
+
+		// reset the selection of the DpLayerSelectionModel
+		layerSelModel.setValueIsAdjusting(true);
+		for (int i = evt.getFirstIndex(); i <= evt.getLastIndex(); i++) {
+			Feature changedFeature = featureTableModel.getFeature(featureTable
+					.convertRowIndexToModel(i));
+			if (featureTable.isRowSelected(i))
+				layerSelModel.addSelection(changedFeature);
+			else
+				layerSelModel.removeSelection(changedFeature);
+		}
+		layerSelModel.setValueIsAdjusting(false);
+
+		// Danger of event circles in propertyChange(..) banned
+		selectionChangeCausedByMe = false;
+	}
 }



More information about the Schmitzm-commits mailing list