Search in sources :

Example 1 with FeatureTypeStyleImpl

use of org.geotools.styling.FeatureTypeStyleImpl 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 2 with FeatureTypeStyleImpl

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

the class ExtractAttributes method visit.

/**
 * (non-Javadoc)
 *
 * @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.
 * FeatureTypeStyle)
 */
public void visit(FeatureTypeStyle fts) {
    FeatureTypeStyle copy = new FeatureTypeStyleImpl(fts);
    Rule[] rules = fts.getRules();
    int length = rules.length;
    Rule[] rulesCopy = new Rule[length];
    for (int i = 0; i < length; i++) {
        if (rules[i] != null) {
            rules[i].accept(this);
            rulesCopy[i] = (Rule) pages.pop();
        }
    }
    copy.setRules(rulesCopy);
    if (fts.getTransformation() != null) {
        copy.setTransformation(copy(fts.getTransformation()));
    }
    if (fts.getOnlineResource() != null) {
        copy.setOnlineResource(fts.getOnlineResource());
    }
    copy.getOptions().clear();
    copy.getOptions().putAll(fts.getOptions());
    String sortbyGroup = fts.getOptions().get(FeatureTypeStyle.SORT_BY_GROUP);
    if (sortbyGroup != null) {
        List<String> foundList = new ArrayList<String>();
        extractAttribute(String.class, ff.property(sortbyGroup), foundList);
    }
    String sortby = fts.getOptions().get(FeatureTypeStyle.SORT_BY);
    if (sortby != null) {
        SortBy[] sortByArray = SLDStyleFactory.getSortBy(fts.getOptions());
        for (SortBy sortBy : sortByArray) {
            List<String> foundList = new ArrayList<String>();
            extractAttribute(String.class, ff.property(sortBy.getPropertyName().getPropertyName()), foundList);
        }
    }
    if (STRICT && !copy.equals(fts)) {
        throw new IllegalStateException("Was unable to duplicate provided FeatureTypeStyle:" + fts);
    }
    pages.push(copy);
}
Also used : SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) LineString(com.vividsolutions.jts.geom.LineString) FeatureTypeStyleImpl(org.geotools.styling.FeatureTypeStyleImpl) Point(com.vividsolutions.jts.geom.Point)

Example 3 with FeatureTypeStyleImpl

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

the class RuleRenderVisitor method visit.

/**
 * Visit.
 *
 * @param fts the fts
 */
/*
     * (non-Javadoc)
     * 
     * @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.
     * FeatureTypeStyle)
     */
@SuppressWarnings("deprecation")
@Override
public void visit(FeatureTypeStyle fts) {
    FeatureTypeStyle copy = new FeatureTypeStyleImpl((FeatureTypeStyleImpl) fts);
    if (!options.isTransformationApplied()) {
        copy.setTransformation(null);
    }
    Rule[] rules = fts.getRules();
    int length = rules.length;
    Rule[] rulesCopy = null;
    if (this.ruleToRender == null) {
        rulesCopy = new Rule[length];
        for (int i = 0; i < length; i++) {
            if (rules[i] != null) {
                rules[i].accept(this);
                rulesCopy[i] = (Rule) pages.pop();
            }
        }
    } else {
        rulesCopy = new Rule[1];
        for (int i = 0; i < length; i++) {
            if (rules[i] != null) {
                if (renderRule(rules[i])) {
                    rules[i].accept(this);
                    rulesCopy[0] = (Rule) pages.pop();
                }
            }
        }
    }
    copy.setRules(rulesCopy);
    if (STRICT && !copy.equals(fts)) {
        throw new IllegalStateException("Was unable to duplicate provided FeatureTypeStyle:" + fts);
    }
    pages.push(copy);
}
Also used : FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) FeatureTypeStyleImpl(org.geotools.styling.FeatureTypeStyleImpl)

Aggregations

FeatureTypeStyleImpl (org.geotools.styling.FeatureTypeStyleImpl)3 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)2 Rule (org.geotools.styling.Rule)2 TreeSelectionData (com.sldeditor.TreeSelectionData)1 SLDTreeTools (com.sldeditor.ui.tree.SLDTreeTools)1 LineString (com.vividsolutions.jts.geom.LineString)1 Point (com.vividsolutions.jts.geom.Point)1 ArrayList (java.util.ArrayList)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)1 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)1 Test (org.junit.Test)1 SortBy (org.opengis.filter.sort.SortBy)1