[Schmitzm-commits] r1985 - trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Sat May 5 19:13:14 CEST 2012


Author: mojays
Date: 2012-05-05 19:13:14 +0200 (Sat, 05 May 2012)
New Revision: 1985

Modified:
   trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/JMapEditorPane.java
   trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/LayeredMapPane.java
   trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapContextControlPane.java
Log:
Changes for GT 2.7.x:
LayeredMapPane/MapContextControlPane: since GT 2.7.x MapLayer.setTitle(.) / Layer.setTitle(.) do not fire an event, so the checkbox title must be updated manually!
JMapEditorPane: With GT 2.7.x MapLayer/FeatureLayer should be used instead of DefaultMapLayer; furthermore FeatureLayer is disposed automatically when removing from MapContext, so a new layer has to be created when moving new layer from editor map context to "real" map context!

Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/JMapEditorPane.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/JMapEditorPane.java	2012-05-05 17:12:33 UTC (rev 1984)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/JMapEditorPane.java	2012-05-05 17:13:14 UTC (rev 1985)
@@ -44,6 +44,7 @@
 import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
 import org.geotools.map.DefaultMapContext;
 import org.geotools.map.DefaultMapLayer;
+import org.geotools.map.FeatureLayer;
 import org.geotools.map.MapContext;
 import org.geotools.map.MapLayer;
 import org.geotools.renderer.GTRenderer;
@@ -607,6 +608,9 @@
 		// move the edited layer to the "real" MapContext
 		editorMapContext.removeLayer(editorLayer);
 		if (mapContext.indexOf(editorLayer) < 0) {
+		    // GT 2.7.x: editorLayer is disposed by .removeLayer, so we have to
+		    //           create a new instance
+		    editorLayer = new MapLayer( new FeatureLayer(editorFeatureCollection, getEditorStyle(), editorLayer.getTitle()) );
 			mapContext.addLayer(editorLayer);
 			editorLayer.setVisible(true);
 		}
