Search in sources :

Example 11 with UserLayer

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

the class FieldConfigInlineFeature method undoAction.

/**
 * Undo action.
 *
 * @param undoRedoObject the undo/redo object
 */
@Override
public void undoAction(UndoInterface undoRedoObject) {
    if (undoRedoObject != null) {
        if (undoRedoObject.getOldValue() instanceof String) {
            String oldValue = (String) undoRedoObject.getOldValue();
            UserLayer userLayer = DefaultSymbols.createNewUserLayer();
            InlineFeatureUtils.setInlineFeatures(userLayer, oldValue);
            if (inlineGML != null) {
                inlineGML.setInlineFeatures(oldValue);
            }
            if (inlineFeature != null) {
                inlineFeature.setInlineFeatures(userLayer);
            }
        }
    }
}
Also used : UserLayer(org.geotools.styling.UserLayer)

Example 12 with UserLayer

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

the class InlineFeatureUtils method extractUserLayers.

/**
 * Extract user layers from an SLD.
 *
 * @param sld the sld
 * @return the list of user layers
 */
public static List<UserLayer> extractUserLayers(StyledLayerDescriptor sld) {
    List<UserLayer> userLayerList = new ArrayList<UserLayer>();
    if (sld != null) {
        for (StyledLayer layer : sld.layers()) {
            if (layer instanceof UserLayer) {
                UserLayer userLayer = (UserLayer) layer;
                userLayerList.add(userLayer);
            }
        }
    }
    return userLayerList;
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) ArrayList(java.util.ArrayList) UserLayer(org.geotools.styling.UserLayer)

Example 13 with UserLayer

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

the class SLDTreeTools method removeItem.

/**
 * Removes the item.
 */
public void removeItem() {
    if (symbolTree == null) {
        return;
    }
    TreePath path = symbolTree.getSelectionPath();
    if (path == null) {
        return;
    }
    DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object obj = lastNode.getUserObject();
    // CHECKSTYLE:OFF
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    if (obj instanceof NamedLayer) {
        SelectedSymbol.getInstance().removeUserNamedLayer((NamedLayer) obj);
        removeTreeNode(lastNode);
    } else if (obj instanceof UserLayer) {
        SelectedSymbol.getInstance().removeUserNamedLayer((UserLayer) obj);
        removeTreeNode(lastNode);
    } else if (obj instanceof Style) {
        SelectedSymbol.getInstance().removeStyle((Style) obj);
        removeTreeNode(lastNode);
    } else if (obj instanceof FeatureTypeStyle) {
        SelectedSymbol.getInstance().removeFeatureTypeStyle((FeatureTypeStyle) obj);
        removeTreeNode(lastNode);
    } else if (obj instanceof Rule) {
        SelectedSymbol.getInstance().removeRule((Rule) obj);
        removeTreeNode(lastNode);
    } else if (obj instanceof Symbolizer) {
        DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) lastNode.getParent();
        if (parentNode != null) {
            if (parentNode.getUserObject() instanceof RasterSymbolizer) {
                SelectedSymbol.getInstance().removeRasterImageOutline((RasterSymbolizer) parentNode.getUserObject());
            } else {
                SelectedSymbol.getInstance().removeSymbolizer((Symbolizer) obj);
            }
            removeTreeNode(lastNode);
        }
    } else {
        return;
    }
    SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
    // Re-render the symbol
    if (renderList != null) {
        for (RenderSymbolInterface render : renderList) {
            render.renderSymbol();
        }
    }
    Object newValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    UndoManager.getInstance().addUndoEvent(new UndoEvent(sldTree.getUndoObject(), getClass().getName(), oldValueObj, newValueObj));
}
Also used : RasterSymbolizer(org.geotools.styling.RasterSymbolizer) UndoEvent(com.sldeditor.common.undo.UndoEvent) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) UserLayer(org.geotools.styling.UserLayer) NamedLayer(org.geotools.styling.NamedLayer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer)

Example 14 with UserLayer

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

the class SLDTreeTools method addNewThing.

/**
 * Adds the new thing.
 *
 * @param hint the hint when the are multiple possibilities
 */
