public Fill createFill( Expression color, Expression backgroundColor, Expression opacity, Graphic graphicFill) { Fill fill = new FillImpl(filterFactory); if (color == null) { color = Fill.DEFAULT.getColor(); } fill.setColor(color); if (backgroundColor == null) { backgroundColor = Fill.DEFAULT.getBackgroundColor(); } fill.setBackgroundColor(backgroundColor); if (opacity == null) { opacity = Fill.DEFAULT.getOpacity(); } // would be nice to check if this was within bounds but we have to wait until use since it // may depend on an attribute fill.setOpacity(opacity); fill.setGraphicFill(graphicFill); return fill; }
/** @see org.geotools.styling.StyleVisitor#visit(org.geotools.styling.Fill) */ public void visit(Fill fill) { if (fill.getBackgroundColor() != null) { fill.getBackgroundColor().accept(this, null); } if (fill.getColor() != null) { fill.getColor().accept(this, null); } if (fill.getGraphicFill() != null) { fill.getGraphicFill().accept(this); } if (fill.getOpacity() != null) { fill.getOpacity().accept(this, null); } }
/** * Null safe fill copy * * @param graphic * @return copy of graphic or null if not provided */ protected Fill copy(Fill fill) { if (fill == null) return null; fill.accept(this); return (Fill) pages.pop(); }
/** Reset to produce the default Fill. */ public FillBuilder reset() { unset = false; color = Fill.DEFAULT.getColor(); opacity = Fill.DEFAULT.getOpacity(); graphic.unset(); return this; }
@Override protected void encode(Fill fill) { putColor("fill-color", fill.getColor()); put("fill-opacity", nullIf(fill.getOpacity(), 1d)); if (fill.getGraphicFill() != null) { push("fill-graphic").inline(new GraphicEncoder(fill.getGraphicFill())); } } }
if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("setting fill graphic with " + g); fill.setGraphicFill(g); fill.setColor(parseCssParameter(child)); } else if (res.equalsIgnoreCase(opacityString) || res.equalsIgnoreCase("fill-opacity")) { fill.setOpacity(parseCssParameter(child)); LOGGER.finest("fill graphic " + fill.getGraphicFill());
@Test public void testRescalePolygonMargin() throws Exception { // create a graphic that needs rescaling StyleBuilder sb = new StyleBuilder(); // a graphic fill Fill fill = sb.createFill(); fill.setColor(null); fill.setGraphicFill( sb.createGraphic(null, sb.createMark("square", null, sb.createStroke(2)), null)); // a polygon and line symbolizer using them PolygonSymbolizer polygonSymbolizer = sb.createPolygonSymbolizer(sb.createStroke(), fill); polygonSymbolizer.getOptions().put(PolygonSymbolizer.GRAPHIC_MARGIN_KEY, "1 2 3 4"); // rescale it polygonSymbolizer.accept(visitor); PolygonSymbolizer rps = (PolygonSymbolizer) visitor.getCopy(); Mark rm = (Mark) rps.getFill().getGraphicFill().graphicalSymbols().get(0); assertEquals(4.0, rm.getStroke().getWidth().evaluate(null, Double.class), 0d); assertEquals("2 4 6 8", rps.getOptions().get(PolygonSymbolizer.GRAPHIC_MARGIN_KEY)); } }
/** * Retrieve the color of a fill object * * @param fill a Fill object * @return color or null if fill was null */ public static Color color(Fill fill) { if (fill == null) { return null; } return color(fill.getColor()); }
public Fill getDefaultFill() { Fill fill = new FillImpl(filterFactory); try { fill.setColor(filterFactory.literal("#808080")); fill.setOpacity(filterFactory.literal(new Double(1.0))); fill.setBackgroundColor(filterFactory.literal("#FFFFFF")); } catch (org.geotools.filter.IllegalFilterException ife) { throw new RuntimeException("Error creating fill", ife); } return fill; }
protected Paint getPaint(Fill fill, Object feature, Symbolizer symbolizer) { if (fill == null) { return null; } // get fill color Paint fillPaint = evalToColor(fill.getColor(), feature, null); // if a graphic fill is to be used, prepare the paint accordingly.... org.geotools.styling.Graphic gr = fill.getGraphicFill(); if (gr != null && gr.graphicalSymbols() != null && gr.graphicalSymbols().size() > 0) { fillPaint = getTexturePaint(gr, feature, symbolizer); } return fillPaint; }
@Override public void handle(YamlObject<?> obj, YamlParseContext context) { YamlMap map = obj.map(); if (map.has("fill-color")) { fill().setColor(Util.color(map.get("fill-color"), factory)); } if (map.has("fill-opacity")) { fill().setOpacity(Util.expression(map.str("fill-opacity"), factory)); } context.push( "fill-graphic", new GraphicParser(factory) { @Override protected void graphic(Graphic g) { fill().setGraphicFill(g); } }); }
/** * Retrieve the opacity from the provided fill; or return the default. * * @param fill * @return opacity from the above fill; or return the Fill.DEFAULT value */ public static double opacity(Fill fill) { if (fill == null) { fill = Fill.DEFAULT; } Expression opacityExp = fill.getOpacity(); if (opacityExp == null) { opacityExp = Fill.DEFAULT.getOpacity(); } return Filters.asDouble(opacityExp); }
@Test public void testSEStyleWithRelativePathProtocol() throws IOException { StyleInfo si = getCatalog().getStyleByName("relative_protocol"); assertNotNull(si); Style style = si.getStyle(); PolygonSymbolizer ps = (PolygonSymbolizer) style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); ExternalGraphic eg = (ExternalGraphic) ps.getFill().getGraphicFill().graphicalSymbols().get(0); URI uri = eg.getOnlineResource().getLinkage(); assertNotNull(uri); File actual = URLs.urlToFile(uri.toURL()).getCanonicalFile(); assertEquals(rockFillSymbolFile, actual); }
if (fill.getGraphicFill() != null) { double size = evalToDouble(fill.getGraphicFill().getSize(), feature, 0); if (isVectorRenderingEnabled() || size > MAX_RASTERIZATION_SIZE) { feature, symbolizer, fill.getGraphicFill(), scaleRange, false); if (!(style2DFill instanceof GraphicStyle2D)) { style.setGraphicFill(style2DFill); opacity = evalOpacity(symbolizer.getFill().getOpacity(), feature);
fill.setOpacity(opacity); fill.setGraphicFill(graphicFill);
@Override public void visit(TextSymbolizer text) { super.visit(text); TextSymbolizer textCopy = (TextSymbolizer) pages.peek(); Fill textFill = textCopy.getFill(); if (textFill != null) { textFill.setOpacity(textExp); } else { textCopy.setFill(defaultTextFill); } } }
private void butFillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butFillActionPerformed JDialog dia = new JDialog(); JGraphicPane pane = new JGraphicPane(); pane.setLayer(layer); if (fill != null) { pane.setEdited(fill.getGraphicFill()); } dia.setContentPane(pane); dia.pack(); dia.setLocationRelativeTo(butFill); dia.setModal(true); dia.setVisible(true); if (fill == null) { fill = new StyleBuilder().createFill(); } fill.setGraphicFill(pane.getEdited()); }//GEN-LAST:event_butFillActionPerformed
/** * Sets the colour to use for outline (stroke) and fill in a polygon symbolizer * * @param symbolizer the polygon symbolizer * @param colour the colour for polygon outlines and fill */ public static void setPolyColour(PolygonSymbolizer symbolizer, Color colour) { if (symbolizer == null || colour == null) { return; } Expression colourExp = ff.literal(colour); Stroke stroke = symbolizer.getStroke(); if (stroke == null) { stroke = sf.createStroke(colourExp, Stroke.DEFAULT.getWidth()); symbolizer.setStroke(stroke); } else { stroke.setColor(ff.literal(colour)); } Fill fill = symbolizer.getFill(); if (fill != null) { fill.setColor(colourExp); } }
@Override protected void graphic(Graphic g) { fill().setGraphicFill(g); } });
public void visit(Fill fill) { start("Fill"); if (fill.getGraphicFill() != null) { start("GraphicFill"); fill.getGraphicFill().accept(this); end("GraphicFill"); } encodeCssParam("fill", fill.getColor(), "#808080"); encodeCssParam("fill-opacity", fill.getOpacity(), 1.0); end("Fill"); }