Search in sources :

Example 16 with Rule

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

the class SLDTreeSymbolizerButtonStateTest method testPolygon.

/**
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#setGeometryType(com.sldeditor.datasource.impl.GeometryTypeEnum)}.
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isMarkerVisible(java.lang.Object, java.lang.Object)}.
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isLineVisible(java.lang.Object, java.lang.Object)}.
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isPolygonVisible(java.lang.Object, java.lang.Object)}.
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isRasterVisible(java.lang.Object, java.lang.Object)}.
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isTextVisible(java.lang.Object, java.lang.Object)}.
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isImageOutlineLineVisible(java.lang.Object, java.lang.Object)}.
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState#isImageOutlinePolygonVisible(java.lang.Object, java.lang.Object)}.
 */
@Test
public void testPolygon() {
    SLDTreeSymbolizerButtonState obj = new SLDTreeSymbolizerButtonState();
    obj.setGeometryType(GeometryTypeEnum.POLYGON);
    obj.showSymbolizerButtons();
    assertFalse(obj.isLineVisible(null, null));
    assertFalse(obj.isMarkerVisible(null, null));
    assertFalse(obj.isPolygonVisible(null, null));
    assertFalse(obj.isRasterVisible(null, null));
    assertFalse(obj.isTextVisible(null, null));
    assertFalse(obj.isImageOutlineLineVisible(null, null));
    assertFalse(obj.isImageOutlinePolygonVisible(null, null));
    Rule rule = DefaultSymbols.createNewRule();
    assertTrue(obj.isPolygonVisible(null, rule));
    assertTrue(obj.isTextVisible(null, rule));
}
Also used : SLDTreeSymbolizerButtonState(com.sldeditor.ui.tree.SLDTreeSymbolizerButtonState) Rule(org.geotools.styling.Rule) Test(org.junit.Test)

Example 17 with Rule

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

the class SimpleRenderer method convert.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.renderer.EsriRendererInterface#convert(com.google.gson.JsonObject, java.lang.String, double, double, int)
     */
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    String label = json.get(CommonRendererKeys.LABEL).getAsString();
    namedLayer.setName(label);
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    // style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    if (minScale > 0.0) {
        rule.setMinScaleDenominator(minScale);
    }
    if (maxScale > 0.0) {
        rule.setMaxScaleDenominator(maxScale);
    }
    JsonElement jsonElement = json.get(CommonRendererKeys.SYMBOL);
    rule.setName(label);
    SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonElement);
    fts.rules().add(rule);
    return sld;
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) JsonElement(com.google.gson.JsonElement) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer)

Example 18 with Rule

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

the class UniqueValueRenderer method convert.

/* (non-Javadoc)
     * @see com.sldeditor.convert.esri.renderer.EsriRendererInterface#convert(com.google.gson.JsonObject, java.lang.String, double, double, int)
     */
@Override
public StyledLayerDescriptor convert(JsonObject json, String layerName, double minScale, double maxScale, int transparency) {
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    boolean useDefaultSymbol = false;
    JsonElement useDefaultSymbolElement = json.get(UniqueValueRendererKeys.USE_DEFAULTSYMBOL);
    if (useDefaultSymbolElement != null) {
        useDefaultSymbol = useDefaultSymbolElement.getAsBoolean();
    }
    JsonElement jsonElement = json.get(CommonRendererKeys.LABEL);
    if (jsonElement != null) {
        namedLayer.setName(jsonElement.getAsString());
    }
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    // style.setAbstract(json.get(IntermediateFileKeys.DESCRIPTION).getAsString());
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    JsonElement element = json.get(UniqueValueRendererKeys.VALUES);
    if (element != null) {
        JsonArray valueList = element.getAsJsonArray();
        for (int index = 0; index < valueList.size(); index++) {
            JsonElement valueElement = valueList.get(index);
            if (valueElement != null) {
                Rule rule = styleFactory.createRule();
                JsonObject valueObj = valueElement.getAsJsonObject();
                String value = getString(valueObj, UniqueValueRendererKeys.VALUES_VALUE);
                String label = getString(valueObj, UniqueValueRendererKeys.VALUES_LABEL);
                rule.setName(label);
                createFilter(rule, json.get(UniqueValueRendererKeys.FIELDS), json.get(UniqueValueRendererKeys.FIELD_DELIMETER), value);
                // Heading /description
                String heading = getString(valueObj, UniqueValueRendererKeys.VALUES_HEADING);
                @SuppressWarnings("unused") String description = getString(valueObj, UniqueValueRendererKeys.VALUES_DESCRIPTION);
                if ((heading != null) && !heading.isEmpty() || (label != null) && !label.isEmpty()) {
                    if (label == null) {
                        label = "";
                    }
                    InternationalString titleString = Text.text(label);
                    if (heading == null) {
                        heading = "";
                    }
                    InternationalString descriptionString = Text.text(heading);
                    Description descriptionObj = styleFactory.description(titleString, descriptionString);
                    rule.setDescription(descriptionObj);
                }
                if (minScale > 0.0) {
                    rule.setMinScaleDenominator(minScale);
                }
                if (maxScale > 0.0) {
                    rule.setMaxScaleDenominator(maxScale);
                }
                JsonElement jsonSymbolElement = valueObj.get(UniqueValueRendererKeys.VALUES_SYMBOL);
                SymbolManager.getInstance().convertSymbols(rule, layerName, transparency, jsonSymbolElement);
                if (useDefaultSymbol && value == null) {
                    rule.setIsElseFilter(true);
                }
                fts.rules().add(rule);
            }
        }
    }
    return sld;
}
Also used : Description(org.geotools.styling.Description) JsonObject(com.google.gson.JsonObject) InternationalString(org.opengis.util.InternationalString) JsonArray(com.google.gson.JsonArray) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) InternationalString(org.opengis.util.InternationalString) JsonElement(com.google.gson.JsonElement) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer)

