use of org.geotools.filter.LiteralExpressionImpl in project sldeditor by robward-scisys.
the class DataSourceAttributePanel method setAttribute.
/**
* Sets the attribute.
*
* @param expression the new attribute
*/
public void setAttribute(Expression expression) {
String propertyName = null;
if (expression instanceof PropertyExistsFunction) {
Expression e = ((PropertyExistsFunction) expression).getParameters().get(0);
Object value = ((LiteralExpressionImpl) e).getValue();
propertyName = ((AttributeExpressionImpl) value).getPropertyName();
} else if (expression instanceof AttributeExpressionImpl) {
propertyName = ((AttributeExpressionImpl) expression).getPropertyName();
} else if (expression instanceof LiteralExpressionImpl) {
propertyName = AttributeUtils.extract((String) ((LiteralExpressionImpl) expression).getValue());
}
if (propertyName != null) {
oldValueObj = propertyName;
attributeComboBox.setSelectedItem(propertyName);
} else {
oldValueObj = propertyName;
attributeComboBox.setSelectedIndex(-1);
}
}
use of org.geotools.filter.LiteralExpressionImpl in project sldeditor by robward-scisys.
the class FieldConfigMarkerTest method testGetFill.
/**
* Test method for {@link
* com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#getFill(org.opengis.style.GraphicFill,
* com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
*/
@Test
public void testGetFill() {
// Test it with null values
boolean valueOnly = true;
ColourFieldConfig fillConfig = new ColourFieldConfig(GroupIdEnum.FILL, FieldIdEnum.FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_WIDTH);
ColourFieldConfig strokeConfig = new ColourFieldConfig(GroupIdEnum.STROKE, FieldIdEnum.STROKE_STROKE_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH);
FieldConfigMarker field = new FieldConfigMarker(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly, false), fillConfig, strokeConfig, null);
assertNull(field.getStringValue());
GraphicFill graphicFill = null;
GraphicPanelFieldManager fieldConfigManager = null;
Fill actualValue = field.getFill(graphicFill, fieldConfigManager);
assertNull(actualValue);
Class<?> panelId = PointFillDetails.class;
fieldConfigManager = new GraphicPanelFieldManager(panelId);
actualValue = field.getFill(graphicFill, fieldConfigManager);
assertNotNull(actualValue);
assertNull(actualValue.getColor());
assertNull(actualValue.getGraphicFill());
assertNull(actualValue.getOpacity());
// Test it with non null values
FieldIdEnum colourFieldId = FieldIdEnum.FILL_COLOUR;
FieldConfigColour colourField = new FieldConfigColour(new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
colourField.createUI();
String expectedColourValue = "#012345";
colourField.setTestValue(null, expectedColourValue);
double expectedOpacityValue = 0.72;
FieldConfigSlider opacityField = new FieldConfigSlider(new FieldConfigCommonData(panelId, colourFieldId, "", false, false));
opacityField.createUI();
opacityField.populateField(expectedOpacityValue);
FieldConfigBase symbolSelectionField = new FieldConfigSymbolType(new FieldConfigCommonData(panelId, colourFieldId, "", false, 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);
FieldConfigMarker field2 = new FieldConfigMarker(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly, false), fillConfig, strokeConfig, symbolSelectionFieldId);
actualValue = field2.getFill(graphicFill, fieldConfigManager);
assertNotNull(actualValue);
LiteralExpressionImpl literalExpressionImpl = (LiteralExpressionImpl) actualValue.getColor();
String actualColourString = literalExpressionImpl.toString();
assertTrue(actualColourString.compareTo(expectedColourValue) == 0);
StyleBuilder styleBuilder = new StyleBuilder();
graphicFill = styleBuilder.createGraphic();
actualValue = field2.getFill(graphicFill, fieldConfigManager);
assertNull(actualValue.getColor());
assertNull(actualValue.getOpacity());
}
use of org.geotools.filter.LiteralExpressionImpl 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, false));
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);
}
Aggregations