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;
}
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());
}
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;
}
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;
}
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));
}
Aggregations