[Schmitzm-commits] r396 - branches/1.0-gt2-2.6/src/schmitzm/geotools/styling
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Sep 14 13:39:07 CEST 2009
Author: alfonx
Date: 2009-09-14 13:39:06 +0200 (Mon, 14 Sep 2009)
New Revision: 396
Modified:
branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.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:37:53 UTC (rev 395)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java 2009-09-14 11:39:06 UTC (rev 396)
@@ -119,6 +119,7 @@
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;
@@ -1688,132 +1689,6 @@
return style;
}
- /**
- * 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 presen in this legend
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Krüger</a>
- */
- public static Box createLegendPanel(List<FeatureTypeStyle> list,
- SimpleFeatureType featureType) {
-
- 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ü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
- Rule[] rules = ftStyle.getRules();
- 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ü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(23,
- fontHeight > 5 ? fontHeight : 5);
-
- // ****************************************************************************
- // 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.getTitle();
-
- Translation labelT = new Translation();
- labelT.fromOneLine(rawText);
-
- final JLabel classTitleLabel = new JLabel(labelT.toString());
- hbox.add(classTitleLabel);
- classTitleLabel.setLabelFor(iconLabel); // Whatever it is good
- // for
-
- box.add(hbox);
-
- }
- }
-
- return box;
- }
-
//
// /**
// * Doubles the number of palettes by adding the reverse palette to every
@@ -2187,5 +2062,145 @@
to.getFonts()[0].setFontStyle(ff2.literal(from.getFonts()[0]
.getFontStyle().toString()));
}
+
+
+ /**
+ * 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ü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ü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ü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