public void visit(ColorMapEntry colorMapEntry) { ColorMapEntry copy = sf.createColorMapEntry(); copy.setColor(copy(colorMapEntry.getColor())); copy.setLabel(colorMapEntry.getLabel()); copy.setOpacity(copy(colorMapEntry.getOpacity())); copy.setQuantity(copy(colorMapEntry.getQuantity())); if (STRICT && !copy.equals(colorMapEntry)) { throw new IllegalStateException( "Was unable to duplicate provided ColorMapEntry:" + colorMapEntry); } pages.push(copy); }
public void visit(ColorMapEntry entry) { entry.accept(this); }
@Override public ColorMapEntryBuilder reset(ColorMapEntry original) { if (original == null) { return unset(); } label = original.getLabel(); color = original.getColor(); opacity = original.getOpacity(); quantity = original.getQuantity(); unset = false; return this; }
@Override public ColorMapEntry build() { if (unset) { return null; } ColorMapEntry entry = sf.createColorMapEntry(); entry.setLabel(label); entry.setColor(color); entry.setOpacity(opacity); entry.setQuantity(quantity); if (parent == null) { reset(); } return entry; }
private void assertEntry(ColorMapEntry entry, double quantity, Color color, float opacity) { assertEquals(quantity, entry.getQuantity().evaluate(null, Double.class), 0d); assertEquals(color, entry.getColor().evaluate(null, Color.class)); assertEquals(opacity, entry.getOpacity().evaluate(null, Double.class), 0.01f); } }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { ColorMapEntry entry = styleFactory.createColorMapEntry(); // <xsd:element ref="se:Data"/> entry.setQuantity(filterFactory.literal(node.getChildValue("Data"))); // <xsd:element ref="se:Value"/> entry.setColor((Expression) node.getChildValue("Value")); return entry; } }
@Test public void testRasterWithDiscreteColors() throws Exception { // <UserStyle> // <Title>SLD Cook Book: Discrete colors</Title> // <FeatureTypeStyle> // <Rule> // <RasterSymbolizer> // <ColorMap type="intervals"> // <ColorMapEntry color="#008000" quantity="150" /> // <ColorMapEntry color="#663333" quantity="256" /> // </ColorMap> // </RasterSymbolizer> // </Rule> // </FeatureTypeStyle> // </UserStyle> Style style = parse("raster", "discrete-colors.sld"); RasterSymbolizer raster = SLD.rasterSymbolizer(style); ColorMapEntry e = raster.getColorMap().getColorMapEntry(0); assertEquals("#008000", Filters.asString(e.getColor())); assertEquals(150, Filters.asInt(e.getQuantity())); e = raster.getColorMap().getColorMapEntry(1); assertEquals("#663333", Filters.asString(e.getColor())); assertEquals(256, Filters.asInt(e.getQuantity())); }
private ColorMapEntry getColorMapEntry(double min, double range) { ColorMapEntry entry = new ColorMapEntryImpl(); entry.setOpacity(filterFactory.literal(opacity)); entry.setColor(filterFactory.literal(toHexColor(color))); entry.setQuantity( filterFactory.literal(min + (Double.isNaN(range) ? 0 : (percentage * range)))); return entry; } }
private void fillColorInEntry(ColorMapEntry startEntry, Color color) { if (color == null) { color = TRANSPARENT; } startEntry.setColor(filterFactory.literal(toHexColor(color))); startEntry.setOpacity(filterFactory.literal(color.getAlpha() / 255.)); }
public void visit(ColorMapEntry cme) { if (cme.getOpacity() != null) { checkOpacity(cme.getOpacity()); } }
/** * @param entry * @return * @throws NumberFormatException */ private static Color getColor(ColorMapEntry entry) throws NumberFormatException { ColorMapUtilities.ensureNonNull("ColorMapEntry", entry); Expression color = entry.getColor(); ColorMapUtilities.ensureNonNull("color", color); String colorString = (String) color.evaluate(null, String.class); if (colorString != null && colorString.startsWith("${")) { color = ExpressionExtractor.extractCqlExpressions(colorString); colorString = color.evaluate(null, String.class); } ColorMapUtilities.ensureNonNull("colorString", colorString); return Color.decode(colorString); }
String label = colorMapEntry.getLabel(); label = label == null ? "ColorMapEntry" + this.colormapElements.size() : label;
public Color[] getColors(final int band) { Color[] colorTable = null; if (this.symbolizer.getColorMap() != null) { final ColorMapEntry[] colors = this.symbolizer.getColorMap() .getColorMapEntries(); final int numColors = colors.length; colorTable = new Color[numColors]; double opacity; for (int ci = 0; ci < numColors; ci++) { opacity = toOpacity( colors[ci].getOpacity() ); colorTable[ci] = toColor( colors[ci].getColor(), opacity ); if (colorTable[ci] == null){ return null; } } } return colorTable; } public static Color toColor( Expression exp, double opacity ){
assertEquals(0, entries[0].getOpacity().evaluate(null, Double.class), TOLERANCE); assertEquals( 0, entries[FilterFunction_svgColorMap.LOG_SAMPLING_DEFAULT + 1] .getOpacity() .evaluate(null, Double.class), TOLERANCE); "Failed at " + i, expected, entries[i + 1].getQuantity().evaluate(null, Double.class), TOLERANCE); 100, entries[FilterFunction_svgColorMap.LOG_SAMPLING_DEFAULT] .getQuantity() .evaluate(null, Double.class), TOLERANCE);
@Test public void testDynamicOpacity() { entry.setOpacity(ff.literal("${0.25*2}")); builder.addColorMapEntry(entry); LinearColorMap colorMap = builder.buildLinearColorMap(); LinearColorMapElement[] domainElements = colorMap.getDomainElements(); assertEquals(1, domainElements.length); assertEquals(1, domainElements[0].getColors().length); assertEquals(128, domainElements[0].getColors()[0].getAlpha()); } }
@Test public void testDynamicColor() { entry.setColor(ff.literal("${strConcat('#FF','0000')}")); builder.addColorMapEntry(entry); LinearColorMap colorMap = builder.buildLinearColorMap(); LinearColorMapElement[] domainElements = colorMap.getDomainElements(); assertEquals(1, domainElements.length); assertEquals(1, domainElements[0].getColors().length); assertEquals(255, domainElements[0].getColors()[0].getRed()); assertEquals(0, domainElements[0].getColors()[0].getGreen()); assertEquals(0, domainElements[0].getColors()[0].getBlue()); }
@Test public void testDynamicQuantity() { entry.setQuantity(ff.literal("${6.0+4.0}")); builder.addColorMapEntry(entry); LinearColorMap colorMap = builder.buildLinearColorMap(); LinearColorMapElement[] domainElements = colorMap.getDomainElements(); assertEquals(1, domainElements.length); assertEquals(10.0, domainElements[0].getInputMinimum(), 0.0); assertEquals(10.0, domainElements[0].getInputMaximum(), 0.0); }
/** * @param entry * @return */ private static double getQuantity(ColorMapEntry entry) { ColorMapUtilities.ensureNonNull("ColorMapEntry", entry); Expression quantity = entry.getQuantity(); ColorMapUtilities.ensureNonNull("quantity", quantity); Double quantityString = (Double) quantity.evaluate(null, Double.class); if (quantityString == null && quantity instanceof Literal) { String quantityExp = quantity.evaluate(null, String.class); quantity = ExpressionExtractor.extractCqlExpressions(quantityExp); quantityString = quantity.evaluate(null, Double.class); } ColorMapUtilities.ensureNonNull("quantityString", quantityString); double q = quantityString.doubleValue(); return q; }
/** * Creates a simple color entity based on a fixed value and a color.<br> * The color alpha will be used as the entry's opacity * * @param quantity The entry's quantity * @param color The entry's color. */ private ColorMapEntry createColorMapEntry(String label, double quantity, Color color) { ColorMapEntry entry = sf.createColorMapEntry(); entry.setQuantity(literalExpression(quantity)); entry.setColor(colorExpression(color)); entry.setOpacity(literalExpression(color.getAlpha() / 255.0)); entry.setLabel(label); return entry; }