use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class SymbolizerTreeItemTest method testGetTreeString.
/**
* Test method for {@link
* com.sldeditor.ui.tree.item.SymbolizerTreeItem#getTreeString(java.lang.Object)}.
*/
@Test
public void testGetTreeString() {
SymbolizerTreeItem item = new SymbolizerTreeItem();
String actualValue = item.getTreeString(null, null);
assertNull(actualValue);
Symbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
actualValue = item.getTreeString(null, pointSymbolizer);
String expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.newMarker");
assertTrue(actualValue.compareTo(expectedValue) == 0);
pointSymbolizer.setName(null);
actualValue = item.getTreeString(null, pointSymbolizer);
expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.marker");
assertTrue(actualValue.compareTo(expectedValue) == 0);
Symbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
actualValue = item.getTreeString(null, lineSymbolizer);
expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.line");
assertTrue(actualValue.compareTo(expectedValue) == 0);
Symbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
actualValue = item.getTreeString(null, polygonSymbolizer);
expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.polygon");
assertTrue(actualValue.compareTo(expectedValue) == 0);
Symbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
actualValue = item.getTreeString(null, textSymbolizer);
expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.newText");
assertTrue(actualValue.compareTo(expectedValue) == 0);
textSymbolizer.setName("");
actualValue = item.getTreeString(null, textSymbolizer);
expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.text");
assertTrue(actualValue.compareTo(expectedValue) == 0);
Symbolizer rasterSymbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
actualValue = item.getTreeString(null, rasterSymbolizer);
expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.raster");
assertTrue(actualValue.compareTo(expectedValue) == 0);
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class SymbolizerTreeItemTest method testItemSelected.
/**
* Test method for {@link
* com.sldeditor.ui.tree.item.SymbolizerTreeItem#itemSelected(javax.swing.tree.DefaultMutableTreeNode,
* java.lang.Object)}.
*/
@Test
public void testItemSelected() {
SymbolizerTreeItem item = new SymbolizerTreeItem();
item.itemSelected(null, null);
Symbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
Rule rule = DefaultSymbols.createNewRule();
DefaultMutableTreeNode parentNode = new DefaultMutableTreeNode();
parentNode.setUserObject(rule);
DefaultMutableTreeNode node = new DefaultMutableTreeNode();
parentNode.add(node);
item.itemSelected(node, symbolizer);
// Get the code coverage stats up
item.itemSelected(parentNode, symbolizer);
parentNode.setUserObject(item);
item.itemSelected(node, null);
}
use of org.geotools.styling.Symbolizer in project sldeditor by robward-scisys.
the class SLDExternalImages method externalGraphicSymbolVisitor.
/**
* Find the SLD graphical symbols.
*
* @param resourceLocator the resource locator
* @param sld the sld
* @param externalImageList the external image list
* @param process the process
*/
private static void externalGraphicSymbolVisitor(URL resourceLocator, StyledLayerDescriptor sld, List<String> externalImageList, ProcessGraphicSymbolInterface process) {
if (sld == null) {
return;
}
if (process == null) {
return;
}
for (StyledLayer styledLayer : sld.layers()) {
List<Style> styles = null;
if (styledLayer instanceof NamedLayer) {
NamedLayerImpl namedLayer = (NamedLayerImpl) styledLayer;
styles = namedLayer.styles();
} else if (styledLayer instanceof UserLayer) {
UserLayerImpl userLayer = (UserLayerImpl) styledLayer;
styles = userLayer.userStyles();
}
if (styles != null) {
for (Style style : styles) {
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
for (Rule rule : fts.rules()) {
for (Symbolizer symbolizer : rule.symbolizers()) {
if (symbolizer instanceof PointSymbolizer) {
PointSymbolizer point = (PointSymbolizer) symbolizer;
if (point.getGraphic() != null) {
process.processGraphicalSymbol(resourceLocator, point.getGraphic().graphicalSymbols(), externalImageList);
}
} else if (symbolizer instanceof LineSymbolizer) {
LineSymbolizer line = (LineSymbolizer) symbolizer;
updateStroke(resourceLocator, line.getStroke(), externalImageList, process);
} else if (symbolizer instanceof PolygonSymbolizer) {
PolygonSymbolizer polygon = (PolygonSymbolizer) symbolizer;
updateStroke(resourceLocator, polygon.getStroke(), externalImageList, process);
updateFill(resourceLocator, polygon.getFill(), externalImageList, process);
}
}
}
}
}
}
}
}
use of org.geotools.styling.Symbolizer in project polymap4-core by Polymap4.
the class StyleCompositeSerializer method defaultFeatureTypeStyle.
protected FeatureTypeStyle defaultFeatureTypeStyle(org.geotools.styling.Style result, Style style, Symbolizer... symbolizers) {
Rule rule = sf.createRule();
// handle visibleIf
FilterStyleProperty visibleIf = (FilterStyleProperty) style.visibleIf.get();
if (visibleIf instanceof ScaleRangeFilter) {
rule.setMinScaleDenominator(((ScaleRangeFilter) visibleIf).minScale.get());
rule.setMaxScaleDenominator(((ScaleRangeFilter) visibleIf).maxScale.get());
} else if (visibleIf instanceof ConstantFilter) {
Filter filter = ((ConstantFilter) visibleIf).filter();
if (!filter.equals(Filter.INCLUDE)) {
rule.setFilter(filter);
}
} else {
throw new RuntimeException("Unhandled Style.visibleIf type: " + visibleIf.getClass());
}
for (Symbolizer s : symbolizers) {
rule.symbolizers().add(s);
}
;
FeatureTypeStyle fts = sf.createFeatureTypeStyle();
fts.rules().add(rule);
result.featureTypeStyles().add(fts);
return fts;
}
use of org.geotools.styling.Symbolizer in project hale by halestudio.
the class DefinitionImages method getLegendImage.
/**
* Get a legend image for a given type definition
*
* @param type the type definition
* @param dataSet the data set the type definition belongs to
* @param definedOnly if only for defined styles a image shall be created
* @return the legend image or <code>null</code>
*/
protected BufferedImage getLegendImage(TypeDefinition type, DataSet dataSet, boolean definedOnly) {
StyleService ss = PlatformUI.getWorkbench().getService(StyleService.class);
Style style = (definedOnly) ? (ss.getDefinedStyle(type)) : (ss.getStyle(type, dataSet));
if (style == null) {
return null;
}
// create a dummy feature based on the style
Drawer d = Drawer.create();
SimpleFeature feature = null;
Symbolizer[] symbolizers = SLD.symbolizers(style);
if (symbolizers.length > 0) {
Symbolizer symbolizer = symbolizers[0];
if (symbolizer instanceof LineSymbolizer) {
feature = d.feature(d.line(LINE_POINTS));
} else if (symbolizer instanceof PointSymbolizer) {
feature = d.feature(d.point(WIDTH / 2, HEIGHT / 2));
}
if (symbolizer instanceof PolygonSymbolizer) {
feature = d.feature(d.polygon(POLY_POINTS));
}
}
if (feature != null) {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
// GraphicsEnvironment.getLocalGraphicsEnvironment().
// getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(WIDTH, HEIGHT,
// Transparency.TRANSLUCENT);
// use white background to have a neutral color even if selected
Color bg = Color.WHITE;
Graphics2D g = image.createGraphics();
try {
g.setColor(bg);
g.fillRect(0, 0, WIDTH, HEIGHT);
} finally {
g.dispose();
}
d.drawDirect(image, feature, style);
return image;
}
return null;
}
Aggregations