Search in sources :

Example 11 with ExternalGraphicImpl

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

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

the class FieldConfigArrowTest method testSetValue.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.arrow.FieldConfigArrow#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);
    FieldConfigArrow field = new FieldConfigArrow(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, 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) 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) FieldConfigArrow(com.sldeditor.ui.detail.vendor.geoserver.marker.arrow.FieldConfigArrow) 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 13 with ExternalGraphicImpl

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

the class FieldConfigWindBarbsTest method testAccept.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs#accept(org.opengis.style.GraphicalSymbol)}.
 */
@Test
public void testAccept() {
    boolean valueOnly = true;
    FieldConfigWindBarbs field = new FieldConfigWindBarbs(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("triangle");
    assertFalse(field.accept(marker1));
    Mark marker2 = styleBuilder.createMark("windbarbs://default(15)[kts]");
    assertTrue(field.accept(marker2));
}
Also used : ExternalGraphicImpl(org.geotools.styling.ExternalGraphicImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StyleBuilder(org.geotools.styling.StyleBuilder) Mark(org.geotools.styling.Mark) FieldConfigWindBarbs(com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs) Test(org.junit.Test)

Aggregations

ExternalGraphicImpl (org.geotools.styling.ExternalGraphicImpl)13 Mark (org.geotools.styling.Mark)10 Test (org.junit.Test)10 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)9 StyleBuilder (org.geotools.styling.StyleBuilder)9 File (java.io.File)6 MalformedURLException (java.net.MalformedURLException)6 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)4 IOException (java.io.IOException)4 PointFillDetails (com.sldeditor.ui.detail.PointFillDetails)3 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)2 FieldConfigSlider (com.sldeditor.ui.detail.config.FieldConfigSlider)2 FieldConfigSymbolType (com.sldeditor.ui.detail.config.FieldConfigSymbolType)2 FieldConfigFilename (com.sldeditor.ui.detail.config.symboltype.externalgraphic.FieldConfigFilename)2 FieldConfigWindBarbs (com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs)2 FieldConfigWKT (com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.FieldConfigWKT)2 URL (java.net.URL)2 GraphicalSymbol (org.opengis.style.GraphicalSymbol)2