Search in sources :

Example 1 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class InlineFeatureUtilsTest method testDetermineGeometryType.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#determineGeometryType(org.opengis.feature.type.GeometryDescriptor, org.geotools.data.simple.SimpleFeatureCollection)}.
 */
@Test
public void testDetermineGeometryType() {
    // Test 1
    SLDData sldData = new SLDData(null, testInline1a);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    UserLayer userLayer1 = (UserLayer) sld.layers().get(0);
    GeometryDescriptor geometryDescriptor = userLayer1.getInlineFeatureType().getGeometryDescriptor();
    String typeName = userLayer1.getInlineFeatureType().getTypeName();
    SimpleFeatureCollection simpleFeatureCollection = null;
    try {
        simpleFeatureCollection = userLayer1.getInlineFeatureDatastore().getFeatureSource(typeName).getFeatures();
    } catch (IOException e) {
        e.printStackTrace();
    }
    assertEquals(GeometryTypeEnum.UNKNOWN, InlineFeatureUtils.determineGeometryType(null, null));
    assertEquals(GeometryTypeEnum.UNKNOWN, InlineFeatureUtils.determineGeometryType(geometryDescriptor, null));
    assertEquals(GeometryTypeEnum.POLYGON, InlineFeatureUtils.determineGeometryType(geometryDescriptor, simpleFeatureCollection));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) IOException(java.io.IOException) UserLayer(org.geotools.styling.UserLayer) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Test(org.junit.Test)

Example 2 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class InlineFeatureUtilsTest method testExtractUserLayers.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#extractUserLayers(org.geotools.styling.StyledLayerDescriptor)}.
 */
@Test
public void testExtractUserLayers() {
    assertTrue(InlineFeatureUtils.extractUserLayers(null).isEmpty());
    // Contains inline data
    SLDData sldData = new SLDData(null, testInline1a);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    assertEquals(1, InlineFeatureUtils.extractUserLayers(sld).size());
    // Contains no inline data
    sldData = new SLDData(null, testNoInline);
    sld = SLDUtils.createSLDFromString(sldData);
    assertEquals(1, InlineFeatureUtils.extractUserLayers(sld).size());
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Test(org.junit.Test)

Example 3 with SLDData

use of com.sldeditor.common.data.SLDData 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);
    URL url = SLDTreeTest.class.getResource("/test/polygon_line_point.sld");
    String sldContents = readFile(new File(url.getFile()).getAbsolutePath());
    SLDData sldData = new SLDData(null, sldContents);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    SelectedSymbol.getInstance().setSld(sld);
    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));
}
Also used : SLDData(com.sldeditor.common.data.SLDData) 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) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) URL(java.net.URL) PopulateDetailsInterface(com.sldeditor.ui.iface.PopulateDetailsInterface) Test(org.junit.Test)

Example 4 with SLDData

use of com.sldeditor.common.data.SLDData 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();
    URL url = SLDTreeTest.class.getResource("/polygon/sld/polygon_attributebasedpolygon.sld");
    String sldContents = readFile(new File(url.getFile()).getAbsolutePath());
    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) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) File(java.io.File) URL(java.net.URL) PopulateDetailsInterface(com.sldeditor.ui.iface.PopulateDetailsInterface) Test(org.junit.Test)

Example 5 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class MapBoxToolTest method testSetSelectedItems.

/**
 * Test method for
 * {@link com.sldeditor.tool.mapbox.MapBoxTool#setSelectedItems(java.util.List, java.util.List)}.
 */
@Test
public void testSetSelectedItems() {
    MapBoxTool tool = new MapBoxTool();
    JPanel panel = tool.getPanel();
    ToolButton toSLD = null;
    for (Component c : panel.getComponents()) {
        if (c instanceof ToolButton) {
            ToolButton button = (ToolButton) c;
            String toolTipText = button.getToolTipText();
            if (toolTipText.compareTo(Localisation.getString(MapBoxTool.class, "MapBoxTool.exportToSLD")) == 0) {
                toSLD = button;
            }
        }
    }
    File testFile1 = null;
    File testFile3 = null;
    try {
        testFile1 = File.createTempFile("invalid", ".tst");
        testFile3 = File.createTempFile("valid", ".json");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Should both be disabled
    assertFalse(toSLD.isEnabled());
    tool.setSelectedItems(null, null);
    // Invalid file
    List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
    SLDData sldData1 = new SLDData(null, null);
    sldData1.setSLDFile(testFile1);
    sldDataList.add(sldData1);
    tool.setSelectedItems(null, sldDataList);
    // Should both be disabled
    assertFalse(toSLD.isEnabled());
    /*
         * // Try with valid mapbox file sldDataList = new ArrayList<SLDDataInterface>(); SLDData
         * sldData3 = getSLDDataFile("/point/mapbox/circleStyleTest.json");
         * sldDataList.add(sldData3); tool.setSelectedItems(null, sldDataList);
         * 
         * // SLD should be enabled assertTrue(toSLD.isEnabled()); toSLD.doClick();
         * 
         * // Try with valid sld files sldDataList = new ArrayList<SLDDataInterface>();
         * sldDataList.add(sldData3); tool.setSelectedItems(null, sldDataList);
         * 
         * // SLD should be enabled assertTrue(toSLD.isEnabled());
         */
    testFile1.delete();
    testFile3.delete();
// tidyUpTempFiles(sldData3.getSLDFile());
}
Also used : JPanel(javax.swing.JPanel) SLDData(com.sldeditor.common.data.SLDData) ToolButton(com.sldeditor.tool.ToolButton) SLDDataInterface(com.sldeditor.common.SLDDataInterface) MapBoxTool(com.sldeditor.tool.mapbox.MapBoxTool) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Component(java.awt.Component) File(java.io.File) Test(org.junit.Test)

Aggregations

SLDData (com.sldeditor.common.data.SLDData)68 Test (org.junit.Test)54 StyleWrapper (com.sldeditor.common.data.StyleWrapper)35 File (java.io.File)27 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)24 SLDDataInterface (com.sldeditor.common.SLDDataInterface)20 IOException (java.io.IOException)20 URL (java.net.URL)16 ArrayList (java.util.ArrayList)14 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)8 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)8 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)7 FileNotFoundException (java.io.FileNotFoundException)7 URISyntaxException (java.net.URISyntaxException)7 MalformedURLException (java.net.MalformedURLException)6 NamedLayer (org.geotools.styling.NamedLayer)6 Style (org.geotools.styling.Style)6 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 VersionData (com.sldeditor.common.vendoroption.VersionData)4