use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class LegendManagerTest method testSeparateSymbolizers.
@Test
public void testSeparateSymbolizers() {
StyledLayerDescriptor sld = testSLD1();
String heading = "Test Heading";
LegendOptionData legendOption = new LegendOptionData();
legendOption.setBackgroundColour(Color.CYAN);
legendOption.setBorder(true);
legendOption.setBandInformation(true);
legendOption.setBorderColour(Color.GREEN);
legendOption.setImageHeight(100);
legendOption.setImageWidth(100);
legendOption.setImageHeight(100);
legendOption.setShowLabels(true);
legendOption.setShowTitle(true);
legendOption.setSplitSymbolizers(true);
int mask = java.awt.Font.PLAIN;
Font labelFont = new Font("Serif", mask, 12);
legendOption.setLabelFont(labelFont);
SelectedSymbol.getInstance().setSld(sld);
StyledLayer styledlayer = sld.layers().get(0);
SelectedSymbol.getInstance().setStyledLayer(styledlayer);
SelectedSymbol.getInstance().setStyle(((UserLayer) styledlayer).userStyles().get(0));
LegendManager.getInstance().sldLoaded(legendOption);
boolean actualResult = compareLegendImage(sld, heading);
assertTrue(actualResult);
File destinationFolder = new File(System.getProperty("java.io.tmpdir"));
String filename = "displayed filename";
List<String> filenameList = new ArrayList<>();
assertTrue(LegendManager.getInstance().saveLegendImage(sld, destinationFolder, "layer name", heading, filename, filenameList));
for (String fileCreated : filenameList) {
File f = new File(fileCreated);
f.delete();
}
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class LegendManagerTest method testSLD1.
/**
* Create test SLD
*
* @return the styled layer descriptor
*/
private StyledLayerDescriptor testSLD1() {
String sldContents = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" " + " xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" " + " xmlns=\"http://www.opengis.net/sld\" " + " xmlns:sld=\"http://www.opengis.net/sld\" " + " xmlns:ogc=\"http://www.opengis.net/ogc\" " + " xmlns:gml=\"http://www.opengis.net/gml\" " + " xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<sld:UserLayer>" + "<sld:Name>Inline</sld:Name>" + "<sld:InlineFeature>" + " <FeatureCollection>" + " <featureMember>" + " <gml:_Feature>" + " <geometryProperty>" + " <Polygon>" + " <outerBoundaryIs>" + " <LinearRing>" + " <coordinates>-127,51 -110,51 -110,41 -127,41 -127,51</coordinates>" + " </LinearRing>" + " </outerBoundaryIs>" + " </Polygon>" + " </geometryProperty>" + " <title>Pacific NW</title>" + " </gml:_Feature>" + " </featureMember>" + " </FeatureCollection>" + "</sld:InlineFeature>" + "<sld:LayerFeatureConstraints>" + " <sld:FeatureTypeConstraint/>" + "</sld:LayerFeatureConstraints>" + "<sld:UserStyle>" + " <sld:Name>Default Styler</sld:Name>" + " <sld:FeatureTypeStyle>" + " <sld:Name>name</sld:Name>" + " <sld:Rule>" + " <sld:PolygonSymbolizer>" + " <sld:Stroke>" + " <sld:CssParameter name=\"stroke\">#FF0000</sld:CssParameter>" + " <sld:CssParameter name=\"stroke-width\">2</sld:CssParameter>" + " </sld:Stroke>" + " </sld:PolygonSymbolizer>" + " <sld:TextSymbolizer>" + " <sld:Label>" + " <ogc:PropertyName>title</ogc:PropertyName>" + " </sld:Label>" + " <sld:LabelPlacement>" + " <sld:PointPlacement>" + " <sld:AnchorPoint>" + " <sld:AnchorPointX>0.0</sld:AnchorPointX>" + " <sld:AnchorPointY>0.5</sld:AnchorPointY>" + " </sld:AnchorPoint>" + " </sld:PointPlacement>" + " </sld:LabelPlacement>" + " <sld:Fill>" + " <sld:CssParameter name=\"fill\">#FF0000</sld:CssParameter>" + " </sld:Fill>" + " </sld:TextSymbolizer>" + " </sld:Rule>" + " </sld:FeatureTypeStyle>" + "</sld:UserStyle>" + "</sld:UserLayer>" + "</StyledLayerDescriptor>";
SLDData sldData = new SLDData(new StyleWrapper(null, "test.sld"), sldContents);
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
return sld;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class LegendManagerTest method testUpdateLegendOptionData.
@Test
public void testUpdateLegendOptionData() {
StyledLayerDescriptor sld = testSLD1();
String heading = "Test Heading";
LegendOptionData legendOption = new LegendOptionData();
legendOption.setBackgroundColour(Color.CYAN);
legendOption.setBorder(true);
legendOption.setBandInformation(true);
legendOption.setBorderColour(Color.GREEN);
legendOption.setImageHeight(100);
legendOption.setImageWidth(100);
legendOption.setImageHeight(100);
legendOption.setShowLabels(true);
legendOption.setShowTitle(true);
int mask = java.awt.Font.BOLD | java.awt.Font.ITALIC;
Font labelFont = new Font("Serif", mask, 12);
legendOption.setLabelFont(labelFont);
LegendManager.getInstance().sldLoaded(legendOption);
boolean actualResult = compareLegendImage(sld, heading);
assertTrue(actualResult);
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class SLDTreeTest method testSLDTreeNull.
/**
* Test method for {@link com.sldeditor.ui.tree.SLDTree#SLDTree(java.util.List)} using null
* values.
*/
@Test
public void testSLDTreeNull() {
List<RenderSymbolInterface> renderList = null;
SLDTree tree1 = new SLDTree(renderList, null);
// Select top level node
tree1.selectFirstSymbol();
String testsldfile = "/polygon/sld/polygon_attributebasedpolygon.sld";
InputStream inputStream = SLDTreeTest.class.getResourceAsStream(testsldfile);
String sldContents = "";
if (inputStream == null) {
assertNotNull(inputStream, "Failed to find sld test file : " + testsldfile);
} else {
File f = null;
try {
f = SLDTestRunner.stream2file(inputStream);
sldContents = readFile(f.getAbsolutePath());
f.delete();
} catch (IOException e1) {
e1.printStackTrace();
}
}
SLDData sldData = new SLDData(null, sldContents);
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
SelectedSymbol.getInstance().setSld(sld);
tree1.populateSLD();
// Nothing selected at this stage
tree1.leafSelected();
PopulateDetailsInterface panel = tree1.getSelectedSymbolPanel();
assertNull(panel);
// Select top level node
tree1.selectFirstSymbol();
tree1.leafSelected();
panel = tree1.getSelectedSymbolPanel();
assertNull(panel);
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class SLDTreeTest method testSLDTree.
/**
* Test method for {@link com.sldeditor.ui.tree.SLDTree#SLDTree(java.util.List)} using values.
* Test method for {@link
* com.sldeditor.ui.tree.SLDTree#addSymbolSelectedListener(com.sldeditor.ui.iface.SymbolizerSelectedInterface)}.
* Test method for {@link com.sldeditor.ui.tree.SLDTree#selectFirstSymbol()}. Test method for
* {@link com.sldeditor.ui.tree.SLDTree#selectTreeItem(com.sldeditor.TreeSelectionData)}. Test
* method for {@link com.sldeditor.ui.tree.SLDTree#getSelectedSymbolPanel()}. Test method for
* {@link com.sldeditor.ui.tree.SLDTree#leafSelected()}.
*/
@Test
public void testSLDTree() {
List<RenderSymbolInterface> renderList = null;
SLDTreeTools treeTools = new SLDTreeTools();
SLDTree tree1 = new SLDTree(renderList, treeTools);
String testsldfile = "/test/polygon_line_point.sld";
InputStream inputStream = SLDTreeTest.class.getResourceAsStream(testsldfile);
String sldContents = "";
if (inputStream == null) {
assertNotNull(inputStream, "Failed to find sld test file : " + testsldfile);
} else {
File f = null;
try {
f = SLDTestRunner.stream2file(inputStream);
sldContents = readFile(f.getAbsolutePath());
f.delete();
} catch (IOException e1) {
e1.printStackTrace();
}
}
SLDData sldData = new SLDData(null, sldContents);
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
SelectedSymbol.getInstance().setSld(sld);
try {
SymbolizerDetailsPanel symbolizerSelectedPanel = new SymbolizerDetailsPanel(null, null);
tree1.addSymbolSelectedListener(symbolizerSelectedPanel);
tree1.populateSLD();
// Nothing selected at this stage
tree1.leafSelected();
PopulateDetailsInterface panel = tree1.getSelectedSymbolPanel();
assertNull(panel);
// Select top level node
tree1.selectFirstSymbol();
tree1.leafSelected();
panel = tree1.getSelectedSymbolPanel();
assertEquals(EmptyPanel.class, panel.getClass());
// Select layer
TreeSelectionData selectedTreeData = new TreeSelectionData();
selectedTreeData.setLayerIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(NamedLayerDetails.class, panel.getClass());
// Select style
selectedTreeData.setStyleIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(StyleDetails.class, panel.getClass());
// Select feature type style
selectedTreeData.setFeatureTypeStyleIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(FeatureTypeStyleDetails.class, panel.getClass());
// Select rule
selectedTreeData.setRuleIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(RuleDetails.class, panel.getClass());
// Select polygon symbolizer
selectedTreeData.setSelectedPanel(PolygonSymbolizerDetails.class);
selectedTreeData.setSymbolizerIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(PolygonSymbolizerDetails.class, panel.getClass());
// Select line symbolizer
selectedTreeData.setSelectedPanel(LineSymbolizerDetails.class);
selectedTreeData.setRuleIndex(1);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(LineSymbolizerDetails.class, panel.getClass());
// Select point symbolizer
selectedTreeData.setSelectedPanel(PointSymbolizerDetails.class);
selectedTreeData.setRuleIndex(2);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(PointSymbolizerDetails.class, panel.getClass());
// Select text symbolizer
selectedTreeData.setSelectedPanel(TextSymbolizerDetails.class);
selectedTreeData.setSymbolizerIndex(1);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(TextSymbolizerDetails.class, panel.getClass());
// Select raster symbolizer
selectedTreeData.setSelectedPanel(RasterSymbolizerDetails.class);
selectedTreeData.setSymbolizerIndex(2);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(RasterSymbolizerDetails.class, panel.getClass());
// Select polygon symbolizer / fill
selectedTreeData.setSelectedPanel(PolygonFillDetails.class);
selectedTreeData.setSymbolizerIndex(0);
selectedTreeData.setSymbolizerDetailIndex(0);
selectedTreeData.setRuleIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(PolygonFillDetails.class, panel.getClass());
// Select polygon symbolizer / stroke
selectedTreeData.setSelectedPanel(StrokeDetails.class);
selectedTreeData.setSymbolizerDetailIndex(1);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(StrokeDetails.class, panel.getClass());
// Select point symbolizer / fill
selectedTreeData.setSelectedPanel(PointFillDetails.class);
selectedTreeData.setRuleIndex(2);
selectedTreeData.setSymbolizerIndex(0);
selectedTreeData.setSymbolizerDetailIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(PointFillDetails.class, panel.getClass());
// Select line symbolizer / stroke
selectedTreeData.setSelectedPanel(StrokeDetails.class);
selectedTreeData.setRuleIndex(1);
selectedTreeData.setSymbolizerIndex(0);
selectedTreeData.setSymbolizerDetailIndex(0);
assertTrue(tree1.selectTreeItem(selectedTreeData));
panel = tree1.getSelectedSymbolPanel();
assertEquals(StrokeDetails.class, panel.getClass());
// Error cases
selectedTreeData.setSymbolizerDetailIndex(-2);
assertFalse(tree1.selectTreeItem(selectedTreeData));
selectedTreeData.setSymbolizerDetailIndex(1);
assertFalse(tree1.selectTreeItem(selectedTreeData));
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
}
Aggregations