[Schmitzm-commits] r514 - in branches/1.0-gt2-2.6: dist src/gtmig/org/geotools/swing src/schmitzm/geotools/feature src/schmitzm/geotools/styling src/skrueger

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Nov 9 16:05:47 CET 2009


Author: alfonx
Date: 2009-11-09 16:05:41 +0100 (Mon, 09 Nov 2009)
New Revision: 514

Modified:
   branches/1.0-gt2-2.6/dist/schmitzm-1.0-gt2-2.6.jar
   branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/SelectXMapPaneMouseListener.java
   branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
   branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java
Log:
Enhanced the saveSLDToFile methods in StyleingUtil



Modified: branches/1.0-gt2-2.6/dist/schmitzm-1.0-gt2-2.6.jar
===================================================================
(Binary files differ)

Modified: branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/SelectXMapPaneMouseListener.java
===================================================================
--- branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/SelectXMapPaneMouseListener.java	2009-11-09 11:17:34 UTC (rev 513)
+++ branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/SelectXMapPaneMouseListener.java	2009-11-09 15:05:41 UTC (rev 514)
@@ -179,7 +179,7 @@
 			}
 		}
 		
-		xMapPane.updateCursorAndRepaintTimer();
+		xMapPane.updateCursor();
 
 	}
 

Modified: branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java	2009-11-09 11:17:34 UTC (rev 513)
+++ branches/1.0-gt2-2.6/src/gtmig/org/geotools/swing/XMapPane.java	2009-11-09 15:05:41 UTC (rev 514)
@@ -613,7 +613,7 @@
 	/**
 	 * Abhaengig von selState wird der Cursor gesetzt
 	 */
-	public void updateCursorAndRepaintTimer() {
+	public void updateCursor() {
 
 		if (bgExecuter != null && bgExecuter.isRunning()
 				|| localExecuter != null && localExecuter.isRunning()) {
@@ -1099,7 +1099,7 @@
 				|| state == ZOOM_OUT || state == PAN));
 
 		// Je nach Aktion den Cursor umsetzen
-		updateCursorAndRepaintTimer();
+		updateCursor();
 	}
 
 	/** Cursor wenn kein Mausbutton gedrueckt wird. default oder SwingUtil.PAN **/
@@ -1131,7 +1131,7 @@
 
 	protected void paintComponent(final Graphics g) {
 		// Maybe update the cursor
-		updateCursorAndRepaintTimer();
+		updateCursor();
 
 		if (!acceptsRepaintCalls)
 			return;
@@ -1508,7 +1508,7 @@
 					createGTRenderer);
 		}
 
