use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.
the class FieldConfigWindBarbsTest method testGetValue.
/**
* Test method for
* {@link com.sldeditor.ui.detail.vendor.geoserver.marker.windbarb.FieldConfigWindBarbs#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;
FieldConfigWindBarbs field = new FieldConfigWindBarbs(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
field.createUI();
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(1, actualValue.size());
Mark actualSymbol = (Mark) actualValue.get(0);
assertTrue(actualSymbol.getWellKnownName().toString().compareTo("windbarbs://default(0)[m/s]") == 0);
}
use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.
the class FieldConfigTTFTest method testGetValue.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.symboltype.ttf.FieldConfigTTF#getValue(com.sldeditor.ui.detail.GraphicPanelFieldManager, org.opengis.filter.expression.Expression, boolean, boolean)}.
*/
@Test
public void testGetValue() {
GraphicPanelFieldManager fieldConfigManager = null;
Class<?> panelId = PointFillDetails.class;
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);
fieldConfigManager.add(colourFieldId, colourField);
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);
boolean valueOnly = true;
FieldConfigTTF field = new FieldConfigTTF(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), fillConfig, strokeConfig, null);
List<GraphicalSymbol> actualValue = field.getValue(null, null, false, false);
assertTrue(actualValue.isEmpty());
field.createUI();
actualValue = field.getValue(null, null, false, false);
assertTrue(actualValue.isEmpty());
actualValue = field.getValue(fieldConfigManager, null, false, false);
assertTrue(actualValue.size() == 1);
}
use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.
the class UpdateGraphicalSymbol method processGraphicalSymbol.
/*
* (non-Javadoc)
*
* @see com.sldeditor.common.data.ProcessGraphicSymbolInterface#processGraphicalSymbol(java.net.URL, java.util.List, java.util.List)
*/
@Override
public void processGraphicalSymbol(URL resourceLocator, List<GraphicalSymbol> graphicalSymbolList, List<String> externalImageList) {
for (GraphicalSymbol symbol : graphicalSymbolList) {
if (symbol instanceof ExternalGraphic) {
ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) symbol;
OnLineResourceImpl onlineResource = (OnLineResourceImpl) externalGraphic.getOnlineResource();
String currentValue = null;
URL currentValueURL = null;
try {
currentValueURL = onlineResource.getLinkage().toURL();
currentValue = currentValueURL.toExternalForm();
} catch (MalformedURLException e) {
ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
}
if ((resourceLocator == null) || RelativePath.hasHost(currentValueURL)) {
// Just report back the external image
URI uri = null;
try {
uri = new URI(currentValue);
externalImageList.add(uri.toASCIIString());
} catch (URISyntaxException e) {
ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
}
} else {
try {
File file = new File(currentValueURL.getFile());
File folder = new File(resourceLocator.getFile());
currentValue = RelativePath.getRelativePath(file, folder);
// If the backslashes are not converted to forward slashes
// creating the URI does not work
currentValue = currentValue.replace('\\', '/');
OnLineResourceImpl updatedOnlineResource = new OnLineResourceImpl();
URI uri = new URI(currentValue);
updatedOnlineResource.setLinkage(uri);
externalGraphic.setOnlineResource(updatedOnlineResource);
externalGraphic.setURI(uri.toASCIIString());
externalImageList.add(uri.toASCIIString());
} catch (URISyntaxException e) {
ConsoleManager.getInstance().exception(SLDExternalImages.class, e);
}
}
}
}
}
use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.
the class DefaultSymbols method createArrow.
/**
* Creates the arrow.
*
* @param angleFunction the angle function
* @param locationFunction the location function
* @param markerSymbol the marker symbol
* @param isSourceArrow the is source arrow
* @return the point symbolizer
*/
private static PointSymbolizer createArrow(FunctionName angleFunction, FunctionName locationFunction, String markerSymbol, boolean isSourceArrow) {
String name = isSourceArrow ? Localisation.getString(SLDTreeTools.class, "TreeItem.sourceArrow") : Localisation.getString(SLDTreeTools.class, "TreeItem.destArrow");
PointSymbolizer pointSymbolizer = createDefaultPointSymbolizer();
pointSymbolizer.setName(name);
Graphic graphic = pointSymbolizer.getGraphic();
graphic.setSize(ff.literal(DEFAULT_ARROW_SIZE));
List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
MarkImpl mark = (MarkImpl) graphicalSymbolList.get(0);
Expression wellKnownName = ff.literal(markerSymbol);
mark.setWellKnownName(wellKnownName);
mark.getFill().setColor(ff.literal(DEFAULT_COLOUR));
// Arrow rotation
List<Expression> rotationArgumentList = new ArrayList<Expression>();
String geometryFieldName = "geom";
DataSourceInterface dsInfo = DataSourceFactory.getDataSource();
if (dsInfo != null) {
geometryFieldName = dsInfo.getGeometryFieldName();
}
rotationArgumentList.add(ff.property(geometryFieldName));
Expression rotation = FunctionManager.getInstance().createExpression(angleFunction, rotationArgumentList);
if (isSourceArrow) {
graphic.setRotation(ff.add(ff.literal(DEGREES_180), rotation));
} else {
graphic.setRotation(rotation);
}
AnchorPoint anchorPoint = styleFactory.anchorPoint(ff.literal(0.5), ff.literal(0.5));
graphic.setAnchorPoint(anchorPoint);
// Set location of the arrow head
List<Expression> endPointArgumentList = new ArrayList<Expression>();
endPointArgumentList.add(ff.property(geometryFieldName));
Expression geometry = FunctionManager.getInstance().createExpression(locationFunction, endPointArgumentList);
pointSymbolizer.setGeometry(geometry);
return pointSymbolizer;
}
use of org.opengis.style.GraphicalSymbol in project sldeditor by robward-scisys.
the class PolygonFillDetails method populate.
/**
* Populate.
*
* @param selectedSymbol the selected symbol
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.SelectedSymbol)
*/
@Override
public void populate(SelectedSymbol selectedSymbol) {
Expression expSize = null;
Expression expRotation = null;
Expression expAnchorPointX = null;
Expression expAnchorPointY = null;
Expression expDisplacementX = null;
Expression expDisplacementY = null;
Expression expFillColour = null;
Expression expGap = null;
Expression expInitialGap = null;
Fill fill = null;
Expression expOpacity = null;
symbolizer = null;
if (selectedSymbol != null) {
symbolizer = selectedSymbol.getSymbolizer();
Graphic graphic = null;
if (symbolizer instanceof PointSymbolizerImpl) {
PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
graphic = pointSymbolizer.getGraphic();
if (graphic != null) {
List<GraphicalSymbol> graphicSymbolList = graphic.graphicalSymbols();
if (!graphicSymbolList.isEmpty()) {
GraphicalSymbol graphicalSymbol = graphicSymbolList.get(0);
if (graphicalSymbol instanceof MarkImpl) {
MarkImpl mark = (MarkImpl) graphicalSymbol;
fill = mark.getFill();
if (fill != null) {
expOpacity = fill.getOpacity();
}
}
}
}
} else if (symbolizer instanceof PolygonSymbolizerImpl) {
PolygonSymbolizer polygonSymbolizer = (PolygonSymbolizer) symbolizer;
if (polygonSymbolizer != null) {
fill = polygonSymbolizer.getFill();
if (fill != null) {
expOpacity = fill.getOpacity();
graphic = fill.getGraphicFill();
}
}
}
if (graphic == null) {
if (fill != null) {
expFillColour = fill.getColor();
}
if (fill == null) {
symbolTypeFactory.setNoFill(this.fieldConfigManager);
} else {
symbolTypeFactory.setSolidFill(this.fieldConfigManager, expFillColour, expOpacity);
}
} else {
expSize = graphic.getSize();
expRotation = graphic.getRotation();
// Anchor point
AnchorPoint anchorPoint = graphic.getAnchorPoint();
if (anchorPoint != null) {
expAnchorPointX = anchorPoint.getAnchorPointX();
expAnchorPointY = anchorPoint.getAnchorPointY();
} else {
expAnchorPointX = defaultAnchorPoint.getAnchorPointX();
expAnchorPointY = defaultAnchorPoint.getAnchorPointY();
}
// Offset
Displacement displacement = graphic.getDisplacement();
if (displacement != null) {
expDisplacementX = displacement.getDisplacementX();
expDisplacementY = displacement.getDisplacementY();
} else {
expDisplacementX = defaultDisplacement.getDisplacementX();
expDisplacementY = defaultDisplacement.getDisplacementY();
}
expGap = graphic.getGap();
expInitialGap = graphic.getInitialGap();
List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
if (!graphicalSymbolList.isEmpty()) {
GraphicalSymbol symbol = graphicalSymbolList.get(0);
symbolTypeFactory.setValue(PolygonSymbolizer.class, this.fieldConfigManager, graphic, symbol);
}
}
}
fieldConfigVisitor.populateField(FieldIdEnum.SIZE, expSize);
fieldConfigVisitor.populateField(FieldIdEnum.ANGLE, expRotation);
fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_H, expAnchorPointX);
fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_V, expAnchorPointY);
fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_X, expDisplacementX);
fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_Y, expDisplacementY);
fieldConfigVisitor.populateField(FieldIdEnum.GAP, expGap);
fieldConfigVisitor.populateField(FieldIdEnum.INITIAL_GAP, expInitialGap);
fieldConfigVisitor.populateField(FieldIdEnum.OVERALL_OPACITY, expOpacity);
if (vendorOptionFillFactory != null) {
if (symbolizer instanceof PolygonSymbolizer) {
vendorOptionFillFactory.populate((PolygonSymbolizer) symbolizer);
}
}
updateSymbol();
}
Aggregations