public void addNewThing(Class<?> hint) {
    if (symbolTree == null) {
        return;
    }
    TreePath path = symbolTree.getSelectionPath();
    if (path == null) {
        return;
    }
    DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    DefaultMutableTreeNode newNode = null;
    Object obj = lastNode.getUserObject();
    // Store current state of the SLD before the add
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    if (obj instanceof String) {
        StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
        SelectedSymbol.getInstance().createNewSLD(sld);
        if (hint == NamedLayer.class) {
            NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
            SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
            newNode = sldTree.addObject(lastNode, namedLayer, true);
        } else if (hint == UserLayer.class) {
            UserLayer userLayer = DefaultSymbols.createNewUserLayer();
            SelectedSymbol.getInstance().addNewStyledLayer(userLayer);
            newNode = sldTree.addObject(lastNode, userLayer, true);
        }
    } else if (obj instanceof StyledLayerDescriptor) {
        if (hint == NamedLayer.class) {
            NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
            SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
            newNode = sldTree.addObject(lastNode, namedLayer, true);
        } else if (hint == UserLayer.class) {
            UserLayer userLayer = DefaultSymbols.createNewUserLayer();
            SelectedSymbol.getInstance().addNewStyledLayer(userLayer);
            newNode = sldTree.addObject(lastNode, userLayer, true);
        }
    } else if (obj instanceof NamedLayer) {
        Style style = DefaultSymbols.createNewStyle();
        SelectedSymbol.getInstance().addNewStyle(style);
        newNode = sldTree.addObject(lastNode, style, true);
    } else if (obj instanceof UserLayer) {
        Style style = DefaultSymbols.createNewStyle();
        SelectedSymbol.getInstance().addNewStyle(style);
        newNode = sldTree.addObject(lastNode, style, true);
    } else if (obj instanceof Style) {
        FeatureTypeStyle featureTypeStyle = DefaultSymbols.createNewFeatureTypeStyle();
        SelectedSymbol.getInstance().addNewFeatureTypeStyle(featureTypeStyle);
        newNode = sldTree.addObject(lastNode, featureTypeStyle, true);
    } else if (obj instanceof FeatureTypeStyle) {
        Rule rule = DefaultSymbols.createNewRule();
        SelectedSymbol.getInstance().addNewRule(rule);
        newNode = sldTree.addObject(lastNode, rule, true);
    }
    // Select the item just added
    if (newNode != null) {
        SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
        TreePath newPath = getPath(newNode);
        symbolTree.setSelectionPath(newPath);
        // Store current state of the SLD after the add
        Object newValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
        UndoManager.getInstance().addUndoEvent(new UndoEvent(sldTree.getUndoObject(), getClass().getName(), oldValueObj, newValueObj));
    }
}
Also used : UndoEvent(com.sldeditor.common.undo.UndoEvent) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) UserLayer(org.geotools.styling.UserLayer) NamedLayer(org.geotools.styling.NamedLayer)

Example 15 with UserLayer

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

the class UserLayerTreeItemTest method testGetTreeString.

/**
 * Test method for
 * {@link com.sldeditor.ui.tree.item.UserLayerTreeItem#getTreeString(java.lang.Object)}.
 */
@Test
public void testGetTreeString() {
    UserLayerTreeItem item = new UserLayerTreeItem();
    String actualValue = item.getTreeString(null, null);
    String expectedValue = String.format("%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.userlayer"), "");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    UserLayer userLayer = DefaultSymbols.createNewUserLayer();
    actualValue = item.getTreeString(null, userLayer);
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    String expectedName = "test name";
    userLayer.setName(expectedName);
    actualValue = item.getTreeString(null, userLayer);
    expectedValue = String.format("%s : %s", Localisation.getString(SLDTreeTools.class, "TreeItem.userlayer"), expectedName);
    assertTrue(actualValue.compareTo(expectedValue) == 0);
}
Also used : UserLayer(org.geotools.styling.UserLayer) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) UserLayerTreeItem(com.sldeditor.ui.tree.item.UserLayerTreeItem) Test(org.junit.Test)

Aggregations

UserLayer (org.geotools.styling.UserLayer)29 Test (org.junit.Test)17 DummyInlineSLDFile (com.sldeditor.test.unit.datasource.impl.DummyInlineSLDFile)10 InLineFeatureModel (com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel)8 Style (org.geotools.styling.Style)6 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)6 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)4 NamedLayer (org.geotools.styling.NamedLayer)4 Rule (org.geotools.styling.Rule)4 StyledLayer (org.geotools.styling.StyledLayer)4 UndoEvent (com.sldeditor.common.undo.UndoEvent)3 IOException (java.io.IOException)3 FeatureSource (org.geotools.data.FeatureSource)3 LineSymbolizer (org.geotools.styling.LineSymbolizer)3 PointSymbolizer (org.geotools.styling.PointSymbolizer)3 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)3 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)3 SLDData (com.sldeditor.common.data.SLDData)2 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)2 FieldConfigInlineFeature (com.sldeditor.ui.detail.config.inlinefeature.FieldConfigInlineFeature)2