Search in sources :

Example 71 with StyledLayerDescriptor

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();
    }
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyledLayer(org.geotools.styling.StyledLayer) ArrayList(java.util.ArrayList) LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) UserLayer(org.geotools.styling.UserLayer) File(java.io.File) Font(java.awt.Font) Test(org.junit.jupiter.api.Test)

Example 72 with StyledLayerDescriptor

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;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Example 73 with StyledLayerDescriptor

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);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) Font(java.awt.Font) Test(org.junit.jupiter.api.Test)

Example 74 with StyledLayerDescriptor

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);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) SLDTree(com.sldeditor.ui.tree.SLDTree) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) InputStream(java.io.InputStream) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) IOException(java.io.IOException) File(java.io.File) PopulateDetailsInterface(com.sldeditor.ui.iface.PopulateDetailsInterface) Test(org.junit.jupiter.api.Test)

Example 75 with StyledLayerDescriptor

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);
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) InputStream(java.io.InputStream) IOException(java.io.IOException) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PopulateDetailsInterface(com.sldeditor.ui.iface.PopulateDetailsInterface) SLDTree(com.sldeditor.ui.tree.SLDTree) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TreeSelectionData(com.sldeditor.TreeSelectionData) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) SymbolizerDetailsPanel(com.sldeditor.ui.detail.SymbolizerDetailsPanel) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)134 Test (org.junit.jupiter.api.Test)80 Rule (org.geotools.styling.Rule)54 Style (org.geotools.styling.Style)52 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)50 NamedLayer (org.geotools.styling.NamedLayer)48 SLDData (com.sldeditor.common.data.SLDData)25 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)24 File (java.io.File)22 StyledLayer (org.geotools.styling.StyledLayer)21 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)19 SLDDataInterface (com.sldeditor.common.SLDDataInterface)17 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)17 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)17 StyleWrapper (com.sldeditor.common.data.StyleWrapper)16 IOException (java.io.IOException)16 PointSymbolizer (org.geotools.styling.PointSymbolizer)16 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)15 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)13 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)12