Search in sources :

Example 11 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.

the class SLDTreeToolsTest method testMoveItemStyle.

/**
 * Check Styles Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#moveItem(boolean)}.
 */
@Test
public void testMoveItemStyle() {
    SLDTreeTools treeTools = new SLDTreeTools();
    TestSLDTree sldTree = new TestSLDTree(null, treeTools);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    // Start off with just a top level SLD and no structure below it
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    SelectedSymbol.getInstance().setSld(sld);
    sldTree.populateSLD();
    sldTree.selectFirstSymbol();
    treeTools.addNewThing(NamedLayer.class);
    treeTools.addNewThing(null);
    DefaultMutableTreeNode rootNode = sldTree.getRootNode();
    DefaultMutableTreeNode style1Node = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0);
    StyleImpl style1 = (StyleImpl) style1Node.getUserObject();
    String expectedStyle1 = "style 1";
    style1.setName(expectedStyle1);
    TreeSelectionData data = new TreeSelectionData();
    data.setLayerIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.addNewThing(null);
    DefaultMutableTreeNode style2Node = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(1);
    StyleImpl style2 = (StyleImpl) style2Node.getUserObject();
    String expectedStyle2 = "style 2";
    style2.setName(expectedStyle2);
    // Have 2 styles
    data = new TreeSelectionData();
    data.setLayerIndex(0);
    data.setStyleIndex(1);
    sldTree.selectTreeItem(data);
    // Move style 2 so that they are reversed
    treeTools.moveItem(true);
    DefaultMutableTreeNode testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0);
    StyleImpl testStyle = (StyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedStyle2) == 0);
    // Try and move 'style 2' up to index -1 which is invalid, result should be same as last
    // time
    data.setStyleIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(true);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0);
    testStyle = (StyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedStyle2) == 0);
    // Move it back
    data.setStyleIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(1);
    testStyle = (StyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedStyle2) == 0);
    // Move it beyond the end of the list, should be the same answer as before
    data.setStyleIndex(1);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(1);
    testStyle = (StyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedStyle2) == 0);
    // Undo the last valid move
    UndoManager.getInstance().undo();
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0);
    testStyle = (StyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedStyle2) == 0);
    // Redo the last valid move
    UndoManager.getInstance().redo();
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(1);
    testStyle = (StyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedStyle2) == 0);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) StyleImpl(org.geotools.styling.StyleImpl) FeatureTypeStyleImpl(org.geotools.styling.FeatureTypeStyleImpl) TreeSelectionData(com.sldeditor.TreeSelectionData) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.Test)

Example 12 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.

the class SLDTreeToolsTest method testRemoveItem.

/**
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#removeItem()}.
 */
