Search in sources :

Example 16 with Fill

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

the class SelectedSymbolTest method getGraphic.

/**
 * Gets the graphic.
 *
 * @param symbolizer the symbolizer
 * @return the graphic
 */
private Graphic getGraphic(Symbolizer symbolizer) {
    Graphic graphic = null;
    if (symbolizer instanceof PointSymbolizerImpl) {
        PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
        graphic = pointSymbolizer.getGraphic();
    } else if (symbolizer instanceof PolygonSymbolizerImpl) {
        PolygonSymbolizer polygonSymbolizer = (PolygonSymbolizer) symbolizer;
        if (polygonSymbolizer != null) {
            Fill fill = polygonSymbolizer.getFill();
            if (fill != null) {
                graphic = fill.getGraphicFill();
            }
        }
    }
    return graphic;
}
Also used : PolygonSymbolizerImpl(org.geotools.styling.PolygonSymbolizerImpl) PointSymbolizer(org.geotools.styling.PointSymbolizer) Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Graphic(org.geotools.styling.Graphic) PointSymbolizerImpl(org.geotools.styling.PointSymbolizerImpl)

Example 17 with Fill

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

the class SelectedSymbolTest method testGetGraphic.

/**
 * Test method for {@link com.sldeditor.common.data.SelectedSymbol#getGraphic()}.
 */
@Test
public void testGetGraphic() {
    SelectedSymbol.destroyInstance();
    SelectedSymbol instance = SelectedSymbol.getInstance();
    // CHECKSTYLE:OFF
    Rule rule = DefaultSymbols.createNewRule();
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    Style style = DefaultSymbols.createNewStyle();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    // CHECKSTYLE:ON
    instance.createNewSLD(sld);
    instance.setSld(sld);
    System.out.println("Select named layer");
    instance.addNewStyledLayer(namedLayer);
    instance.setStyledLayer(namedLayer);
    instance.addNewStyle(style);
    instance.setStyle(style);
    instance.addNewFeatureTypeStyle(fts);
    instance.setFeatureTypeStyle(fts);
    instance.addNewRule(rule);
    instance.setRule(rule);
    instance.addSymbolizerToRule(symbolizer);
    instance.setSymbolizer(symbolizer);
    Graphic graphic = getGraphic(symbolizer);
    assertNull(graphic);
    Fill graphicFill = DefaultSymbols.createDefaultGraphicFill();
    PolygonSymbolizer newSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    newSymbolizer.setFill(graphicFill);
    instance.addSymbolizerToRule(newSymbolizer);
    instance.setSymbolizer(newSymbolizer);
    graphic = getGraphic(newSymbolizer);
    assertNotNull(graphic);
    assertTrue(instance.hasFill());
    assertTrue(instance.hasStroke());
    LineSymbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    instance.addSymbolizerToRule(lineSymbolizer);
    instance.setSymbolizer(lineSymbolizer);
    graphic = getGraphic(lineSymbolizer);
    assertNull(graphic);
    assertFalse(instance.hasFill());
    assertTrue(instance.hasStroke());
    PointSymbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    instance.addSymbolizerToRule(pointSymbolizer);
    instance.setSymbolizer(pointSymbolizer);
    graphic = getGraphic(pointSymbolizer);
    assertNotNull(graphic);
    assertTrue(instance.hasFill());
    assertFalse(instance.hasStroke());
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) PointSymbolizer(org.geotools.styling.PointSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Graphic(org.geotools.styling.Graphic) LineSymbolizer(org.geotools.styling.LineSymbolizer) 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) Test(org.junit.Test)

Example 18 with Fill

use of org.geotools.styling.Fill in project polymap4-core by Polymap4.

the class DefaultStyles method createPolygonStyle.

/**
 * Create a Style to draw polygon features with a thin blue outline and
 * a cyan fill
 */
public static Style createPolygonStyle(Style style) {
    // create a partially opaque outline stroke
    Stroke stroke = sf.createStroke(ff.literal(Color.DARK_GRAY), ff.literal(0.5), ff.literal(0.5));
    // create a partial opaque fill
    Fill fill = sf.createFill(ff.literal(Color.CYAN), ff.literal(0.5));
    /*
         * Setting the geometryPropertyName arg to null signals that we want to
         * draw the default geometry of features
         */
    PolygonSymbolizer sym = sf.createPolygonSymbolizer(stroke, fill, null);
    Rule rule = sf.createRule();
    rule.setName("Rule for PolygonSymbolizer");
    rule.symbolizers().add(sym);
    style.featureTypeStyles().get(0).rules().add(rule);
    return style;
}
Also used : Stroke(org.geotools.styling.Stroke) Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Rule(org.geotools.styling.Rule)

Example 19 with Fill

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

the class StyleHelper method createPolygonSymbolizer.

/**
 * Create a default polygon symbolizer.
 *
 * @param color the color
 * @param width the line width
 * @return the polygon symbolizer
 */
public static PolygonSymbolizer createPolygonSymbolizer(Color color, double width) {
    PolygonSymbolizer symbolizer = styleFactory.createPolygonSymbolizer();
    SLD.setPolyColour(symbolizer, color);
    symbolizer.getStroke().setWidth(filterFactory.literal(width));
    Fill fill = styleFactory.createFill(filterFactory.literal(color), filterFactory.literal(DEFAULT_FILL_OPACITY));
    symbolizer.setFill(fill);
    return symbolizer;
}
Also used : Fill(org.geotools.styling.Fill) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer)

Example 20 with Fill

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

the class SelectedSymbolTest method testGetSymbolList.

/**
 * Test method for
 * {@link com.sldeditor.common.data.SelectedSymbol#getSymbolList(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testGetSymbolList() {
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Stroke stroke = null;
    Fill fill = styleFactory.createFill(ff.literal(DefaultSymbols.defaultColour()));
    GraphicalSymbol symbolToAdd = styleFactory.mark(ff.literal("circle"), fill, stroke);
    List<GraphicalSymbol> symbolList = SelectedSymbol.getInstance().getSymbolList(symbolToAdd);
    assertEquals(1, symbolList.size());
    assertEquals(symbolToAdd, symbolList.get(0));
}
Also used : Stroke(org.opengis.style.Stroke) Fill(org.geotools.styling.Fill) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) GraphicalSymbol(org.opengis.style.GraphicalSymbol) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Aggregations

Fill (org.geotools.styling.Fill)39 Expression (org.opengis.filter.expression.Expression)23 Stroke (org.geotools.styling.Stroke)18 GraphicFill (org.opengis.style.GraphicFill)17 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)14 GraphicalSymbol (org.opengis.style.GraphicalSymbol)14 Graphic (org.geotools.styling.Graphic)13 ArrayList (java.util.ArrayList)11 Mark (org.geotools.styling.Mark)11 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)10 JsonObject (com.google.gson.JsonObject)9 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)8 AnchorPoint (org.geotools.styling.AnchorPoint)7 Displacement (org.geotools.styling.Displacement)7 PointSymbolizer (org.geotools.styling.PointSymbolizer)6 Test (org.junit.Test)6 ExternalGraphic (org.geotools.styling.ExternalGraphic)5 JsonElement (com.google.gson.JsonElement)4 MarkImpl (org.geotools.styling.MarkImpl)4 Symbolizer (org.geotools.styling.Symbolizer)4