use of org.geotools.styling.ExternalGraphicImpl 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.geotools.styling.ExternalGraphicImpl in project sldeditor by robward-scisys.
the class FieldConfigFilename method setValue.
/**
* Sets the value.
*
* @param symbolizerType the symbolizer type
* @param fieldConfigManager the field config manager
* @param multiOptionPanel the multi option panel
* @param graphic the graphic
* @param symbol the symbol
*/
@Override
public void setValue(Class<?> symbolizerType, GraphicPanelFieldManager fieldConfigManager, FieldConfigSymbolType multiOptionPanel, Graphic graphic, GraphicalSymbol symbol) {
if (symbol instanceof ExternalGraphicImpl) {
ExternalGraphicImpl markerSymbol = (ExternalGraphicImpl) symbol;
if (externalGraphicPanel != null) {
externalGraphicPanel.setValue(markerSymbol);
}
if (multiOptionPanel != null) {
multiOptionPanel.setSelectedItem(EXTERNAL_SYMBOL_KEY);
}
FieldConfigBase opacity = fieldConfigManager.get(FieldIdEnum.OVERALL_OPACITY);
if (opacity != null) {
opacity.populate(graphic.getOpacity());
}
}
}
use of org.geotools.styling.ExternalGraphicImpl in project sldeditor by robward-scisys.
the class StrokeDetails method populateStroke.
/**
* Populate stroke.
*
* @param symbolizerType the symbolizer type
* @param stroke the stroke
*/
private void populateStroke(Class<?> symbolizerType, Stroke stroke) {
Expression expColour = null;
Expression expStrokeColour = null;
Expression expOpacity = null;
Expression expStrokeWidth = null;
Expression expStrokeOffset = null;
Expression expStrokeLineCap = null;
Expression expStrokeLineJoin = null;
Expression expStrokeDashArray = null;
Expression expAnchorPointX = null;
Expression expAnchorPointY = null;
Expression expDisplacementX = null;
Expression expDisplacementY = null;
Expression expGap = null;
Expression expInitialGap = null;
Expression expSymbolSize = null;
Expression expSymbolRotation = null;
if (stroke == null) {
expColour = getFilterFactory().literal("#000000");
expOpacity = getFilterFactory().literal(1.0);
symbolTypeFactory.setSolidFill(fieldConfigManager, expColour, expOpacity);
expStrokeWidth = getFilterFactory().literal(1.0);
expStrokeOffset = getFilterFactory().literal(0.0);
expStrokeLineCap = getFilterFactory().literal("round");
expStrokeLineJoin = getFilterFactory().literal("round");
expStrokeDashArray = getFilterFactory().literal("");
} else {
Graphic graphicFill = stroke.getGraphicFill();
Graphic graphicStroke = stroke.getGraphicStroke();
if ((graphicFill == null) && (graphicStroke == null)) {
expOpacity = stroke.getOpacity();
symbolTypeFactory.setSolidFill(fieldConfigManager, stroke.getColor(), stroke.getOpacity());
}
expOpacity = stroke.getOpacity();
expStrokeWidth = stroke.getWidth();
expStrokeOffset = stroke.getDashOffset();
expStrokeLineCap = stroke.getLineCap();
expStrokeLineJoin = stroke.getLineJoin();
expColour = stroke.getColor();
List<Float> dashesArray = getStrokeDashArray(stroke);
expStrokeDashArray = getFilterFactory().literal(createDashArrayString(dashesArray));
if (graphicStroke != null) {
// Anchor points
AnchorPoint anchorPoint = graphicStroke.getAnchorPoint();
if (anchorPoint != null) {
expAnchorPointX = anchorPoint.getAnchorPointX();
expAnchorPointY = anchorPoint.getAnchorPointY();
} else {
expAnchorPointX = defaultAnchorPoint.getAnchorPointX();
expAnchorPointY = defaultAnchorPoint.getAnchorPointY();
}
// Displacement
Displacement displacement = graphicStroke.getDisplacement();
if (displacement != null) {
expDisplacementX = displacement.getDisplacementX();
expDisplacementY = displacement.getDisplacementY();
} else {
expDisplacementX = defaultDisplacement.getDisplacementX();
expDisplacementY = defaultDisplacement.getDisplacementY();
}
expGap = graphicStroke.getGap();
expInitialGap = graphicStroke.getInitialGap();
expSymbolSize = graphicStroke.getSize();
expSymbolRotation = graphicStroke.getRotation();
List<GraphicalSymbol> graphicSymbolList = graphicStroke.graphicalSymbols();
for (GraphicalSymbol graphicSymbol : graphicSymbolList) {
if (graphicSymbol instanceof MarkImpl) {
MarkImpl mark = (MarkImpl) graphicSymbol;
Mark defaultMark = getStyleFactory().getDefaultMark();
Fill markFill = mark.getFill();
if (markFill != null) {
expColour = markFill.getColor();
}
expStrokeColour = defaultMark.getStroke().getColor();
Stroke markStroke = mark.getStroke();
if (markStroke != null) {
expStrokeColour = markStroke.getColor();
}
} else if (graphicSymbol instanceof ExternalGraphicImpl) {
@SuppressWarnings("unused") ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) graphicSymbol;
}
symbolTypeFactory.setValue(symbolizerType, this.fieldConfigManager, graphicStroke, graphicSymbol);
}
}
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_WIDTH, expStrokeWidth);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_OFFSET, expStrokeOffset);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_CAP, expStrokeLineCap);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_LINE_JOIN, expStrokeLineJoin);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_DASH_ARRAY, expStrokeDashArray);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_GAP, expGap);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_INITIAL_GAP, expInitialGap);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_SIZE, expSymbolSize);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANGLE, expSymbolRotation);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_H, expAnchorPointX);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_ANCHOR_POINT_V, expAnchorPointY);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_X, expDisplacementX);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_SYMBOL_DISPLACEMENT_Y, expDisplacementY);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_FILL_COLOUR, expColour);
fieldConfigVisitor.populateField(FieldIdEnum.STROKE_STROKE_COLOUR, expStrokeColour);
if ((graphicFill == null) && (graphicStroke == null)) {
GroupConfigInterface fillColourGroup = getGroup(GroupIdEnum.FILLCOLOUR);
if (fillColourGroup != null) {
fillColourGroup.enable(true);
}
}
//
// GroupConfigInterface strokeColourGroup = getGroup(GroupIdEnum.STROKECOLOUR);
// if (strokeColourGroup != null) {
// strokeColourGroup.enable(strokeColourEnabled);
// }
}
}
use of org.geotools.styling.ExternalGraphicImpl in project sldeditor by robward-scisys.
the class FieldConfigMarkerTest method testAccept.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.symboltype.FieldConfigMarker#accept(org.opengis.style.GraphicalSymbol)}.
*/
@Test
public void testAccept() {
boolean valueOnly = true;
FieldConfigMarker field = new FieldConfigMarker(new FieldConfigCommonData(String.class, FieldIdEnum.NAME, "test label", valueOnly), null, null, null);
assertFalse(field.accept(null));
StyleBuilder styleBuilder = new StyleBuilder();
ExternalGraphicImpl externalGraphic = (ExternalGraphicImpl) styleBuilder.createExternalGraphic("test.tmp", "png");
assertFalse(field.accept(externalGraphic));
Mark marker = styleBuilder.createMark("triangle");
assertFalse(field.accept(marker));
List<ValueComboBoxData> dataList = new ArrayList<ValueComboBoxData>();
dataList.add(new ValueComboBoxData("star", "Star", this.getClass()));
dataList.add(new ValueComboBoxData("square", "Square", this.getClass()));
dataList.add(new ValueComboBoxData("triangle", "Triangle", this.getClass()));
List<ValueComboBoxDataGroup> groupList = new ArrayList<ValueComboBoxDataGroup>();
groupList.add(new ValueComboBoxDataGroup(dataList));
field.populateSymbolList(String.class, groupList);
field.populateSymbolList(PointFillDetails.class, groupList);
assertTrue(field.accept(marker));
field.populateSymbolList(PointFillDetails.class, groupList);
assertTrue(field.accept(marker));
}
use of org.geotools.styling.ExternalGraphicImpl in project sldeditor by robward-scisys.
the class ExternalGraphicDetailsTest method testSetValueExternalGraphicImpl.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.symboltype.externalgraphic.ExternalGraphicDetails#setValue(org.geotools.styling.ExternalGraphicImpl)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.symboltype.externalgraphic.ExternalGraphicDetails#getSymbol()}.
*/
@Test
public void testSetValueExternalGraphicImpl() {
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
ExternalGraphicImpl externalGraphic = null;
DummyExternalGraphicUpdate callback = new DummyExternalGraphicUpdate();
ExternalGraphicDetails panel = new ExternalGraphicDetails(callback);
assertNull(panel.getSymbol());
panel.setValue(externalGraphic);
String expectedString = "a/b/c/test.png";
URL expectedURL = null;
try {
expectedURL = new File(expectedString).toURI().toURL();
externalGraphic = (ExternalGraphicImpl) styleFactory.createExternalGraphic(expectedURL, "image/png");
} catch (MalformedURLException e) {
e.printStackTrace();
fail();
}
assertFalse(callback.isCalled());
panel.setValue(externalGraphic);
ExternalGraphicImpl actual = (ExternalGraphicImpl) panel.getSymbol();
try {
assertEquals(expectedURL.toExternalForm(), actual.getLocation().toExternalForm());
} catch (MalformedURLException e) {
e.printStackTrace();
fail();
}
assertTrue(callback.isCalled());
expectedString = "http://example.com/test.png";
externalGraphic = (ExternalGraphicImpl) styleFactory.createExternalGraphic(expectedString, "image/png");
assertFalse(callback.isCalled());
panel.setValue(externalGraphic);
actual = (ExternalGraphicImpl) panel.getSymbol();
assertTrue(callback.isCalled());
try {
assertEquals(externalGraphic.getLocation().toExternalForm(), actual.getLocation().toExternalForm());
} catch (MalformedURLException e) {
e.printStackTrace();
fail();
}
}
Aggregations