Search in sources :

Example 26 with FieldConfigColour

use of com.sldeditor.ui.detail.config.FieldConfigColour 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 27 with FieldConfigColour

use of com.sldeditor.ui.detail.config.FieldConfigColour in project sldeditor by robward-scisys.

the class FieldConfigColourTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#generateExpression()}. Test method
 * for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#populateExpression(java.lang.Object, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.lang.String)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#getColourExpression()}. Test method
 * for {@link com.sldeditor.ui.detail.config.FieldConfigColour#getColourOpacityExpression()}.
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigColour#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    class TestFieldConfigColour extends FieldConfigColour {

        public TestFieldConfigColour(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public Expression callGenerateExpression() {
            return generateExpression();
        }
    }
    TestFieldConfigColour field = new TestFieldConfigColour(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly));
    Expression actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);
    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.populateExpression(null);
    assertNull(field.getColourExpression());
    assertNull(field.getColourOpacityExpression());
    // Try string values - erroneous
    field.createUI();
    field.populateExpression("");
    String actualValue = field.getStringValue();
    assertTrue(actualValue.compareTo("#000000") == 0);
    String colour1 = "#123456";
    field.populateExpression(colour1);
    actualValue = field.getStringValue();
    assertTrue(colour1.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour1) == 0);
    String colour2 = "#AABBCC";
    field.setTestValue(FieldIdEnum.UNKNOWN, colour2);
    actualValue = field.getStringValue();
    assertTrue(colour2.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour2) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    LiteralExpressionImpl literal = (LiteralExpressionImpl) actualExpression;
    double opacity = (Double) literal.getValue();
    double expectedOpacity = 1.0;
    assertTrue(Math.abs(opacity - expectedOpacity) < 0.0001);
    // Try using FieldConfigBase.populate(colour expression, opacity)
    String colour3 = "#001122";
    expectedOpacity = DefaultSymbols.defaultColourOpacity();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    field.populate(ff.literal(colour3));
    actualValue = field.getStringValue();
    assertTrue(colour3.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour3) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    literal = (LiteralExpressionImpl) actualExpression;
    opacity = (Double) literal.getValue();
    assertTrue(Math.abs(opacity - expectedOpacity) < 0.1);
    AttributeExpressionImpl attributeExpression = new AttributeExpressionImpl("colour");
    field.populate(attributeExpression);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof AttributeExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(attributeExpression.toString()) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression.toString().compareTo(attributeExpression.toString()) == 0);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 28 with FieldConfigColour

use of com.sldeditor.ui.detail.config.FieldConfigColour in project sldeditor by robward-scisys.

the class FieldConfigColourTest method testSetVisible.

/**
 * Test method for {@link com.sldeditor.ui.detail.config.FieldConfigColour#setVisible(boolean)}.
 */
@Test
public void testSetVisible() {
    boolean valueOnly = true;
    FieldConfigColour field = new FieldConfigColour(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly));
    boolean expectedValue = true;
    field.setVisible(expectedValue);
    field.createUI();
    field.setVisible(expectedValue);
    expectedValue = false;
    field.setVisible(expectedValue);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) Test(org.junit.Test)

Example 29 with FieldConfigColour

use of com.sldeditor.ui.detail.config.FieldConfigColour in project sldeditor by robward-scisys.

the class FieldConfigColourTest method testRevertToDefaultValue.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#revertToDefaultValue()}.
 */
@Test
public void testRevertToDefaultValue() {
    boolean valueOnly = true;
    FieldConfigColour field = new FieldConfigColour(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly));
    field.revertToDefaultValue();
    assertTrue(field.getStringValue().compareTo("") == 0);
    field.createUI();
    field.revertToDefaultValue();
    String expectedDefaultValue = "default value";
    assertTrue(expectedDefaultValue.compareTo(field.getStringValue()) != 0);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) Test(org.junit.Test)

Example 30 with FieldConfigColour

use of com.sldeditor.ui.detail.config.FieldConfigColour in project sldeditor by robward-scisys.

the class FieldConfigColourTest method testCreateCopy.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#createCopy(com.sldeditor.ui.detail.config.FieldConfigBase)}.
 */
@Test
public void testCreateCopy() {
    boolean valueOnly = true;
    class TestFieldConfigColour extends FieldConfigColour {

        public TestFieldConfigColour(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public FieldConfigPopulate callCreateCopy(FieldConfigBase fieldConfigBase) {
            return createCopy(fieldConfigBase);
        }
    }
    TestFieldConfigColour field = new TestFieldConfigColour(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly));
    FieldConfigColour copy = (FieldConfigColour) field.callCreateCopy(null);
    assertNull(copy);
    copy = (FieldConfigColour) field.callCreateCopy(field);
    assertEquals(field.getFieldId(), copy.getFieldId());
    assertTrue(field.getLabel().compareTo(copy.getLabel()) == 0);
    assertEquals(field.isValueOnly(), copy.isValueOnly());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) Test(org.junit.Test)

Aggregations

FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)33 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)24 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)23 Test (org.junit.Test)22 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)17 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)16 Expression (org.opengis.filter.expression.Expression)15 PointFillDetails (com.sldeditor.ui.detail.PointFillDetails)14 FieldConfigSlider (com.sldeditor.ui.detail.config.FieldConfigSlider)13 Mark (org.geotools.styling.Mark)13 FieldConfigSymbolType (com.sldeditor.ui.detail.config.FieldConfigSymbolType)12 ColourFieldConfig (com.sldeditor.ui.detail.ColourFieldConfig)11 StyleBuilder (org.geotools.styling.StyleBuilder)11 GraphicalSymbol (org.opengis.style.GraphicalSymbol)11 Geometry (com.vividsolutions.jts.geom.Geometry)9 Fill (org.geotools.styling.Fill)8 GraphicFill (org.opengis.style.GraphicFill)8 FieldConfigMarker (com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker)6 ArrayList (java.util.ArrayList)6 Stroke (org.geotools.styling.Stroke)5