[Schmitzm-commits] r397 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/styling skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Sep 14 13:40:18 CEST 2009


Author: alfonx
Date: 2009-09-14 13:40:17 +0200 (Mon, 14 Sep 2009)
New Revision: 397

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java
Log:
* Moving towards a better raster legend

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-09-14 11:39:06 UTC (rev 396)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-09-14 11:40:17 UTC (rev 397)
@@ -30,9 +30,6 @@
 package schmitzm.geotools.styling;
 
 import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -51,10 +48,6 @@
 import java.util.Vector;
 
 import javax.measure.unit.Unit;
-import javax.swing.Box;
-import javax.swing.BoxLayout;
-import javax.swing.ImageIcon;
-import javax.swing.JLabel;
 import javax.xml.transform.TransformerException;
 
 import org.apache.commons.io.IOUtils;
@@ -118,9 +111,6 @@
 import schmitzm.geotools.feature.FeatureUtil.GeometryForm;
 import schmitzm.geotools.grid.GridUtil;
 import schmitzm.lang.LangUtil;
-import skrueger.geotools.LegendIconFeatureRenderer;
-import skrueger.geotools.StyledRasterInterface;
-import skrueger.i8n.Translation;
 
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.LineString;
@@ -2065,142 +2055,4 @@
 	
 	
 
-	/**
-	 * Creates a {@link Box} that shows a legend for a list of
-	 * {@link FeatureTypeStyle}s and a targeted featureType
-	 * 
-	 * @param featureType
-	 *            If this a legend for Point, Polygon or Line?
-	 * @param list
-	 *            The Styles to presented in this legend
-	 * 
-	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
-	 *         Kr&uuml;ger</a>
-	 */
-	public static Box createLegendPanel(List<FeatureTypeStyle> list,
-			SimpleFeatureType featureType, int iconWidth, int iconHeight) {
-
-		Box box = new Box(BoxLayout.Y_AXIS) {
-
-			/**
-			 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot
-			 * gemacht wird) wird. Dann werden wird der Hintergrund auf WEISS
-			 * gesetzt.
-			 * 
-			 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
-			 *         Kr&uuml;ger</a>
-			 */
-			@Override
-			public void print(Graphics g) {
-				final Color orig = getBackground();
-				setBackground(Color.WHITE);
-				// wrap in try/finally so that we always restore the state
-				try {
-					super.print(g);
-				} finally {
-					setBackground(orig);
-				}
-			}
-		};
-
-		for (FeatureTypeStyle ftStyle : list) {
-
-			// One child-node for every rule
-			List<Rule> rules = ftStyle.rules();
-			for (Rule rule : rules) {
-
-				/**
-				 * Let's not create a hbox for Rules that only contain
-				 * TextSymbolizers
-				 */
-				if (StylingUtil.getTextSymbolizers(rule.getSymbolizers())
-						.size() == rule.getSymbolizers().length)
-					continue;
-
-				Box hbox = new Box(BoxLayout.X_AXIS) {
-
-					/**
-					 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein
-					 * Screenshot gemacht wird) wird. Dann werden wird der
-					 * Hintergrund auf WEISS gesetzt.
-					 * 
-					 * @author <a href="mailto:skpublic at wikisquare.de">Stefan
-					 *         Alfons Kr&uuml;ger</a>
-					 */
-					@Override
-					public void print(Graphics g) {
-						final Color orig = getBackground();
-						setBackground(Color.WHITE);
-						// wrap in try/finally so that we always restore the
-						// state
-						try {
-							super.print(g);
-						} finally {
-							setBackground(orig);
-						}
-					}
-				};
-
-				/**
-				 * The size of the legend Symbol is dependent on the size of the
-				 * font.
-				 */
-				final int fontHeight = new JLabel().getFontMetrics(
-						new JLabel().getFont()).getHeight();
-				
-				final Dimension ICON_SIZE = new Dimension(iconWidth,
-						fontHeight > 5 ? fontHeight : iconHeight);
-
-				// ****************************************************************************
-				// Create the actual icon
-				// ****************************************************************************
-				final BufferedImage imageForRule = LegendIconFeatureRenderer
-						.getInstance().createImageForRule(rule, featureType,
-								ICON_SIZE);
-
-				// LOGGER.debug("Creating a new Legend Image for RUle name =
-				// "+rule.getName());
-
-				ImageIcon legendIcon = new ImageIcon(imageForRule);
-
-				final JLabel iconLabel = new JLabel(legendIcon);
-				hbox.setAlignmentX(0f);
-				hbox.add(iconLabel);
-				hbox.add(Box.createHorizontalStrut(3));
-
-				// ****************************************************************************
-				// The labeltext is read from the SLD. Its either the title
-				// directly, or interpreted as OneLine Code
-				// ****************************************************************************
-				// final String rawText =
-				// rule.getDescription().getTitle().toString();
-				final String rawText = rule.getDescription().getTitle().toString();
-
-				Translation labelT = new Translation();
-				labelT.fromOneLine(rawText);
-
-				final JLabel classTitleLabel = new JLabel(labelT.toString());
-				hbox.add(classTitleLabel);
-				classTitleLabel.setLabelFor(iconLabel); 
-
-				box.add(hbox);
-
-			}
-		}
-
-		return box;
-	}
-
-
-	/**
-	 * Creates a 
-	 * @param styledGrid
-	 * @param iconHeight 
-	 * @param iconWidth 
-	 * @return
-	 */
-	public static Box createLegendPanel(StyledRasterInterface<?> styledGrid, int iconWidth, int iconHeight) {
-		throw new RuntimeException("Not yet...");
-	}
-
 }

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-14 11:39:06 UTC (rev 396)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledLayerUtil.java	2009-09-14 11:40:17 UTC (rev 397)
@@ -29,6 +29,10 @@
  ******************************************************************************/
 package skrueger.geotools;
 
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileWriter;
@@ -40,6 +44,11 @@
 import java.util.SortedMap;
 import java.util.TreeMap;
 
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+
 import org.apache.log4j.Logger;
 import org.geotools.coverage.grid.GridCoverage2D;
 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
