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();
}
}
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);
}
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);
}
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);
}
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());
}
Aggregations