Search in sources :

Example 1 with StyleImpl

use of org.geotools.styling.StyleImpl 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)

Aggregations

TreeSelectionData (com.sldeditor.TreeSelectionData)1 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 FeatureTypeStyleImpl (org.geotools.styling.FeatureTypeStyleImpl)1 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)1 StyleImpl (org.geotools.styling.StyleImpl)1 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)1 Test (org.junit.Test)1