Search in sources :

Example 16 with PolygonSymbolizer

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

the class SLDEditorBufferedImageLegendGraphicBuilder method getSampleShape.

/**
 * Returns a <code>java.awt.Shape</code> appropiate to render a legend graphic given the
 * symbolizer type and the legend dimensions.
 *
 * @param symbolizer the Symbolizer for whose type a sample shape will be created
 * @param legendWidth the requested width, in output units, of the legend graphic
 * @param legendHeight the requested height, in output units, of the legend graphic
 *
 * @return an appropiate Line2D, Rectangle2D or LiteShape(Point) for the symbolizer, wether it
 *         is a LineSymbolizer, a PolygonSymbolizer, or a Point ot Text Symbolizer
 *
 * @throws IllegalArgumentException if an unknown symbolizer impl was passed in.
 */
private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth, int legendHeight) {
    LiteShape2 sampleShape;
    final float hpad = (legendWidth * LegendUtils.hpaddingFactor);
    final float vpad = (legendHeight * LegendUtils.vpaddingFactor);
    if (symbolizer instanceof LineSymbolizer) {
        Coordinate[] coords = { new Coordinate(hpad, legendHeight - vpad - 1), new Coordinate(legendWidth - hpad - 1, vpad) };
        LineString geom = geomFac.createLineString(coords);
        try {
            this.sampleLine = new LiteShape2(geom, null, null, false);
        } catch (Exception e) {
            this.sampleLine = null;
        }
        sampleShape = this.sampleLine;
    } else if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof RasterSymbolizer)) {
        final float w = legendWidth - (2 * hpad) - 1;
        final float h = legendHeight - (2 * vpad) - 1;
        Coordinate[] coords = { new Coordinate(hpad, vpad), new Coordinate(hpad, vpad + h), new Coordinate(hpad + w, vpad + h), new Coordinate(hpad + w, vpad), new Coordinate(hpad, vpad) };
        LinearRing shell = geomFac.createLinearRing(coords);
        Polygon geom = geomFac.createPolygon(shell, null);
        try {
            this.sampleRect = new LiteShape2(geom, null, null, false);
        } catch (Exception e) {
            this.sampleRect = null;
        }
        sampleShape = this.sampleRect;
    } else if (symbolizer instanceof PointSymbolizer || symbolizer instanceof TextSymbolizer) {
        Coordinate coord = new Coordinate(legendWidth / 2, legendHeight / 2);
        try {
            this.samplePoint = new LiteShape2(geomFac.createPoint(coord), null, null, false);
        } catch (Exception e) {
            this.samplePoint = null;
        }
        sampleShape = this.samplePoint;
    } else {
        throw new IllegalArgumentException("Unknown symbolizer: " + symbolizer);
    }
    return sampleShape;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ServiceException(org.geoserver.platform.ServiceException) SchemaException(org.geotools.feature.SchemaException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalAttributeException(org.opengis.feature.IllegalAttributeException) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) TextSymbolizer(org.geotools.styling.TextSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) LiteShape2(org.geotools.geometry.jts.LiteShape2) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 17 with PolygonSymbolizer

use of org.geotools.styling.PolygonSymbolizer 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 18 with PolygonSymbolizer

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

the class CheckBoxNodeEditor method isCellEditable.

/*
     * (non-Javadoc)
     * 
     * @see javax.swing.AbstractCellEditor#isCellEditable(java.util.EventObject)
     */
public boolean isCellEditable(EventObject event) {
    boolean returnValue = false;
    if (event instanceof MouseEvent) {
        MouseEvent mouseEvent = (MouseEvent) event;
        TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
        if (path != null) {
            Object node = path.getLastPathComponent();
            if ((node != null) && (node instanceof DefaultMutableTreeNode)) {
                DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
                if (treeNode.getParent() != null) {
                    Object parentUserObject = ((DefaultMutableTreeNode) treeNode.getParent()).getUserObject();
                    if (parentUserObject instanceof PolygonSymbolizer) {
                        symbolizer = (Symbolizer) parentUserObject;
                        userObject = treeNode.getUserObject();
                        returnValue = treeNode.isLeaf();
                    }
                }
            }
        }
    }
    return returnValue;
}
Also used : MouseEvent(java.awt.event.MouseEvent) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) EventObject(java.util.EventObject)

Example 19 with PolygonSymbolizer

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

the class SLDTree method populateSLD.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.tree.UpdateTreeStructureInterface#populateSLD()
     */