@Test
public void testRemoveItem() {
    SLDTreeTools treeTools = new SLDTreeTools();
    TestRenderSymbolInterface renderSymbol = new TestRenderSymbolInterface();
    List<RenderSymbolInterface> renderList = new ArrayList<RenderSymbolInterface>();
    renderList.add(renderSymbol);
    TestSLDTree sldTree = new TestSLDTree(renderList, treeTools);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    // Start off with just a top level SLD and no structure below it
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    SelectedSymbol.getInstance().setSld(sld);
    sldTree.populateSLD();
    sldTree.selectFirstSymbol();
    // Named layer
    treeTools.addNewThing(NamedLayer.class);
    // Style
    treeTools.addNewThing(null);
    // Feature type style
    treeTools.addNewThing(null);
    // Rule
    treeTools.addNewThing(null);
    DefaultMutableTreeNode rootNode = sldTree.getRootNode();
    // Make sure we have a rule selected
    DefaultMutableTreeNode rule = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    assertEquals(RuleImpl.class, rule.getUserObject().getClass());
    assertEquals(0, rule.getChildCount());
    treeTools.addNewText();
    rule = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    assertEquals(RuleImpl.class, rule.getUserObject().getClass());
    assertEquals(1, rule.getChildCount());
    // The selected item (text symbolizer) is removed
    treeTools.removeItem();
    assertTrue(renderSymbol.hasRenderSymbolBeenCalled());
    rule = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    assertEquals(RuleImpl.class, rule.getUserObject().getClass());
    assertEquals(0, rule.getChildCount());
    // The selected item (rule) is removed
    treeTools.removeItem();
    assertTrue(renderSymbol.hasRenderSymbolBeenCalled());
    DefaultMutableTreeNode featureTypeStyle = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0);
    assertEquals(FeatureTypeStyleImpl.class, featureTypeStyle.getUserObject().getClass());
    assertEquals(0, featureTypeStyle.getChildCount());
    // The selected item (style) is removed
    treeTools.removeItem();
    assertTrue(renderSymbol.hasRenderSymbolBeenCalled());
    DefaultMutableTreeNode style = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0);
    assertEquals(StyleImpl.class, style.getUserObject().getClass());
    assertEquals(0, style.getChildCount());
    // The selected item (named layer) is removed
    treeTools.removeItem();
    assertTrue(renderSymbol.hasRenderSymbolBeenCalled());
    DefaultMutableTreeNode namedLayer = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    assertEquals(NamedLayerImpl.class, namedLayer.getUserObject().getClass());
    assertEquals(0, namedLayer.getChildCount());
    // The selected item (styled layer descriptor) is removed
    treeTools.removeItem();
    assertTrue(renderSymbol.hasRenderSymbolBeenCalled());
    assertEquals(0, rootNode.getChildCount());
    treeTools.removeItem();
    assertEquals(0, rootNode.getChildCount());
    assertFalse(renderSymbol.hasRenderSymbolBeenCalled());
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) ArrayList(java.util.ArrayList) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.Test)

Example 13 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.

the class SLDTreeToolsTest method testAddRaster.

/**
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addRaster()}.
 */
@Test
public void testAddRaster() {
    SLDTreeTools treeTools = new SLDTreeTools();
    TestSLDTree sldTree = new TestSLDTree(null, treeTools);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    // Start off with just a top level SLD and no structure below it
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    SelectedSymbol.getInstance().setSld(sld);
    sldTree.populateSLD();
    sldTree.selectFirstSymbol();
    treeTools.addNewThing(NamedLayer.class);
    treeTools.addNewThing(null);
    treeTools.addNewThing(null);
    treeTools.addNewThing(null);
    DefaultMutableTreeNode rootNode = sldTree.getRootNode();
    // Make sure we have a rule selected
    DefaultMutableTreeNode rule = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    assertEquals(RuleImpl.class, rule.getUserObject().getClass());
    assertEquals(0, rule.getChildCount());
    treeTools.addNewRaster();
    DefaultMutableTreeNode rasterNode = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(RasterSymbolizerImpl.class, rasterNode.getUserObject().getClass());
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.Test)

Example 14 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.

the class SLDTreeToolsTest method testMoveItemNamedLayer.

/**
 * Check NamedLayers Test method for
 * {@link com.sldeditor.ui.tree.SLDTreeTools#moveItem(boolean)}.
 */
