Search in sources :

Example 46 with Symbolizer

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

the class SLDTreeTools method moveItem.

/**
 * Move item within a list. The direction parameter determines which way the item is moved.
 *
 * @param moveUp the move up flags (true), or down (false)
 */
public void moveItem(boolean moveUp) {
    if (symbolTree == null) {
        return;
    }
    if (treeModel == null) {
        return;
    }
    if (sldTree == null) {
        return;
    }
    TreePath path = symbolTree.getSelectionPath();
    if (path == null) {
        return;
    }
    DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (lastNode == null) {
        return;
    }
    Object obj = lastNode.getUserObject();
    if (obj == null) {
        return;
    }
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) lastNode.getParent();
    if (parentNode == null) {
        return;
    }
    Object parentObj = parentNode.getUserObject();
    if (parentObj == null) {
        return;
    }
    // Calculate index offset value based on direction
    int direction = moveUp ? -1 : 1;
    // Store current state of the SLD before the move
    // CHECKSTYLE:OFF
    Object oldValueObj = sldWriter.encodeSLD(null, SelectedSymbol.getInstance().getSld());
    if (obj instanceof StyledLayer) {
        StyledLayerDescriptor sld = (StyledLayerDescriptor) parentObj;
        // NamedLayerImpl.equals() doesn't work in the way I
        // want it to, so indexOf() does not work
        boolean found = false;
        int index = 0;
        for (StyledLayer styledLayer : sld.layers()) {
            if (styledLayer == obj) {
                found = true;
                break;
            } else {
                index++;
            }
        }
        if (found && ((index + direction) >= 0) && (index + direction) < sld.layers().size()) {
            StyledLayer styledLayer = sld.layers().remove(index);
            sld.layers().add(index + direction, styledLayer);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Style) {
        if (parentObj instanceof NamedLayerImpl) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) parentObj;
            int index = namedLayer.styles().indexOf(obj);
            if (((index + direction) >= 0) && (index + direction) < namedLayer.styles().size()) {
                Style style = namedLayer.styles().remove(index);
                namedLayer.styles().add(index + direction, style);
                treeModel.removeNodeFromParent(lastNode);
                treeModel.insertNodeInto(lastNode, parentNode, index + direction);
            } else {
                return;
            }
        }
    } else if (obj instanceof FeatureTypeStyle) {
        Style style = (Style) parentObj;
        int index = style.featureTypeStyles().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < style.featureTypeStyles().size()) {
            FeatureTypeStyle fts = style.featureTypeStyles().remove(index);
            style.featureTypeStyles().add(index + direction, fts);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Rule) {
        FeatureTypeStyle fts = (FeatureTypeStyle) parentObj;
        int index = fts.rules().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < fts.rules().size()) {
            Rule rule = fts.rules().remove(index);
            fts.rules().add(index + direction, rule);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    } else if (obj instanceof Symbolizer) {
        Rule rule = (Rule) parentObj;
        int index = rule.symbolizers().indexOf(obj);
        if (((index + direction) >= 0) && (index + direction) < rule.symbolizers().size()) {
            Symbolizer symbolizer = rule.symbolizers().remove(index);
            rule.symbolizers().add(index + direction, symbolizer);
            treeModel.removeNodeFromParent(lastNode);
            treeModel.insertNodeInto(lastNode, parentNode, index + direction);
        } else {
            return;
        }
    }
    // Refresh the tree structure. Not very efficient but gets result wanted.
    // The node has been moved in the tree above. Now going to refresh model.
    treeModel.nodeStructureChanged(lastNode);
    // Get path for item moved
    TreePath newNodePath = getPath(lastNode);
    int[] selectedRows = new int[1];
    selectedRows[0] = symbolTree.getRowForPath(newNodePath);
    // Find the row of item moved
    // Now clear tree structure and re-populate, inefficient but it means
    // that all items are expanded as required.
    SLDTreeManager.getInstance().rebuildTree((SLDTree) sldTree);
    // Make item moved selected again
    symbolTree.setSelectionRows(selectedRows);
    // Re-render the symbol
    if (renderList != null) {
        for (RenderSymbolInterface render : renderList) {
            render.renderSymbol();
        }
    }
    // Store current state of the SLD after the move
    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) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) 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) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TreePath(javax.swing.tree.TreePath) 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)

