[Schmitzm-commits] r97 - trunk/src/skrueger/geotools/selection
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri May 8 14:10:43 CEST 2009
Author: alfonx
Date: 2009-05-08 14:10:42 +0200 (Fri, 08 May 2009)
New Revision: 97
Added:
trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
Modified:
trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java
trunk/src/skrueger/geotools/selection/StyledLayerSelectionModelSynchronizer.java
trunk/src/skrueger/geotools/selection/TableSelectionSynchronizer.java
Log:
(Hacking Session in action - atomic commits can't be ensured)
- Remodeling the SelectionModels
Added: trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java 2009-05-08 11:23:16 UTC (rev 96)
+++ trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java 2009-05-08 12:10:42 UTC (rev 97)
@@ -0,0 +1,198 @@
+/**
+ Copyright 2008 Stefan Alfons Krüger
+
+ atlas-framework - This file is part of the Atlas Framework
+
+ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
+ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+ Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+ Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+ Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+package skrueger.geotools.selection;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Collection;
+import java.util.Vector;
+
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+import org.geotools.feature.Feature;
+import org.geotools.map.MapLayer;
+import org.geotools.styling.Style;
+
+import schmitzm.geotools.gui.FeatureCollectionTableModel;
+import schmitzm.geotools.gui.JMapPane;
+import schmitzm.geotools.map.event.FeatureSelectedEvent;
+import schmitzm.geotools.map.event.JMapPaneEvent;
+import schmitzm.geotools.map.event.JMapPaneListener;
+import schmitzm.geotools.styling.StylingUtil;
+import skrueger.geotools.StyledFeatureCollectionInterface;
+import skrueger.geotools.StyledMapInterface;
+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:
+ * <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>
+ * </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)
+ */
+public class FeatureMapLayerSelectionSynchronizer extends
+ StyledLayerSelectionModelSynchronizer<Feature> implements
+ JMapPaneListener {
+ /**
+ * Holds the {@link MapLayer} to keep synchronized with the layer selection
+ * model.
+ */
+ protected final MapLayer mapLayer;
+ protected final StyledMapInterface<?> styledMapLayer;
+ protected final JMapPane mapPane;
+
+ /**
+ * Creates a new synchronizer
+ *
+ * @param layerSelModel
+ * layer selection model to keep synchronized with the
+ * {@link MapLayer}
+ *
+ * @param mapLayer
+ * {@link MapLayer} to keep synchronized with.
+ */
+ public FeatureMapLayerSelectionSynchronizer(
+ StyledFeatureLayerSelectionModel layerSelModel,
+ StyledMapInterface<?> styledMapLayer, MapLayer mapLayer,
+ JMapPane mapPane) {
+
+ super(layerSelModel);
+ this.styledMapLayer = styledMapLayer;
+
+ this.mapLayer = mapLayer;
+ this.mapPane = mapPane;
+ }
+
+ /**
+ * Called by {@link StyledLayerSelectionModel} when a the selection on other
+ * selection components (map, chart, ...) has changed. When calling this
+ *
+ * method changes the {@link MapLayer} 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;
+
+ changeLayerStyle(newSelection);
+
+ // Danger of event circles in valueChanged(..) banned
+ selectionChangeCausedByMe = false;
+ }
+
+ private void changeLayerStyle(Vector<Feature> newSelection) {
+ Style selectionMapStyle = null;
+ try {
+ if (newSelection.isEmpty()) {
+
+ LOGGER.debug("NO SELECTION");
+ selectionMapStyle = styledMapLayer.getStyle();
+ } else {
+ LOGGER.debug("SELECTION EXISTEnT");
+ selectionMapStyle = StylingUtil
+ .createDefaultStyle(styledMapLayer.getGeoObject());
+ }
+
+ mapLayer.setStyle(selectionMapStyle);
+ mapPane.refresh();
+ } catch (Exception e) {
+ LOGGER.error("Error while trying to create a selection style", e);
+ }
+ }
+
+ //
+ // /**
+ // * 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) {
+ //
+ // }
+
+ @Override
+ public void performMapPaneEvent(JMapPaneEvent e) {
+ if (!(e instanceof FeatureSelectedEvent))
+ return;
+
+ FeatureSelectedEvent fse = (FeatureSelectedEvent) e;
+
+ // 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);
+
+ layerSelModel.addSelection((Collection<Feature>) fse
+ .getSelectionResult());
+
+ // 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);
+
+ // Show selected feature in the map, which is not automatically done by
+ // the FeatureSelectedEvent
+ changeLayerStyle(layerSelModel.getSelection());
+
+ // Danger of event circles in propertyChange(..) banned
+ selectionChangeCausedByMe = false;
+ }
+}
Property changes on: trunk/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java
===================================================================
--- trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java 2009-05-08 11:23:16 UTC (rev 96)
+++ trunk/src/skrueger/geotools/selection/StyledLayerSelectionModel.java 2009-05-08 12:10:42 UTC (rev 97)
@@ -33,7 +33,7 @@
*/
public abstract class StyledLayerSelectionModel<E> extends PropertyChangeEmitter {
/** A static logger for this class */
- private static final Logger LOGGER = Logger.getLogger(StyledLayerSelectionModel.class);
+ protected final Logger LOGGER = Logger.getLogger(this.getClass());
/** Holds the current selection as {@link Feature}-list. This
* is the basis to create the other selection objects. */
Modified: trunk/src/skrueger/geotools/selection/StyledLayerSelectionModelSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/StyledLayerSelectionModelSynchronizer.java 2009-05-08 11:23:16 UTC (rev 96)
+++ trunk/src/skrueger/geotools/selection/StyledLayerSelectionModelSynchronizer.java 2009-05-08 12:10:42 UTC (rev 97)
@@ -4,9 +4,12 @@
import javax.swing.ListSelectionModel;
+import org.apache.log4j.Logger;
+
import skrueger.geotools.selection.StyledLayerSelectionModel;
public abstract class StyledLayerSelectionModelSynchronizer<E> implements PropertyChangeListener{
+ protected final Logger LOGGER = Logger.getLogger(this.getClass());
/** Flag to avoid event circles between {@link DpLayerVectorSelectionModel}
* and {@link ListSelectionModel} of the feature table. */
Modified: trunk/src/skrueger/geotools/selection/TableSelectionSynchronizer.java
===================================================================
--- trunk/src/skrueger/geotools/selection/TableSelectionSynchronizer.java 2009-05-08 11:23:16 UTC (rev 96)
+++ trunk/src/skrueger/geotools/selection/TableSelectionSynchronizer.java 2009-05-08 12:10:42 UTC (rev 97)
@@ -59,8 +59,6 @@
* table
* @param table
* table to keep synchronized with the layer selection model
- * @param tableModel
- * feature table's data
*/
public TableSelectionSynchronizer(
StyledFeatureLayerSelectionModel layerSelModel, JTable table) {
More information about the Schmitzm-commits
mailing list