[Schmitzm-commits] r1987 - in trunk/schmitzm-gt/src/main/java: de/schmitzm/geotools/gui org/geotools org/geotools/map

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Sat May 5 22:41:16 CEST 2012


Author: mojays
Date: 2012-05-05 22:41:15 +0200 (Sat, 05 May 2012)
New Revision: 1987

Added:
   trunk/schmitzm-gt/src/main/java/org/geotools/map/
   trunk/schmitzm-gt/src/main/java/org/geotools/map/MapUtil.java
Modified:
   trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/LayeredMapPane.java
Log:
MapUtil: Workaround for missing MapLayerEvent on Layer title change

Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/LayeredMapPane.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/LayeredMapPane.java	2012-05-05 19:50:31 UTC (rev 1986)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/LayeredMapPane.java	2012-05-05 20:41:15 UTC (rev 1987)
@@ -43,6 +43,8 @@
 import org.geotools.feature.FeatureCollection;
 import org.geotools.map.MapContext;
 import org.geotools.map.MapLayer;
+import org.geotools.map.MapUtil;
+import org.geotools.map.event.MapLayerEvent;
 import org.geotools.map.event.MapLayerListEvent;
 import org.geotools.map.event.MapLayerListListener;
 import org.geotools.styling.ColorMap;
@@ -231,11 +233,11 @@
 	 */
 	private void setNewLayerTitle(String desc) {
 	  MapLayer newLayer = mapContext.getLayer(mapContext.getLayerCount() - 1);
-	  newLayer.setTitle(desc);
+//	  newLayer.setTitle(desc);
 	  // GT 2.7.x (at least 2.7.4) does not (yet) fire an event on title change (see
 	  // Layer.setTitle(.)) so we have to update the MapContextControlPane checkbox
 	  // title manually
-	  layerControlList.updateLayerTitle(0); 
+	  MapUtil.setLayerTitle(newLayer.toLayer(), desc);
 	}
 	
 	/**

Added: trunk/schmitzm-gt/src/main/java/org/geotools/map/MapUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/org/geotools/map/MapUtil.java	                        (rev 0)
+++ trunk/schmitzm-gt/src/main/java/org/geotools/map/MapUtil.java	2012-05-05 20:41:15 UTC (rev 1987)
@@ -0,0 +1,39 @@
+package org.geotools.map;
+
+import org.geotools.map.event.MapLayerEvent;
+
+/**
+ * This class is a workaround until {@link MapLayer} / {@link Layer} invokes
+ * an {@link MapLayerEvent} when the layer title changes. Since GT 2.7.x this
+ * is not done (although Java-Doc to {@link Layer#setTitle(String)} says so)!
+ * @author Martin O.J. Schmitz
+ *
+ */
+public class MapUtil {
+  
+  /**
+   * Invokes {@link Layer#fireMapLayerListenerLayerChanged(int)} for the
+   * given layer. Because this util class is in the same package, this public
+   * method can call the protected method!
+   * @param layer layer to invoke the event for
+   * @param eventType event type
+   */
+  public static void fireMapLayerListenerLayerChanged(Layer layer, int eventType) {
+    layer.fireMapLayerListenerLayerChanged(eventType);
+  }
+  
+  /**
+   * Sets the layer title. If title changes {@link Layer#fireMapLayerListenerLayerChanged(int)}
+   * is called.
+   * @param layer layer to set the title for
+   * @param title new layer title
+   */
+  public static void setLayerTitle(Layer layer, String title) {
+    String oldTitle = layer.getTitle();
+    layer.setTitle(title);
+    if (  title != null && !title.equals(oldTitle) ||
+          oldTitle != null && title == null )
+      fireMapLayerListenerLayerChanged(layer, MapLayerEvent.METADATA_CHANGED);
+  }
+
+}



More information about the Schmitzm-commits mailing list