Example 47 with Symbolizer

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

the class SymbolizerTreeItem method getTreeString.

/**
 * Gets the tree string.
 *
 * <p>Code just returns image outline prefix regardless of symbolizer type,
 *  doesn't just restrict to line and polygon
 *
 * @param node the node
 * @param nodeObject the node object
 * @return the tree string
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.tree.item.SLDTreeItemInterface#getTreeString(javax.swing.tree.DefaultMutableTreeNode, java.lang.Object)
     */
@Override
public String getTreeString(DefaultMutableTreeNode node, Object nodeObject) {
    Symbolizer symbol = (Symbolizer) nodeObject;
    String name = null;
    if (symbol != null) {
        name = symbol.getName();
        if ((name == null) || name.isEmpty()) {
            name = defaultString(symbol);
        }
        if (imageOutline(node)) {
            name = String.format("%s - %s", OUTLINE_NAME, name);
        }
    }
    return name;
}
Also used : Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer)

Example 48 with Symbolizer

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

the class FillTreeItemTest method testItemSelected.

/**
 * Test method for {@link com.sldeditor.ui.tree.item.FillTreeItem#itemSelected(javax.swing.tree.DefaultMutableTreeNode, java.lang.Object)}.
 */
@Test
public void testItemSelected() {
    FillTreeItem item = new FillTreeItem();
    item.itemSelected(null, null);
    Symbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    DefaultMutableTreeNode parentNode = new DefaultMutableTreeNode();
    parentNode.setUserObject(symbolizer);
    DefaultMutableTreeNode node = new DefaultMutableTreeNode();
    parentNode.add(node);
    item.itemSelected(node, symbolizer);
    // Get the code coverage stats up
    item.itemSelected(parentNode, symbolizer);
    parentNode.setUserObject(item);
    item.itemSelected(node, null);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FillTreeItem(com.sldeditor.ui.tree.item.FillTreeItem) Symbolizer(org.geotools.styling.Symbolizer) Test(org.junit.Test)

Example 49 with Symbolizer

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

the class StrokeTreeItemTest method testItemSelected.

/**
 * Test method for {@link com.sldeditor.ui.tree.item.StrokeTreeItem#itemSelected(javax.swing.tree.DefaultMutableTreeNode, java.lang.Object)}.
 */
@Test
public void testItemSelected() {
    StrokeTreeItem item = new StrokeTreeItem();
    item.itemSelected(null, null);
    Symbolizer symbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    DefaultMutableTreeNode parentNode = new DefaultMutableTreeNode();
    parentNode.setUserObject(symbolizer);
    DefaultMutableTreeNode node = new DefaultMutableTreeNode();
    parentNode.add(node);
    item.itemSelected(node, symbolizer);
    // Get the code coverage stats up
    item.itemSelected(parentNode, symbolizer);
    parentNode.setUserObject(item);
    item.itemSelected(node, null);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StrokeTreeItem(com.sldeditor.ui.tree.item.StrokeTreeItem) Symbolizer(org.geotools.styling.Symbolizer) Test(org.junit.Test)

Example 50 with Symbolizer

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

the class SymbolizerTreeItemTest method testGetTreeStringImageOutline.

/**
 * Test method for
 * {@link com.sldeditor.ui.tree.item.SymbolizerTreeItem#getTreeString(java.lang.Object)}.
 *
 * <p>NOTE:
 * Code just returns image outline prefix regardless of symbolizer type, doesn't just restrict
 * to line and polygon
 */
@Test
public void testGetTreeStringImageOutline() {
    SymbolizerTreeItem item = new SymbolizerTreeItem();
    String actualValue = item.getTreeString(null, null);
    assertNull(actualValue);
    Symbolizer parentRasterSymbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
    DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode();
    treeNode.setUserObject(parentRasterSymbolizer);
    DefaultMutableTreeNode symbolizerNode = new DefaultMutableTreeNode();
    treeNode.add(symbolizerNode);
    Symbolizer pointSymbolizer = DefaultSymbols.createDefaultPointSymbolizer();
    actualValue = item.getTreeString(symbolizerNode, pointSymbolizer);
    String expectedValue = String.format("%s - %s", Localisation.getString(SLDTreeTools.class, "TreeItem.imageOutline"), Localisation.getString(SLDTreeTools.class, "TreeItem.newMarker"));
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    pointSymbolizer.setName(null);
    actualValue = item.getTreeString(symbolizerNode, pointSymbolizer);
    expectedValue = String.format("%s - %s", Localisation.getString(SLDTreeTools.class, "TreeItem.imageOutline"), Localisation.getString(SLDTreeTools.class, "TreeItem.marker"));
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    Symbolizer lineSymbolizer = DefaultSymbols.createDefaultLineSymbolizer();
    actualValue = item.getTreeString(symbolizerNode, lineSymbolizer);
    expectedValue = String.format("%s - %s", Localisation.getString(SLDTreeTools.class, "TreeItem.imageOutline"), Localisation.getString(SLDTreeTools.class, "TreeItem.line"));
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    Symbolizer polygonSymbolizer = DefaultSymbols.createDefaultPolygonSymbolizer();
    actualValue = item.getTreeString(symbolizerNode, polygonSymbolizer);
    expectedValue = String.format("%s - %s", Localisation.getString(SLDTreeTools.class, "TreeItem.imageOutline"), Localisation.getString(SLDTreeTools.class, "TreeItem.polygon"));
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    Symbolizer textSymbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    actualValue = item.getTreeString(symbolizerNode, textSymbolizer);
    expectedValue = String.format("%s - %s", Localisation.getString(SLDTreeTools.class, "TreeItem.imageOutline"), Localisation.getString(SLDTreeTools.class, "TreeItem.newText"));
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    textSymbolizer.setName("");
    actualValue = item.getTreeString(symbolizerNode, textSymbolizer);
    expectedValue = String.format("%s - %s", Localisation.getString(SLDTreeTools.class, "TreeItem.imageOutline"), Localisation.getString(SLDTreeTools.class, "TreeItem.text"));
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    Symbolizer rasterSymbolizer = DefaultSymbols.createDefaultRasterSymbolizer();
    actualValue = item.getTreeString(symbolizerNode, rasterSymbolizer);
    expectedValue = String.format("%s - %s", Localisation.getString(SLDTreeTools.class, "TreeItem.imageOutline"), Localisation.getString(SLDTreeTools.class, "TreeItem.raster"));
    assertTrue(actualValue.compareTo(expectedValue) == 0);
    // Try an invalid node
    actualValue = item.getTreeString(treeNode, rasterSymbolizer);
    expectedValue = Localisation.getString(SLDTreeTools.class, "TreeItem.raster");
    assertTrue(actualValue.compareTo(expectedValue) == 0);
}
Also used : SymbolizerTreeItem(com.sldeditor.ui.tree.item.SymbolizerTreeItem) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Symbolizer(org.geotools.styling.Symbolizer) SLDTreeTools(com.sldeditor.ui.tree.SLDTreeTools) Test(org.junit.Test)

Aggregations

Symbolizer (org.geotools.styling.Symbolizer)65 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)30 LineSymbolizer (org.geotools.styling.LineSymbolizer)29 PointSymbolizer (org.geotools.styling.PointSymbolizer)28 Rule (org.geotools.styling.Rule)22 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)20 Style (org.geotools.styling.Style)19 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)16 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)15 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 StyledLayer (org.geotools.styling.StyledLayer)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 JsonObject (com.google.gson.JsonObject)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 NamedLayer (org.geotools.styling.NamedLayer)8 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)8 JsonElement (com.google.gson.JsonElement)7 Stroke (org.geotools.styling.Stroke)6 JsonArray (com.google.gson.JsonArray)5