Search in sources :

Example 31 with Symbolizer

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

the class SymbolizerTreeItemTest method testGetTreeString.

/**
 * Test method for {@link
 * com.sldeditor.ui.tree.item.SymbolizerTreeItem#getTreeString(java.lang.Object)}.
 */
@Test
public void testGetTreeString() {
    SymbolizerTreeItem item = new SymbolizerTreeItem();
    String actualValue = item.getTreeString(null, null);
    assertNull(actualValue);
    Symbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    actualValue = item.getTreeString(null, pointSymbolizer);
    String expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.newMarker");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    pointSymbolizer.setName(null);
    actualValue = item.getTreeString(null, pointSymbolizer);
    expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.marker");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    Symbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    actualValue = item.getTreeString(null, lineSymbolizer);
    expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.line");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    Symbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    actualValue = item.getTreeString(null, polygonSymbolizer);
    expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.polygon");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    Symbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    actualValue = item.getTreeString(null, textSymbolizer);
    expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.newText");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    textSymbolizer.setName("");
    actualValue = item.getTreeString(null, textSymbolizer);
    expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.text");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    Symbolizer rasterSymbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
    actualValue = item.getTreeString(null, rasterSymbolizer);
    expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.raster");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
}
Also used : SymbolizerTreeItem(com.sldeditor.ui.tree.item.SymbolizerTreeItem) Symbolizer(org.geotools.styling.Symbolizer) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.jupiter.api.Test)

Example 32 with Symbolizer

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

the class SymbolizerTreeItemTest method testItemSelected.

/**
 * Test method for {@link
 * com.sldeditor.ui.tree.item.SymbolizerTreeItem#itemSelected(javax.swing.tree.DefaultMutableTreeNode,
 * java.lang.Object)}.
 */
@Test
public void testItemSelected() {
    SymbolizerTreeItem item = new SymbolizerTreeItem();
    item.itemSelected(null, null);
    Symbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    Rule rule = DefaultSymbols.createNewRule();
    DefaultMutableTreeNode parentNode = new DefaultMutableTreeNode();
    parentNode.setUserObject(rule);
    DefaultMutableTreeNode node = new DefaultMutableTreeNode();
    parentNode.add(node);
    item.itemSelected(node, symbolizer);
    // Get the code coverage stats up
    item.itemSelected(parentNode, symbolizer);
    parentNode.setUserObject(item);
    item.itemSelected(node, null);
}
Also used : SymbolizerTreeItem(com.sldeditor.ui.tree.item.SymbolizerTreeItem) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Rule(org.geotools.styling.Rule) Symbolizer(org.geotools.styling.Symbolizer) Test(org.junit.jupiter.api.Test)

Example 33 with Symbolizer

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

the class SLDExternalImages method externalGraphicSymbolVisitor.

/**
 * Find the SLD graphical symbols.
 *
 * @param resourceLocator the resource locator
 * @param sld the sld
 * @param externalImageList the external image list
 * @param process the process
 */
