Search in sources :

Example 1 with Halo

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

Example 2 with Halo

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

the class DefaultSymbols method createDefaultTextSymbolizer.

/**
 * Creates the default text symbolizer.
 *
 * @return the text symbolizer
 */
public static TextSymbolizer createDefaultTextSymbolizer() {
    Expression fontFamily = ff.literal("Serif");
    Expression fontSize = ff.literal(10.0);
    Expression fontStyle = ff.literal("normal");
    Expression fontWeight = ff.literal("normal");
    Expression rotation = ff.literal(0.0);
    Expression label = ff.literal("Test");
    String geometryFieldName = null;
    Expression geometryField = ff.property(geometryFieldName);
    String name = Localisation.getString(SLDTreeTools.class, "TreeItem.newText");
    AnchorPoint anchor = null;
    Displacement displacement = null;
    PointPlacement pointPlacement = (PointPlacement) styleFactory.pointPlacement(anchor, displacement, rotation);
    Expression fillColour = ff.literal(DEFAULT_COLOUR);
    Expression fillColourOpacity = ff.literal(1.0);
    Fill fill = styleFactory.fill(null, fillColour, fillColourOpacity);
    Halo halo = null;
    List<Expression> fontFamilyList = new ArrayList<Expression>();
    fontFamilyList.add(fontFamily);
    Font font = (Font) styleFactory.font(fontFamilyList, fontStyle, fontWeight, fontSize);
    Description description = null;
    Unit<Length> unit = null;
    TextSymbolizer newTextSymbolizer = (TextSymbolizer) styleFactory.textSymbolizer(name, geometryField, description, unit, label, font, pointPlacement, halo, fill);
    return newTextSymbolizer;
}
Also used : PointPlacement(org.geotools.styling.PointPlacement) Fill(org.geotools.styling.Fill) Description(org.geotools.styling.Description) ArrayList(java.util.ArrayList) Displacement(org.opengis.style.Displacement) Font(org.geotools.styling.Font) AnchorPoint(org.geotools.styling.AnchorPoint) Expression(org.opengis.filter.expression.Expression) Length(javax.measure.quantity.Length) TextSymbolizer(org.geotools.styling.TextSymbolizer) Halo(org.geotools.styling.Halo)

Example 3 with Halo

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

the class TextSymbolizerDetails method updateSymbol.

/**
 * Update symbol.
 */
