Search in sources :

Example 11 with SLDTreeTools

use of com.sldeditor.ui.tree.SLDTreeTools in project sldeditor by robward-scisys.

the class SLDTreeToolsTest method testAddNewThingNamedLayer.

/**
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addNewThing()}.
 */
@Test
public void testAddNewThingNamedLayer() {
    SLDTreeTools treeTools = new SLDTreeTools();
    TestSLDTree sldTree = new TestSLDTree(null, treeTools);
    treeTools.addNewThing(null);
    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();
    DefaultMutableTreeNode rootNode = sldTree.getRootNode();
    // Check it has no structure below just the root node
    assertEquals(0, rootNode.getChildCount());
    // Add a thing - a quick way of creating sld structure
    // This should add a named layer and select it
    treeTools.addNewThing(NamedLayer.class);
    assertEquals(1, rootNode.getChildCount());
    DefaultMutableTreeNode namedLayer = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    assertEquals(NamedLayerImpl.class, namedLayer.getUserObject().getClass());
    // This should add a style and select it
    assertEquals(0, namedLayer.getChildCount());
    treeTools.addNewThing(null);
    assertEquals(1, namedLayer.getChildCount());
    DefaultMutableTreeNode styleLayer = (DefaultMutableTreeNode) namedLayer.getChildAt(0);
    assertEquals(StyleImpl.class, styleLayer.getUserObject().getClass());
    // This should add a feature type style and select it
    assertEquals(0, styleLayer.getChildCount());
    treeTools.addNewThing(null);
    assertEquals(1, styleLayer.getChildCount());
    DefaultMutableTreeNode featureTypeStyle = (DefaultMutableTreeNode) styleLayer.getChildAt(0);
    assertEquals(FeatureTypeStyleImpl.class, featureTypeStyle.getUserObject().getClass());
    // This should add a rule and select it
    assertEquals(0, featureTypeStyle.getChildCount());
    treeTools.addNewThing(null);
    assertEquals(1, featureTypeStyle.getChildCount());
    DefaultMutableTreeNode rule = (DefaultMutableTreeNode) featureTypeStyle.getChildAt(0);
    assertEquals(RuleImpl.class, rule.getUserObject().getClass());
    // This should do nothing
    assertEquals(0, rule.getChildCount());
    treeTools.addNewThing(null);
    assertEquals(0, rule.getChildCount());
    // Undo last add of rule to feature type style
    UndoManager.getInstance().undo();
    DefaultMutableTreeNode featureTypeStyleNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0);
    assertEquals(FeatureTypeStyleImpl.class, featureTypeStyleNode.getUserObject().getClass());
    assertEquals(0, featureTypeStyleNode.getChildCount());
    // Undo last add of rule to feature type style
    UndoManager.getInstance().redo();
    featureTypeStyleNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0);
    assertEquals(FeatureTypeStyleImpl.class, featureTypeStyleNode.getUserObject().getClass());
    assertEquals(1, featureTypeStyleNode.getChildCount());
}
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.jupiter.api.Test)

Example 12 with SLDTreeTools

use of com.sldeditor.ui.tree.SLDTreeTools 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)

Example 13 with SLDTreeTools

use of com.sldeditor.ui.tree.SLDTreeTools in project sldeditor by robward-scisys.

the class SLDTreeToolsTest method testAddNewText.

/**
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addNewText()}.
 */
