Search in sources :

Example 1 with GraphicalSymbol

use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.

the class FieldConfigWindBarbsTest method testGetValue.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs#getValue(com.sldeditor.ui.detail.GraphicPanelFieldManager, org.opengis.filter.expression.Expression, boolean, boolean)}.
 */
@Test
public void testGetValue() {
    // Test it with null values
    boolean valueOnly = true;
    FieldConfigWindBarbs field = new FieldConfigWindBarbs(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
    field.createUI();
    assertNull(field.getStringValue());
    GraphicPanelFieldManager fieldConfigManager = null;
    Expression symbolType = null;
    List<GraphicalSymbol> actualValue = field.getValue(fieldConfigManager, symbolType, false, false);
    assertTrue(actualValue.isEmpty());
    Class<?> panelId = PointFillDetails.class;
    fieldConfigManager = new GraphicPanelFieldManager(panelId);
    String actualMarkerSymbol = "solid";
    StyleBuilder styleBuilder = new StyleBuilder();
    symbolType = styleBuilder.literalExpression(actualMarkerSymbol);
    FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
    FieldConfigColour colourField = new FieldConfigColour(new FieldConfigCommonData(panelId, colourFieldId, "", false));
    colourField.createUI();
    String expectedColourValue = "#012345";
    colourField.setTestValue(null, expectedColourValue);
    double expectedOpacityValue = 0.72;
    FieldConfigSlider opacityField = new FieldConfigSlider(new FieldConfigCommonData(panelId, colourFieldId, "", false));
    opacityField.createUI();
    opacityField.populateField(expectedOpacityValue);
    FieldConfigBase symbolSelectionField = new FieldConfigSymbolType(new FieldConfigCommonData(panelId, colourFieldId, "", false));
    symbolSelectionField.createUI();
    fieldConfigManager.add(colourFieldId, colourField);
    FieldIdEnum opacityFieldId = FieldIdEnum.OVERALL_OPACITY;
    fieldConfigManager.add(opacityFieldId, opacityField);
    FieldIdEnum symbolSelectionFieldId = FieldIdEnum.SYMBOL_TYPE;
    fieldConfigManager.add(symbolSelectionFieldId, symbolSelectionField);
    // Try without setting any fields
    actualValue = field.getValue(fieldConfigManager, symbolType, false, false);
    assertNotNull(actualValue);
    assertEquals(1, actualValue.size());
    Mark actualSymbol = (Mark) actualValue.get(0);
    assertTrue(actualSymbol.getWellKnownName().toString().compareTo("windbarbs://default(0)[m/s]") == 0);
}
Also used : FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) GraphicalSymbol(org.opengis.style.GraphicalSymbol) StyleBuilder(org.geotools.styling.StyleBuilder) FieldConfigSlider(com.sldeditor.ui.detail.config.FieldConfigSlider) Mark(org.geotools.styling.Mark) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) Expression(org.opengis.filter.expression.Expression) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigWindBarbs(com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) PointFillDetails(com.sldeditor.ui.detail.PointFillDetails) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) FieldConfigSymbolType(com.sldeditor.ui.detail.config.FieldConfigSymbolType) Test(org.junit.Test)

Example 2 with GraphicalSymbol

use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.

the class FieldConfigTTFTest method testGetValue.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.symboltype.ttf.FieldConfigTTF#getValue(com.sldeditor.ui.detail.GraphicPanelFieldManager, org.opengis.filter.expression.Expression, boolean, boolean)}.
 */