private void updateSymbol() {
    if (!Controller.getInstance().isPopulating()) {
        Expression haloRadius = fieldConfigVisitor.getExpression(FieldIdEnum.HALO_RADIUS);
        // Label placement
        LabelPlacement labelPlacement = null;
        MultiOptionGroup labelPlacementPanel = (MultiOptionGroup) getGroup(GroupIdEnum.PLACEMENT);
        OptionGroup labelPlacementOption = labelPlacementPanel.getSelectedOptionGroup();
        if (labelPlacementOption.getId() == GroupIdEnum.POINTPLACEMENT) {
            AnchorPoint anchor = null;
            GroupConfigInterface anchorPointPanel = getGroup(GroupIdEnum.ANCHORPOINT);
            if (anchorPointPanel == null) {
                String errorMessage = String.format("%s : %s", Localisation.getString(TextSymbolizerDetails.class, "TextSymbol.error1"), GroupIdEnum.ANCHORPOINT);
                ConsoleManager.getInstance().error(this, errorMessage);
            } else if (anchorPointPanel.isPanelEnabled()) {
                Expression anchorPointH = fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_H);
                Expression anchorPointV = fieldConfigVisitor.getExpression(FieldIdEnum.ANCHOR_POINT_V);
                anchor = (AnchorPoint) getStyleFactory().anchorPoint(anchorPointH, anchorPointV);
            }
            // 
            // Displacement
            // 
            Displacement displacement = null;
            GroupConfigInterface displacementPanel = getGroup(GroupIdEnum.DISPLACEMENT);
            if (displacementPanel == null) {
                ConsoleManager.getInstance().error(this, String.format("%s : %s", Localisation.getString(TextSymbolizerDetails.class, "TextSymbol.error1"), GroupIdEnum.DISPLACEMENT));
            } else if (displacementPanel.isPanelEnabled()) {
                displacement = getStyleFactory().displacement(fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_X), fieldConfigVisitor.getExpression(FieldIdEnum.DISPLACEMENT_Y));
            }
            // 
            // Rotation
            // 
            Expression rotation = null;
            GroupConfigInterface rotationPanel = getGroup(GroupIdEnum.ROTATION);
            if (rotationPanel == null) {
                ConsoleManager.getInstance().error(this, String.format("%s : %s", Localisation.getString(TextSymbolizerDetails.class, "TextSymbol.error1"), GroupIdEnum.ROTATION));
            } else if (rotationPanel.isPanelEnabled()) {
                rotation = fieldConfigVisitor.getExpression(FieldIdEnum.ANGLE);
            }
            labelPlacement = getStyleFactory().pointPlacement(anchor, displacement, rotation);
        } else if (labelPlacementOption.getId() == GroupIdEnum.LINEPLACEMENT) {
            Expression offset = fieldConfigVisitor.getExpression(FieldIdEnum.PERPENDICULAR_OFFSET);
            Expression initialGap = fieldConfigVisitor.getExpression(FieldIdEnum.INITIAL_GAP);
            Expression gap = fieldConfigVisitor.getExpression(FieldIdEnum.GAP);
            boolean repeated = fieldConfigVisitor.getBoolean(FieldIdEnum.REPEATED);
            boolean aligned = fieldConfigVisitor.getBoolean(FieldIdEnum.ALIGN);
            boolean generalizedLine = fieldConfigVisitor.getBoolean(FieldIdEnum.GENERALISED_LINE);
            labelPlacement = getStyleFactory().linePlacement(offset, initialGap, gap, repeated, aligned, generalizedLine);
        }
        FieldConfigColour fdmFillColour = (FieldConfigColour) fieldConfigManager.get(FieldIdEnum.FILL_COLOUR);
        Expression fillColour = fdmFillColour.getColourExpression();
        Expression fillColourOpacity = fieldConfigVisitor.getExpression(FieldIdEnum.TEXT_OPACITY);
        Fill fill = getStyleFactory().createFill(fillColour, fillColourOpacity);
        FieldConfigColour fdmHaloColour = (FieldConfigColour) fieldConfigManager.get(FieldIdEnum.HALO_COLOUR);
        Expression haloFillColour = fdmHaloColour.getColourExpression();
        Expression haloFillColourOpacity = fdmHaloColour.getColourOpacityExpression();
        Fill haloFill = getStyleFactory().fill(null, haloFillColour, haloFillColourOpacity);
        // 
        // Halo
        // 
        Halo halo = null;
        GroupConfigInterface haloPanel = getGroup(GroupIdEnum.HALO);
        if (haloPanel.isPanelEnabled()) {
            halo = (Halo) getStyleFactory().halo(haloFill, haloRadius);
        }
        // 
        // Font
        // 
        Font font = extractFont();
        // Any changes made to the font details need to be reflected
        // back to the FieldConfigFontPreview field
        fieldConfigVisitor.populateFontField(FieldIdEnum.FONT_PREVIEW, font);
        StandardData standardData = getStandardData();
        Expression label = fieldConfigVisitor.getExpression(FieldIdEnum.LABEL);
        Expression geometryField = fieldConfigVisitor.getExpression(FieldIdEnum.GEOMETRY);
        String geometryFieldName = null;
        Expression defaultGeometryField = getFilterFactory().property(geometryFieldName);
        TextSymbolizer textSymbolizer = (TextSymbolizer) getStyleFactory().textSymbolizer(standardData.name, defaultGeometryField, standardData.description, standardData.unit, label, font, labelPlacement, halo, fill);
        if ((geometryField != null) && !geometryField.toString().isEmpty()) {
            textSymbolizer.setGeometry(geometryField);
        }
        if (vendorOptionTextFactory != null) {
            vendorOptionTextFactory.updateSymbol(textSymbolizer);
        }
        SelectedSymbol.getInstance().replaceSymbolizer(textSymbolizer);
        this.fireUpdateSymbol();
    }
}
Also used : Fill(org.opengis.style.Fill) Displacement(org.geotools.styling.Displacement) Font(org.geotools.styling.Font) OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) AnchorPoint(org.geotools.styling.AnchorPoint) LabelPlacement(org.geotools.styling.LabelPlacement) Expression(org.opengis.filter.expression.Expression) TextSymbolizer(org.geotools.styling.TextSymbolizer) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) Halo(org.geotools.styling.Halo)

Aggregations

AnchorPoint (org.geotools.styling.AnchorPoint)3 Font (org.geotools.styling.Font)3 Halo (org.geotools.styling.Halo)3 TextSymbolizer (org.geotools.styling.TextSymbolizer)3 Expression (org.opengis.filter.expression.Expression)3 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)2 MultiOptionGroup (com.sldeditor.ui.detail.config.base.MultiOptionGroup)2 Displacement (org.geotools.styling.Displacement)2 LabelPlacement (org.geotools.styling.LabelPlacement)2 Fill (org.opengis.style.Fill)2 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)1 OptionGroup (com.sldeditor.ui.detail.config.base.OptionGroup)1 ArrayList (java.util.ArrayList)1 Length (javax.measure.quantity.Length)1 Description (org.geotools.styling.Description)1 Fill (org.geotools.styling.Fill)1 FillImpl (org.geotools.styling.FillImpl)1 LinePlacementImpl (org.geotools.styling.LinePlacementImpl)1 PointPlacement (org.geotools.styling.PointPlacement)1 PointPlacementImpl (org.geotools.styling.PointPlacementImpl)1