@Test
public void testAddNewText() {
    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.addNewText();
    DefaultMutableTreeNode textNode = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(TextSymbolizerImpl.class, textNode.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.jupiter.api.Test)

Example 14 with SLDTreeTools

use of com.sldeditor.ui.tree.SLDTreeTools in project sldeditor by robward-scisys.

the class SLDTreeToolsTest method testAddArrows.

/**
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addSourceArrow()}. Test method for
 * {@link com.sldeditor.ui.tree.SLDTreeTools#addDestArrow()}.
 */
@Test
public void testAddArrows() {
    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.addNewLine();
    treeTools.addSourceArrow();
    treeTools.addDestArrow();
    DefaultMutableTreeNode lineNode = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(LineSymbolizerImpl.class, lineNode.getUserObject().getClass());
    DefaultMutableTreeNode srcArrowNode = (DefaultMutableTreeNode) rule.getChildAt(1);
    assertEquals(PointSymbolizerImpl.class, srcArrowNode.getUserObject().getClass());
    DefaultMutableTreeNode destArrowNode = (DefaultMutableTreeNode) rule.getChildAt(2);
    assertEquals(PointSymbolizerImpl.class, destArrowNode.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.jupiter.api.Test)

Example 15 with SLDTreeTools

use of com.sldeditor.ui.tree.SLDTreeTools in project sldeditor by robward-scisys.

the class SLDTreeToolsTest method testMoveItemRules.

/**
 * Check Rules Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#moveItem(boolean)}.
 */
@Test
public void testMoveItemRules() {
    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();
    DefaultMutableTreeNode rule1Node = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    RuleImpl rule1 = (RuleImpl) rule1Node.getUserObject();
    String expectedRule1 = "rule 1";
    rule1.setName(expectedRule1);
    TreeSelectionData data = new TreeSelectionData();
    data.setLayerIndex(0);
    data.setStyleIndex(0);
    data.setFeatureTypeStyleIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.addNewThing(null);
    DefaultMutableTreeNode rule2Node = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
    RuleImpl rule2 = (RuleImpl) rule2Node.getUserObject();
    String expectedRule2 = "rule 2";
    rule2.setName(expectedRule2);
    // Have 2 styles
    data = new TreeSelectionData();
    data.setLayerIndex(0);
    data.setStyleIndex(0);
    data.setFeatureTypeStyleIndex(0);
    data.setRuleIndex(1);
    sldTree.selectTreeItem(data);
    // Move style 2 so that they are reversed
    treeTools.moveItem(true);
    DefaultMutableTreeNode testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    RuleImpl testRule = (RuleImpl) testNode.getUserObject();
    assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
    // Try and move 'style 2' up to index -1 which is invalid, result should be same as last
    // time
    data.setRuleIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(true);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    testRule = (RuleImpl) testNode.getUserObject();
    assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
    // Move it back
    data.setRuleIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
    testRule = (RuleImpl) testNode.getUserObject();
    assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
    // Move it beyond the end of the list, should be the same answer as before
    data.setRuleIndex(1);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
    testRule = (RuleImpl) testNode.getUserObject();
    assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
    // Undo the last valid move
    UndoManager.getInstance().undo();
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    testRule = (RuleImpl) testNode.getUserObject();
    assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
    // Redo the last valid move
    UndoManager.getInstance().redo();
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(1);
    testRule = (RuleImpl) testNode.getUserObject();
    assertTrue(testRule.getName().compareTo(expectedRule2) == 0);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) TreeSelectionData(com.sldeditor.TreeSelectionData) RuleImpl(org.geotools.styling.RuleImpl) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.jupiter.api.Test)

Aggregations

SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)21 Test (org.junit.jupiter.api.Test)20 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)17 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)16 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)16 TreeSelectionData (com.sldeditor.TreeSelectionData)6 RenderSymbolInterface (com.sldeditor.datasource.RenderSymbolInterface)3 ArrayList (java.util.ArrayList)2 FeatureTypeStyleImpl (org.geotools.styling.FeatureTypeStyleImpl)2 SLDData (com.sldeditor.common.data.SLDData)1 SymbolizerDetailsPanel (com.sldeditor.ui.detail.SymbolizerDetailsPanel)1 PopulateDetailsInterface (com.sldeditor.ui.iface.PopulateDetailsInterface)1 SLDTree (com.sldeditor.ui.tree.SLDTree)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)1 RuleImpl (org.geotools.styling.RuleImpl)1 StyleImpl (org.geotools.styling.StyleImpl)1