[Schmitzm-commits] r1270 - in trunk: src/org src/org/geopublishing src/schmitzm/geotools/styling src/skrueger/geotools src/skrueger/swing src_junit/schmitzm/geotools/styling

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Nov 14 01:26:04 CET 2010


Author: alfonx
Date: 2010-11-14 01:25:52 +0100 (Sun, 14 Nov 2010)
New Revision: 1270

Added:
   trunk/src/org/geopublishing/
   trunk/src/org/geopublishing/atlasStyler/
Modified:
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src/skrueger/geotools/LegendIconFeatureRenderer.java
   trunk/src/skrueger/geotools/StyledLayerUtil.java
   trunk/src/skrueger/swing/AtlasDialog.java
   trunk/src/skrueger/swing/CancellableDialogAdapter.java
   trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
Log:


Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-11-13 22:34:29 UTC (rev 1269)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-11-14 00:25:52 UTC (rev 1270)
@@ -603,7 +603,7 @@
 					}
 
 				}
-				return (Filter) super.copy(filter);
+				return super.copy(filter);
 			};
 
 			@Override
@@ -635,6 +635,7 @@
 				super.visit(sym);
 			}
 
+			@Override
 			public void visit(RasterSymbolizer sym) {
 				sym.setGeometryPropertyName("geom");
 				super.visit(sym);
@@ -977,7 +978,7 @@
 		GridSampleDimension gsd = new GridSampleDimension(name, categories
 				.values().toArray(new Category[0]), unit).geophysics(true);
 
-		for (Category c : (List<Category>) gsd.getCategories())
+		for (Category c : gsd.getCategories())
 			LOGGER.debug(c.toString());
 
 		return gsd;
@@ -3152,4 +3153,18 @@
 
 		return isStyleDifferent(style1, style2);
 	}
+
+	public static String sldToString(Style style) throws TransformerException {
+
+		// StringWriter w = null;
+		String xml = SLDTRANSFORMER.transform(style);
+		// w = new StringWriter();
+		// w.write(xml);
+		// w.close();
+		// w.getBuffer();
+		// final String sldString = w.getBuffer().toString();
+
+		return xml;
+
+	}
 }

Modified: trunk/src/skrueger/geotools/LegendIconFeatureRenderer.java
===================================================================
--- trunk/src/skrueger/geotools/LegendIconFeatureRenderer.java	2010-11-13 22:34:29 UTC (rev 1269)
+++ trunk/src/skrueger/geotools/LegendIconFeatureRenderer.java	2010-11-14 00:25:52 UTC (rev 1270)
@@ -48,12 +48,9 @@
 import java.awt.RenderingHints;
 import java.awt.image.BufferedImage;
 
-import javax.swing.tree.DefaultTreeCellRenderer;
-
 import org.apache.log4j.Logger;
 import org.geotools.factory.GeoTools;
 import org.geotools.factory.Hints;
-import org.geotools.feature.IllegalAttributeException;
 import org.geotools.geometry.jts.LiteShape2;
 import org.geotools.renderer.lite.StyledShapePainter;
 import org.geotools.renderer.style.SLDStyleFactory;
@@ -67,6 +64,7 @@
 import org.geotools.styling.Symbolizer;
 import org.geotools.styling.TextSymbolizer;
 import org.geotools.util.NumberRange;
+import org.opengis.feature.IllegalAttributeException;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.feature.type.AttributeDescriptor;
@@ -83,8 +81,6 @@
  * Based on geoserver!
  * <hr>
  * <b>Changes by <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a></b>
