[Schmitzm-commits] r76 - in trunk/src: org/geotools/gui/swing schmitzm/geotools/gui

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Apr 21 23:15:28 CEST 2009


Author: alfonx
Date: 2009-04-21 23:15:25 +0200 (Tue, 21 Apr 2009)
New Revision: 76

Modified:
   trunk/src/org/geotools/gui/swing/JMapPane.java
   trunk/src/schmitzm/geotools/gui/FeatureTablePane.java
   trunk/src/schmitzm/geotools/gui/JMapPane.java
   trunk/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java
Log:
* SelectableFeatureTablePane can be constructed with a mapPane parameter. if not null, the toolbar contains a "ZoomToSelected" button.
* Added a zoomTom(FeatureCollection) to JMapPane. This is now used in the FeatureTablePane's preview, in the Atlas search dialog, and in the ZoomToSelected button of SelectableFeatureTablePane


Modified: trunk/src/org/geotools/gui/swing/JMapPane.java
===================================================================
--- trunk/src/org/geotools/gui/swing/JMapPane.java	2009-04-21 18:35:45 UTC (rev 75)
+++ trunk/src/org/geotools/gui/swing/JMapPane.java	2009-04-21 21:15:25 UTC (rev 76)
@@ -58,8 +58,11 @@
 import javax.swing.JPanel;
 
 import org.apache.log4j.Logger;
+import org.geotools.data.memory.MemoryFeatureCollection;
+import org.geotools.feature.Feature;
 import org.geotools.feature.FeatureCollection;
 import org.geotools.filter.IllegalFilterException;
+import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.geotools.gui.swing.event.HighlightChangeListener;
 import org.geotools.gui.swing.event.HighlightChangedEvent;
 import org.geotools.gui.swing.event.SelectionChangeListener;
@@ -88,6 +91,7 @@
 
 import schmitzm.swing.SwingUtil;
 
+import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException;
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;
@@ -1240,49 +1244,60 @@
 
 
 //xulu.sn
