Search in sources :

Example 1 with AnchorPoint

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

the class DetailsUtilitiesTest method testIsSameAnchorPointAnchorPoint.

/**
 * Test method for {@link com.sldeditor.ui.detail.DetailsUtilities#isSame(org.geotools.styling.AnchorPoint, org.geotools.styling.AnchorPoint)}.
 */
@Test
public void testIsSameAnchorPointAnchorPoint() {
    assertFalse(DetailsUtilities.isSame((AnchorPoint) null, (AnchorPoint) null));
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    // Try values that are the same
    AnchorPoint anchorPoint1 = new AnchorPointImpl();
    anchorPoint1.setAnchorPointX(ff.literal(0.58));
    anchorPoint1.setAnchorPointY(ff.literal(0.1));
    AnchorPoint anchorPoint2 = new AnchorPointImpl();
    anchorPoint2.setAnchorPointX(ff.literal(0.58));
    anchorPoint2.setAnchorPointY(ff.literal("0.1"));
    assertTrue(DetailsUtilities.isSame(anchorPoint1, anchorPoint2));
    // Try values that are not the same
    AnchorPoint anchorPoint3 = new AnchorPointImpl();
    anchorPoint3.setAnchorPointX(ff.literal(1.0));
    anchorPoint3.setAnchorPointY(ff.literal(0.1));
    assertFalse(DetailsUtilities.isSame(anchorPoint1, anchorPoint3));
    assertFalse(DetailsUtilities.isSame(anchorPoint2, anchorPoint3));
}
Also used : AnchorPoint(org.geotools.styling.AnchorPoint) FilterFactory(org.opengis.filter.FilterFactory) AnchorPointImpl(org.geotools.styling.AnchorPointImpl) Test(org.junit.Test)

Example 2 with AnchorPoint

use of org.geotools.styling.AnchorPoint 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 3 with AnchorPoint

use of org.geotools.styling.AnchorPoint 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)

Example 4 with AnchorPoint

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

the class PolygonFillDetails method getGraphicFill.

/**
 * Gets the graphic fill.
 *
 * @return the graphic fill
 */
private GraphicFill getGraphicFill() {
    GroupConfigInterface fillGroup = getGroup(GroupIdEnum.FILL);
    boolean hasFill = fillGroup.isPanelEnabled();
    GroupConfigInterface strokeGroup = getGroup(GroupIdEnum.STROKE);
    boolean hasStroke = (strokeGroup == null) ? false : strokeGroup.isPanelEnabled();
    Expression opacity = null;
    Expression size = fieldConfigVisitor.getExpression(FieldIdEnum.SIZE);
    Expression rotation = fieldConfigVisitor.getExpression(FieldIdEnum.ANGLE);
    Expression symbolType = fieldConfigVisitor.getExpression(FieldIdEnum.SYMBOL_TYPE);
    // 
    // Anchor point
    // 
    AnchorPoint anchorPoint = null;
    GroupConfigInterface anchorPointPanel = getGroup(GroupIdEnum.ANCHORPOINT);
    if (anchorPointPanel.isPanelEnabled()) {
        anchorPoint = (AnchorPoint) getStyleFactory().anchorPoint(fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_H), fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_V));
        // default so it doesn't appear in the SLD
        if (DetailsUtilities.isSame(defaultAnchorPoint, anchorPoint)) {
            anchorPoint = null;
        }
    }
    // 
    // Displacement
    // 
    Displacement displacement = null;
    GroupConfigInterface displacementPanel = getGroup(GroupIdEnum.DISPLACEMENT);
    if (displacementPanel.isPanelEnabled()) {
        displacement = getStyleFactory().displacement(fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_X), fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_Y));
        // it doesn't appear in the SLD
        if (DetailsUtilities.isSame(defaultDisplacement, displacement)) {
            displacement = null;
        }
    }
    List<GraphicalSymbol> symbols = symbolTypeFactory.getValue(this.fieldConfigManager, symbolType, hasFill, hasStroke, selectedFillPanelId);
    GraphicFill graphicFill = getStyleFactory().graphicFill(symbols, opacity, size, rotation, anchorPoint, displacement);
    return graphicFill;
}
Also used : AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) GraphicFill(org.opengis.style.GraphicFill) GraphicalSymbol(org.opengis.style.GraphicalSymbol) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) Displacement(org.geotools.styling.Displacement)

Example 5 with AnchorPoint

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

the class TextSymbolizerDetails method populate.

