Search in sources :

Example 41 with UndoEvent

use of com.sldeditor.common.undo.UndoEvent 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 42 with UndoEvent

use of com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.

the class SLDTreeTools method addNewPolygon.

/**
 * Adds the new polygon symbolizer.
 */
public void addNewPolygon() {
    if (symbolTree == null) {
        return;
    }
    // Store current state of the SLD before the add
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    PolygonSymbolizer newPolygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    DefaultMutableTreeNode ruleNode = getRuleTreeNode();
    SelectedSymbol.getInstance().addSymbolizerToRule(newPolygonSymbolizer);
    DefaultMutableTreeNode newNode = sldTree.addObject(ruleNode, newPolygonSymbolizer, true);
    if (newNode != null) {
        sldTree.addObject(newNode, SLDTreeLeafFactory.getInstance().getFill(newPolygonSymbolizer), true);
        sldTree.addObject(newNode, SLDTreeLeafFactory.getInstance().getStroke(newPolygonSymbolizer), true);
        SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
        // Select the item just added
        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) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer)

Example 43 with UndoEvent

use of com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.

the class SLDTreeTools method addNewRaster.

/**
 * Adds the new raster symbolizer.
 */
public void addNewRaster() {
    if (symbolTree == null) {
        return;
    }
    // Store current state of the SLD before the add
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    RasterSymbolizer newRasterSymbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
    DefaultMutableTreeNode ruleNode = getRuleTreeNode();
    SelectedSymbol.getInstance().addSymbolizerToRule(newRasterSymbolizer);
    DefaultMutableTreeNode newNode = sldTree.addObject(ruleNode, newRasterSymbolizer, 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 : RasterSymbolizer(org.geotools.styling.RasterSymbolizer) UndoEvent(com.sldeditor.common.undo.UndoEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath)

Example 44 with UndoEvent

use of com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.

the class SLDTreeTools method addArrow.

/**
 * Adds the arrow.
 *
 * @param isSourceArrow the is source arrow
 */
private void addArrow(boolean isSourceArrow) {
    if (symbolTree == null) {
        return;
    }
    // Store current state of the SLD before the add
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    PointSymbolizer pointSymbolizer = DefaultSymbols.createArrow(isSourceArrow);
    DefaultMutableTreeNode ruleNode = getRuleTreeNode();
    SelectedSymbol.getInstance().addSymbolizerToRule(pointSymbolizer);
    DefaultMutableTreeNode newNode = sldTree.addObject(ruleNode, pointSymbolizer, true);
    // Select the item just added
    if (newNode != null) {
        sldTree.addObject(newNode, SLDTreeLeafFactory.getInstance().getFill(pointSymbolizer), true);
        SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
        // Re-render the symbol
        if (renderList != null) {
            for (RenderSymbolInterface render : renderList) {
                render.renderSymbol();
            }
        }
        // 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) PointSymbolizer(org.geotools.styling.PointSymbolizer) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RenderSymbolInterface(com.sldeditor.datasource.RenderSymbolInterface)

Example 45 with UndoEvent

use of com.sldeditor.common.undo.UndoEvent in project sldeditor by robward-scisys.

the class SLDTreeTools method addNewLine.

/**
 * Adds the new line symbolizer.
 */
public void addNewLine() {
    if (symbolTree == null) {
        return;
    }
    // Store current state of the SLD before the add
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    LineSymbolizer newLineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    DefaultMutableTreeNode ruleNode = getRuleTreeNode();
    SelectedSymbol.getInstance().addSymbolizerToRule(newLineSymbolizer);
    DefaultMutableTreeNode newNode = sldTree.addObject(ruleNode, newLineSymbolizer, true);
    if (newNode != null) {
        sldTree.addObject(newNode, SLDTreeLeafFactory.getInstance().getStroke(newLineSymbolizer), true);
        SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
        // Select the item just added
        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) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) LineSymbolizer(org.geotools.styling.LineSymbolizer)

Aggregations

UndoEvent (com.sldeditor.common.undo.UndoEvent)84 Test (org.junit.Test)27 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)20 UndoActionInterface (com.sldeditor.common.undo.UndoActionInterface)16 FieldPanel (com.sldeditor.ui.widgets.FieldPanel)12 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)11 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 TreePath (javax.swing.tree.TreePath)10 Geometry (com.vividsolutions.jts.geom.Geometry)9 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)5 ArrayList (java.util.ArrayList)4 JPanel (javax.swing.JPanel)4 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)4 RenderSymbolInterface (com.sldeditor.datasource.RenderSymbolInterface)3 ValueComboBox (com.sldeditor.ui.widgets.ValueComboBox)3 Color (java.awt.Color)3 JButton (javax.swing.JButton)3 JCheckBox (javax.swing.JCheckBox)3 LineSymbolizer (org.geotools.styling.LineSymbolizer)3