-    /**
-     * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste erlaubte Flaeche damit
-     * die Massstabsbeschaenkungen noch eingehalten werden, FALLS der uebergeben Envelope
-     * nicht schon gueltig sein sollte.
-     * 
-     * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
-     */
-  public Envelope bestAllowedMapArea(Envelope env) {
-    if (getWidth() == 0) return env;
-    if (env == null) return env;
+	/**
+	 * Korrigiert den {@link Envelope} aka {@code mapArea} auf die beste
+	 * erlaubte Flaeche damit die Massstabsbeschaenkungen noch eingehalten
+	 * werden, FALLS der uebergeben Envelope nicht schon gueltig sein sollte.<br/>
+	 * Since 21. April 09: Before thecalculation starts, the aspect ratio is
+	 * corrected. This change implies, that setMapArea() will most of the time
+	 * not allow setting to a wrong aspectRatio.
+	 * 
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 */
+	public Envelope bestAllowedMapArea(Envelope env) {
+		if (getWidth() == 0)
+			return env;
+		if (env == null)
+			return env;
 
-    double scale = env.getWidth() / getWidth();
-    double centerX = env.getMinX() + env.getWidth() / 2.;
-    double centerY = env.getMinY() + env.getHeight() / 2.;
-    double newWidth2;
-    double newHeight2;
-    if (scale < getMaxZoomScale()) {
-      //****************************************************************************
-      // Wir zoomen weiter rein als erlaubt => Anpassen des envelope
-      //****************************************************************************
-      newWidth2 = getMaxZoomScale() * getWidth() / 2.;
-      newHeight2 = getMaxZoomScale() * getHeight() / 2.;
-    } else if (scale > getMinZoomScale()) {
-      //****************************************************************************
-      // Wir zoomen weiter raus als erlaubt => Anpassen des envelope
-      //****************************************************************************
-      newWidth2 = getMinZoomScale() * getWidth() / 2.;
-      newHeight2 = getMinZoomScale() * getHeight() / 2.;
-    } else {
-      //****************************************************************************
-      // Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
-      //****************************************************************************
-      return env;
-    }
+		/**
+		 * Correct the aspect Ratio before we check the rest. Otherwise we might easily fail.
+		 */
+		env = fixAspectRatio(this.getBounds(), env);
 
-    Coordinate ll = new Coordinate(centerX - newWidth2, centerY
-                                   - newHeight2);
-    Coordinate ur = new Coordinate(centerX + newWidth2, centerY
-                                   + newHeight2);
+		double scale = env.getWidth() / getWidth();
+		double centerX = env.getMinX() + env.getWidth() / 2.;
+		double centerY = env.getMinY() + env.getHeight() / 2.;
+		double newWidth2;
+		double newHeight2;
+		if (scale < getMaxZoomScale()) {
+			// ****************************************************************************
+			// Wir zoomen weiter rein als erlaubt => Anpassen des envelope
+			// ****************************************************************************
+			newWidth2 = getMaxZoomScale() * getWidth() / 2.;
+			newHeight2 = getMaxZoomScale() * getHeight() / 2.;
+		} else if (scale > getMinZoomScale()) {
+			// ****************************************************************************
+			// Wir zoomen weiter raus als erlaubt => Anpassen des envelope
+			// ****************************************************************************
+			newWidth2 = getMinZoomScale() * getWidth() / 2.;
+			newHeight2 = getMinZoomScale() * getHeight() / 2.;
+		} else {
+			// ****************************************************************************
+			// Die mapArea / der Envelope ist ist gueltig! Keine Aenderungen
+			// ****************************************************************************
+			return env;
+		}
 
-    return new Envelope(ll, ur);
-  }
+		Coordinate ll = new Coordinate(centerX - newWidth2, centerY
+				- newHeight2);
+		Coordinate ur = new Coordinate(centerX + newWidth2, centerY
+				+ newHeight2);
 
+		return new Envelope(ll, ur);
+	}
+
   /**
    * Retuns the minimum allowed zoom scale. This is the bigger number value of the two.
    * Defaults to {@link Double}.MAX_VALUE
@@ -1323,4 +1338,5 @@
   }
 //xulu.en
 
+
 }

Modified: trunk/src/schmitzm/geotools/gui/FeatureTablePane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/FeatureTablePane.java	2009-04-21 18:35:45 UTC (rev 75)
+++ trunk/src/schmitzm/geotools/gui/FeatureTablePane.java	2009-04-21 21:15:25 UTC (rev 76)
@@ -81,8 +81,13 @@
   /** Splitpane, das die Karten-Vorschau von der Tabelle trennt ({@code null}
    *  wenn Karten-Vorschau deaktiviert ist). */
   protected JSplitPane splitPane = null;
+  private JScrollPane featuresTableScrollPane;
 