@Test
public void testGetValue() {
    GraphicPanelFieldManager fieldConfigManager = null;
    Class<?> panelId = PointFillDetails.class;
    fieldConfigManager = new GraphicPanelFieldManager(panelId);
    FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
    FieldConfigColour colourField = new FieldConfigColour(new FieldConfigCommonData(panelId, colourFieldId, "", false));
    colourField.createUI();
    String expectedColourValue = "#012345";
    colourField.setTestValue(null, expectedColourValue);
    fieldConfigManager.add(colourFieldId, colourField);
    ColourFieldConfig fillConfig = new ColourFieldConfig(GroupIdEnum.FILL, FieldIdEnum.FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_WIDTH);
    ColourFieldConfig strokeConfig = new ColourFieldConfig(GroupIdEnum.STROKE, FieldIdEnum.STROKE_STROKE_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH);
    boolean valueOnly = true;
    FieldConfigTTF field = new FieldConfigTTF(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), fillConfig, strokeConfig, null);
    List<GraphicalSymbol> actualValue = field.getValue(null, null, false, false);
    assertTrue(actualValue.isEmpty());
    field.createUI();
    actualValue = field.getValue(null, null, false, false);
    assertTrue(actualValue.isEmpty());
    actualValue = field.getValue(fieldConfigManager, null, false, false);
    assertTrue(actualValue.size() == 1);
}
Also used : ColourFieldConfig(com.sldeditor.ui.detail.ColourFieldConfig) GraphicalSymbol(org.opengis.style.GraphicalSymbol) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigTTF(com.sldeditor.ui.detail.config.symboltype.ttf.FieldConfigTTF) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) PointFillDetails(com.sldeditor.ui.detail.PointFillDetails) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) Test(org.junit.Test)

Example 3 with GraphicalSymbol

use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.

the class UpdateGraphicalSymbol method processGraphicalSymbol.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.common.data.ProcessGraphicSymbolInterface#processGraphicalSymbol(java.net.URL, java.util.List, java.util.List)
     */
@Override
public void processGraphicalSymbol(URL resourceLocator, List<GraphicalSymbol> graphicalSymbolList, List<String> externalImageList) {
    for (GraphicalSymbol symbol : graphicalSymbolList) {
        if (symbol instanceof ExternalGraphic) {
            ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) symbol;
            OnLineResourceImpl onlineResource = (OnLineResourceImpl) externalGraphic.getOnlineResource();
            String currentValue = null;
            URL currentValueURL = null;
            try {
                currentValueURL = onlineResource.getLinkage().toURL();
                currentValue = currentValueURL.toExternalForm();
            } catch (MalformedURLException e) {
                ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
            }
            if ((resourceLocator == null) || RelativePath.hasHost(currentValueURL)) {
                // Just report back the external image
                URI uri = null;
                try {
                    uri = new URI(currentValue);
                    externalImageList.add(uri.toASCIIString());
                } catch (URISyntaxException e) {
                    ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
                }
            } else {
                try {
                    File file = new File(currentValueURL.getFile());
                    File folder = new File(resourceLocator.getFile());
                    currentValue = RelativePath.getRelativePath(file, folder);
                    // If the backslashes are not converted to forward slashes
                    // creating the URI does not work
                    currentValue = currentValue.replace('\\', '/');
                    OnLineResourceImpl updatedOnlineResource = new OnLineResourceImpl();
                    URI uri = new URI(currentValue);
                    updatedOnlineResource.setLinkage(uri);
                    externalGraphic.setOnlineResource(updatedOnlineResource);
                    externalGraphic.setURI(uri.toASCIIString());
                    externalImageList.add(uri.toASCIIString());
                } catch (URISyntaxException e) {
                    ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
                }
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) GraphicalSymbol(org.opengis.style.GraphicalSymbol) OnLineResourceImpl(org.geotools.metadata.iso.citation.OnLineResourceImpl) URISyntaxException(java.net.URISyntaxException) ExternalGraphic(org.geotools.styling.ExternalGraphic) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Example 4 with GraphicalSymbol

use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.

the class DefaultSymbols method createArrow.

/**
 * Creates the arrow.
 *
 * @param angleFunction the angle function
 * @param locationFunction the location function
 * @param markerSymbol the marker symbol
 * @param isSourceArrow the is source arrow
 * @return the point symbolizer
 */
private static PointSymbolizer createArrow(FunctionName angleFunction, FunctionName locationFunction, String markerSymbol, boolean isSourceArrow) {
    String name = isSourceArrow ? Localisation.getString(SLDTreeTools.class, "TreeItem.sourceArrow") : Localisation.getString(SLDTreeTools.class, "TreeItem.destArrow");
    PointSymbolizer pointSymbolizer = createDefaultPointSymbolizer();
    pointSymbolizer.setName(name);
    Graphic graphic = pointSymbolizer.getGraphic();
    graphic.setSize(ff.literal(DEFAULT_ARROW_SIZE));
    List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
    MarkImpl mark = (MarkImpl) graphicalSymbolList.get(0);
    Expression wellKnownName = ff.literal(markerSymbol);
    mark.setWellKnownName(wellKnownName);
    mark.getFill().setColor(ff.literal(DEFAULT_COLOUR));
    // Arrow rotation
    List<Expression> rotationArgumentList = new ArrayList<Expression>();
    String geometryFieldName = "geom";
    DataSourceInterface dsInfo = DataSourceFactory.getDataSource();
    if (dsInfo != null) {
        geometryFieldName = dsInfo.getGeometryFieldName();
    }
    rotationArgumentList.add(ff.property(geometryFieldName));
    Expression rotation = FunctionManager.getInstance().createExpression(angleFunction, rotationArgumentList);
    if (isSourceArrow) {
        graphic.setRotation(ff.add(ff.literal(DEGREES_180), rotation));
    } else {
        graphic.setRotation(rotation);
    }
    AnchorPoint anchorPoint = styleFactory.anchorPoint(ff.literal(0.5), ff.literal(0.5));
    graphic.setAnchorPoint(anchorPoint);
    // Set location of the arrow head
    List<Expression> endPointArgumentList = new ArrayList<Expression>();
    endPointArgumentList.add(ff.property(geometryFieldName));
    Expression geometry = FunctionManager.getInstance().createExpression(locationFunction, endPointArgumentList);
    pointSymbolizer.setGeometry(geometry);
    return pointSymbolizer;
}
Also used : DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) PointSymbolizer(org.geotools.styling.PointSymbolizer) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) MarkImpl(org.geotools.styling.MarkImpl) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools)

