Search in sources :

Example 21 with StyleBuilder

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

the class FieldConfigWKTTest method testAccept.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.FieldConfigWKT#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigWKT field = new FieldConfigWKT(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
    assertFalse(field.accept(null));
    StyleBuilder styleBuilder = new StyleBuilder();
    ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
    assertFalse(field.accept(externalGraphic));
    Mark marker1 = styleBuilder.createMark("star");
    assertFalse(field.accept(marker1));
    // CHECKSTYLE:OFF
    Mark marker2 = styleBuilder.createMark("wkt://MULTILINESTRING((-0.25 -0.25, -0.125 -0.25), (0.125 -0.25, 0.25 -0.25), (-0.25 0.25, -0.125 0.25), (0.125 0.25, 0.25 0.25))");
    // CHECKSTYLE:ON
    assertTrue(field.accept(marker2));
}
Also used : ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) FieldConfigWKT(com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.FieldConfigWKT) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StyleBuilder(org.geotools.styling.StyleBuilder) Mark(org.geotools.styling.Mark) Test(org.junit.Test)

Example 22 with StyleBuilder

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

the class FieldConfigWKTTest method testGetValue.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.FieldConfigWKT#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;
    FieldConfigWKT field = new FieldConfigWKT(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
    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(0, actualValue.size());
    // Try with symbol type of solid
    ColourFieldConfig fillConfig = new ColourFieldConfig(GroupIdEnum.FILLCOLOUR, FieldIdEnum.STROKE_FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH);
    ColourFieldConfig strokeConfig = new ColourFieldConfig(GroupIdEnum.STROKECOLOUR, FieldIdEnum.STROKE_STROKE_COLOUR, FieldIdEnum.POLYGON_STROKE_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH);
    FieldConfigWKT field2 = new FieldConfigWKT(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), fillConfig, strokeConfig, null);
    actualValue = field2.getValue(fieldConfigManager, symbolType, false, false);
    assertNotNull(actualValue);
    assertEquals(0, actualValue.size());
    field2.createUI();
    // Try with symbol type of wkt shape
    actualMarkerSymbol = "wkt://POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))";
    field2.setTestValue(null, actualMarkerSymbol);
    symbolType = styleBuilder.literalExpression(actualMarkerSymbol);
    actualValue = field2.getValue(fieldConfigManager, symbolType, false, false);
    assertNotNull(actualValue);
    assertEquals(1, actualValue.size());
    Mark actualSymbol = (Mark) actualValue.get(0);
    assertTrue(actualSymbol.getWellKnownName().toString().compareTo(actualMarkerSymbol) == 0);
    assertNull(actualSymbol.getFill());
    assertNull(actualSymbol.getStroke());
    // Enable stroke and fill flags
    actualValue = field2.getValue(fieldConfigManager, symbolType, true, true);
    assertNotNull(actualValue);
    assertEquals(1, actualValue.size());
    actualSymbol = (Mark) actualValue.get(0);
    assertTrue(actualSymbol.getWellKnownName().toString().compareTo(actualMarkerSymbol) == 0);
    assertNotNull(actualSymbol.getFill());
    assertNotNull(actualSymbol.getStroke());
}
Also used : FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigWKT(com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.FieldConfigWKT) 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) ColourFieldConfig(com.sldeditor.ui.detail.ColourFieldConfig) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) 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 23 with StyleBuilder

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

the class FieldConfigWKTTest method testSetValue.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.FieldConfigWKT#setValue(com.sldeditor.ui.detail.GraphicPanelFieldManager, com.sldeditor.ui.detail.config.FieldConfigSymbolType, org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testSetValue() {
    boolean valueOnly = true;
    GraphicPanelFieldManager fieldConfigManager = null;
    Class<?> panelId = PointFillDetails.class;
    fieldConfigManager = new GraphicPanelFieldManager(panelId);
    ColourFieldConfig fillConfig = new ColourFieldConfig(GroupIdEnum.FILLCOLOUR, FieldIdEnum.STROKE_FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH);
    ColourFieldConfig strokeConfig = new ColourFieldConfig(GroupIdEnum.STROKECOLOUR, FieldIdEnum.STROKE_STROKE_COLOUR, FieldIdEnum.POLYGON_STROKE_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH);
    FieldConfigWKT field = new FieldConfigWKT(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), fillConfig, strokeConfig, null);
    field.setValue(null, null, null, null, null);
    field.setValue(null, fieldConfigManager, null, null, null);
    field.createUI();
    StyleBuilder styleBuilder = new StyleBuilder();
    Mark marker1 = styleBuilder.createMark("star");
    field.setValue(null, null, null, null, marker1);
    field.setValue(null, fieldConfigManager, null, null, marker1);
    Mark marker2 = styleBuilder.createMark("wkt://POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))", styleBuilder.createFill(), styleBuilder.createStroke());
    field.setValue(null, null, null, null, marker2);
    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);
    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);
    field.setValue(null, fieldConfigManager, null, null, marker2);
    File f = null;
    String filename = null;
    try {
        f = File.createTempFile(getClass().getSimpleName(), ".png");
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        if ((f != null) && (f.toURI() != null)) {
            if (f.toURI().toURL() != null) {
                filename = f.toURI().toURL().toString();
            }
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    // Try unsupported symbol
    ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) styleBuilder.createExternalGraphic(filename, "png");
    field.setValue(null, fieldConfigManager, null, null, externalGraphic);
    if (f != null) {
        f.delete();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigWKT(com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.FieldConfigWKT) StyleBuilder(org.geotools.styling.StyleBuilder) Mark(org.geotools.styling.Mark) FieldConfigSlider(com.sldeditor.ui.detail.config.FieldConfigSlider) IOException(java.io.IOException) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) ColourFieldConfig(com.sldeditor.ui.detail.ColourFieldConfig) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) 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) File(java.io.File) Test(org.junit.Test)

