Search in sources :

Example 6 with TextSymbolizer

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

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

the class DefaultTextSymbols method getDefaultValue.

/**
 * Gets the default value.
 *
 * @param fieldName the field name
 * @return the default value
 */
private static Object getDefaultValue(String fieldName) {
    // Instantiate the interface once and then cache it
    if (expectedInterface == null) {
        TextSymbolizer textObj = styleFactory.createTextSymbolizer();
        Class<?>[] interfaceArray = textObj.getClass().getInterfaces();
        for (Class<?> interfaceObj : interfaceArray) {
            for (String expectedPrefix : EXPECTED_PREFIX_LIST) {
                if (interfaceObj.getTypeName().compareTo(expectedPrefix) == 0) {
                    expectedInterface = interfaceObj;
                    break;
                }
            }
        }
    }
    if (expectedInterface != null) {
        try {
            Field f = expectedInterface.getField(fieldName);
            Object obj = f.get(expectedInterface);
            return obj;
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) TextSymbolizer(org.geotools.styling.TextSymbolizer)

Example 8 with TextSymbolizer

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

the class VOGeoServerLabellingUnderline method getMinimumVersion.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#getMinimumVersion(java.lang.Object, java.util.List)
     */
@Override
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
    if (sldObj instanceof TextSymbolizer) {
        TextSymbolizer textSymbolizer = (TextSymbolizer) sldObj;
        Map<String, String> options = textSymbolizer.getOptions();
        for (FieldIdEnum key : fieldMap.keySet()) {
            String vendorOptionAttributeKey = fieldMap.get(key);
            if (options.containsKey(vendorOptionAttributeKey)) {
                VendorOptionPresent voPresent = new VendorOptionPresent(sldObj, getVendorOptionInfo());
                vendorOptionsPresentList.add(voPresent);
            }
        }
    }
}
Also used : VendorOptionPresent(com.sldeditor.common.vendoroption.minversion.VendorOptionPresent) TextSymbolizer(org.geotools.styling.TextSymbolizer) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum)

Example 9 with TextSymbolizer

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

the class VOGeoServerTextSpacing method getMinimumVersion.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#getMinimumVersion(java.lang.Object, java.util.List)
     */
@Override
public void getMinimumVersion(Object parentObj, Object sldObj, List<VendorOptionPresent> vendorOptionsPresentList) {
    if (sldObj instanceof TextSymbolizer) {
        TextSymbolizer textSymbolizer = (TextSymbolizer) sldObj;
        Map<String, String> options = textSymbolizer.getOptions();
        for (FieldIdEnum key : fieldMap.keySet()) {
            String vendorOptionAttributeKey = fieldMap.get(key);
            if (options.containsKey(vendorOptionAttributeKey)) {
                VendorOptionPresent voPresent = new VendorOptionPresent(sldObj, getVendorOptionInfo());
                vendorOptionsPresentList.add(voPresent);
            }
        }
    }
}
Also used : VendorOptionPresent(com.sldeditor.common.vendoroption.minversion.VendorOptionPresent) TextSymbolizer(org.geotools.styling.TextSymbolizer) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum)

Example 10 with TextSymbolizer

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

the class SLDEditorBufferedImageLegendGraphicBuilder method getSampleShape.

/**
 * Returns a <code>java.awt.Shape</code> appropiate to render a legend graphic given the
 * symbolizer type and the legend dimensions.
 *
 * @param symbolizer the Symbolizer for whose type a sample shape will be created
 * @param legendWidth the requested width, in output units, of the legend graphic
 * @param legendHeight the requested height, in output units, of the legend graphic
 *
 * @return an appropiate Line2D, Rectangle2D or LiteShape(Point) for the symbolizer, wether it
 *         is a LineSymbolizer, a PolygonSymbolizer, or a Point ot Text Symbolizer
 *
 * @throws IllegalArgumentException if an unknown symbolizer impl was passed in.
 */
private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth, int legendHeight) {
    LiteShape2 sampleShape;
    final float hpad = (legendWidth * LegendUtils.hpaddingFactor);
    final float vpad = (legendHeight * LegendUtils.vpaddingFactor);
    if (symbolizer instanceof LineSymbolizer) {
        Coordinate[] coords = { new Coordinate(hpad, legendHeight - vpad - 1), new Coordinate(legendWidth - hpad - 1, vpad) };
        LineString geom = geomFac.createLineString(coords);
        try {
            this.sampleLine = new LiteShape2(geom, null, null, false);
        } catch (Exception e) {
            this.sampleLine = null;
        }
        sampleShape = this.sampleLine;
    } else if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof RasterSymbolizer)) {
        final float w = legendWidth - (2 * hpad) - 1;
        final float h = legendHeight - (2 * vpad) - 1;
        Coordinate[] coords = { new Coordinate(hpad, vpad), new Coordinate(hpad, vpad + h), new Coordinate(hpad + w, vpad + h), new Coordinate(hpad + w, vpad), new Coordinate(hpad, vpad) };
        LinearRing shell = geomFac.createLinearRing(coords);
        Polygon geom = geomFac.createPolygon(shell, null);
        try {
            this.sampleRect = new LiteShape2(geom, null, null, false);
        } catch (Exception e) {
            this.sampleRect = null;
        }
        sampleShape = this.sampleRect;
    } else if (symbolizer instanceof PointSymbolizer || symbolizer instanceof TextSymbolizer) {
        Coordinate coord = new Coordinate(legendWidth / 2, legendHeight / 2);
        try {
            this.samplePoint = new LiteShape2(geomFac.createPoint(coord), null, null, false);
        } catch (Exception e) {
            this.samplePoint = null;
        }
        sampleShape = this.samplePoint;
    } else {
        throw new IllegalArgumentException("Unknown symbolizer: " + symbolizer);
    }
    return sampleShape;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ServiceException(org.geoserver.platform.ServiceException) SchemaException(org.geotools.feature.SchemaException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalAttributeException(org.opengis.feature.IllegalAttributeException) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) TextSymbolizer(org.geotools.styling.TextSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) LiteShape2(org.geotools.geometry.jts.LiteShape2) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

Aggregations

TextSymbolizer (org.geotools.styling.TextSymbolizer)33 Test (org.junit.Test)19 Font (org.geotools.styling.Font)9 PointSymbolizer (org.geotools.styling.PointSymbolizer)9 Rule (org.geotools.styling.Rule)9 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)8 LineSymbolizer (org.geotools.styling.LineSymbolizer)8 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)8 Style (org.geotools.styling.Style)8 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)6 NamedLayer (org.geotools.styling.NamedLayer)5 SLDTreeLeafText (com.sldeditor.common.tree.leaf.SLDTreeLeafText)4 SLDData (com.sldeditor.common.data.SLDData)3 StyleWrapper (com.sldeditor.common.data.StyleWrapper)3 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)3 VendorOptionPresent (com.sldeditor.common.vendoroption.minversion.VendorOptionPresent)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)3 BatchUpdateFontData (com.sldeditor.tool.batchupdatefont.BatchUpdateFontData)3 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)3 Symbolizer (org.geotools.styling.Symbolizer)3