@@ -623,13 +627,13 @@
 	}
 
 	/**
-	 * Cancels the current edititing operation. The edited layer is removed.
+	 * Cancels the current editing operation. The edited layer is removed.
 	 */
 	public void cancelEditing() {
 		if (editorLayer != null)
 			this.editorMapContext.removeLayer(editorLayer);
 		if (editorFeatureCollection != null) {
-			if (mapContext.indexOf(editorLayer) < 0) {
+			if (editorLayer == null || mapContext.indexOf(editorLayer) < 0) {
 				// Layer was a new one, so clear it completly
 				editorFeatureCollection.clear();
 				initUndoRedo();
@@ -799,8 +803,8 @@
 		editorFeatureCollection.add(DUMMY_EDITOR_FEATURE);
 		editorGeometryForm = FeatureUtil
 				.getGeometryForm(editorFeatureCollection);
-		editorLayer = new DefaultMapLayer(editorFeatureCollection,
-				getEditorStyle(editorGeometryForm));
+		editorLayer = new MapLayer(new FeatureLayer(editorFeatureCollection,
+				getEditorStyle(editorGeometryForm)));
 		editorLayer.setTitle(title);
 	}
 
@@ -818,8 +822,8 @@
 			segmLineFeatureType = createFeatureType(LineString.class, null);
 			DUMMY_LINE_FEATURE = createDummyFeature(segmLineFeatureType);
 			segmLineFeatureCollection.add(DUMMY_LINE_FEATURE);
-			segmLineLayer = new DefaultMapLayer(segmLineFeatureCollection,
-					getEditorStyle(GeometryForm.LINE));
+			segmLineLayer = new MapLayer(new FeatureLayer(segmLineFeatureCollection,
+					getEditorStyle(GeometryForm.LINE)));
 			segmLineLayer.setTitle("Line layer for current segment");
 			editorMapContext.addLayer(segmLineLayer);
 			// initialize the objects used to display the
@@ -829,8 +833,8 @@
 			segmPointFeatureType = createFeatureType(MultiPoint.class, null);
 			DUMMY_POINT_FEATURE = createDummyFeature(segmPointFeatureType);
 			segmPointFeatureCollection.add(DUMMY_POINT_FEATURE);
-			segmPointLayer = new DefaultMapLayer(segmPointFeatureCollection,
-					getEditorStyle(GeometryForm.POINT));
+			segmPointLayer = new MapLayer(new FeatureLayer(segmPointFeatureCollection,
+					getEditorStyle(GeometryForm.POINT)));
 			segmPointLayer.setTitle("Point layer for current segment");
 			editorMapContext.addLayer(segmPointLayer);
 		} else {
@@ -1043,7 +1047,7 @@
 
 		// New without gt-legacy:
 		GeometryDescriptor geomAttrType = AttributeTypeFactory
-				.newGeometryAttributeDescriptor(GEOMETRY_ATTR, gtype, null, null,
+				.newGeometryAttributeDescriptor(GEOMETRY_ATTR, gtype, false, null,
 						createGeometryFromPoints(gtype, null),
 						mapContext.getCoordinateReferenceSystem());
 

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 17:12:33 UTC (rev 1984)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/LayeredMapPane.java	2012-05-05 17:13:14 UTC (rev 1985)
@@ -225,6 +225,20 @@
 	}
 
 	/**
+	 * Sets the title for the last added layer. 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  
+	 */
+	private void setNewLayerTitle(String desc) {
+	  MapLayer newLayer = mapContext.getLayer(mapContext.getLayerCount() - 1);
+	  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); 
+	}
+	
+	/**
 	 * Fuegt ein Raster-Layer (als oberstes Layer) ein.
 	 * 
 	 * @param gc
@@ -305,7 +319,8 @@
 		// Layer erzeugen
 		mapContext.addLayer(gc, style);
 		MapLayer newLayer = mapContext.getLayer(mapContext.getLayerCount() - 1);
-		newLayer.setTitle(desc);
+//		newLayer.setTitle(desc);
+		setNewLayerTitle(desc);
 
 		// neuer Anzeigebereich: Das komplette Raster
 		if (mapPane.getMapArea() == null) {
@@ -344,7 +359,8 @@
 		// Layer erzeugen
 		mapContext.addLayer(fc, style);
 		MapLayer newLayer = mapContext.getLayer(mapContext.getLayerCount() - 1);
-		newLayer.setTitle(desc);
+//		newLayer.setTitle(desc);
+		setNewLayerTitle(desc);
 
 		// neuer Anzeigebereich: Die komplette FeatureCollection
 		if (mapPane.getMapArea() == null)

Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapContextControlPane.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapContextControlPane.java	2012-05-05 17:12:33 UTC (rev 1984)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/gui/MapContextControlPane.java	2012-05-05 17:13:14 UTC (rev 1985)
@@ -266,6 +266,7 @@
 		// loeschen, verschieben
 		mapPane.getMapContext().addMapLayerListListener(
 				new MapLayerListListener() {
+				    @Override
 					public void layerAdded(MapLayerListEvent e) {
 						addLayerControl(getComponentCount() - e.getToIndex(),
 								e.getLayer());
@@ -358,6 +359,16 @@
 		validate();
 		repaint();
 	}
+	
+	/**
+	 * Aktualisiert die Bezeichnung der Kontroll-Komponente mit dessen aktuellem
+	 * Layer-Titel. 
+     * @param idx
+     *            Index der zu aktualisierenden Komponente (0 ist die oberste)
+	 */
+	public void updateLayerTitle(int idx) {
+	  ((MapLayerControl)getComponent(idx)).updateTitle();
+	}
 
 	// ////////////////////////////////////////////////////////////////////////
 	// Kontext-Menue fuer Layer-Aktionen
@@ -527,6 +538,14 @@
 			}
 			mapPane.refresh();
 		}
+		
+		/**
+		 * Updates the checkbox text with the current map layer title.
+		 * 
+		 */
+		public void updateTitle() {
+		  setText( layer.getTitle() );
+		}
 
 		/**
 		 * Belegt die Bezeichnungen der Menue-Eintraege neu.



More information about the Schmitzm-commits mailing list