X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=gis%2Fruntime%2Forg.argeo.gis.geotools%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fgeotools%2Fstyling%2FStylingUtils.java;fp=gis%2Fruntime%2Forg.argeo.gis.geotools%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fgeotools%2Fstyling%2FStylingUtils.java;h=0000000000000000000000000000000000000000;hb=93854671977f419c5a2c1f2d343fd063450168db;hp=a4811ac8763466971f60115009e8c9024ff34700;hpb=c3be9f8db8a79e159d6a057758dfc7f3580efc2d;p=lgpl%2Fargeo-commons.git diff --git a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/styling/StylingUtils.java b/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/styling/StylingUtils.java deleted file mode 100644 index a4811ac87..000000000 --- a/gis/runtime/org.argeo.gis.geotools/src/main/java/org/argeo/geotools/styling/StylingUtils.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.argeo.geotools.styling; - -import java.awt.Color; - -import org.argeo.ArgeoException; -import org.geotools.factory.CommonFactoryFinder; -import org.geotools.filter.text.cql2.CQL; -import org.geotools.filter.text.cql2.CQLException; -import org.geotools.styling.FeatureTypeStyle; -import org.geotools.styling.LineSymbolizer; -import org.geotools.styling.Rule; -import org.geotools.styling.Stroke; -import org.geotools.styling.Style; -import org.geotools.styling.StyleFactory; -import org.opengis.filter.Filter; -import org.opengis.filter.FilterFactory; - -/** Utilities related to GeoTools styling */ -public class StylingUtils { - static StyleFactory styleFactory = CommonFactoryFinder - .getStyleFactory(null); - static FilterFactory filterFactory = CommonFactoryFinder - .getFilterFactory(null); - - /** - * Style for a line - * - * @param color - * the AWT color in upper case - * @param width - * the width of the line - * @param cqlFilter - * filter in CQL formqt restricting the feqture upon which the - * style will apply - */ - public static Style createLineStyle(String color, Integer width) { - Rule rule = styleFactory.createRule(); - rule.symbolizers().add(createLineSymbolizer(color, width)); - FeatureTypeStyle fts = styleFactory - .createFeatureTypeStyle(new Rule[] { rule }); - Style style = styleFactory.createStyle(); - style.featureTypeStyles().add(fts); - return style; - } - - public static Style createFilteredLineStyle(String cqlFilter, - String matchedColor, Integer matchedWidth, String unmatchedColor, - Integer unmatchedWidth) { - // selection filter - Filter filter; - try { - filter = CQL.toFilter(cqlFilter); - } catch (CQLException e) { - throw new ArgeoException("Cannot parse CQL filter: " + cqlFilter, e); - } - - Rule[] rules; - // matched - Rule ruleMatched = styleFactory.createRule(); - ruleMatched.symbolizers().add( - createLineSymbolizer(matchedColor, matchedWidth)); - ruleMatched.setFilter(filter); - - // unmatched - if (unmatchedColor != null) { - Rule ruleUnMatched = styleFactory.createRule(); - ruleUnMatched.symbolizers().add( - createLineSymbolizer(unmatchedColor, - unmatchedWidth != null ? unmatchedWidth - : matchedWidth)); - ruleUnMatched.setFilter(filterFactory.not(filter)); - rules = new Rule[] { ruleMatched, ruleUnMatched }; - } else { - rules = new Rule[] { ruleMatched }; - } - - FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(rules); - Style style = styleFactory.createStyle(); - style.featureTypeStyles().add(fts); - return style; - } - - public static LineSymbolizer createLineSymbolizer(String color, - Integer width) { - Stroke stroke = styleFactory.createStroke( - filterFactory.literal(stringToColor(color)), - filterFactory.literal(width)); - return styleFactory.createLineSymbolizer(stroke, null); - } - - /** - * Converts a string to a color, using reflection, so that other methods - * don't need AWT dependencies in their signature. Package protected and not - * public so that it has less impact on the overall signature. - */ - static Color stringToColor(String color) { - try { - return (Color) Color.class.getField(color).get(null); - } catch (Exception e) { - throw new ArgeoException("Color " + color + " not found", e); - } - } -}