Search in sources :

Example 1 with SLDTreeTools

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

the class SLDTreeToolsTest method testMoveItemSymbolizer.

/**
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#moveItem(boolean)}.
 */
@Test
public void testMoveItemSymbolizer() {
    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.addNewPolygon();
    treeTools.addNewMarker();
    treeTools.addNewLine();
    treeTools.addNewText();
    assertEquals(4, rule.getChildCount());
    // Now have 4 symbolizers for the rule
    DefaultMutableTreeNode symbolizer = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(PolygonSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(1);
    assertEquals(PointSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(2);
    assertEquals(LineSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(3);
    assertEquals(TextSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    // The last text symbolizer is selected as it was the last added
    treeTools.moveItem(true);
    // Tree has been repopulated so the root node has changed so get hold of rule node again
    rule = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(PolygonSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(1);
    assertEquals(PointSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(2);
    assertEquals(TextSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(3);
    assertEquals(LineSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    // The last text symbolizer is selected as it was the last added
    TreeSelectionData data = new TreeSelectionData();
    data.setLayerIndex(0);
    data.setStyleIndex(0);
    data.setFeatureTypeStyleIndex(0);
    data.setRuleIndex(0);
    data.setSymbolizerIndex(2);
    data.setSelectedPanel(TextSymbolizerDetails.class);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(true);
    data.setSymbolizerIndex(1);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(true);
    // Tree has been repopulated so the root node has changed so get hold of rule node again
    rule = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(TextSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(1);
    assertEquals(PolygonSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(2);
    assertEquals(PointSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(3);
    assertEquals(LineSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    // Now try and move to index -1, everything should still be the same
    data.setSymbolizerIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(true);
    // Tree has been repopulated so the root node has changed so get hold of rule node again
    rule = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(TextSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(1);
    assertEquals(PolygonSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(2);
    assertEquals(PointSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(3);
    assertEquals(LineSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    // Now try and move to index -1, everything should still be the same
    data.setSymbolizerIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    data.setSymbolizerIndex(1);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    data.setSymbolizerIndex(2);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    // Tree has been repopulated so the root node has changed so get hold of rule node again
    rule = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(PolygonSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(1);
    assertEquals(PointSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(2);
    assertEquals(LineSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(3);
    assertEquals(TextSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    data.setSymbolizerIndex(3);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    // Tree has been repopulated so the root node has changed so get hold of rule node again
    rule = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(PolygonSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(1);
    assertEquals(PointSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(2);
    assertEquals(LineSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(3);
    assertEquals(TextSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    // Undo the last valid move
    UndoManager.getInstance().undo();
    // Tree has been repopulated so the root node has changed so get hold of rule node again
    rule = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(PolygonSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(1);
    assertEquals(PointSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(2);
    assertEquals(TextSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(3);
    assertEquals(LineSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    // Redo the last valid move
    UndoManager.getInstance().redo();
    // Tree has been repopulated so the root node has changed so get hold of rule node again
    rule = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0).getChildAt(0);
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(PolygonSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(1);
    assertEquals(PointSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(2);
    assertEquals(LineSymbolizerImpl.class, symbolizer.getUserObject().getClass());
    symbolizer = (DefaultMutableTreeNode) rule.getChildAt(3);
    assertEquals(TextSymbolizerImpl.class, symbolizer.getUserObject().getClass());
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) TreeSelectionData(com.sldeditor.TreeSelectionData) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.jupiter.api.Test)

Example 2 with SLDTreeTools

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

the class SLDTreeToolsTest method testGetButtonPanel.

/**
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#getButtonPanel()}.
 */
@Test
public void testGetButtonPanel() {
    SLDTreeTools treeTools = new SLDTreeTools();
    TestSLDTree sldTree = new TestSLDTree(null, treeTools);
    assertNotNull(sldTree);
    assertNotNull(treeTools.getButtonPanel());
}
Also used : SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.jupiter.api.Test)

Example 3 with SLDTreeTools

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

Example 4 with SLDTreeTools

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

the class SLDTreeToolsTest method testSLDTreeTools.

/**
 * Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeTools#SLDTreeTools(com.sldeditor.ui.tree.UpdateTreeStructureInterface,
 * javax.swing.JTree, java.util.List)}.
 */
@Test
public void testSLDTreeTools() {
    SLDTreeTools treeTools = new SLDTreeTools();
    // Try calling public methods when constructor parameters are null
    treeTools.addNewLine();
    treeTools.addNewMarker();
    treeTools.addNewPolygon();
    treeTools.addNewText();
    treeTools.addNewThing(null);
    treeTools.addNewThing(UserLayer.class);
    treeTools.addNewThing(NamedLayer.class);
    treeTools.addNewRaster();
    treeTools.addDestArrow();
    treeTools.addSourceArrow();
    treeTools.moveItem(true);
    treeTools.removeItem();
}
Also used : SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.jupiter.api.Test)

Example 5 with SLDTreeTools

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

the class SLDTreeToolsTest method testMoveItemFeatureTypeStyles.

/**
 * Check Feature Type Styles Test method for {@link
 * com.sldeditor.ui.tree.SLDTreeTools#moveItem(boolean)}.
 */
@Test
public void testMoveItemFeatureTypeStyles() {
    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);
    DefaultMutableTreeNode rootNode = sldTree.getRootNode();
    DefaultMutableTreeNode featureTypeStyle1Node = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(0);
    FeatureTypeStyleImpl featureTypeStyle1 = (FeatureTypeStyleImpl) featureTypeStyle1Node.getUserObject();
    String expectedFeatureTypeStyle1 = "feature type style 1";
    featureTypeStyle1.setName(expectedFeatureTypeStyle1);
    TreeSelectionData data = new TreeSelectionData();
    data.setLayerIndex(0);
    data.setStyleIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.addNewThing(null);
    DefaultMutableTreeNode featureTypeStyle2Node = (DefaultMutableTreeNode) rootNode.getChildAt(0).getChildAt(0).getChildAt(1);
    FeatureTypeStyleImpl featureTypeStyle2 = (FeatureTypeStyleImpl) featureTypeStyle2Node.getUserObject();
    String expectedFeatureTypeStyle2 = "feature type style 2";
    featureTypeStyle2.setName(expectedFeatureTypeStyle2);
    // Have 2 styles
    data = new TreeSelectionData();
    data.setLayerIndex(0);
    data.setStyleIndex(0);
    data.setFeatureTypeStyleIndex(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);
    FeatureTypeStyleImpl testStyle = (FeatureTypeStyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedFeatureTypeStyle2) == 0);
    // Try and move 'style 2' up to index -1 which is invalid, result should be same as last
    // time
    data.setFeatureTypeStyleIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(true);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0);
    testStyle = (FeatureTypeStyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedFeatureTypeStyle2) == 0);
    // Move it back
    data.setFeatureTypeStyleIndex(0);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(1);
    testStyle = (FeatureTypeStyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedFeatureTypeStyle2) == 0);
    // Move it beyond the end of the list, should be the same answer as before
    data.setFeatureTypeStyleIndex(1);
    sldTree.selectTreeItem(data);
    treeTools.moveItem(false);
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(1);
    testStyle = (FeatureTypeStyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedFeatureTypeStyle2) == 0);
    // Undo the last valid move
    UndoManager.getInstance().undo();
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(0);
    testStyle = (FeatureTypeStyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedFeatureTypeStyle2) == 0);
    // Redo the last valid move
    UndoManager.getInstance().redo();
    testNode = (DefaultMutableTreeNode) sldTree.getRootNode().getChildAt(0).getChildAt(0).getChildAt(1);
    testStyle = (FeatureTypeStyleImpl) testNode.getUserObject();
    assertTrue(testStyle.getName().compareTo(expectedFeatureTypeStyle2) == 0);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) TreeSelectionData(com.sldeditor.TreeSelectionData) FeatureTypeStyleImpl(org.geotools.styling.FeatureTypeStyleImpl) 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