Search in sources :

Example 66 with StyledLayerDescriptor

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

the class SLDTreeToolsTest method testAddNewLine.

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

Example 68 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.jupiter.api.Test)

Example 69 with StyledLayerDescriptor

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

the class SLDTreeToolsTest method testAddNewMarker.

/**
 * Test method for {@link com.sldeditor.ui.tree.SLDTreeTools#addNewMarker()}.
 */
@Test
public void testAddNewMarker() {
    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.addNewMarker();
    DefaultMutableTreeNode marker = (DefaultMutableTreeNode) rule.getChildAt(0);
    assertEquals(PointSymbolizerImpl.class, marker.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 70 with StyledLayerDescriptor

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

Aggregations

StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)134 Test (org.junit.jupiter.api.Test)80 Rule (org.geotools.styling.Rule)54 Style (org.geotools.styling.Style)52 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)50 NamedLayer (org.geotools.styling.NamedLayer)48 SLDData (com.sldeditor.common.data.SLDData)25 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)24 File (java.io.File)22 StyledLayer (org.geotools.styling.StyledLayer)21 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)19 SLDDataInterface (com.sldeditor.common.SLDDataInterface)17 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)17 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)17 StyleWrapper (com.sldeditor.common.data.StyleWrapper)16 IOException (java.io.IOException)16 PointSymbolizer (org.geotools.styling.PointSymbolizer)16 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)15 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)13 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)12