- * <br>
- * <ul>
  * <li>07.02.2008:<br>
  * Determining the default values of a {@link SimpleFeatureType} by
  * {@link FeatureUtil#getDefaultAttributeValues(SimpleFeatureType)} instead of
@@ -94,7 +90,7 @@
  * 
  * @author Stefan Alfons Tzeggai
  */
-public class LegendIconFeatureRenderer extends DefaultTreeCellRenderer {
+public class LegendIconFeatureRenderer {
 	// private static final Dimension SIZE = new Dimension(30,20);
 
 	Logger LOGGER = Logger.getLogger(LegendIconFeatureRenderer.class);
@@ -108,18 +104,7 @@
 	final static LegendIconFeatureRenderer instance = new LegendIconFeatureRenderer();
 
 	public static LegendIconFeatureRenderer getInstance() {
-		// In GT 2.4.5 it we have to create a new one all the time!
-
-		// TODO TEST, whether we still need to recreate the renderer here....
-		// TODO TEST, whether we still need to recreate the renderer here....
-		// TODO TEST, whether we still need to recreate the renderer here....
-		// TODO TEST, whether we still need to recreate the renderer here....
-		// TODO TEST, whether we still need to recreate the renderer here....
-		// TODO TEST, whether we still need to recreate the renderer here....
-		// TODO TEST, whether we still need to recreate the renderer here....
-		// TODO TEST, whether we still need to recreate the renderer here....
-		return new LegendIconFeatureRenderer();
-		// return instance;
+		return instance;
 	}
 
 	/**
@@ -155,7 +140,7 @@
 	private Hints hints;
 
 	/**
-	 * Returns a <code>java.awt.Shape</code> appropiate to render a legend
+	 * Returns a <code>java.awt.Shape</code> appropriate to render a legend
 	 * graphic given the symbolizer type and the legend dimensions.
 	 * 
 	 * @param symbolizer
@@ -169,8 +154,6 @@
 	 *         symbolizer, wether it is a LineSymbolizer, a PolygonSymbolizer,
 	 *         or a Point ot Text Symbolizer
 	 * 
-	 * @throws IllegalArgumentException
-	 *             if an unknown symbolizer impl was passed in.
 	 */
 	private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth,
 			int legendHeight) {
@@ -307,9 +290,10 @@
 						size.height);
 
 				if (style2d != null) {
-					StyledShapePainter styledShapePainter = new StyledShapePainter(null);
-					styledShapePainter.paint(graphics, shape,
-							style2d, Integer.MAX_VALUE);
+					StyledShapePainter styledShapePainter = new StyledShapePainter(
+							null);
+					styledShapePainter.paint(graphics, shape, style2d,
+							Integer.MAX_VALUE);
 				}
 			}
 		} catch (Exception e) {

Modified: trunk/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- trunk/src/skrueger/geotools/StyledLayerUtil.java	2010-11-13 22:34:29 UTC (rev 1269)
+++ trunk/src/skrueger/geotools/StyledLayerUtil.java	2010-11-14 00:25:52 UTC (rev 1270)
@@ -45,6 +45,7 @@
 import java.net.URL;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -84,8 +85,10 @@
 import org.opengis.feature.type.AttributeDescriptor;
 import org.opengis.feature.type.GeometryDescriptor;
 import org.opengis.feature.type.Name;
+import org.opengis.filter.FilterFactory2;
 import org.opengis.parameter.GeneralParameterValue;
 
+import schmitzm.geotools.FilterUtil;
 import schmitzm.geotools.JTSUtil;
 import schmitzm.geotools.feature.FeatureUtil;
 import schmitzm.geotools.styling.StylingUtil;
@@ -115,6 +118,12 @@
 	private static final SAXBuilder SAX_BUILDER = new SAXBuilder();
 	private static final XMLOutputter XML_OUTPUTTER = new XMLOutputter();
 
+	/**
+	 * Is appended to the name of a rule, this rule shall not be shown in the
+	 * legend
+	 */
+	public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND";
+
 	/** URL for Atlas XML schema */
 	public static final String AMLURI = "http://www.wikisquare.de/AtlasML";
 	/** Name of the XML Element for the attribute meta data map */
@@ -127,6 +136,7 @@
 	public static final String ELEM_NAME_RASTERLEGEND = "rasterLegendItem";
 	/** Name of the XML Element for a translation */
 	public static final String ELEM_NAME_TRANSLATION = "translation";
+	private static FilterFactory2 ff = FilterUtil.FILTER_FAC2;
 
 	/**
 	 * Creates a Geotools {@link MapLayer} from an object. If the object is a
@@ -925,19 +935,13 @@
 	}
 
 	/**
-	 * *If appended to the name of a rule, this rule shall not be shown in the
-	 * legend
-	 */
-	public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND";
-
-	/**
 	 * Creates a {@link JPanel} that shows a legend for a list of
 	 * {@link FeatureTypeStyle}s and a targeted featureType
 	 * 
 	 * @param style
 	 *            The Style to presented in this legend
 	 * @param featureType
-	 *            If this a legend for Point, Polygon or Line?
+	 *            If this a legend for Point, Polygon or Line? Or ANY or NONE?
 	 * 
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
@@ -951,24 +955,30 @@
 			return new JPanel();
 		}
 
-		final List<FeatureTypeStyle> list = style.featureTypeStyles();
-
 		final JPanel panel = new JPanel(new MigLayout("wrap 2", "[]:3:[]"));
-
 		if (style == null) {
 			// No Style => no legend
 			return panel;
 		}
 
-		for (final FeatureTypeStyle ftStyle : list) {
+		// Reversing the list, because a point that is painted above a polygon
+		// should be higher in the list.
+		final List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
+		Collections.reverse(ftsList);
+		for (final FeatureTypeStyle ftStyle : ftsList) {
 
+			// // Try to import the FeatureType into an AtlasStyler RuleList to
+			// // determine whether this RL is actually disabled.
+			// StylingUtil.sldToString(ftStyle).contains(RL_DISABLED_FILTER.toString())
+			// return;
+
 			// One child-node for every rule
 			final List<Rule> rules = ftStyle.rules();
 			for (final Rule rule : rules) {
 
 				// Check if this RULE shall actually appear in the legend
 				if (rule.getName() != null
-						&& rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT))
+						&& rule.getName().contains(HIDE_IN_LAYER_LEGEND_HINT))
 					continue;
 
 				/**
@@ -1181,7 +1191,7 @@
 					throw new RuntimeException("need a reader...");
 				//
 
-				final GridCoverage2D cov = (GridCoverage2D) aReader
+				final GridCoverage2D cov = aReader
 						.read(new GeneralParameterValue[] { readGG });
 				colorModel = cov.getRenderedImage().getColorModel();
 			}

Modified: trunk/src/skrueger/swing/AtlasDialog.java
===================================================================
--- trunk/src/skrueger/swing/AtlasDialog.java	2010-11-13 22:34:29 UTC (rev 1269)
+++ trunk/src/skrueger/swing/AtlasDialog.java	2010-11-14 00:25:52 UTC (rev 1270)
@@ -7,6 +7,7 @@
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 
+import javax.swing.AbstractAction;
 import javax.swing.JComponent;
 import javax.swing.JDialog;
 import javax.swing.JRootPane;
@@ -22,11 +23,14 @@
  */
 public class AtlasDialog extends JDialog {
 
+	protected OkButton okButton;
+	protected CancelButton cancelButton;
+
 	public AtlasDialog(final Component owner, String title) {
 		super(SwingUtil.getParentWindow(owner), title);
 		initDialog();
 	}
-	
+
 	public AtlasDialog(final Component owner) {
 		super(SwingUtil.getParentWindow(owner));
 		initDialog();
@@ -89,4 +93,36 @@
 		super.dispose();
 		isDisposed = true;
 	}
+
+	/**
+	 * @return a default OkButton that will call {@link #okClose()}
+	 */
+	protected OkButton getOkButton() {
+		if (okButton == null) {
+			okButton = new OkButton(new AbstractAction() {
+
+				@Override
+				public void actionPerformed(ActionEvent e) {
+					close();
+				}
+			});
+		}
+		return okButton;
+	}
+
+	/**
+	 * @return a default CancelButton that will call {@link #cancelClose()}
+	 */
+	protected CancelButton getCancelButton() {
+		if (cancelButton == null) {
+			cancelButton = new CancelButton(new AbstractAction() {
+
+				@Override
+				public void actionPerformed(ActionEvent e) {
+					dispose();
+				}
+			});
+		}
+		return cancelButton;
+	}
 }

Modified: trunk/src/skrueger/swing/CancellableDialogAdapter.java
===================================================================
--- trunk/src/skrueger/swing/CancellableDialogAdapter.java	2010-11-13 22:34:29 UTC (rev 1269)
+++ trunk/src/skrueger/swing/CancellableDialogAdapter.java	2010-11-14 00:25:52 UTC (rev 1270)
@@ -32,10 +32,6 @@
 	/** Has this dialog been canceled ? **/
 	protected boolean cancelled = false;
 
-	private OkButton okButton;
-
-	private CancelButton cancelButton;
-
 	public CancellableDialogAdapter(Component parentWindow) {
 		super(parentWindow);
 	}
@@ -127,6 +123,7 @@
 	/**
 	 * @return a default OkButton that will call {@link #okClose()}
 	 */
+	@Override
 	protected OkButton getOkButton() {
 		if (okButton == null) {
 			okButton = new OkButton(new AbstractAction() {
@@ -143,6 +140,7 @@
 	/**
 	 * @return a default CancelButton that will call {@link #cancelClose()}
 	 */
+	@Override
 	protected CancelButton getCancelButton() {
 		if (cancelButton == null) {
 			cancelButton = new CancelButton(new AbstractAction() {

Modified: trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-11-13 22:34:29 UTC (rev 1269)
+++ trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-11-14 00:25:52 UTC (rev 1270)
@@ -13,6 +13,7 @@
 import javax.swing.ImageIcon;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.xml.transform.TransformerException;
 
 import junit.framework.TestCase;
 
@@ -127,35 +128,46 @@
 		assertEquals("3.0", colorMapEntries[1].getQuantity().toString());
 		assertEquals("4.0", colorMapEntries[2].getQuantity().toString());
 	}
-	
 
-
 	@Test
 	public void testSldEncoding() throws IOException {
-		
+
 		Style style = StylingUtil.createDefaultStyle(GeometryForm.POLYGON);
-		
+
 		assertTrue(StylingUtil.validates(style));
-		
+
 		File tf = File.createTempFile("junit", ".sld");
 		StylingUtil.saveStyleToSld(style, tf);
 		assertTrue(tf.exists());
-		
+
 		String ss = IOUtil.readFileAsString(tf);
-		assertTrue("SLD is not written in UTF-8 encoding", ss.contains("encoding=\"UTF-8"));
+		assertTrue("SLD is not written in UTF-8 encoding",
+				ss.contains("encoding=\"UTF-8"));
 	}
 
-//	@Test
-//	@Ignore
-//	public void testParseColormapToSld() throws IOException, TransformerException {
-//		URL colormapUrl = StylingUtilTest.class.getResource("gdaloutput.txt");
-//		assertNotNull(colormapUrl);
-//		ColorMap cm = StylingUtil.parseColormapToSld(colormapUrl);
-//		assertEquals(256, cm.getColorMapEntries().length);
-//		
-//		RasterSymbolizer createRasterSymbolizer = StylingUtil.STYLE_BUILDER.createRasterSymbolizer(cm, 1.0);
-//		Style style = StylingUtil.STYLE_BUILDER.createStyle(createRasterSymbolizer);
-//		StylingUtil.saveStyleToSld(style, new File("/home/stefan/Desktop/colors.sld"));
-//	}
+	@Test
+	public void testSldToStringUsesUTF8() throws TransformerException {
+		Style createStyle = StylingUtil.STYLE_BUILDER.createStyle();
+		String sldToString = StylingUtil.sldToString(createStyle);
+		assertTrue(sldToString.length() > 100);
+		assertTrue(sldToString.contains("UTF-8"));
+	}
 
+	// @Test
+	// @Ignore
+	// public void testParseColormapToSld() throws IOException,
+	// TransformerException {
+	// URL colormapUrl = StylingUtilTest.class.getResource("gdaloutput.txt");
+	// assertNotNull(colormapUrl);
+	// ColorMap cm = StylingUtil.parseColormapToSld(colormapUrl);
+	// assertEquals(256, cm.getColorMapEntries().length);
+	//
+	// RasterSymbolizer createRasterSymbolizer =
+	// StylingUtil.STYLE_BUILDER.createRasterSymbolizer(cm, 1.0);
+	// Style style =
+	// StylingUtil.STYLE_BUILDER.createStyle(createRasterSymbolizer);
+	// StylingUtil.saveStyleToSld(style, new
+	// File("/home/stefan/Desktop/colors.sld"));
+	// }
+
 }



More information about the Schmitzm-commits mailing list