/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.selectedsymbol.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    if (selectedSymbol != null) {
        TextSymbolizer textSymbolizer = (TextSymbolizer) selectedSymbol.getSymbolizer();
        if (textSymbolizer != null) {
            populateStandardData(textSymbolizer);
            // 
            // Geometry
            // 
            fieldConfigVisitor.populateField(FieldIdEnum.GEOMETRY, textSymbolizer.getGeometry());
            // 
            // Label
            // 
            fieldConfigVisitor.populateField(FieldIdEnum.LABEL, textSymbolizer.getLabel());
            // Font
            Font font = textSymbolizer.getFont();
            GroupConfigInterface group = getGroup(GroupIdEnum.FONT);
            group.enable(font != null);
            if (font != null) {
                fieldConfigVisitor.populateFontField(FieldIdEnum.FONT_FAMILY, font);
                fieldConfigVisitor.populateField(FieldIdEnum.FONT_WEIGHT, font.getWeight());
                fieldConfigVisitor.populateField(FieldIdEnum.FONT_STYLE, font.getStyle());
                fieldConfigVisitor.populateField(FieldIdEnum.FONT_SIZE, font.getSize());
            }
            fieldConfigVisitor.populateFontField(FieldIdEnum.FONT_PREVIEW, font);
            // Fill
            Fill fill = (FillImpl) textSymbolizer.getFill();
            if (fill != null) {
                fieldConfigVisitor.populateField(FieldIdEnum.FILL_COLOUR, fill.getColor());
                fieldConfigVisitor.populateField(FieldIdEnum.TEXT_OPACITY, fill.getOpacity());
            }
            // Halo
            Halo halo = textSymbolizer.getHalo();
            group = getGroup(GroupIdEnum.HALO);
            group.enable(halo != null);
            if (halo != null) {
                Fill haloFill = halo.getFill();
                fieldConfigVisitor.populateField(FieldIdEnum.HALO_COLOUR, haloFill.getColor());
                fieldConfigVisitor.populateField(FieldIdEnum.HALO_RADIUS, halo.getRadius());
            } else {
                fieldConfigVisitor.populateField(FieldIdEnum.HALO_COLOUR, (Expression) null);
                fieldConfigVisitor.populateField(FieldIdEnum.HALO_RADIUS, (Expression) null);
            }
            group = getGroup(GroupIdEnum.PLACEMENT);
            if (group != null) {
                MultiOptionGroup labelPlacementGroup = (MultiOptionGroup) group;
                LabelPlacement placement = textSymbolizer.getLabelPlacement();
                if (placement instanceof PointPlacementImpl) {
                    PointPlacementImpl pointPlacement = (PointPlacementImpl) placement;
                    labelPlacementGroup.setOption(GroupIdEnum.POINTPLACEMENT);
                    Expression anchorPointX = null;
                    Expression anchorPointY = null;
                    AnchorPoint anchorPoint = pointPlacement.getAnchorPoint();
                    if (anchorPoint != null) {
                        anchorPointX = anchorPoint.getAnchorPointX();
                        anchorPointY = anchorPoint.getAnchorPointY();
                    } else {
                        // Use the defaults as non specified
                        anchorPointX = defaultPointPlacementAnchorPointX;
                        anchorPointY = defaultPointPlacementAnchorPointY;
                    }
                    fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_H, anchorPointX);
                    fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_V, anchorPointY);
                    Displacement displacement = pointPlacement.getDisplacement();
                    if (displacement == null) {
                        displacement = DisplacementImpl.DEFAULT;
                    }
                    fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_X, displacement.getDisplacementX());
                    fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_Y, displacement.getDisplacementY());
                    fieldConfigVisitor.populateField(FieldIdEnum.ANGLE, pointPlacement.getRotation());
                } else if (placement instanceof LinePlacementImpl) {
                    LinePlacementImpl linePlacement = (LinePlacementImpl) placement;
                    labelPlacementGroup.setOption(GroupIdEnum.LINEPLACEMENT);
                    fieldConfigVisitor.populateField(FieldIdEnum.GAP, linePlacement.getGap());
                    fieldConfigVisitor.populateField(FieldIdEnum.INITIAL_GAP, linePlacement.getInitialGap());
                    fieldConfigVisitor.populateField(FieldIdEnum.PERPENDICULAR_OFFSET, linePlacement.getPerpendicularOffset());
                    fieldConfigVisitor.populateBooleanField(FieldIdEnum.GENERALISED_LINE, linePlacement.isGeneralizeLine());
                    fieldConfigVisitor.populateBooleanField(FieldIdEnum.ALIGN, linePlacement.isAligned());
                    fieldConfigVisitor.populateBooleanField(FieldIdEnum.REPEATED, linePlacement.isRepeated());
                }
            }
            if (vendorOptionTextFactory != null) {
                vendorOptionTextFactory.populate(textSymbolizer);
            }
        }
    }
}
Also used : Fill(org.opengis.style.Fill) FillImpl(org.geotools.styling.FillImpl) Font(org.geotools.styling.Font) PointPlacementImpl(org.geotools.styling.PointPlacementImpl) Displacement(org.geotools.styling.Displacement) AnchorPoint(org.geotools.styling.AnchorPoint) LabelPlacement(org.geotools.styling.LabelPlacement) TextSymbolizer(org.geotools.styling.TextSymbolizer) Expression(org.opengis.filter.expression.Expression) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) LinePlacementImpl(org.geotools.styling.LinePlacementImpl) Halo(org.geotools.styling.Halo)

Aggregations

AnchorPoint (org.geotools.styling.AnchorPoint)16 Expression (org.opengis.filter.expression.Expression)15 Displacement (org.geotools.styling.Displacement)12 GraphicalSymbol (org.opengis.style.GraphicalSymbol)11 Graphic (org.geotools.styling.Graphic)8 Fill (org.geotools.styling.Fill)7 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)6 ArrayList (java.util.ArrayList)4 Font (org.geotools.styling.Font)4 PointSymbolizer (org.geotools.styling.PointSymbolizer)4 Stroke (org.geotools.styling.Stroke)4 GraphicFill (org.opengis.style.GraphicFill)4 JsonObject (com.google.gson.JsonObject)3 Halo (org.geotools.styling.Halo)3 MarkImpl (org.geotools.styling.MarkImpl)3 TextSymbolizer (org.geotools.styling.TextSymbolizer)3 JsonElement (com.google.gson.JsonElement)2 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)2 MultiOptionGroup (com.sldeditor.ui.detail.config.base.MultiOptionGroup)2 ConstantExpression (org.geotools.filter.ConstantExpression)2