Example 5 with GraphicalSymbol

use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.

the class PolygonFillDetails method populate.

/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    Expression expSize = null;
    Expression expRotation = null;
    Expression expAnchorPointX = null;
    Expression expAnchorPointY = null;
    Expression expDisplacementX = null;
    Expression expDisplacementY = null;
    Expression expFillColour = null;
    Expression expGap = null;
    Expression expInitialGap = null;
    Fill fill = null;
    Expression expOpacity = null;
    symbolizer = null;
    if (selectedSymbol != null) {
        symbolizer = selectedSymbol.getSymbolizer();
        Graphic graphic = null;
        if (symbolizer instanceof PointSymbolizerImpl) {
            PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
            graphic = pointSymbolizer.getGraphic();
            if (graphic != null) {
                List<GraphicalSymbol> graphicSymbolList = graphic.graphicalSymbols();
                if (!graphicSymbolList.isEmpty()) {
                    GraphicalSymbol graphicalSymbol = graphicSymbolList.get(0);
                    if (graphicalSymbol instanceof MarkImpl) {
                        MarkImpl mark = (MarkImpl) graphicalSymbol;
                        fill = mark.getFill();
                        if (fill != null) {
                            expOpacity = fill.getOpacity();
                        }
                    }
                }
            }
        } else if (symbolizer instanceof PolygonSymbolizerImpl) {
            PolygonSymbolizer polygonSymbolizer = (PolygonSymbolizer) symbolizer;
            if (polygonSymbolizer != null) {
                fill = polygonSymbolizer.getFill();
                if (fill != null) {
                    expOpacity = fill.getOpacity();
                    graphic = fill.getGraphicFill();
                }
            }
        }
        if (graphic == null) {
            if (fill != null) {
                expFillColour = fill.getColor();
            }
            if (fill == null) {
                symbolTypeFactory.setNoFill(this.fieldConfigManager);
            } else {
                symbolTypeFactory.setSolidFill(this.fieldConfigManager, expFillColour, expOpacity);
            }
        } else {
            expSize = graphic.getSize();
            expRotation = graphic.getRotation();
            // Anchor point
            AnchorPoint anchorPoint = graphic.getAnchorPoint();
            if (anchorPoint != null) {
                expAnchorPointX = anchorPoint.getAnchorPointX();
                expAnchorPointY = anchorPoint.getAnchorPointY();
            } else {
                expAnchorPointX = defaultAnchorPoint.getAnchorPointX();
                expAnchorPointY = defaultAnchorPoint.getAnchorPointY();
            }
            // Offset
            Displacement displacement = graphic.getDisplacement();
            if (displacement != null) {
                expDisplacementX = displacement.getDisplacementX();
                expDisplacementY = displacement.getDisplacementY();
            } else {
                expDisplacementX = defaultDisplacement.getDisplacementX();
                expDisplacementY = defaultDisplacement.getDisplacementY();
            }
            expGap = graphic.getGap();
            expInitialGap = graphic.getInitialGap();
            List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
            if (!graphicalSymbolList.isEmpty()) {
                GraphicalSymbol symbol = graphicalSymbolList.get(0);
                symbolTypeFactory.setValue(PolygonSymbolizer.class, this.fieldConfigManager, graphic, symbol);
            }
        }
    }
    fieldConfigVisitor.populateField(FieldIdEnum.SIZE, expSize);
    fieldConfigVisitor.populateField(FieldIdEnum.ANGLE, expRotation);
    fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_H, expAnchorPointX);
    fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_V, expAnchorPointY);
    fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_X, expDisplacementX);
    fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_Y, expDisplacementY);
    fieldConfigVisitor.populateField(FieldIdEnum.GAP, expGap);
    fieldConfigVisitor.populateField(FieldIdEnum.INITIAL_GAP, expInitialGap);
    fieldConfigVisitor.populateField(FieldIdEnum.OVERALL_OPACITY, expOpacity);
    if (vendorOptionFillFactory != null) {
        if (symbolizer instanceof PolygonSymbolizer) {
            vendorOptionFillFactory.populate((PolygonSymbolizer) symbolizer);
        }
    }
    updateSymbol();
}
Also used : PolygonSymbolizerImpl(org.geotools.styling.PolygonSymbolizerImpl) PointSymbolizer(org.geotools.styling.PointSymbolizer) Fill(org.geotools.styling.Fill) GraphicFill(org.opengis.style.GraphicFill) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) MarkImpl(org.geotools.styling.MarkImpl) PointSymbolizerImpl(org.geotools.styling.PointSymbolizerImpl) Displacement(org.geotools.styling.Displacement)

Aggregations

GraphicalSymbol (org.opengis.style.GraphicalSymbol)36 Expression (org.opengis.filter.expression.Expression)23 Graphic (org.geotools.styling.Graphic)16 Fill (org.geotools.styling.Fill)14 Mark (org.geotools.styling.Mark)14 Stroke (org.geotools.styling.Stroke)12 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)11 AnchorPoint (org.geotools.styling.AnchorPoint)11 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)10 Test (org.junit.Test)10 Displacement (org.geotools.styling.Displacement)9 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 GraphicFill (org.opengis.style.GraphicFill)9 ArrayList (java.util.ArrayList)8 ExternalGraphic (org.geotools.styling.ExternalGraphic)7 MarkImpl (org.geotools.styling.MarkImpl)7 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)6 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)6 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)5 ColourFieldConfig (com.sldeditor.ui.detail.ColourFieldConfig)5