Search in sources :

Example 11 with LineSymbolizer

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

the class LineSymbolizerDetails method populate.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.marker.iface.PointMarkerDetailsInterface#populate(com.sldeditor.marker.detail.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    if (selectedSymbol != null) {
        LineSymbolizer lineSymbolizer = (LineSymbolizer) selectedSymbol.getSymbolizer();
        if (lineSymbolizer != null) {
            populateStandardData(lineSymbolizer);
            fieldConfigVisitor.populateField(FieldIdEnum.PERPENDICULAR_OFFSET, lineSymbolizer.getPerpendicularOffset());
            fieldConfigVisitor.populateField(FieldIdEnum.GEOMETRY, lineSymbolizer.getGeometry());
        }
    }
}
Also used : LineSymbolizer(org.geotools.styling.LineSymbolizer)

Example 12 with LineSymbolizer

use of org.geotools.styling.LineSymbolizer 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 13 with LineSymbolizer

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

the class SLDTreeTools method addNewImageOutlineLine.

/**
 * Adds the new image outline line symbolizer.
 */
public void addNewImageOutlineLine() {
    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 = getRasterTreeNode();
    SelectedSymbol.getInstance().addImageOutlineSymbolizerToRaster(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)

Example 14 with LineSymbolizer

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

the class SLDTreeTools method setButtonState.

/**
 * Sets the buttons state.
 *
 * @param parentNode the parent node
 * @param selectedNode the new button state
 * @param currentGeometryType the current geometry type
 */
public void setButtonState(DefaultMutableTreeNode parentNode, DefaultMutableTreeNode selectedNode, GeometryTypeEnum currentGeometryType) {
    boolean addButtonEnabled = true;
    boolean removeButtonEnabled = true;
    boolean addNamedLayerButtonEnabled = false;
    boolean addUserLayerButtonEnabled = false;
    boolean showMoveButtons = true;
    boolean hasMoreThan1Item = false;
    boolean isFirstSelected = false;
    boolean isLastSelected = false;
    boolean showLineArrowButtons = false;
    symbolizerButtonState.setGeometryType(currentGeometryType);
    Object obj = null;
    Object parentObj = null;
    if (selectedNode != null) {
        obj = selectedNode.getUserObject();
        if (parentNode != null) {
            parentObj = parentNode.getUserObject();
        }
        if (obj instanceof StyledLayerDescriptor) {
            addNamedLayerButtonEnabled = true;
            addUserLayerButtonEnabled = true;
            addButtonEnabled = false;
        } else if (obj instanceof StyledLayer) {
            if (parentObj != null) {
                StyledLayerDescriptor sld = (StyledLayerDescriptor) parentObj;
                hasMoreThan1Item = sld.layers().size() > 1;
                isFirstSelected = (obj == sld.layers().get(0));
                isLastSelected = (obj == sld.layers().get(sld.layers().size() - 1));
            }
        } else if (obj instanceof Style) {
            if (parentObj != null) {
                if (parentObj instanceof NamedLayerImpl) {
                    NamedLayerImpl namedLayer = (NamedLayerImpl) parentObj;
                    hasMoreThan1Item = namedLayer.styles().size() > 1;
                    isFirstSelected = (obj == namedLayer.styles().get(0));
                    isLastSelected = (obj == namedLayer.styles().get(namedLayer.styles().size() - 1));
                }
            }
        } else if (obj instanceof FeatureTypeStyle) {
            if (parentObj != null) {
                Style style = (Style) parentObj;
                hasMoreThan1Item = style.featureTypeStyles().size() > 1;
                isFirstSelected = (obj == style.featureTypeStyles().get(0));
                isLastSelected = (obj == style.featureTypeStyles().get(style.featureTypeStyles().size() - 1));
            }
        } else if (obj instanceof Rule) {
            symbolizerButtonState.showSymbolizerButtons();
            addButtonEnabled = false;
            if (parentObj != null) {
                FeatureTypeStyle fts = (FeatureTypeStyle) parentObj;
                hasMoreThan1Item = fts.rules().size() > 1;
                isFirstSelected = (obj == fts.rules().get(0));
                isLastSelected = (obj == fts.rules().get(fts.rules().size() - 1));
            }
        } else if (obj instanceof Symbolizer) {
            symbolizerButtonState.showSymbolizerButtons();
            addButtonEnabled = false;
            if (parentObj != null) {
                if (parentObj instanceof Rule) {
                    Rule rule = (Rule) parentObj;
                    hasMoreThan1Item = rule.symbolizers().size() > 1;
                    isFirstSelected = (obj == rule.symbolizers().get(0));
                    isLastSelected = (obj == rule.symbolizers().get(rule.symbolizers().size() - 1));
                }
            }
            showLineArrowButtons = (obj instanceof LineSymbolizer);
        } else {
            addButtonEnabled = false;
            removeButtonEnabled = false;
            showMoveButtons = false;
        }
    }
    btnAddNamedLayerButton.setVisible(addNamedLayerButtonEnabled);
    btnAddUserLayerButton.setVisible(addUserLayerButtonEnabled);
    btnAddButton.setVisible(addButtonEnabled);
    // All symbolizer types are allowed be added to an SLD
    boolean allSymbolizer = symbolizerButtonState.isMarkerVisible(parentObj, obj) || symbolizerButtonState.isLineVisible(parentObj, obj) || symbolizerButtonState.isPolygonVisible(parentObj, obj) || symbolizerButtonState.isRasterVisible(parentObj, obj);
    btnNewMarker.setVisible(allSymbolizer);
    btnNewLine.setVisible(allSymbolizer);
    btnNewImageOutlineLine.setVisible(symbolizerButtonState.isImageOutlineLineVisible(parentObj, obj));
    btnNewPolygon.setVisible(allSymbolizer);
    btnNewImageOutlinePolygon.setVisible(symbolizerButtonState.isImageOutlinePolygonVisible(parentObj, obj));
    btnNewRaster.setVisible(allSymbolizer);
    btnNewText.setVisible(symbolizerButtonState.isTextVisible(parentObj, obj));
    btnRemoveMarker.setVisible(removeButtonEnabled);
    // Up / down buttons
    btnMoveUp.setVisible(showMoveButtons);
    btnMoveUp.setEnabled(hasMoreThan1Item && !isFirstSelected);
    btnMoveDown.setVisible(showMoveButtons);
    btnMoveDown.setEnabled(hasMoreThan1Item && !isLastSelected);
    btnSourceArrowButton.setVisible(showLineArrowButtons);
    btnDestArrowButton.setVisible(showLineArrowButtons);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) 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) 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 15 with LineSymbolizer

use of org.geotools.styling.LineSymbolizer 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

LineSymbolizer (org.geotools.styling.LineSymbolizer)51 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)24 PointSymbolizer (org.geotools.styling.PointSymbolizer)23 Test (org.junit.Test)18 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)17 Style (org.geotools.styling.Style)17 Rule (org.geotools.styling.Rule)16 Symbolizer (org.geotools.styling.Symbolizer)15 Stroke (org.geotools.styling.Stroke)12 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)10 TextSymbolizer (org.geotools.styling.TextSymbolizer)10 NamedLayer (org.geotools.styling.NamedLayer)9 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)7 StyledLayer (org.geotools.styling.StyledLayer)5 JsonObject (com.google.gson.JsonObject)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 Graphic (org.geotools.styling.Graphic)4 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)4 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)3 SLDTreeLeafLine (com.sldeditor.common.tree.leaf.SLDTreeLeafLine)3