use of com.sldeditor.ui.detail.config.FieldConfigSlider 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.FieldConfigSlider in project sldeditor by robward-scisys.
the class FieldConfigMarkerTest method testGetFieldList.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#getFieldList(com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
*/
@Test
public void testGetFieldList() {
Class<?> panelId = PointFillDetails.class;
// Test it with non null values
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();
GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(panelId);
fieldConfigManager.add(colourFieldId, colourField);
FieldIdEnum opacityFieldId = FieldIdEnum.OVERALL_OPACITY;
fieldConfigManager.add(opacityFieldId, opacityField);
FieldIdEnum symbolSelectionFieldId = FieldIdEnum.SYMBOL_TYPE;
fieldConfigManager.add(symbolSelectionFieldId, symbolSelectionField);
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), fillConfig, strokeConfig, null);
assertTrue(field.getFieldList(null).isEmpty());
Map<FieldIdEnum, FieldConfigBase> actualFieldList = field.getFieldList(fieldConfigManager);
assertFalse(actualFieldList.isEmpty());
assertEquals(5, actualFieldList.size());
}
use of com.sldeditor.ui.detail.config.FieldConfigSlider 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();
}
}
use of com.sldeditor.ui.detail.config.FieldConfigSlider in project sldeditor by robward-scisys.
the class FieldConfigArrowTest method testGetValue.
/**
* Test method for
* {@link com.sldeditor.ui.detail.vendor.geoserver.marker.arrow.FieldConfigArrow#getValue(com.sldeditor.ui.detail.GraphicPanelFieldManager, org.opengis.filter.expression.Expression, boolean, boolean)}.
*/
@Test
public void testGetValue() {
// Test it with null values
boolean valueOnly = true;
FieldConfigArrow field = new FieldConfigArrow(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
assertNull(field.getStringValue());
GraphicPanelFieldManager fieldConfigManager = null;
Expression symbolType = null;
List<GraphicalSymbol> actualValue = field.getValue(fieldConfigManager, symbolType, false, false);
assertTrue(actualValue.isEmpty());
Class<?> panelId = PointFillDetails.class;
fieldConfigManager = new GraphicPanelFieldManager(panelId);
String actualMarkerSymbol = "solid";
StyleBuilder styleBuilder = new StyleBuilder();
symbolType = styleBuilder.literalExpression(actualMarkerSymbol);
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);
// Try without setting any fields
actualValue = field.getValue(fieldConfigManager, symbolType, false, false);
assertNotNull(actualValue);
assertEquals(0, actualValue.size());
// Try with symbol type of solid
ColourFieldConfig fillFieldConfig = new ColourFieldConfig(GroupIdEnum.FILLCOLOUR, FieldIdEnum.FILL_COLOUR, FieldIdEnum.POINT_STROKE_OPACITY, FieldIdEnum.SYMBOL_TYPE);
ColourFieldConfig strokeFieldConfig = new ColourFieldConfig(GroupIdEnum.STROKECOLOUR, FieldIdEnum.STROKE_FILL_COLOUR, FieldIdEnum.POINT_STROKE_OPACITY, FieldIdEnum.SYMBOL_TYPE);
FieldConfigArrow field2 = new FieldConfigArrow(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), fillFieldConfig, strokeFieldConfig, null);
actualValue = field2.getValue(fieldConfigManager, symbolType, false, false);
assertNotNull(actualValue);
assertEquals(0, actualValue.size());
field2.createUI();
// Try with symbol type of extshape://arrow shape
actualMarkerSymbol = "extshape://arrow?hr=1.2&t=0.34&ab=0.5";
field2.setTestValue(null, actualMarkerSymbol);
symbolType = styleBuilder.literalExpression(actualMarkerSymbol);
actualValue = field2.getValue(fieldConfigManager, symbolType, false, false);
assertNotNull(actualValue);
assertEquals(1, actualValue.size());
Mark actualSymbol = (Mark) actualValue.get(0);
assertTrue(actualSymbol.getWellKnownName().toString().compareTo(actualMarkerSymbol) == 0);
assertNull(actualSymbol.getFill());
assertNull(actualSymbol.getStroke());
// Enable stroke and fill flags
actualValue = field2.getValue(fieldConfigManager, symbolType, true, true);
assertNotNull(actualValue);
assertEquals(1, actualValue.size());
actualSymbol = (Mark) actualValue.get(0);
assertTrue(actualSymbol.getWellKnownName().toString().compareTo(actualMarkerSymbol) == 0);
assertNotNull(actualSymbol.getFill());
assertNotNull(actualSymbol.getStroke());
}
use of com.sldeditor.ui.detail.config.FieldConfigSlider 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