@Override
public void populateSLD() {
    reset();
    SelectedSymbol selectedSymbol = SelectedSymbol.getInstance();
    if (selectedSymbol != null) {
        StyledLayerDescriptor sld = selectedSymbol.getSld();
        rootNode.setUserObject(sld);
        treeModel.nodeChanged(rootNode);
        if (sld != null) {
            List<StyledLayer> styledLayerList = sld.layers();
            if (styledLayerList != null) {
                for (StyledLayer styledLayer : styledLayerList) {
                    DefaultMutableTreeNode styledLayerTreeNode = null;
                    List<Style> styleList = null;
                    if (styledLayer instanceof NamedLayerImpl) {
                        NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                        styleList = namedLayerImpl.styles();
                        styledLayerTreeNode = addObject(rootNode, namedLayerImpl, true);
                    } else if (styledLayer instanceof UserLayerImpl) {
                        UserLayerImpl userLayerImpl = (UserLayerImpl) styledLayer;
                        styleList = userLayerImpl.userStyles();
                        styledLayerTreeNode = addObject(rootNode, userLayerImpl, true);
                    }
                    if (styleList != null) {
                        for (Style style : styleList) {
                            DefaultMutableTreeNode styleTreeNode = addObject(styledLayerTreeNode, style, true);
                            for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                                DefaultMutableTreeNode ftsTreeNode = addObject(styleTreeNode, fts, true);
                                for (Rule rule : fts.rules()) {
                                    DefaultMutableTreeNode ruleTreeNode = addObject(ftsTreeNode, rule, true);
                                    for (Symbolizer symbolizer : rule.symbolizers()) {
                                        DefaultMutableTreeNode symbolizerTreeNode = addObject(ruleTreeNode, symbolizer, true);
                                        if ((symbolizer instanceof PointSymbolizer) || (symbolizer instanceof PolygonSymbolizer)) {
                                            addObject(symbolizerTreeNode, SLDTreeLeafFactory.getInstance().getFill(symbolizer), true);
                                        }
                                        if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof LineSymbolizer)) {
                                            addObject(symbolizerTreeNode, SLDTreeLeafFactory.getInstance().getStroke(symbolizer), true);
                                        }
                                        if (symbolizer instanceof RasterSymbolizer) {
                                            handleRasterSymbolizer(symbolizer, symbolizerTreeNode);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) PointSymbolizer(org.geotools.styling.PointSymbolizer) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StyledLayer(org.geotools.styling.StyledLayer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) UserLayerImpl(org.geotools.styling.UserLayerImpl) LineSymbolizer(org.geotools.styling.LineSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 20 with PolygonSymbolizer

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

the class SLDTree method handleRasterSymbolizer.

/**
 * Handle raster symbolizer.
 *
 * @param symbolizer the symbolizer
 * @param symbolizerTreeNode the symbolizer tree node
 */
private void handleRasterSymbolizer(Symbolizer symbolizer, DefaultMutableTreeNode symbolizerTreeNode) {
    // Handle the image outline symbolizer for raster symbols
    Symbolizer outlineSymbolizer = ((RasterSymbolizer) symbolizer).getImageOutline();
    if (outlineSymbolizer instanceof LineSymbolizer) {
        LineSymbolizer outlineLineSymbolizer = (LineSymbolizer) outlineSymbolizer;
        if (outlineLineSymbolizer != null) {
            DefaultMutableTreeNode symbolizerImageOutlineLineNode = addObject(symbolizerTreeNode, outlineLineSymbolizer, true);
            addObject(symbolizerImageOutlineLineNode, SLDTreeLeafFactory.getInstance().getStroke(outlineLineSymbolizer), true);
        }
    } else if (outlineSymbolizer instanceof PolygonSymbolizer) {
        PolygonSymbolizer outlinePolygonSymbolizer = (PolygonSymbolizer) outlineSymbolizer;
        if (outlinePolygonSymbolizer != null) {
            DefaultMutableTreeNode symbolizerImageOutlinePolygonNode = addObject(symbolizerTreeNode, outlinePolygonSymbolizer, true);
            addObject(symbolizerImageOutlinePolygonNode, SLDTreeLeafFactory.getInstance().getFill(outlinePolygonSymbolizer), true);
            addObject(symbolizerImageOutlinePolygonNode, SLDTreeLeafFactory.getInstance().getStroke(outlinePolygonSymbolizer), true);
        }
    }
}
Also used : RasterSymbolizer(org.geotools.styling.RasterSymbolizer) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer)

Aggregations

PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)65 Test (org.junit.Test)28 PointSymbolizer (org.geotools.styling.PointSymbolizer)25 LineSymbolizer (org.geotools.styling.LineSymbolizer)24 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)19 Rule (org.geotools.styling.Rule)18 Style (org.geotools.styling.Style)18 Symbolizer (org.geotools.styling.Symbolizer)15 Fill (org.geotools.styling.Fill)14 NamedLayer (org.geotools.styling.NamedLayer)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)12 Stroke (org.geotools.styling.Stroke)10 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)9 TextSymbolizer (org.geotools.styling.TextSymbolizer)9 SLDTreeLeafPolygon (com.sldeditor.common.tree.leaf.SLDTreeLeafPolygon)8 Graphic (org.geotools.styling.Graphic)8 ArrayList (java.util.ArrayList)7 Expression (org.opengis.filter.expression.Expression)7 JsonObject (com.google.gson.JsonObject)5 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)5