-		updateCursorAndRepaintTimer();
+		updateCursor();
 //
 //		// start regular repaints until all renderers are done.
 //		repainterTimer.setRepeats(true);

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java	2009-11-09 11:17:34 UTC (rev 513)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java	2009-11-09 15:05:41 UTC (rev 514)
@@ -65,8 +65,10 @@
    */
   @Override
   public Filter parseFilter(String rule) {
-    if (rule == null || rule.trim().equals(""))
+    if (rule == null || rule.trim().equals("")|| rule.equalsIgnoreCase("Filter.INCLUDE"))
       return Filter.INCLUDE;
+    if (rule.equalsIgnoreCase("Filter.EXCLUDE"))
+        return Filter.EXCLUDE;    
     try {
       return CQL.toFilter(rule);
     } catch (CQLException err) {

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-11-09 11:17:34 UTC (rev 513)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-11-09 15:05:41 UTC (rev 514)
@@ -119,6 +119,8 @@
 import schmitzm.geotools.grid.GridUtil;
 import schmitzm.lang.LangUtil;
 import skrueger.geotools.StyledFeaturesInterface;
+import skrueger.geotools.StyledRasterInterface;
+import skrueger.geotools.selection.FeatureMapLayerSelectionSynchronizer;
 
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.LineString;
@@ -255,9 +257,9 @@
 			style = FeatureUtil
 					.createDefaultStyle(((StyledFeaturesInterface<?>) object)
 							.getSchema().getGeometryDescriptor());
-
+		
 		if (object instanceof GridCoverage2D
-				|| object instanceof AbstractGridCoverage2DReader)
+				|| object instanceof AbstractGridCoverage2DReader || object instanceof StyledRasterInterface)
 			style = GridUtil.createDefaultStyle();
 
 		if (object instanceof FeatureCollection)
@@ -1067,7 +1069,7 @@
 	 *         Kr&uuml;ger</a>
 	 */
 	public static Style[] loadSLD(File sldFile) throws FileNotFoundException {
-		LOGGER.debug("Loading styles from File...");
+//		LOGGER.debug("Loading styles from File...");
 
 		FileInputStream inputStream = null;
 		try {
@@ -1080,10 +1082,14 @@
 	}
 
 	/**
-	 * Saves the {@link Style} to OGC SLD. Overwrites any existing file.
+	 * Saves the {@link Style} to OGC SLD. Overwrites any existing file. If a
+	 * FeatureTypeStyle for selection is used, it is automatically removed. This
+	 * method also checks, whether the style is actually differing from any
+	 * existing style in the File.
 	 * 
-	 * @param style
-	 *            {@link Style} to save
+	 * @param origStyle
+	 *            {@link Style} to save. Any selectino related FeatureTypeStyle
+	 *            will be removed.
 	 * @param charset
 	 *            The charset to use for the XML, e.g. <?xml version="1.0"
 	 *            encoding="UTF-8"?>. If null, non is set, the default is used?!
@@ -1094,25 +1100,101 @@
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
 	 */
-	public static final void saveStyleToSLD(Style style, File exportFile,
+	public static final boolean saveStyleToSLD(Style origStyle, File exportFile,
 			Charset charset) throws TransformerException, IOException {
-		//
-		// if (charset != null) {
-		// LOGGER
-		// .warn("Explicitly setting the Chartset to "
-		// + charset
-		// + "! Steve thinks that this is a bad idea, because it doesn't"
-		// + " transform the content but just declares the header.");
-		// SLDTRANSFORMER.setEncoding(charset);
-		// }
 		SLDTRANSFORMER.setIndentation(2);
-		SLDTRANSFORMER.transform(style, new FileWriter(exportFile));
+		
+		Style exportStyle = removeSelectionFeatureTypeStyle(origStyle);
 
+		if (!isStyleDifferent(exportStyle, exportFile)) {
+			LOGGER.debug("Style "+exportFile+" didn't change, not saving.");
+			return false;
+		}
+
+		SLDTRANSFORMER.transform(exportStyle, new FileWriter(exportFile));
+
 		LOGGER.info("Saved a Style with charset "
 				+ SLDTRANSFORMER.getEncoding().name() + " to " + exportFile);
+		
+		return true;
 	}
 
 	/**
+	 * Creates a copy of the given {@link Style}, removing any {@link FeatureTypeStyle}s that are only SELECTION related.
+	 */
+	public static Style removeSelectionFeatureTypeStyle(final Style style) {
+
+		// Create a copy of the style
+		DuplicatingStyleVisitor duplVisitor = new DuplicatingStyleVisitor();
+		duplVisitor.visit(style);
+		Style cleanStyle = (Style) duplVisitor.getCopy();
+
+		// Remove any selection-FeatureTypeStyle from the new Style
+		for (int ii = 0; ii < style.featureTypeStyles().size(); ii++) {
+			if (style.featureTypeStyles().get(ii).getName().equals(
+					FeatureMapLayerSelectionSynchronizer.SELECTION_STYLING)) {
+				cleanStyle.featureTypeStyles().remove(ii);
+				break;
+			}
+		}
+
+		return cleanStyle;
+	}
+
+	/**
+	 * Compares a given Style and a {@link File} containg a {@link Style}.
+	 * 
+	 * @param style1
+	 *            The first {@link Style}
+	 * @param style2file
+	 *            A {@link File} pointing to the second {@link Style}
+	 * @return <code>true</code> is they are different, ignoring any XML
+	 *         fomatting.
+	 */
+	public static boolean isStyleDifferent(Style style1, File style2file) {
+		SLDTRANSFORMER.setIndentation(2);
+		
+		try {
+
+			if (!style2file.exists())
+				return true;
+
+			Style style2 = loadSLD(style2file)[0];
+			
+			return isStyleDifferent(style1, style2);
+			
+		} catch (Exception e) {
+			LOGGER.debug("Comparing styles "+style1+" and "+style2file+" failed. So we assume they are different.",e);
+			return true;
+		}
+	}
+
+	/**
+	 * Compares a given Style and a {@link File} containg a {@link Style}.
+	 * 
+	 * @param style1
+	 *            The first {@link Style}
+	 * @param style2
+	 *            The second {@link Style} to compare to
+	 * @return <code>true</code> is they are different, ignoring any XML
+	 *         fomatting.
+	 */
+	public static boolean isStyleDifferent(Style style1, Style style2) {
+		try {
+		// Transforming style2 to an XML String
+		String style1string = SLDTRANSFORMER.transform(style1);
+		String style2string = SLDTRANSFORMER.transform(style2);
+		
+		return !style1string.equals(style2string);
+		
+		} catch (Exception e) {
+			LOGGER.debug("Compating styles "+style1+" and "+style2+" failed. So we assume they are different.",e);
+			return true;
+		}
+
+	}
+
+	/**
 	 * Saves the {@link Style} to OGC SLD using UTF-8 as charset. Overwrites any
 	 * existing file.
 	 * 
@@ -1125,9 +1207,9 @@
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
 	 */
-	public static final void saveStyleToSLD(Style style, File exportFile)
+	public static final boolean saveStyleToSLD(Style style, File exportFile)
 			throws TransformerException, IOException {
-		saveStyleToSLD(style, exportFile, null);
+		return saveStyleToSLD(style, exportFile, null);
 	}
 
 	/**

Modified: branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java	2009-11-09 11:17:34 UTC (rev 513)
+++ branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java	2009-11-09 15:05:41 UTC (rev 514)
@@ -41,6 +41,7 @@
 
 import schmitzm.geotools.GTUtil;
 import schmitzm.geotools.grid.GridUtil;
+import skrueger.geotools.Copyable;
 import skrueger.i8n.Translation;
 
 /**
@@ -49,6 +50,7 @@
  *
  * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
  *
+ * TODO implements {@link Copyable}
  */
 public class RasterLegendData extends HashMap<Double, Translation> {
 	static private final Logger LOGGER = Logger.getLogger(RasterLegendData.class);



More information about the Schmitzm-commits mailing list