Example 19 with Rule

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

the class LabelEngineLayerProperties method convert.

/* (non-Javadoc)
     * @see com.sldeditor.extension.convert.esri.label.EsriLabelRendererInterface#convert(java.util.List, org.geotools.styling.Rule, com.google.gson.JsonElement, int)
     */
@Override
public void convert(List<Rule> labelRuleList, Rule rule, JsonElement json, int transparency) {
    if ((json != null) && (rule != null) && (labelRuleList != null)) {
        JsonObject jsonObj = json.getAsJsonObject();
        TextSymbolizer textSymbolizer = styleFactory.createTextSymbolizer();
        textSymbolizer.setUnitOfMeasure(NonSI.PIXEL);
        textSymbolizer.setLabel(extractExpression(jsonObj));
        JsonElement jsonElement = jsonObj.get(LabelEngineLayerPropertiesKey.SYMBOL);
        SymbolManager.getInstance().convertTextSymbols(textSymbolizer, transparency, jsonElement);
        // Yes, this really is round the wrong way
        double maxScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MINIMUM_SCALE);
        double minScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MAXIMUM_SCALE);
        if ((minScale > 0.0) || (maxScale > 0.0)) {
            Rule labelRule = styleFactory.createRule();
            labelRule.setName(extractString(jsonObj, LabelEngineLayerPropertiesKey.CLASS));
            if (minScale > 0.0) {
                labelRule.setMinScaleDenominator(minScale);
            }
            if (maxScale > 0.0) {
                labelRule.setMaxScaleDenominator(maxScale);
            }
            labelRule.symbolizers().add(textSymbolizer);
            labelRuleList.add(labelRule);
        } else {
            rule.symbolizers().add(textSymbolizer);
        }
    }
}
Also used : TextSymbolizer(org.geotools.styling.TextSymbolizer) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Rule(org.geotools.styling.Rule)

Example 20 with Rule

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

the class StrokeDetailsTest method testStrokeDetailsPolygon.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testStrokeDetailsPolygon() {
    StrokeDetails panel = new StrokeDetails();
    panel.populate(null);
    // Set up test data
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    String expectedNameLayerValue = "named layer test value";
    namedLayer.setName(expectedNameLayerValue);
    Style style = DefaultSymbols.createNewStyle();
    String expectedNameStyleValue = "style test value";
    style.setName(expectedNameStyleValue);
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedNameFTSValue = "feature type style test value";
    fts.setName(expectedNameFTSValue);
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    String expectedNameValue = "rule test value";
    rule.setName(expectedNameValue);
    PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    rule.symbolizers().add(symbolizer);
    fts.rules().add(rule);
    sld.layers().add(namedLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyledLayer(namedLayer);
    SelectedSymbol.getInstance().setStyle(style);
    SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
    SelectedSymbol.getInstance().setRule(rule);
    SelectedSymbol.getInstance().setSymbolizer(symbolizer);
    panel.populate(SelectedSymbol.getInstance());
    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);
    FieldConfigSymbolType symbolTypeField = (FieldConfigSymbolType) fieldDataManager.get(FieldIdEnum.STROKE_STYLE);
    symbolTypeField.populateField("circle");
    double expectedAngle = 14.5;
    FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.STROKE_SYMBOL_ANGLE);
    angleField.populateField(expectedAngle);
    FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
    double opacity = 0.15;
    opacityField.populateField(opacity);
    FieldConfigString dashField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.STROKE_DASH_ARRAY);
    String dashArray = "1 2";
    dashField.populateField(dashArray);
    panel.dataChanged(null);
    double actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
    assertTrue(panel.isDataPresent());
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - opacity) < 0.01);
    // Reset to default value
    panel.preLoadSymbol();
    actualValue = angleField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 0.0) < 0.01);
    actualValue = opacityField.getDoubleValue();
    assertTrue(Math.abs(actualValue - 1.0) < 0.01);
}
Also used : FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) StrokeDetails(com.sldeditor.ui.detail.StrokeDetails) FieldConfigDouble(com.sldeditor.ui.detail.config.FieldConfigDouble) FieldConfigSlider(com.sldeditor.ui.detail.config.FieldConfigSlider) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) FieldConfigSymbolType(com.sldeditor.ui.detail.config.FieldConfigSymbolType) Test(org.junit.Test)

Aggregations

Rule (org.geotools.styling.Rule)110 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)65 Style (org.geotools.styling.Style)60 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)51 Test (org.junit.Test)48 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)28 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)26 LineSymbolizer (org.geotools.styling.LineSymbolizer)24 Symbolizer (org.geotools.styling.Symbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)19 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)16 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)16 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)13 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)11 ArrayList (java.util.ArrayList)11 Filter (org.opengis.filter.Filter)11 UserLayerImpl (org.geotools.styling.UserLayerImpl)10 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)8