Search in sources :

Example 41 with Rule

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

the class RuleRenderVisitor method visit.

/**
 * Visit.
 *
 * @param rule the rule
 */
/*
     * (non-Javadoc)
     * 
     * @see org.geotools.styling.visitor.DuplicatingStyleVisitor#visit(org.geotools.styling.Rule)
     */
@SuppressWarnings("deprecation")
@Override
public void visit(Rule rule) {
    Rule copy = null;
    Symbolizer[] symsCopy = null;
    if (!displayOverall) {
        if ((symbolizerIndex >= 0) && (symbolizerIndex < rule.getSymbolizers().length)) {
            symsCopy = new Symbolizer[1];
            symsCopy[0] = copy(rule.getSymbolizers()[symbolizerIndex]);
        }
    }
    // As a catch all copy everything
    if (symsCopy == null) {
        symsCopy = rule.getSymbolizers();
        for (int i = 0; i < symsCopy.length; i++) {
            symsCopy[i] = copy(symsCopy[i]);
        }
    }
    Graphic[] legendCopy = rule.getLegendGraphic();
    for (int i = 0; i < legendCopy.length; i++) {
        legendCopy[i] = copy(legendCopy[i]);
    }
    Description descCopy = rule.getDescription();
    descCopy = copy(descCopy);
    copy = sf.createRule();
    copy.setSymbolizers(symsCopy);
    copy.setDescription(descCopy);
    copy.setLegendGraphic(legendCopy);
    copy.setName(rule.getName());
    Filter filterCopy = null;
    copy.setFilter(filterCopy);
    copy.setElseFilter(rule.isElseFilter());
    if (STRICT && !copy.equals(rule)) {
        throw new IllegalStateException("Was unable to duplicate provided Rule:" + rule);
    }
    pages.push(copy);
}
Also used : Description(org.opengis.style.Description) Filter(org.opengis.filter.Filter) Graphic(org.geotools.styling.Graphic) Rule(org.geotools.styling.Rule) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer)

Example 42 with Rule

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

the class BatchUpdateFontUtils method containsFonts.

/**
 * Contains font details.
 *
 * @param sldData the sld data
 * @return the scale sld data
 */
public static List<BatchUpdateFontData> containsFonts(SLDDataInterface sldData) {
    List<BatchUpdateFontData> dataList = null;
    if (sldData != null) {
        StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
        if (sld != null) {
            List<StyledLayer> styledLayerList = sld.layers();
            if (sld != null) {
                for (StyledLayer styledLayer : styledLayerList) {
                    if (styledLayer instanceof NamedLayerImpl) {
                        NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
                        for (Style style : namedLayerImpl.styles()) {
                            for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                                for (Rule rule : fts.rules()) {
                                    for (Symbolizer symbolizer : rule.symbolizers()) {
                                        if (symbolizer instanceof TextSymbolizer) {
                                            TextSymbolizer textSymbol = (TextSymbolizer) symbolizer;
                                            Font font = textSymbol.getFont();
                                            if (font != null) {
                                                if (dataList == null) {
                                                    dataList = new ArrayList<BatchUpdateFontData>();
                                                }
                                                BatchUpdateFontData fontSLDData = new BatchUpdateFontData(sld, sldData);
                                                fontSLDData.setNamedLayer(namedLayerImpl.getName());
                                                fontSLDData.setFeatureTypeStyle(fts.getName());
                                                fontSLDData.setStyle(style.getName());
                                                fontSLDData.setRule(rule);
                                                fontSLDData.setSymbolizer(textSymbol);
                                                fontSLDData.setFont(font);
                                                dataList.add(fontSLDData);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return dataList;
}
Also used : StyledLayer(org.geotools.styling.StyledLayer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Symbolizer(org.geotools.styling.Symbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) Font(org.geotools.styling.Font) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule)

Example 43 with Rule

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

the class ScaleSLDData method updateScales.

/**
 * Update scales.
 *
 * @param sldWriter the sld writer
 */
public boolean updateScales(SLDWriterInterface sldWriter) {
    boolean refreshUI = false;
    if (rule != null) {
        if (isMinimumScaleUpdated()) {
            rule.setMinScaleDenominator(minScale);
            minimumScaleUpdated = false;
        }
        if (isMaximumScaleUpdated()) {
            rule.setMaxScaleDenominator(maxScale);
            maximumScaleUpdated = false;
        }
        String sldContents = sldWriter.encodeSLD(null, this.sld);
        SLDDataInterface current = SLDEditorFile.getInstance().getSLDData();
        if (current.getSLDFile().equals(sldData.getSLDFile()) || current.getSLDURL().equals(sldData.getSLDURL())) {
            Rule currentFule = SLDUtils.findRule(sld, rule, SelectedSymbol.getInstance().getSld());
            if (currentFule != null) {
                currentFule.setMinScaleDenominator(minScale);
                currentFule.setMaxScaleDenominator(maxScale);
                refreshUI = true;
            }
        }
        sldData.updateSLDContents(sldContents);
    }
    return refreshUI;
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) Rule(org.geotools.styling.Rule)

Example 44 with Rule

use of org.geotools.styling.Rule 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 45 with Rule

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

Aggregations

Rule (org.geotools.styling.Rule)110 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)65 Style (org.geotools.styling.Style)60 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)51 Test (org.junit.Test)48 NamedLayer (org.geotools.styling.NamedLayer)38 PointSymbolizer (org.geotools.styling.PointSymbolizer)28 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)26 LineSymbolizer (org.geotools.styling.LineSymbolizer)24 Symbolizer (org.geotools.styling.Symbolizer)22 StyledLayer (org.geotools.styling.StyledLayer)19 NamedLayerImpl (org.geotools.styling.NamedLayerImpl)16 RasterSymbolizer (org.geotools.styling.RasterSymbolizer)16 TextSymbolizer (org.geotools.styling.TextSymbolizer)15 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)13 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)11 ArrayList (java.util.ArrayList)11 Filter (org.opengis.filter.Filter)11 UserLayerImpl (org.geotools.styling.UserLayerImpl)10 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)8