[Schmitzm-commits] r725 - in trunk/src: schmitzm/geotools/gui schmitzm/geotools/map/event skrueger/geotools skrueger/geotools/labelsearch

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Feb 25 19:40:46 CET 2010


Author: alfonx
Date: 2010-02-25 19:40:44 +0100 (Thu, 25 Feb 2010)
New Revision: 725

Added:
   trunk/src/schmitzm/geotools/map/event/MapRenderingStateEvent.java
Modified:
   trunk/src/schmitzm/geotools/gui/SelectableXMapPane.java
   trunk/src/schmitzm/geotools/map/event/MapPaneEvent.java
   trunk/src/skrueger/geotools/XMapPane.java
   trunk/src/skrueger/geotools/labelsearch/SearchResultFeature.java
Log:
AtlasFeature: Selecting Feature Search Results now blinks the feature

Modified: trunk/src/schmitzm/geotools/gui/SelectableXMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/SelectableXMapPane.java	2010-02-25 17:31:17 UTC (rev 724)
+++ trunk/src/schmitzm/geotools/gui/SelectableXMapPane.java	2010-02-25 18:40:44 UTC (rev 725)
@@ -131,7 +131,6 @@
  */
 public class SelectableXMapPane extends XMapPane {
 	
-
 	/**
 	 * "SimpleFeature-Auswahl auf allen (sichtbaren) Layern".
 	 */
@@ -341,12 +340,14 @@
 	/**
 	 * Sets the mapArea to smartly present the given features. Note: The method
 	 * does not call {@link #repaint()} on the {@link SelectableXMapPane}.
+	 * 
+	 * @return <code>true</code> if the {@link #mapArea} has changed and rendering has been triggered.
 	 */
-	public void zoomTo(SimpleFeature feature) {
+	public boolean zoomTo(SimpleFeature feature) {
 		final MemoryFeatureCollection mfc = new MemoryFeatureCollection(feature
 				.getFeatureType());
 		mfc.add(feature);
-		zoomTo(mfc);
+		return zoomTo(mfc);
 	}
 
 	/**
@@ -570,16 +571,6 @@
 		return result;
 	}
 
-	/**
-	 * Propagiert ein Ereignis an alle angeschlossenen Listener.
-	 * 
-	 * @param e
-	 *            Ereignis
-	 */
-	public void fireMapPaneEvent(MapPaneEvent e) {
-		for (JMapPaneListener l : mapPaneListeners)
-			l.performMapPaneEvent(e);
-	}
 
 	/**
 	 * Verarbeitet die Selektion eines Karten-Ausschnitts. Erzeugt immer ein

Modified: trunk/src/schmitzm/geotools/map/event/MapPaneEvent.java
===================================================================
--- trunk/src/schmitzm/geotools/map/event/MapPaneEvent.java	2010-02-25 17:31:17 UTC (rev 724)
+++ trunk/src/schmitzm/geotools/map/event/MapPaneEvent.java	2010-02-25 18:40:44 UTC (rev 725)
@@ -40,7 +40,7 @@
  */
 public abstract class MapPaneEvent {
   /** Beinhaltet das {@link XMapPane}, das das Ereignis ausgeloest hat */
-  protected SelectableXMapPane source = null;
+  protected XMapPane source = null;
   /** Beinhaltet ein Objekt, das das Ereignis initiiert hat */
   protected Object sourceObject = null;
 
@@ -50,23 +50,23 @@
    * @param sourceObject Objeckt, das das Ereignis initiiert hat (wenn {@code null},
    *        wird das MapPane als Ausloeser gesetzt)
    */
-  public MapPaneEvent(SelectableXMapPane source, Object sourceObject) {
+  public MapPaneEvent(XMapPane source, Object sourceObject) {
     this.source       = source;
     this.sourceObject = (sourceObject != null) ? sourceObject : source;
   }
 
   /**
    * Erzeugt ein neues Ereignis.
-   * @param source {@link XMapPane}, das das Ereignis ausgeloest hat
+   * @param source2 {@link XMapPane}, das das Ereignis ausgeloest hat
    */
-  public MapPaneEvent(SelectableXMapPane source) {
-    this(source,null);
+  public MapPaneEvent(XMapPane source2) {
+    this(source2,null);
   }
 
   /**
-   * Liefert das {@link SelectableXMapPane}, das das Ereignis ausgeloest hat.
+   * Liefert das {@link XMapPane}, das das Ereignis ausgeloest hat.
    */
-  public SelectableXMapPane getSource() {
+  public XMapPane getSource() {
     return source;
   }
 

Added: trunk/src/schmitzm/geotools/map/event/MapRenderingStateEvent.java
===================================================================
--- trunk/src/schmitzm/geotools/map/event/MapRenderingStateEvent.java	2010-02-25 17:31:17 UTC (rev 724)
+++ trunk/src/schmitzm/geotools/map/event/MapRenderingStateEvent.java	2010-02-25 18:40:44 UTC (rev 725)
@@ -0,0 +1,27 @@
+package schmitzm.geotools.map.event;
+
+import org.opengis.display.canvas.RenderingState;
+
+import skrueger.geotools.XMapPane;
+
+/**
+ * Events of this Class are fired, when rendering starts and stops. Cancels and
+ * Errors are fired as Stops.
+ * 
+ * @author stefan
+ * 
+ */
+public class MapRenderingStateEvent extends MapPaneEvent {
+
+	private final RenderingState state;
+
+	public MapRenderingStateEvent(XMapPane source, RenderingState state) {
+		super(source);
+		this.state = state;
+	}
+
+	public RenderingState getState() {
+		return state;
+	}
+
+}


Property changes on: trunk/src/schmitzm/geotools/map/event/MapRenderingStateEvent.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Modified: trunk/src/skrueger/geotools/XMapPane.java
===================================================================
--- trunk/src/skrueger/geotools/XMapPane.java	2010-02-25 17:31:17 UTC (rev 724)
+++ trunk/src/skrueger/geotools/XMapPane.java	2010-02-25 18:40:44 UTC (rev 725)
@@ -30,6 +30,7 @@
 import javax.swing.border.Border;
 
 import org.apache.log4j.Logger;
+import org.geotools.data.memory.MemoryFeatureCollection;
 import org.geotools.factory.GeoTools;
 import org.geotools.feature.FeatureCollection;
 import org.geotools.geometry.DirectPosition2D;
@@ -53,8 +54,8 @@
 import org.geotools.styling.Style;
 import org.geotools.swing.JMapPane;
 import org.geotools.swing.event.MapMouseEvent;
-import org.geotools.swing.event.MapPaneEvent;
 import org.geotools.swing.event.MapPaneListener;
+import org.opengis.display.canvas.RenderingState;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.referencing.FactoryException;
@@ -68,6 +69,8 @@
 import schmitzm.geotools.io.GeoImportUtil;
 import schmitzm.geotools.map.event.JMapPaneListener;
 import schmitzm.geotools.map.event.MapLayerAdapter;
+import schmitzm.geotools.map.event.MapPaneEvent;
+import schmitzm.geotools.map.event.MapRenderingStateEvent;
 import schmitzm.geotools.styling.StylingUtil;
 import schmitzm.lang.LangUtil;
 import schmitzm.swing.JPanel;
@@ -126,7 +129,8 @@
 	}
 
 	/**
-	 * If the {@link JPanel} is disabled, it shows nothing and the images are disposed. 
+	 * If the {@link JPanel} is disabled, it shows nothing and the images are
+	 * disposed.
 	 */
 	@Override
 	public void setEnabled(boolean enabled) {
@@ -760,6 +764,18 @@
 	}
 
 	/**
+	 * Propagiert ein Ereignis an alle angeschlossenen Listener. Es gibt
+	 * verschiedene implementationen von {@link MapPaneEvent}
+	 * 
+	 * @param e
+	 *            Ereignis
+	 */
+	public void fireMapPaneEvent(MapPaneEvent e) {
+		for (JMapPaneListener l : mapPaneListeners)
+			l.performMapPaneEvent(e);
+	}
+
+	/**
 	 * Fuegt der Map einen Listener hinzu.
 	 * 
 	 * @param l
@@ -1481,6 +1497,12 @@
 	public void onRenderingCancelled() {
 		// LOGGER.debug("Rendering cancelled");
 		repaintTimer.stop();
+
+		// Inform listeners that rendering has completed if have no requests to
+		// start again
+		if (!requestStartRendering)
+			fireMapPaneEvent(new MapRenderingStateEvent(this,
+					RenderingState.ON_HOLD));
 	}
 
 	/**
@@ -1505,6 +1527,12 @@
 
 		updateFinalImage();
 		repaint();
+
+		// Inform listeners that rendering has completed if have no requests to
+		// start again
+		if (!requestStartRendering)
+			fireMapPaneEvent(new MapRenderingStateEvent(this,
+					RenderingState.ON_HOLD));
 	}
 
 	/**
@@ -1533,6 +1561,11 @@
 		updateFinalImage();
 		repaint();
 
+		// Inform listeners that rendering has completed if have no requests to
+		// start again
+		if (!requestStartRendering)
+			fireMapPaneEvent(new MapRenderingStateEvent(this,
+					RenderingState.ON_HOLD));
 	}
 
 	@Override
@@ -2073,6 +2106,12 @@
 		}
 
 		localExecuter.cancelTask();
+		
+		// Inform listeners that rendering has completed if have no requests to
+		// start again
+		if (!requestStartRendering)
+			fireMapPaneEvent(new MapRenderingStateEvent(this,
+					RenderingState.RENDERING));
 
 		final Rectangle curPaintArea = getVisibleRect();
 
@@ -2365,8 +2404,10 @@
 	 * 
 	 * @param features
 	 *            if <code>null</code> or size==0, the function doesn nothing.
+	 *            
+	 * @return <code>true</code> if the {@link #mapArea} has changed and rendering has been triggered.            
 	 */
-	public void zoomTo(
+	public boolean zoomTo(
 			final FeatureCollection<SimpleFeatureType, SimpleFeature> features) {
 
 		// if (!isWellDefined()) return;
@@ -2387,7 +2428,7 @@
 
 		if (features == null || features.size() == 0) {
 			// feature count == 0 Zoom to the full extend
-			return;
+			return false;
 		} else if (features.size() == 1) {
 
 			// feature count == 1 Just move the window to the point and zoom 'a
@@ -2429,7 +2470,7 @@
 
 			final Envelope newMapArea = new Envelope(newLeftBottom, newTopRight);
 
-			setMapArea(newMapArea);
+			return setMapArea(newMapArea);
 
 		} else {
 			final ReferencedEnvelope fBounds = features.getBounds();
@@ -2445,7 +2486,7 @@
 			// Expand a bit
 			addDefaultMargin(bounds);
 
-			setMapArea(bounds);
+			return setMapArea(bounds);
 		}
 	}
 
@@ -2735,6 +2776,16 @@
 	}
 
 	/**
+	 * Makes the given {@link SimpleFeature} bink in the map for a moment
+	 */
+	public void blink(SimpleFeature feature) {
+		MemoryFeatureCollection memoryFeatureCollection = new MemoryFeatureCollection(
+				feature.getFeatureType());
+		memoryFeatureCollection.add(feature);
+		blink(memoryFeatureCollection);
+	}
+
+	/**
 	 * Makes the given {@link FeatureCollection} bink in the map for a moment
 	 */
 	public void blink(

Modified: trunk/src/skrueger/geotools/labelsearch/SearchResultFeature.java
===================================================================
--- trunk/src/skrueger/geotools/labelsearch/SearchResultFeature.java	2010-02-25 17:31:17 UTC (rev 724)
+++ trunk/src/skrueger/geotools/labelsearch/SearchResultFeature.java	2010-02-25 18:40:44 UTC (rev 725)
@@ -33,8 +33,13 @@
 
 import org.apache.log4j.Logger;
 import org.geotools.map.MapLayer;
+import org.opengis.display.canvas.RenderingState;
 import org.opengis.feature.simple.SimpleFeature;
 
+import schmitzm.geotools.map.event.JMapPaneListener;
+import schmitzm.geotools.map.event.MapPaneEvent;
+import schmitzm.geotools.map.event.MapRenderingStateEvent;
+
 public class SearchResultFeature implements SearchResult {
 	final static private Logger LOGGER = Logger
 			.getLogger(SearchResultFeature.class);
@@ -46,8 +51,9 @@
 
 	private final MapLayer mapLayer;
 
-	public SearchResultFeature(SimpleFeature feature, String title, String inTitle,
-			schmitzm.geotools.gui.SelectableXMapPane mapPane, MapLayer mapLayer) {
+	public SearchResultFeature(SimpleFeature feature, String title,
+			String inTitle, schmitzm.geotools.gui.SelectableXMapPane mapPane,
+			MapLayer mapLayer) {
 		this.feature = feature;
 		this.title = title;
 		this.inTitle = inTitle;
@@ -78,14 +84,31 @@
 			throw new RuntimeException("Not on EDT!");
 		}
 
-		mapPane.zoomTo(feature);
-		mapPane.refresh();
+		// ZOmming will take some time, until the new map is correctly rendered
+		if (mapPane.zoomTo(feature)) {
+			mapPane.addMapPaneListener(new JMapPaneListener() {
 
-		// TODO
-		// Mark the selected SimpleFeature using a spacial style.. similar to the
-		// selection stuff.
-		// mapLayer.getStyle().addFeatureTypeStyle( new FeatureTypeStyle());
+				boolean virgin = true;
 
+				@Override
+				public void performMapPaneEvent(MapPaneEvent e) {
+					if (virgin && e instanceof MapRenderingStateEvent) {
+						MapRenderingStateEvent mre = (MapRenderingStateEvent) e;
+						if (mre.getState() == RenderingState.ON_HOLD) {
+							// Remove this listener, and blink!
+							mapPane.blink(feature);
+							virgin = false;
+							// mapPane.removeMapPaneListener(this);
+						}
+					}
+				}
+			});
+			// TODO Remove the listener and the virgin flag again! otherwise the
+			// listener is never removed!
+		} else {
+			// Just blink
+			mapPane.blink(feature);
+		}
 	}
 
 	@Override



More information about the Schmitzm-commits mailing list