Search in sources :

Example 66 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.

the class StyleHelper method createPolygonStyle.

/**
 * Create a default polygon style.
 *
 * @param color the polygon color
 * @param width the line width
 * @return a Style for Polygon objects
 */
private static FeatureTypeStyle createPolygonStyle(Color color, double width) {
    PolygonSymbolizer symbolizer = createPolygonSymbolizer(color, width);
    Rule rule = styleFactory.createRule();
    rule.symbolizers().add(symbolizer);
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    fts.rules().add(rule);
    return fts;
}
Also used : PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 67 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.

the class StyleHelper method getDefaultStyle.

/**
 * Returns a default style for the given type.
 *
 * @param typeDef the type definition
 * @param dataSet the data set (if known)
 * @return the style
 */
public static FeatureTypeStyle getDefaultStyle(TypeDefinition typeDef, @Nullable DataSet dataSet) {
    // GeometrySchemaService gss = (GeometrySchemaService) PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
    // List<QName> geomPath = gss.getDefaultGeometry(typeDef);
    // TODO determine default style from default geometry?
    Color defColor;
    if (dataSet != null) {
        defColor = StylePreferences.getDefaultColor(dataSet);
    } else {
        defColor = Color.DARK_GRAY;
    }
    int defWidth = StylePreferences.getDefaultWidth();
    FeatureTypeStyle result;
    // XXX for now create a polygon style in any case, as it contains fill
    // and stroke
    // if (type != null) {
    // if (type.isAssignableFrom(Polygon.class)
    // || type.isAssignableFrom(MultiPolygon.class)) {
    result = createPolygonStyle(defColor, defWidth);
    // } else if (type.isAssignableFrom(LineString.class)
    // || type.isAssignableFrom(MultiLineString.class)) {
    // result = createLineStyle(defColor, defWidth);
    // } else {
    // result = createPointStyle(defColor, defWidth);
    // }
    // }
    // else {
    // result = createPointStyle(defColor, defWidth);
    // }
    // XXX StyleBuilder does not support feature type names with namespace
    // QName name = getFeatureTypeName(typeDef);
    // result.featureTypeNames().add(new NameImpl(name.getNamespaceURI(), name.getLocalPart()));
    result.featureTypeNames().add(new NameImpl(getFeatureTypeName(typeDef)));
    return result;
}
Also used : NameImpl(org.geotools.feature.NameImpl) Color(java.awt.Color) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Example 68 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.

the class StyleServiceImpl method getStyle.

/**
 * This implementation will build a simple style if none is defined
 * previously.
 *
 * @see StyleService#getStyle(TypeDefinition, DataSet)
 */
@Override
public Style getStyle(TypeDefinition type, @Nullable DataSet dataSet) {
    FeatureTypeStyle fts = styles.get(type);
    Style style = styleFactory.createStyle();
    if (fts != null) {
        style.featureTypeStyles().add(fts);
    } else {
        if (fbStyle != null) {
            style.featureTypeStyles().add(fbStyle);
        } else {
            style.featureTypeStyles().add(StyleHelper.getDefaultStyle(type, dataSet));
        }
    }
    return style;
}
Also used : Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle)

Example 69 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.

the class SLDUtilsTest method testFindRule.

@Test
public void testFindRule() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
    Rule actualRule = SLDUtils.findRule(sld, rule, sldCopy);
    assertNotNull(actualRule);
    assertEquals(rule.getName(), actualRule.getName());
    actualRule = SLDUtils.findRule(sld, null, sldCopy);
    assertNull(actualRule);
    actualRule = SLDUtils.findRule(sld, rule, null);
    assertNull(actualRule);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) DuplicatingStyleVisitor(org.geotools.styling.visitor.DuplicatingStyleVisitor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Test(org.junit.Test)

Example 70 with FeatureTypeStyle

use of org.geotools.styling.FeatureTypeStyle in project sldeditor by robward-scisys.

the class SLDUtilsTest method testFindSymbolizer.

@Test
public void testFindSymbolizer() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
    Symbolizer actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, sldCopy);
    assertNotNull(actualSymbolizer);
    assertEquals(symbolizer.getLabel().toString(), ((TextSymbolizer) actualSymbolizer).getLabel().toString());
    actualSymbolizer = SLDUtils.findSymbolizer(sld, null, sldCopy);
    assertNull(actualSymbolizer);
    actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, null);
    assertNull(actualSymbolizer);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) DuplicatingStyleVisitor(org.geotools.styling.visitor.DuplicatingStyleVisitor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) Test(org.junit.Test)

Aggregations

FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)110 Style (org.geotools.styling.Style)81 Rule (org.geotools.styling.Rule)65 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)43 Test (org.junit.Test)42 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)24 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)21 LineSymbolizer (org.geotools.styling.LineSymbolizer)20 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)17 Symbolizer (org.geotools.styling.Symbolizer)16 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)15 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)14 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)12 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)12 TextSymbolizer (org.geotools.styling.TextSymbolizer)12 UserLayerImpl (org.geotools.styling.UserLayerImpl)12 ArrayList (java.util.ArrayList)11 LineStyle (org.polymap.core.style.model.feature.LineStyle)11