@Test
public void testMoveItemNamedLayer() {
    TestRenderSymbolInterface renderSymbol = new TestRenderSymbolInterface();
    List<RenderSymbolInterface> renderList = new ArrayList<RenderSymbolInterface>();
    renderList.add(renderSymbol);
    SLDTreeTools treeTools = new SLDTreeTools();
    TestSLDTree sldTree = new TestSLDTree(renderList, treeTools);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    // Start off with just a top level SLD and no structure below it
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    SelectedSymbol.getInstance().setSld(sld);
    sldTree.populateSLD();
    sldTree.selectFirstSymbol();
    treeTools.addNewThing(NamedLayer.class);
    DefaultMutableTreeNode rootNode = sldTree.getRootNode();
    DefaultMutableTreeNode namedLayer1Node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    NamedLayerImpl namedLayer1 = (NamedLayerImpl) namedLayer1Node.getUserObject();
    String expectedNamedLayer1 = "named layer 1";
    namedLayer1.setName(expectedNamedLayer1);
    sldTree.selectFirstSymbol();
    treeTools.addNewThing(NamedLayer.class);
    DefaultMutableTreeNode namedLayer2Node = (DefaultMutableTreeNode) rootNode.getChildAt(1);
    NamedLayerImpl namedLayer2 = (NamedLayerImpl) namedLayer2Node.getUserObject();
    String expectedNamedLayer2 = "named layer 2";
    namedLayer2.setName(expectedNamedLayer2);
    // Have 2 named layers
    TreeSelectionData data = new TreeSelectionData();
    data.setLayerIndex(1);
    sldTree.selectTreeItem(data);
    // Move named layer 2 so that they are reversed
    treeTools.moveItem(true);
    assertTrue(renderSymbol.hasRenderSymbolBeenCalled());
    DefaultMutableTreeNode testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0);
    NamedLayerImpl testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
    // Try and move 'named layer 2' up to index -1 which is invalid, result should be same as
    // last time
    data.setLayerIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(true);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0);
    testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
    // Move it back
    data.setLayerIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    assertTrue(renderSymbol.hasRenderSymbolBeenCalled());
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(1);
    testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
    // Move it beyond the end of the list, should be the same answer as before
    data.setLayerIndex(1);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(1);
    testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
    // Undo the last valid move
    UndoManager.getInstance().undo();
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0);
    testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
    // Redo the last valid move
    UndoManager.getInstance().redo();
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(1);
    testNamedLayer = (NamedLayerImpl) testNode.getUserObject();
    assertTrue(testNamedLayer.getName().compareTo(expectedNamedLayer2) == 0);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) TreeSelectionData(com.sldeditor.TreeSelectionData) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) ArrayList(java.util.ArrayList) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.Test)

Example 15 with StyledLayerDescriptor

use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.

the class YSLDToolTest method getSLDDataFile.

/**
 * Gets the SLD/YSLD file.
 *
 * @param testfile the testfile
 * @return the SLD data file
 */
private static SLDData getSLDDataFile(String testfile) {
    SLDData sldData = null;
    InputStream inputStream = YSLDToolTest.class.getResourceAsStream(testfile);
    if (inputStream == null) {
        Assert.assertNotNull("Failed to find test file : " + testfile, inputStream);
    } else {
        File f = null;
        try {
            String fileExtension = ExternalFilenames.getFileExtension(testfile);
            f = stream2file(inputStream, ExternalFilenames.addFileExtensionSeparator(fileExtension));
            String sldContents = readFile(f.getAbsolutePath());
            if (fileExtension.compareTo("ysld") == 0) {
                StyledLayerDescriptor sld = Ysld.parse(sldContents);
                // Convert YSLD to SLD string
                SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
                sldContents = sldWriter.encodeSLD(null, sld);
            }
            sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
            sldData.setSLDFile(f);
            SelectedSymbol.getInstance().setSld(SLDUtils.createSLDFromString(sldData));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) InputStream(java.io.InputStream) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) IOException(java.io.IOException) File(java.io.File)

Aggregations

StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)123 Test (org.junit.Test)73 Rule (org.geotools.styling.Rule)51 Style (org.geotools.styling.Style)49 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)47 NamedLayer (org.geotools.styling.NamedLayer)44 SLDData (com.sldeditor.common.data.SLDData)24 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)23 File (java.io.File)19 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)19 StyledLayer (org.geotools.styling.StyledLayer)19 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)17 PointSymbolizer (org.geotools.styling.PointSymbolizer)17 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)16 StyleWrapper (com.sldeditor.common.data.StyleWrapper)15 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)14 IOException (java.io.IOException)14 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 LineSymbolizer (org.geotools.styling.LineSymbolizer)12