Search in sources :

Example 1 with TreeSelectionData

use of com.sldeditor.TreeSelectionData 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 2 with TreeSelectionData

use of com.sldeditor.TreeSelectionData 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.Test)

Example 3 with TreeSelectionData

use of com.sldeditor.TreeSelectionData 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.Test)

Example 4 with TreeSelectionData

use of com.sldeditor.TreeSelectionData 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 5 with TreeSelectionData

use of com.sldeditor.TreeSelectionData 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)

Aggregations

TreeSelectionData (com.sldeditor.TreeSelectionData)15 Test (org.junit.Test)14 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)5 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)5 RenderSymbolInterface (com.sldeditor.datasource.RenderSymbolInterface)2 PopulateDetailsInterface (com.sldeditor.ui.iface.PopulateDetailsInterface)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 FeatureTypeStyleImpl (org.geotools.styling.FeatureTypeStyleImpl)2 SLDData (com.sldeditor.common.data.SLDData)1 VersionData (com.sldeditor.common.vendoroption.VersionData)1 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)1 GroupIdEnum (com.sldeditor.common.xml.ui.GroupIdEnum)1 SldEditorTest (com.sldeditor.common.xml.ui.SldEditorTest)1 XMLColourMapEntries (com.sldeditor.common.xml.ui.XMLColourMapEntries)1 XMLFieldAttribute (com.sldeditor.common.xml.ui.XMLFieldAttribute)1 XMLFieldBase (com.sldeditor.common.xml.ui.XMLFieldBase)1 XMLFieldDisabled (com.sldeditor.common.xml.ui.XMLFieldDisabled)1