Search in sources :

Example 1 with StyleFactoryImpl

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

the class FieldConfigFeatureTypeConstraintTest method testGenerateExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#generateExpression()}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#populateExpression(java.lang.Object)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#setTestValue(com.sldeditor.ui.detail.config.FieldId, java.util.List)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#populateField(java.util.List)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint#getFeatureTypeConstraint()}.
 */
@Test
public void testGenerateExpression() {
    FieldConfigFeatureTypeConstraint field = new FieldConfigFeatureTypeConstraint(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", true));
    List<FeatureTypeConstraint> testValue = null;
    field.populate(null);
    field.setTestValue(FieldIdEnum.UNKNOWN, testValue);
    field.populateField(testValue);
    field.createUI();
    assertNull(field.getStringValue());
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FeatureTypeConstraint expectedValue1 = styleFactory.createFeatureTypeConstraint("Feature", Filter.INCLUDE, new Extent[0]);
    testValue = new ArrayList<FeatureTypeConstraint>();
    testValue.add(expectedValue1);
    field.populateField(testValue);
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));
    field.setTestValue(FieldIdEnum.UNKNOWN, testValue);
    assertEquals(expectedValue1, field.getFeatureTypeConstraint().get(0));
    field.populateExpression((String) null);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FeatureTypeConstraint(org.geotools.styling.FeatureTypeConstraint) FieldConfigFeatureTypeConstraint(com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigFeatureTypeConstraint(com.sldeditor.ui.detail.config.featuretypeconstraint.FieldConfigFeatureTypeConstraint) Test(org.junit.Test)

Example 2 with StyleFactoryImpl

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

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

Example 4 with StyleFactoryImpl

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

Example 5 with StyleFactoryImpl

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

Aggregations

StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)43 Test (org.junit.Test)43 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)23 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)16 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)16 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)12 ArrayList (java.util.ArrayList)11 FilterFactory (org.opengis.filter.FilterFactory)11 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)10 Rule (org.geotools.styling.Rule)8 RasterSymbolizerDetails (com.sldeditor.ui.detail.RasterSymbolizerDetails)7 NamedLayer (org.geotools.styling.NamedLayer)7 Style (org.geotools.styling.Style)7 VendorOptionPresent (com.sldeditor.common.vendoroption.minversion.VendorOptionPresent)6 TreeSelectionData (com.sldeditor.TreeSelectionData)5 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)5 MultiOptionGroup (com.sldeditor.ui.detail.config.base.MultiOptionGroup)5 Box (javax.swing.Box)5 ChannelSelection (org.geotools.styling.ChannelSelection)5 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)4