private static void externalGraphicSymbolVisitor(URL resourceLocator, StyledLayerDescriptor sld, List<String> externalImageList, ProcessGraphicSymbolInterface process) {
    if (sld == null) {
        return;
    }
    if (process == null) {
        return;
    }
    for (StyledLayer styledLayer : sld.layers()) {
        List<Style> styles = null;
        if (styledLayer instanceof NamedLayer) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) styledLayer;
            styles = namedLayer.styles();
        } else if (styledLayer instanceof UserLayer) {
            UserLayerImpl userLayer = (UserLayerImpl) styledLayer;
            styles = userLayer.userStyles();
        }
        if (styles != null) {
            for (Style style : styles) {
                for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                    for (Rule rule : fts.rules()) {
                        for (Symbolizer symbolizer : rule.symbolizers()) {
                            if (symbolizer instanceof PointSymbolizer) {
                                PointSymbolizer point = (PointSymbolizer) symbolizer;
                                if (point.getGraphic() != null) {
                                    process.processGraphicalSymbol(resourceLocator, point.getGraphic().graphicalSymbols(), externalImageList);
                                }
                            } else if (symbolizer instanceof LineSymbolizer) {
                                LineSymbolizer line = (LineSymbolizer) symbolizer;
                                updateStroke(resourceLocator, line.getStroke(), externalImageList, process);
                            } else if (symbolizer instanceof PolygonSymbolizer) {
                                PolygonSymbolizer polygon = (PolygonSymbolizer) symbolizer;
                                updateStroke(resourceLocator, polygon.getStroke(), externalImageList, process);
                                updateFill(resourceLocator, polygon.getFill(), externalImageList, process);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) StyledLayer(org.geotools.styling.StyledLayer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) UserLayerImpl(org.geotools.styling.UserLayerImpl) 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) UserLayer(org.geotools.styling.UserLayer) NamedLayer(org.geotools.styling.NamedLayer)

Example 34 with Symbolizer

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

the class StyleCompositeSerializer method defaultFeatureTypeStyle.

protected FeatureTypeStyle defaultFeatureTypeStyle(org.geotools.styling.Style result, Style style, Symbolizer... symbolizers) {
    Rule rule = sf.createRule();
    // handle visibleIf
    FilterStyleProperty visibleIf = (FilterStyleProperty) style.visibleIf.get();
    if (visibleIf instanceof ScaleRangeFilter) {
        rule.setMinScaleDenominator(((ScaleRangeFilter) visibleIf).minScale.get());
        rule.setMaxScaleDenominator(((ScaleRangeFilter) visibleIf).maxScale.get());
    } else if (visibleIf instanceof ConstantFilter) {
        Filter filter = ((ConstantFilter) visibleIf).filter();
        if (!filter.equals(Filter.INCLUDE)) {
            rule.setFilter(filter);
        }
    } else {
        throw new RuntimeException("Unhandled Style.visibleIf type: " + visibleIf.getClass());
    }
    for (Symbolizer s : symbolizers) {
        rule.symbolizers().add(s);
    }
    ;
    FeatureTypeStyle fts = sf.createFeatureTypeStyle();
    fts.rules().add(rule);
    result.featureTypeStyles().add(fts);
    return fts;
}
Also used : ScaleRangeFilter(org.polymap.core.style.model.feature.ScaleRangeFilter) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Filter(org.opengis.filter.Filter) FilterStyleProperty(org.polymap.core.style.model.feature.FilterStyleProperty) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) Symbolizer(org.geotools.styling.Symbolizer) ScaleRangeFilter(org.polymap.core.style.model.feature.ScaleRangeFilter)

Example 35 with Symbolizer

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

the class DefinitionImages method getLegendImage.

/**
 * Get a legend image for a given type definition
 *
 * @param type the type definition
 * @param dataSet the data set the type definition belongs to
 * @param definedOnly if only for defined styles a image shall be created
 * @return the legend image or <code>null</code>
 */
protected BufferedImage getLegendImage(TypeDefinition type, DataSet dataSet, boolean definedOnly) {
    StyleService ss = PlatformUI.getWorkbench().getService(StyleService.class);
    Style style = (definedOnly) ? (ss.getDefinedStyle(type)) : (ss.getStyle(type, dataSet));
    if (style == null) {
        return null;
    }
    // create a dummy feature based on the style
    Drawer d = Drawer.create();
    SimpleFeature feature = null;
    Symbolizer[] symbolizers = SLD.symbolizers(style);
    if (symbolizers.length > 0) {
        Symbolizer symbolizer = symbolizers[0];
        if (symbolizer instanceof LineSymbolizer) {
            feature = d.feature(d.line(LINE_POINTS));
        } else if (symbolizer instanceof PointSymbolizer) {
            feature = d.feature(d.point(WIDTH / 2, HEIGHT / 2));
        }
        if (symbolizer instanceof PolygonSymbolizer) {
            feature = d.feature(d.polygon(POLY_POINTS));
        }
    }
    if (feature != null) {
        BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
        // GraphicsEnvironment.getLocalGraphicsEnvironment().
        // getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(WIDTH, HEIGHT,
        // Transparency.TRANSLUCENT);
        // use white background to have a neutral color even if selected
        Color bg = Color.WHITE;
        Graphics2D g = image.createGraphics();
        try {
            g.setColor(bg);
            g.fillRect(0, 0, WIDTH, HEIGHT);
        } finally {
            g.dispose();
        }
        d.drawDirect(image, feature, style);
        return image;
    }
    return null;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) StyleService(eu.esdihumboldt.hale.ui.common.service.style.StyleService) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) Color(java.awt.Color) Style(org.geotools.styling.Style) Drawer(org.geotools.map.legend.Drawer) SimpleFeature(org.opengis.feature.simple.SimpleFeature) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

Symbolizer (org.geotools.styling.Symbolizer)65 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)29 LineSymbolizer (org.geotools.styling.LineSymbolizer)28 PointSymbolizer (org.geotools.styling.PointSymbolizer)27 Rule (org.geotools.styling.Rule)21 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)20 Style (org.geotools.styling.Style)18 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)15 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)14 Test (org.junit.jupiter.api.Test)13 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 JsonObject (com.google.gson.JsonObject)11 StyledLayer (org.geotools.styling.StyledLayer)11 NamedLayer (org.geotools.styling.NamedLayer)10 ArrayList (java.util.ArrayList)8 JsonElement (com.google.gson.JsonElement)7 Stroke (org.geotools.styling.Stroke)6 JsonArray (com.google.gson.JsonArray)5 Expression (org.opengis.filter.expression.Expression)5