SimpleFeatureFigureFactory implements FigureFactory { static String getStyleCss(SimpleFeature simpleFeature, String defaultStyleCss) { Object styleAttribute = simpleFeature.getAttribute(PlainFeatureFactory.ATTRIB_NAME_STYLE_CSS); if (styleAttribute instanceof String) { String css = (String) styleAttribute; if (!css.trim().isEmpty()) { final StringBuilder sb = new StringBuilder(css); final String[] cssAttributes = defaultStyleCss.split(";"); for (String cssAttribute : cssAttributes) { if (!css.contains(cssAttribute.split(":")[0].trim())) { sb.append(";"); sb.append(cssAttribute); } } return sb.toString(); } } return defaultStyleCss; } SimpleFeatureFigureFactory(SimpleFeatureType simpleFeatureType); @Override PointFigure createPointFigure(Point2D point, FigureStyle style); @Override ShapeFigure createLineFigure(Shape shape, FigureStyle style); @Override ShapeFigure createPolygonFigure(Shape shape, FigureStyle style); PointFigure createPointFigure(Point geometry, FigureStyle style); SimpleFeatureFigure createSimpleFeatureFigure(SimpleFeature simpleFeature, String defaultStyleCss); ShapeFigure createShapeFigure(Geometry geometry, FigureStyle style); SimpleFeature createSimpleFeature(Geometry geometry); FigureStyle deriveSelectedStyle(FigureStyle style);  }
@Test public void testGetStyleCss_WithAdditionalStyles() throws Exception { simpleFeature.setAttribute(PlainFeatureFactory.ATTRIB_NAME_STYLE_CSS, "fill:120,120,120;stroke:0,10,0"); final String styleCss = SimpleFeatureFigureFactory.getStyleCss(simpleFeature, "symbol:pin"); assertEquals("fill:120,120,120;stroke:0,10,0;symbol:pin", styleCss); }
@Test public void testGetStyleCss_WithOverride() throws Exception { simpleFeature.setAttribute(PlainFeatureFactory.ATTRIB_NAME_STYLE_CSS, "symbol:cross;fill:100,100,100"); final String styleCss = SimpleFeatureFigureFactory.getStyleCss(simpleFeature, "symbol:pin;fill:0,0,0"); assertEquals("symbol:cross;fill:100,100,100", styleCss); }
@Test public void testGetStyleCss_WithOverrideAndDefaultValue() throws Exception { simpleFeature.setAttribute(PlainFeatureFactory.ATTRIB_NAME_STYLE_CSS, "fill:120,120,120;stroke:0,10,0"); final String styleCss = SimpleFeatureFigureFactory.getStyleCss(simpleFeature, "symbol:pin;fill:0,0,0"); assertEquals("fill:120,120,120;stroke:0,10,0;symbol:pin", styleCss); }
@Test public void testGetStyleCss_KeepDefault() throws Exception { simpleFeature.setAttribute(PlainFeatureFactory.ATTRIB_NAME_STYLE_CSS, ""); final String styleCss = SimpleFeatureFigureFactory.getStyleCss(simpleFeature, "symbol:pin;fill:0,0,0"); assertEquals("symbol:pin;fill:0,0,0", styleCss); }
@Test public void testGetStyleCss_EmptyDefault() throws Exception { simpleFeature.setAttribute(PlainFeatureFactory.ATTRIB_NAME_STYLE_CSS, "symbol:cross;fill:100,100,100"); final String styleCss = SimpleFeatureFigureFactory.getStyleCss(simpleFeature, ""); assertEquals("symbol:cross;fill:100,100,100", styleCss); }