use of com.sldeditor.ui.detail.config.FieldConfigDouble in project sldeditor by robward-scisys.
the class FieldConfigPopulationTest method testDouble.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateDoubleField(com.sldeditor.ui.detail.config.FieldId, java.lang.Double)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getDouble(com.sldeditor.ui.detail.config.FieldId)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getDouble(com.sldeditor.common.xml.ui.FieldIdEnum)}.
*/
@Test
public void testDouble() {
FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;
GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);
FieldConfigDouble doubleField = new FieldConfigDouble(new FieldConfigCommonData(Geometry.class, fieldId, "label", true));
doubleField.createUI();
fieldConfigManager.add(fieldId, doubleField);
FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
double expectedValue = 1.256;
obj.populateDoubleField(fieldId, expectedValue);
assertTrue(Math.abs(expectedValue - obj.getDouble(fieldId)) < 0.001);
// This shouldn't work as it does not know about the field
FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
assertTrue(Math.abs(obj.getDouble(wrongFieldEnum) - 0.0) < 0.001);
// Try with null - should revert to default value (0.0)
obj.populateDoubleField(fieldId, null);
assertTrue(Math.abs(obj.getDouble(fieldId) - 0.0) < 0.001);
}
use of com.sldeditor.ui.detail.config.FieldConfigDouble in project sldeditor by robward-scisys.
the class GraphicPanelFieldManagerTest method testAddGraphicPanelFieldManager.
/**
* Test method for {@link com.sldeditor.ui.detail.GraphicPanelFieldManager#add(com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
*/
@Test
public void testAddGraphicPanelFieldManager() {
// Set up manager 1
Class<?> expectedPanelId = StrokeDetails.class;
GraphicPanelFieldManager mgr1 = new GraphicPanelFieldManager(expectedPanelId);
FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
FieldConfigString stringField = new FieldConfigString(new FieldConfigCommonData(String.class, expectedFieldId, "test label", false), "button text");
mgr1.addField(stringField);
assertTrue(mgr1.getFields(FieldConfigBoolean.class).isEmpty());
assertEquals(1, mgr1.getFields(FieldConfigString.class).size());
// Set up manager 2
Class<?> expectedPanelId2 = PointFillDetails.class;
GraphicPanelFieldManager mgr2 = new GraphicPanelFieldManager(expectedPanelId2);
FieldIdEnum expectedFieldId2 = FieldIdEnum.ANGLE;
FieldConfigDouble doubleField = new FieldConfigDouble(new FieldConfigCommonData(Double.class, expectedFieldId2, "test label", false));
mgr2.addField(doubleField);
assertEquals(1, mgr2.getFields(FieldConfigDouble.class).size());
// Add manager 2 to manager 1
mgr1.add(mgr2);
FieldIdEnum actualFieldId = mgr1.getFieldEnum(expectedPanelId, stringField);
assertEquals(expectedFieldId, actualFieldId);
actualFieldId = mgr1.getFieldEnum(expectedPanelId2, doubleField);
assertEquals(expectedFieldId2, actualFieldId);
}
use of com.sldeditor.ui.detail.config.FieldConfigDouble in project sldeditor by robward-scisys.
the class StrokeDetailsTest method testStrokeDetailsLine.
/**
* Test method for
* {@link com.sldeditor.ui.detail.StrokeDetails#StrokeDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testStrokeDetailsLine() {
StrokeDetails panel = new StrokeDetails();
panel.populate(null);
// Set up test data
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
SelectedSymbol.getInstance().createNewSLD(sld);
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
String expectedNameLayerValue = "named layer test value";
namedLayer.setName(expectedNameLayerValue);
Style style = DefaultSymbols.createNewStyle();
String expectedNameStyleValue = "style test value";
style.setName(expectedNameStyleValue);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedNameFTSValue = "feature type style test value";
fts.setName(expectedNameFTSValue);
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
String expectedNameValue = "rule test value";
rule.setName(expectedNameValue);
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Stroke stroke = styleFactory.getDefaultStroke();
SymbolTypeFactory fillFactory = new SymbolTypeFactory(StrokeDetails.class, new ColourFieldConfig(GroupIdEnum.FILLCOLOUR, FieldIdEnum.STROKE_FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH), new ColourFieldConfig(GroupIdEnum.STROKECOLOUR, FieldIdEnum.STROKE_FILL_COLOUR, FieldIdEnum.OVERALL_OPACITY, FieldIdEnum.STROKE_FILL_WIDTH), FieldIdEnum.STROKE_STYLE);
fillFactory.populate(panel, panel.getFieldDataManager());
Expression symbolType = ff.literal("star");
List<GraphicalSymbol> symbols = fillFactory.getValue(panel.getFieldDataManager(), symbolType, true, true, FieldConfigMarker.class);
Expression initalGap = ff.literal(0);
Expression gap = ff.literal(0);
GraphicStroke graphicStroke = styleFactory.graphicStroke(symbols, null, ff.literal(10), ff.literal(0), styleFactory.createAnchorPoint(ff.literal(0.5), ff.literal(0.75)), styleFactory.createDisplacement(ff.literal(0.35), ff.literal(0.12)), initalGap, gap);
stroke.setDashArray(new float[] { 1.0f, 2.0f, 3.0f });
stroke.setGraphicStroke(graphicStroke);
LineSymbolizer symbolizer = DefaultSymbols.createDefaultLineSymbolizer();
symbolizer.setStroke(stroke);
rule.symbolizers().add(symbolizer);
fts.rules().add(rule);
sld.layers().add(namedLayer);
SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyle(style);
SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
SelectedSymbol.getInstance().setRule(rule);
SelectedSymbol.getInstance().setSymbolizer(symbolizer);
panel.populate(SelectedSymbol.getInstance());
GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
assertNotNull(fieldDataManager);
double expectedAngle = 14.5;
FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.STROKE_SYMBOL_ANGLE);
angleField.populateField(expectedAngle);
FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY);
double opacity = 0.15;
opacityField.populateField(opacity);
panel.dataChanged(null);
double actualValue = angleField.getDoubleValue();
assertTrue(Math.abs(actualValue - expectedAngle) < 0.01);
assertTrue(panel.isDataPresent());
actualValue = opacityField.getDoubleValue();
assertTrue(Math.abs(actualValue - opacity) < 0.01);
// Reset to default value
panel.preLoadSymbol();
actualValue = angleField.getDoubleValue();
assertTrue(Math.abs(actualValue - 0.0) < 0.01);
actualValue = opacityField.getDoubleValue();
assertTrue(Math.abs(actualValue - 1.0) < 0.01);
}
Aggregations