Example 24 with StyleBuilder

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

the class FieldConfigFontPreviewTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFontPreview#generateExpression()}. Test
 * method for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFontPreview#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFontPreview#populateField(org.geotools.styling.Font)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFontPreview#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFontPreview#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    FieldConfigFontPreview field = new FieldConfigFontPreview(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly));
    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.populateField((String) null);
    field.populateField((Font) null);
    field.populateExpression((Font) null);
    String expectedValue = fontFamilies[0];
    field.createUI();
    field.populateField(expectedValue);
    String actualValue = field.getStringValue();
    assertNotNull(actualValue);
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
    actualValue = field.getStringValue();
    assertNotNull(actualValue);
    StyleBuilder styleBuilder = new StyleBuilder();
    Font f1 = styleBuilder.createFont(expectedValue, false, true, 24.0);
    field.populateField(f1);
    assertNotNull(field.getStringValue());
    Font f2 = styleBuilder.createFont(expectedValue, true, true, 24.0);
    field.populateField(f2);
    assertNotNull(field.getStringValue());
    Font f3 = styleBuilder.createFont(expectedValue, true, false, 24.0);
    field.populateField(f3);
    assertNotNull(field.getStringValue());
    Font f4 = styleBuilder.createFont(expectedValue, false, false, 24.0);
    field.populateField(f4);
    assertNotNull(field.getStringValue());
}
Also used : FieldConfigFontPreview(com.sldeditor.ui.detail.config.font.FieldConfigFontPreview) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StyleBuilder(org.geotools.styling.StyleBuilder) Font(org.geotools.styling.Font) Test(org.junit.Test)

Example 25 with StyleBuilder

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

the class FieldConfigFontTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#generateExpression()}. Test method
 * for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#populateField(org.geotools.styling.Font)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
 * Test method for {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#getFont()}. Test
 * method for
 * {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
 * Test method for {@link com.sldeditor.ui.detail.config.font.FieldConfigFont#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    FieldConfigFont field = new FieldConfigFont(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly));
    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.populateField((String) null);
    field.populateField((Font) null);
    field.populateExpression((Font) null);
    String expectedValue = fontFamilies[0];
    field.createUI();
    field.populateField(expectedValue);
    String actualValue = field.getStringValue();
    assertTrue(expectedValue.compareTo(actualValue) == 0);
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue);
    actualValue = field.getStringValue();
    assertTrue(expectedValue.compareTo(actualValue) == 0);
    StyleBuilder styleBuilder = new StyleBuilder();
    Font f1 = styleBuilder.createFont(expectedValue, false, true, 24.0);
    field.populateField(f1);
    actualValue = field.getStringValue();
    assertTrue(expectedValue.compareTo(actualValue) == 0);
}
Also used : FieldConfigFont(com.sldeditor.ui.detail.config.font.FieldConfigFont) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StyleBuilder(org.geotools.styling.StyleBuilder) FieldConfigFont(com.sldeditor.ui.detail.config.font.FieldConfigFont) Font(org.geotools.styling.Font) Test(org.junit.Test)

Aggregations

StyleBuilder (org.geotools.styling.StyleBuilder)30 Test (org.junit.Test)25 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)24 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)16 Mark (org.geotools.styling.Mark)16 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)14 PointFillDetails (com.sldeditor.ui.detail.PointFillDetails)11 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)11 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)9 FieldConfigSlider (com.sldeditor.ui.detail.config.FieldConfigSlider)9 FieldConfigSymbolType (com.sldeditor.ui.detail.config.FieldConfigSymbolType)9 ExternalGraphicImpl (org.geotools.styling.ExternalGraphicImpl)9 ColourFieldConfig (com.sldeditor.ui.detail.ColourFieldConfig)7 Expression (org.opengis.filter.expression.Expression)6 Font (org.geotools.styling.Font)5 FieldConfigPopulation (com.sldeditor.ui.detail.config.FieldConfigPopulation)4 FieldConfigMarker (com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker)4 Geometry (com.vividsolutions.jts.geom.Geometry)4 File (java.io.File)4 IOException (java.io.IOException)4