@@ -48,12 +57,15 @@
 import org.geotools.map.MapLayer;
 import org.geotools.styling.ColorMap;
 import org.geotools.styling.ColorMapEntry;
+import org.geotools.styling.FeatureTypeStyle;
 import org.geotools.styling.RasterSymbolizer;
+import org.geotools.styling.Rule;
 import org.geotools.styling.Style;
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.input.SAXBuilder;
 import org.jdom.output.XMLOutputter;
+import org.opengis.feature.simple.SimpleFeatureType;
 
 import schmitzm.geotools.styling.StylingUtil;
 import schmitzm.io.IOUtil;
@@ -724,5 +736,146 @@
     else
       saveStyledLayerStyle(style,geoObjectURL, "sld", "amd");
   }
+  
+  
 
+	/**
+	 * Creates a {@link Box} that shows a legend for a list of
+	 * {@link FeatureTypeStyle}s and a targeted featureType
+	 * 
+	 * @param featureType
+	 *            If this a legend for Point, Polygon or Line?
+	 * @param list
+	 *            The Styles to presented in this legend
+	 * 
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 */
+	public static Box createLegendPanel(List<FeatureTypeStyle> list,
+			SimpleFeatureType featureType, int iconWidth, int iconHeight) {
+
+		Box box = new Box(BoxLayout.Y_AXIS) {
+
+			/**
+			 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot
+			 * gemacht wird) wird. Dann werden wird der Hintergrund auf WEISS
+			 * gesetzt.
+			 * 
+			 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+			 *         Kr&uuml;ger</a>
+			 */
+			@Override
+			public void print(Graphics g) {
+				final Color orig = getBackground();
+				setBackground(Color.WHITE);
+				// wrap in try/finally so that we always restore the state
+				try {
+					super.print(g);
+				} finally {
+					setBackground(orig);
+				}
+			}
+		};
+
+		for (FeatureTypeStyle ftStyle : list) {
+
+			// One child-node for every rule
+			List<Rule> rules = ftStyle.rules();
+			for (Rule rule : rules) {
+
+				/**
+				 * Let's not create a hbox for Rules that only contain
+				 * TextSymbolizers
+				 */
+				if (StylingUtil.getTextSymbolizers(rule.getSymbolizers())
+						.size() == rule.getSymbolizers().length)
+					continue;
+
+				Box hbox = new Box(BoxLayout.X_AXIS) {
+
+					/**
+					 * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein
+					 * Screenshot gemacht wird) wird. Dann werden wird der
+					 * Hintergrund auf WEISS gesetzt.
+					 * 
+					 * @author <a href="mailto:skpublic at wikisquare.de">Stefan
+					 *         Alfons Kr&uuml;ger</a>
+					 */
+					@Override
+					public void print(Graphics g) {
+						final Color orig = getBackground();
+						setBackground(Color.WHITE);
+						// wrap in try/finally so that we always restore the
+						// state
+						try {
+							super.print(g);
+						} finally {
+							setBackground(orig);
+						}
+					}
+				};
+
+				/**
+				 * The size of the legend Symbol is dependent on the size of the
+				 * font.
+				 */
+				final int fontHeight = new JLabel().getFontMetrics(
+						new JLabel().getFont()).getHeight();
+				
+				final Dimension ICON_SIZE = new Dimension(iconWidth,
+						fontHeight > 5 ? fontHeight : iconHeight);
+
+				// ****************************************************************************
+				// Create the actual icon
+				// ****************************************************************************
+				final BufferedImage imageForRule = LegendIconFeatureRenderer
+						.getInstance().createImageForRule(rule, featureType,
+								ICON_SIZE);
+
+				// LOGGER.debug("Creating a new Legend Image for RUle name =
+				// "+rule.getName());
+
+				ImageIcon legendIcon = new ImageIcon(imageForRule);
+
+				final JLabel iconLabel = new JLabel(legendIcon);
+				hbox.setAlignmentX(0f);
+				hbox.add(iconLabel);
+				hbox.add(Box.createHorizontalStrut(3));
+
+				// ****************************************************************************
+				// The labeltext is read from the SLD. Its either the title
+				// directly, or interpreted as OneLine Code
+				// ****************************************************************************
+				// final String rawText =
+				// rule.getDescription().getTitle().toString();
+				final String rawText = rule.getDescription().getTitle().toString();
+
+				Translation labelT = new Translation();
+				labelT.fromOneLine(rawText);
+
+				final JLabel classTitleLabel = new JLabel(labelT.toString());
+				hbox.add(classTitleLabel);
+				classTitleLabel.setLabelFor(iconLabel); 
+
+				box.add(hbox);
+
+			}
+		}
+
+		return box;
+	}
+
+
+	/**
+	 * Creates a 
+	 * @param styledGrid
+	 * @param iconHeight 
+	 * @param iconWidth 
+	 * @return
+	 */
+	public static Box createLegendPanel(StyledRasterInterface<?> styledGrid, int iconWidth, int iconHeight) {
+		throw new RuntimeException("Not yet...");
+	}
+
+
 }



More information about the Schmitzm-commits mailing list