Search in sources :

Example 1 with Rule

use of org.opengis.style.Rule in project sldeditor by robward-scisys.

the class RuleDetails method updateSymbol.

/**
 * Update symbol.
 */
private void updateSymbol() {
    if (!Controller.getInstance().isPopulating()) {
        StandardData standardData = getStandardData();
        double minScale = getMinimumValue(fieldConfigManager.get(FieldIdEnum.MINIMUM_SCALE));
        double maxScale = getMaximumValue(fieldConfigManager.get(FieldIdEnum.MAXIMUM_SCALE));
        // 
        // Read filter string
        // 
        String filterText = fieldConfigVisitor.getText(FieldIdEnum.FILTER);
        Filter filter = originalFilter;
        if (originalFilter == null) {
            try {
                if (!filterText.isEmpty()) {
                    filter = CQL.toFilter(filterText);
                }
            } catch (CQLException e) {
                filter = originalFilter;
                ConsoleManager.getInstance().exception(this, e);
            }
        }
        // 
        // Use existing symbolizers
        // 
        org.geotools.styling.Rule existingRule = SelectedSymbol.getInstance().getRule();
        if (existingRule != null) {
            List<org.geotools.styling.Symbolizer> symbolizerList = existingRule.symbolizers();
            org.geotools.styling.Symbolizer[] symbolizerArray = new org.geotools.styling.Symbolizer[symbolizerList.size()];
            int index = 0;
            for (org.geotools.styling.Symbolizer symbolizer : symbolizerList) {
                symbolizerArray[index] = symbolizer;
                index++;
            }
            // 
            // Legend
            // 
            GraphicLegend existingLegend = existingRule.getLegend();
            Graphic[] legendGraphics = null;
            if (existingLegend != null) {
                int legendGraphicCount = existingLegend.graphicalSymbols().size();
                legendGraphics = new Graphic[legendGraphicCount];
                index = 0;
                for (GraphicalSymbol graphicalSymbol : existingLegend.graphicalSymbols()) {
                    legendGraphics[index] = (Graphic) graphicalSymbol;
                    index++;
                }
            } else {
                legendGraphics = new Graphic[0];
            }
            // 
            // Else filter
            // 
            boolean isElseFilter = fieldConfigVisitor.getBoolean(FieldIdEnum.ELSE_FILTER);
            // 
            // Create new rule object
            // 
            Rule rule = getStyleFactory().createRule(symbolizerArray, standardData.description, legendGraphics, standardData.name, filter, isElseFilter, maxScale, minScale);
            SelectedSymbol.getInstance().replaceRule((org.geotools.styling.Rule) rule);
            this.fireUpdateSymbol();
        }
    }
}
Also used : Graphic(org.geotools.styling.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) GraphicLegend(org.opengis.style.GraphicLegend) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) Filter(org.opengis.filter.Filter) CQLException(org.geotools.filter.text.cql2.CQLException) Rule(org.opengis.style.Rule)

Example 2 with Rule

use of org.opengis.style.Rule in project sldeditor by robward-scisys.

the class RuleDetails method populate.

/**
 * Populate.
 *
 * @param selectedSymbol the selected symbol
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.selectedsymbol.SelectedSymbol)
     */
@Override
public void populate(SelectedSymbol selectedSymbol) {
    boolean rangeSet = false;
    String minScaleText = "";
    String maxScaleText = "";
    if (selectedSymbol != null) {
        Rule rule = selectedSymbol.getRule();
        if (rule != null) {
            populateStandardData(rule);
            originalFilter = rule.getFilter();
            String filterString = "";
            if (originalFilter != null) {
                try {
                    filterString = CQL.toCQL(originalFilter);
                } catch (Exception e) {
                // Do nothing
                }
            }
            fieldConfigVisitor.populateTextField(FieldIdEnum.FILTER, filterString);
            rangeSet = ScaleUtil.isPresent(rule);
            minScaleText = ScaleUtil.getValue(rule.getMinScaleDenominator());
            maxScaleText = ScaleUtil.getValue(rule.getMaxScaleDenominator());
            fieldConfigVisitor.populateBooleanField(FieldIdEnum.ELSE_FILTER, rule.isElseFilter());
        }
    }
    fieldConfigVisitor.populateTextField(FieldIdEnum.MINIMUM_SCALE, minScaleText);
    fieldConfigVisitor.populateTextField(FieldIdEnum.MAXIMUM_SCALE, maxScaleText);
    populateScaleRange(rangeSet);
}
Also used : FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) Rule(org.opengis.style.Rule) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 3 with Rule

use of org.opengis.style.Rule in project sldeditor by robward-scisys.

the class RuleDetails method editFilter.

/**
 * Edits the filter.
 *
 * @param filterFieldId the filter field id
 */
protected void editFilter(FieldIdEnum filterFieldId) {
    FilterPanelInterface filterPanel = ExpressionPanelFactory.getFilterPanel(null);
    String panelTitle = Localisation.getString(RuleDetails.class, "RuleDetails.panelTitle");
    filterPanel.configure(panelTitle, Object.class, SelectedSymbol.getInstance().isRasterSymbol());
    Rule rule = SelectedSymbol.getInstance().getRule();
    if (rule != null) {
        filterPanel.populate(rule.getFilter());
    }
    if (filterPanel.showDialog()) {
        originalFilter = filterPanel.getFilter();
        fieldConfigVisitor.populateTextField(filterFieldId, filterPanel.getFilterString());
        updateSymbol();
    }
}
Also used : FilterPanelInterface(com.sldeditor.filter.FilterPanelInterface) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) Rule(org.opengis.style.Rule)

Aggregations

FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)3 Rule (org.opengis.style.Rule)3 CQLException (org.geotools.filter.text.cql2.CQLException)2 FilterPanelInterface (com.sldeditor.filter.FilterPanelInterface)1 Graphic (org.geotools.styling.Graphic)1 Filter (org.opengis.filter.Filter)1 GraphicLegend (org.opengis.style.GraphicLegend)1 GraphicalSymbol (org.opengis.style.GraphicalSymbol)1