-  /**
+  public JScrollPane getFeaturesTableScrollPane() {
+	return featuresTableScrollPane;
+}
+
+/**
    * Erzeugt einen neue Komponente mit Preview-Bereich.
    */
   public FeatureTablePane() {
@@ -142,7 +147,7 @@
 
     initGUI( geomPreview );
 
-    JScrollPane featuresTableScrollPane = new JScrollPane(
+    featuresTableScrollPane = new JScrollPane(
       featuresTable,
       JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
       JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
@@ -154,7 +159,7 @@
 //      splitPane.setInnerBorder(null);
       splitPane.setLeftComponent(mapPane);
       splitPane.setRightComponent(featuresTableScrollPane);
-      splitPane.setDividerLocation(0.5); 
+      splitPane.setDividerLocation(0.3); // SK: Does have no effect because JMapPane overrules this 
       splitPane.setOneTouchExpandable(true);
       add(splitPane);
     } else {
@@ -304,22 +309,25 @@
 			return;
 		mapPane.getContext().clearLayerList();
 
-		Envelope bounds = null;
+//		Envelope bounds = null;
 
 		if (fc != null && fc.size() > 0
 				&& fc.getSchema().getDefaultGeometry() != null) {
 			if (getFeatureStyle() == null)
 				setFeatureStyle(FeatureUtil.createDefaultStyle(fc));
 			mapPane.getContext().addLayer(fc, getFeatureStyle());
-			if (featuresTableModel instanceof StyledFeatureCollectionTableModel) {
-				bounds = ((StyledFeatureCollectionTableModel) featuresTableModel)
-						.getBounds();
-			}
-			// featuresTableModel.getFeatureCollection().getBounds();
-			if (bounds == null)
-				bounds = fc.getBounds();
+			
+//			if (featuresTableModel instanceof StyledFeatureCollectionTableModel) {
+//				bounds = ((StyledFeatureCollectionTableModel) featuresTableModel)
+//						.getBounds();
+//			}
+//			// featuresTableModel.getFeatureCollection().getBounds();
+//			if (bounds == null)
+//				bounds = fc.getBounds();
+			
+//			System.out.println(fc.size());
 
-			mapPane.setMapArea(bounds); // zoom to the full bound if available,
+			mapPane.zoomTo(fc); // zoom to the full bound if available,
 			// otherwise just to the bounds of the
 			// selected.
 

Modified: trunk/src/schmitzm/geotools/gui/JMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/JMapPane.java	2009-04-21 18:35:45 UTC (rev 75)
+++ trunk/src/schmitzm/geotools/gui/JMapPane.java	2009-04-21 21:15:25 UTC (rev 76)
@@ -59,6 +59,7 @@
 import org.geotools.map.MapContext;
 import org.geotools.map.MapLayer;
 import org.geotools.parameter.Parameter;
+import org.geotools.referencing.CRS;
 import org.geotools.referencing.crs.DefaultGeographicCRS;
 import org.geotools.renderer.GTRenderer;
 import org.geotools.renderer.lite.RendererUtilities;
@@ -70,7 +71,10 @@
 import org.opengis.filter.FilterFactory2;
 import org.opengis.filter.expression.Expression;
 import org.opengis.parameter.GeneralParameterValue;
+import org.opengis.referencing.FactoryException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.TransformException;
 
 import schmitzm.geotools.FilterUtil;
 import schmitzm.geotools.GTUtil;
@@ -86,6 +90,7 @@
 import schmitzm.geotools.map.event.ScaleChangedEvent;
 import schmitzm.geotools.styling.StylingUtil;
 import schmitzm.swing.SwingUtil;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
 
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
@@ -1071,13 +1076,11 @@
 	@Override
 	public void setMapArea(Envelope env) {
 		//**********************************************************************
-		// ******
 		// Ueber die Funktionen setMaxZoomScale und setMinZoomScale kann der
 		// geotools JMapPane ein gueltiger Massstabsbereich gesetzt werden.
 		// Dieser
 		// wird hier ueberprueft. (SK)
 		//**********************************************************************
-		// ******
 		if (super.getMapArea() != null) {
 			env = bestAllowedMapArea(env);
 		}
@@ -2247,5 +2250,101 @@
 			setBackground(orig);
 		}
 	}
+	
+	
+	  /**
+	   * Sets the mapArea to smartly present the given features. Note: The method does not call {@link #repaint()} on the {@link JMapPane}.
+	   */
+	  public void zoomTo(org.geotools.feature.Feature feature){
+			final MemoryFeatureCollection mfc = new MemoryFeatureCollection(feature.getFeatureType());
+			mfc.add(feature);
+			zoomTo(mfc);
+	  }
 
+	  /**
+		 * Sets the mapArea to best possibly present the given features. If only one single point is given, the window is moved over the point.
+		 * 
+		 * Note: The method does not call {@link #repaint()} on the {@link JMapPane}
+		 * .
+		 * 
+		 * @param features
+		 *            if <code>null</code> or size==0, the function doesn nothing.
+		 */
+		public void zoomTo(FeatureCollection features) {
+			
+			CoordinateReferenceSystem mapCRS = getContext().getCoordinateReferenceSystem();
+			CoordinateReferenceSystem fCRS = features.getSchema().getDefaultGeometry().getCoordinateSystem();
+//			if (! mapCRS.equals(fCRS)) {
+//				throw new RuntimeException("Projecting the features to show to the map CRS is not yet implemented.");
+//			}
+
+			double width = mapArea.getWidth();
+			double height = mapArea.getHeight();
+			double ratio = height / width;
+
+			if (features == null || features.size() == 0) {
+				// feature count == 0 Zoom to the full extend
+				return;
+			} else if (features.size() == 1) {
+				
+				// feature count == 1 Just move the window to the point and zoom 'a
+				// bit'
+				Feature singleFeature = (Feature) features.iterator().next();
+
+				if (singleFeature.getDefaultGeometry().getCoordinates().length > 1) {
+//					System.out.println("Zoomed to only pne poylgon");
+					// Poly
+					//TODO max width vs. height
+					width = features.getBounds().getWidth() * 3;
+					height = ratio * width;
+				} else {
+//					System.out.println("Zoomed in a bit becasue only one point");
+//					width *= .9;
+//					height *= .9;
+				}
+
+				Coordinate centre = features.getBounds().centre();
+				if (! mapCRS.equals(fCRS)) {
+					// only to calculations if the CRS differ
+					try {
+						MathTransform fToMap;
+						fToMap = CRS.findMathTransform(fCRS,mapCRS);
+						// centre is transformed to the mapCRS
+						centre = JTS.transform(centre, null, fToMap);;
+					} catch (FactoryException e) {
+						LOGGER.error(e);
+					} catch (TransformException e) {
+						LOGGER.error(e);
+					}
+				}
+
+				Coordinate newLeftBottom = new Coordinate(
+						centre.x - width / 2., centre.y - height / 2.);
+				Coordinate newTopRight = new Coordinate(centre.x + width / 2.,
+						centre.y + height / 2.);
+
+				Envelope newMapArea = new Envelope(newLeftBottom, newTopRight);
+
+				setMapArea(newMapArea);
+
+			} else {
+				ReferencedEnvelope fBounds = features.getBounds();
+				
+				Envelope bounds;
+				if (! mapCRS.equals(fCRS)) {
+					bounds = JTSUtil.transformEnvelope(fBounds, fCRS, mapCRS);
+				} else {
+					bounds = fBounds;
+				}
+				// BB umrechnen von Layer-CRS in Map-CRS
+
+				// Expand a bit
+				bounds.expandBy(bounds.getWidth() / 6., bounds
+						.getHeight() / 6.);
+				
+				setMapArea(bounds);
+			}
+		}
+
+
 }

Modified: trunk/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java	2009-04-21 18:35:45 UTC (rev 75)
+++ trunk/src/schmitzm/geotools/gui/SelectableFeatureTablePane.java	2009-04-21 21:15:25 UTC (rev 76)
@@ -12,8 +12,11 @@
 
 import java.awt.BorderLayout;
 import java.awt.Component;
+import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Locale;
 
 import javax.swing.AbstractAction;
@@ -21,126 +24,220 @@
 import javax.swing.ImageIcon;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JScrollBar;
+import javax.swing.JScrollPane;
 import javax.swing.JToolBar;
+import javax.swing.JViewport;
+import javax.swing.SortOrder;
+import javax.swing.RowSorter.SortKey;
 
 import org.geotools.feature.FeatureCollection;
 
-import schmitzm.lang.LangUtil;
-import schmitzm.lang.ResourceProvider;
+import com.vividsolutions.jts.geom.Envelope;
 
-
 /**
  * Extends the {@link FeatureTablePane} with buttons and functionality to select
- * lines
+ * lines. Can be configured to set the regions on an external a {@link JMapPane}
+ * . Can be configured to show a simple preview {@link JMapPane} to the left of
+ * the table.
  * 
  * @author Stefan A. Krüger
  * 
  */
 public class SelectableFeatureTablePane extends FeatureTablePane {
 
-
 	public static final ImageIcon ICON_SELECTION_INVERT = new ImageIcon(
 			SelectableFeatureTablePane.class
 					.getResource("resource/icons/mActionInvertSelection.png"));
 	public static final ImageIcon ICON_SELECTED_TO_TOP = new ImageIcon(
 			SelectableFeatureTablePane.class
-					.getResource("resource/icons/mActionSelectedToTop.png") );
+					.getResource("resource/icons/mActionSelectedToTop.png"));
 	public static final ImageIcon ICON_UNSELECT = new ImageIcon(
 			SelectableFeatureTablePane.class
 					.getResource("resource/icons/mActionUnselectAttributes.png"));
 	public static final ImageIcon ICON_ZOMM_TO_SELECTED = new ImageIcon(
 			SelectableFeatureTablePane.class
 					.getResource("resource/icons/mActionZoomToSelected.png"));
+	private final JMapPane externalMapPane;
 
+	/**
+	 * @param model
+	 *            {@link FeatureCollectionTableModel} that holds the data.
+	 * @param geomPreview
+	 *            If <code>true</code>, a preview {@link JMapPane} is attached
+	 *            to the left of the table.
+	 * @param externalMapPane
+	 *            <code>null</code> if this component is NOT linked to an
+	 *            external JMapPane. If mapPane == <code>null</code>, the
+	 *            "ZoomToSelection" Button is automatically disabled. If a
+	 *            {@link JMapPane} is passed, the "ZoomToSelectedFeature"
+	 *            function will be enabled.
+	 */
 	public SelectableFeatureTablePane(FeatureCollectionTableModel model,
-			boolean geomPreview) {
+			boolean geomPreview, JMapPane externalMapPane) {
 		super(model, null, geomPreview);
-		
-		JPanel newPanelArroundTable = new JPanel(  new BorderLayout() );
-		
-		
+
+		this.externalMapPane = externalMapPane;
+
+		JPanel newPanelArroundTable = new JPanel(new BorderLayout());
+
 		if (splitPane != null) {
-			newPanelArroundTable.add(splitPane.getRightComponent(), BorderLayout.CENTER);
+			newPanelArroundTable.add(splitPane.getRightComponent(),
+					BorderLayout.CENTER);
 			splitPane.setRightComponent(newPanelArroundTable);
-			splitPane.setDividerLocation(0.33);
+			splitPane.setDividerLocation(0.33); // SK: Does have no effect
+												// because JMapPane overrules
+												// this
 		} else {
 			newPanelArroundTable.add(getComponent(0), BorderLayout.CENTER);
 			removeAll();
 			add(newPanelArroundTable);
 		}
-		
+
+		// Change the sizes
+		mapPane.setPreferredSize(new Dimension(200, 300));
+		featuresTable.getParent().setPreferredSize(new Dimension(400, 300));
+
 		newPanelArroundTable.add(getToolBar(), BorderLayout.NORTH);
 		newPanelArroundTable.add(getSearchBar(), BorderLayout.SOUTH);
 	}
-	
 
 	private Component getSearchBar() {
 		return new JLabel(""); // TODO Add ability to search here!
 	}
 
-	
 	/**
-	 * Creates
+	 * Creates a {@link JToolBar} with actions to perform on the map.
 	 */
 	protected JToolBar getToolBar() {
 		JToolBar toolBar = new JToolBar();
-		
+
 		/**
 		 * Add an Action to clear the selection
 		 */
-		AbstractAction clearSelectionAction = new AbstractAction("", ICON_UNSELECT){
+		AbstractAction clearSelectionAction = new AbstractAction("",
+				ICON_UNSELECT) {
 
 			@Override
 			public void actionPerformed(ActionEvent e) {
+				getTable().getSelectionModel().clearSelection();
 			}
-			
+
 		};
-		clearSelectionAction.putValue(Action.SHORT_DESCRIPTION, GeotoolsGUIUtil.R("schmitzm.geotools.gui.SelectableFeatureTablePane.button.clearSelection.tt")); 
+		clearSelectionAction
+				.putValue(
+						Action.SHORT_DESCRIPTION,
+						GeotoolsGUIUtil
+								.R("schmitzm.geotools.gui.SelectableFeatureTablePane.button.clearSelection.tt"));
 		toolBar.add(clearSelectionAction);
-		
 
 		/**
-		 * Add an Action to move the selected items
+		 * Add an Action to move the selected items to the top
 		 */
-		AbstractAction selectionToTopAction = new AbstractAction("", ICON_SELECTED_TO_TOP){
-			
+		AbstractAction selectionToTopAction = new AbstractAction("",
+				ICON_SELECTED_TO_TOP) {
+
+			// A bug? Sorting only works from the second time on..
+			boolean isFirstClick = true;
+
 			@Override
 			public void actionPerformed(ActionEvent e) {
+
+				// moves the select rows to the top by sorting according to the
+				// first column
+
+				List<SortKey> keys = new ArrayList<SortKey>(getTable()
+						.getRowSorter().getSortKeys());
+
+				SortKey sortKey = new SortKey(0, SortOrder.DESCENDING);
+				keys.add(0, sortKey);
+
+				getTable().getRowSorter().setSortKeys(keys);
+				
+				// Move the scrollbars to the top
+				JScrollPane scrollPane = getFeaturesTableScrollPane();
+				JScrollBar verticalScrollBar = scrollPane
+						.getVerticalScrollBar();
+				JScrollBar horizontalScrollBar = scrollPane
+						.getHorizontalScrollBar();
+				verticalScrollBar.setValue(verticalScrollBar.getMinimum());
+				horizontalScrollBar.setValue(horizontalScrollBar.getMinimum());
+
+
+				// A bug? Sorting only works from the second time on..
+				if (isFirstClick) {
+					isFirstClick = false;
+					actionPerformed(e);
+				}
 			}
-			
+
 		};
-		selectionToTopAction.putValue(Action.SHORT_DESCRIPTION, GeotoolsGUIUtil.R("schmitzm.geotools.gui.SelectableFeatureTablePane.button.selectionToTop.tt")); 
+		selectionToTopAction
+				.putValue(
+						Action.SHORT_DESCRIPTION,
+						GeotoolsGUIUtil
+								.R("schmitzm.geotools.gui.SelectableFeatureTablePane.button.selectionToTop.tt"));
 		toolBar.add(selectionToTopAction);
-		
+
 		/**
 		 * Add an Action to move the selected items
 		 */
-		AbstractAction selectionInverseAction = new AbstractAction("", ICON_SELECTION_INVERT){
-			
+		AbstractAction selectionInverseAction = new AbstractAction("",
+				ICON_SELECTION_INVERT) {
+
 			@Override
 			public void actionPerformed(ActionEvent e) {
+
+				getTable().getSelectionModel().setValueIsAdjusting(true);
+				for (int i = 0; i < getTable().getModel().getRowCount(); i++) {
+					if (getTable().getSelectionModel().isSelectedIndex(i)) {
+						getTable().getSelectionModel().removeSelectionInterval(
+								i, i);
+					} else {
+						getTable().getSelectionModel().addSelectionInterval(i,
+								i);
+					}
+				}
+				getTable().getSelectionModel().setValueIsAdjusting(false);
+
 			}
-			
+
 		};
-		selectionInverseAction.putValue(Action.SHORT_DESCRIPTION, GeotoolsGUIUtil.R("schmitzm.geotools.gui.SelectableFeatureTablePane.button.invertSelection.tt"));
+		selectionInverseAction
+				.putValue(
+						Action.SHORT_DESCRIPTION,
+						GeotoolsGUIUtil
+								.R("schmitzm.geotools.gui.SelectableFeatureTablePane.button.invertSelection.tt"));
 		toolBar.add(selectionInverseAction);
-		
-		
+
 		/**
 		 * Add an Action to move the selected items
 		 */
-		AbstractAction zoomToselectionAction = new AbstractAction("", ICON_ZOMM_TO_SELECTED){
-			
-			@Override
-			public void actionPerformed(ActionEvent e) {
-			}
-			
-		};
-		zoomToselectionAction.putValue(Action.SHORT_DESCRIPTION, GeotoolsGUIUtil.R("schmitzm.geotools.gui.SelectableFeatureTablePane.button.zoomToSelection.tt")); 
-		toolBar.add(zoomToselectionAction);
-		
+		if (externalMapPane != null) {
+
+			AbstractAction zoomToSelection = new AbstractAction("",
+					ICON_ZOMM_TO_SELECTED) {
+
+				@Override
+				public void actionPerformed(ActionEvent e) {
+					FeatureCollection selectedFeatures = getSelectedFeatures();
+					if (selectedFeatures.size() == 0)
+						selectedFeatures = getFeatureCollection();
+					externalMapPane.zoomTo(selectedFeatures);
+					externalMapPane.refresh();
+
+				}
+
+			};
+			zoomToSelection
+					.putValue(
+							Action.SHORT_DESCRIPTION,
+							GeotoolsGUIUtil
+									.R("schmitzm.geotools.gui.SelectableFeatureTablePane.button.zoomToSelection.tt"));
+			toolBar.add(zoomToSelection);
+		}
+
 		return toolBar;
 	}
- 
 
 }



More information about the Schmitzm-commits mailing list