[Schmitzm-commits] r419 - in branches/1.0-gt2-2.6/src/skrueger: geotools geotools/selection swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Sep 30 17:36:41 CEST 2009


Author: alfonx
Date: 2009-09-30 17:36:39 +0200 (Wed, 30 Sep 2009)
New Revision: 419

Added:
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledRasterPyramidInterface.java
Modified:
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
   branches/1.0-gt2-2.6/src/skrueger/swing/TranslationAskJDialog.java
Log:
* A way has been found to set the transparency color of a DpLayerRasterPyramid.

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-09-28 15:36:11 UTC (rev 418)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-09-30 15:36:39 UTC (rev 419)
@@ -1195,7 +1195,7 @@
 			if (geoObject instanceof GridCoverage2D) {
 				GridCoverage2D cov = (GridCoverage2D) geoObject;
 				colorModel = cov.getRenderedImage().getColorModel();
-			} else if (geoObject instanceof ImagePyramidReader) {
+			} else if (styledGrid instanceof StyledRasterPyramidInterface) {
 
 				Parameter readGG = new Parameter(
 						AbstractGridFormat.READ_GRIDGEOMETRY2D);

Added: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledRasterPyramidInterface.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledRasterPyramidInterface.java	2009-09-28 15:36:11 UTC (rev 418)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledRasterPyramidInterface.java	2009-09-30 15:36:39 UTC (rev 419)
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Stefan A. Krüger.
+ * 
+ * This file is part of the AtlasViewer application - A GIS viewer application targeting at end-users with no GIS-experience. Its main purpose is to present the atlases created with the Geopublisher application.
+ * http://www.geopublishing.org
+ * 
+ * AtlasViewer is part of the Geopublishing Framework hosted at:
+ * http://wald.intevation.org/projects/atlas-framework/
+ * 
+ * This program 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 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program 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 General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Stefan A. Krüger - initial API and implementation
+ ******************************************************************************/
+package skrueger.geotools;
+
+import org.geotools.feature.FeatureCollection;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+
+import skrueger.geotools.StyledRasterInterface;
+
+
+public interface StyledRasterPyramidInterface extends
+		StyledRasterInterface<FeatureCollection<SimpleFeatureType, SimpleFeature>> {
+};


Property changes on: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledRasterPyramidInterface.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-09-28 15:36:11 UTC (rev 418)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java	2009-09-30 15:36:39 UTC (rev 419)
@@ -42,8 +42,10 @@
  **/
 package skrueger.geotools.selection;
 
+import java.awt.RenderingHints;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
@@ -54,8 +56,13 @@
 import javax.swing.event.ListSelectionListener;
 
 import org.geotools.map.MapLayer;
+import org.geotools.renderer.GTRenderer;
+import org.geotools.renderer.label.LabelCacheImpl;
+import org.geotools.renderer.lite.StreamingRenderer;
+import org.geotools.renderer.shape.ShapefileRenderer;
 import org.geotools.styling.FeatureTypeStyle;
 import org.geotools.styling.Style;
+import org.geotools.styling.visitor.DuplicatingStyleVisitor;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.filter.identity.FeatureId;
 
@@ -98,6 +105,7 @@
 	protected final StyledLayerInterface<?> styledLayer;
 	protected final JMapPane mapPane;
 	private final MapPaneToolBar toolBar;
+	private final HashMap<Object, Object> defaultGTRenderingHints;
 
 	/**
 	 * Creates a new synchronizer
@@ -112,7 +120,7 @@
 	public FeatureMapLayerSelectionSynchronizer(
 			StyledFeatureLayerSelectionModel layerSelModel,
 			StyledLayerInterface<?> styledLayer, MapLayer mapLayer,
-			JMapPane mapPane, MapPaneToolBar toolBar) {
+			JMapPane mapPane, MapPaneToolBar toolBar, HashMap<Object, Object> defaultGTRenderingHints) {
 
 		super(layerSelModel);
 		this.styledLayer = styledLayer;
@@ -120,6 +128,10 @@
 		this.mapLayer = mapLayer;
 		this.mapPane = mapPane;
 		this.toolBar = toolBar;
+		if (defaultGTRenderingHints != null)
+			this.defaultGTRenderingHints = defaultGTRenderingHints;
+		else 
+			this.defaultGTRenderingHints = new HashMap<Object, Object>();
 	}
 
 	/**
@@ -176,6 +188,8 @@
 //			}
 //			
 			
+
+			
 			Style originalStyle = mapLayer.getStyle();
 			if (newSelection.isEmpty()) {
 
@@ -188,7 +202,9 @@
 							&& fts.getName().equals(SELECTION_STYLING)) {
 						originalStyle.featureTypeStyles().remove(fts);
 						
-						mapPane.refresh();
+						replaceRenderer();
+//						mapPane.refresh();
+						
 
 						return;
 					}
@@ -247,9 +263,21 @@
 				if (!foundAndReplaced) {
 					originalStyle.featureTypeStyles().add(selectionFTStyle);
 				}
+				
+				
 
 				// Refresh the map
-				mapPane.refresh();
+//				mapPane.refresh();
+				
+				DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();
+				dsv.visit(originalStyle);
+				Style newStyle = (Style)dsv.getCopy();
+				
+//				Style newStyle = StylingUtil.STYLE_BUILDER.createStyle();
+//				newStyle.featureTypeStyles().addAll(originalStyle.featureTypeStyles());
+				mapLayer.setStyle(newStyle);
+				
+				replaceRenderer();
 			}
 //			
 //			if (r instanceof ShapefileRenderer) {
@@ -263,6 +291,44 @@
 		}
 	}
 
+	private void replaceRenderer() {
+//
+//		// Has to be done before we apply the new Renderer
+//		mapLayer.setStyle(style);
+
+		GTRenderer oldRenderer = mapPane.getRenderer();
+
+		/**
+		 * Explicitly putting a new instance of LabelCacheDefault into the
+		 * renderer instance, so JMapPane doesn't reuse the old one. This is
+		 * very useful when changing the TextSymbolizer with AtlasStyler<br/>
+		 * SK 9.7.09: It's not enought to user LabelCache.clear(). We can not
+		 * reuse the old Renderer - better to create a new one!
+		 */
+		final GTRenderer newRenderer = new ShapefileRenderer();
+
+		final HashMap<Object, Object> rendererHints = defaultGTRenderingHints;
+		rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY,
+				new LabelCacheImpl());
+
+		newRenderer.setRendererHints(rendererHints);
+		mapPane.setRenderer(newRenderer);
+
+		if (oldRenderer != null) {
+			
+			RenderingHints java2DHints = oldRenderer.getJava2DHints();
+			if (java2DHints != null) {
+				newRenderer.setRendererHints(java2DHints);
+			}
+			
+			oldRenderer.setContext(null);
+			oldRenderer = null;
+		}
+		
+		mapPane.refresh();
+
+	}
+
 	/**
 	 * Used to synchronize {@link FeatureSelectedEvent}s with the
 	 * {@link StyledFeatureLayerSelectionModel}

Modified: branches/1.0-gt2-2.6/src/skrueger/swing/TranslationAskJDialog.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/swing/TranslationAskJDialog.java	2009-09-28 15:36:11 UTC (rev 418)
+++ branches/1.0-gt2-2.6/src/skrueger/swing/TranslationAskJDialog.java	2009-09-30 15:36:39 UTC (rev 419)
@@ -200,9 +200,11 @@
 	}
 
 	/**
-	 * Called when the dilaog is closed using the cancel button.
+	 * Called when the dilaog is closed using the cancel button. When
+	 * overwriting this method, call super.cancel() after restoring your
+	 * properties.
 	 */
-	protected void cancel() {
+	public void cancel() {
 		restore();
 		firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null);
 		setCancelled(true);
@@ -213,7 +215,7 @@
 	/**
 	 * Used to restore all the values when cancel has been pressed.
 	 */
-	protected void restore() {
+	private void restore() {
 		int count = 0;
 		for (JComponent component : translationEditJPanelsOrJustComponents) {
 			if (component instanceof TranslationEditJPanel) {
@@ -269,12 +271,12 @@
 		if (cancelButton == null) {
 			cancelButton = new CancelButton(new AbstractAction("") {
 				public void actionPerformed(ActionEvent evt) {
-//					restore();
-//					TranslationAskJDialog.this.firePropertyChange(
-//							PROPERTY_CANCEL_AND_CLOSE, null, null);
-//					setVisible(false);
-//					setCancelled(true);
-//					dispose();
+					// restore();
+					// TranslationAskJDialog.this.firePropertyChange(
+					// PROPERTY_CANCEL_AND_CLOSE, null, null);
+					// setVisible(false);
+					// setCancelled(true);
+					// dispose();
 					cancel();
 				}
 			});



More information about the Schmitzm-commits mailing list