Package org.geotools.styling

Examples of org.geotools.styling.Rule


     */
    public Rule getDefaultRule( Style style ) {
        FeatureTypeStyle ftStyle = getDefaultFeatureTypeStyle(style);
        if (ftStyle.getRules() == null || ftStyle.getRules().length == 0) {
            // create an empty rule
            Rule rule = styleBuilder.createRule(new Symbolizer[]{});
            ftStyle.addRule(rule);
            return rule;
        }

        return ftStyle.getRules()[0];
View Full Code Here


        FeatureTypeStyle[] styles = style.getFeatureTypeStyles();
        for( int i = 0; i < styles.length; i++ ) {
            FeatureTypeStyle fstyle = styles[i];
            Rule[] rules = fstyle.getRules();
            for( int j = 0; j < rules.length; j++ ) {
                Rule rule = rules[j];
                symbs.addAll(Arrays.asList(rule.getSymbolizers()));
            }
        }
        return symbs.toArray(new Symbolizer[symbs.size()]);
    }
View Full Code Here

        FeatureTypeStyle[] styles=style.getFeatureTypeStyles();
        for( int i = 0; i < styles.length; i++ ) {
            FeatureTypeStyle fstyle = styles[i];
            Rule[] rules=fstyle.getRules();
            for( int j = 0; j < rules.length; j++ ) {
                Rule rule = rules[j];
                symbs.addAll(Arrays.asList(rule.getSymbolizers()));
            }
        }
        return symbs.toArray(new Symbolizer[symbs.size()]);
    }
View Full Code Here

        Style sld = (Style) blackboard.lookup(Style.class); // or
        // blackboard.get(
        // "org.locationtech.udig.style.sld"
        // );
        if (sld != null) {
            Rule rule = getRule(sld);

            BufferedImage swtIcon = null;
            if (layer.hasResource(FeatureSource.class) && rule != null) {
                SimpleFeatureType type = layer.getSchema();
                GeometryDescriptor geom = type.getGeometryDescriptor();
View Full Code Here

        }
        return null;
    }

    private Rule getRule( Style sld ) {
        Rule rule = null;
        int size = 0;

        for( FeatureTypeStyle style : sld.getFeatureTypeStyles() ) {
            for( Rule potentialRule : style.getRules() ) {
                if (potentialRule != null) {
View Full Code Here

    }

    public boolean canModify(Object element, String property) {
        if (property.equals("styleExpr")) { //$NON-NLS-1$
            if (element instanceof Rule) {
                Rule rule = (Rule) element;
                if (rule.getName().startsWith("rule")) { //$NON-NLS-1$
                    if (rule.hasElseFilter()) {
                        return false;
                    }
                    return true;
                } else {
                    return false;
View Full Code Here

    }

    public Object getValue(Object element, String property) {
        if (property.equals("styleExpr")) { //$NON-NLS-1$
            if (element instanceof Rule) {
                Rule rule = (Rule) element;
                if (rule.hasElseFilter()) {
                    return "else"; //$NON-NLS-1$
                } else {
                    return StyleGenerator.toStyleExpression(rule.getFilter());
                }
            }
        } else if (property.equals("title")) { //$NON-NLS-1$
            if (element instanceof Rule) {
                Rule rule = (Rule) element;
                //the title contains the same value, but we'll obtain it from the rule anyways
                return rule.getTitle();
            }
        } else if (property.equals("colour")) { //$NON-NLS-1$
            if (element instanceof Rule) {
                Rule rule = (Rule) element;
                Color colour = SLDs.toColor(SLDs.colors(rule)[0]);
                RGB rgb = new RGB(colour.getRed(), colour.getGreen(), colour.getBlue());
                return rgb;
            }
        }
View Full Code Here

        } else if (property.equals("title")) { //$NON-NLS-1$
            if (element instanceof TreeItem) {
                TreeItem item = (TreeItem) element;
                Object data = item.getData();
                if (data instanceof Rule) {
                    Rule rule = (Rule) data;
                    if (rule.getTitle().equals(value)) return; //don't bother -- value is the same
                    rule.setTitle(value.toString());
                }
                this.styleThemePage.treeViewer.refresh();
            }
        } else if (property.equals("colour")) { //$NON-NLS-1$
            if (value == null) return;
View Full Code Here

                newColor = new Color(rgb.red, rgb.green, rgb.blue);
                String htmlColor = SLDs.toHTMLColor(newColor);
                newColorExpr = sb.literalExpression(htmlColor);
            }
            if (data instanceof Rule) {
                Rule rule = (Rule) data;
                Symbolizer[] symb = rule.getSymbolizers();
                if (symb.length == 1) { //we're only expecting 1
                    if (symb[0] instanceof PolygonSymbolizer) {
                        PolygonSymbolizer ps = (PolygonSymbolizer) symb[0];
                        Fill fill = ps.getFill();
                        oldColorExpr = fill.getColor();
                        fill.setColor(newColorExpr);
                    }else if (symb[0] instanceof PointSymbolizer) {
                        PointSymbolizer ps = (PointSymbolizer) symb[0];
                        Mark[] marks = ps.getGraphic().getMarks();
                        if(marks!=null && marks.length>0){
                            oldColorExpr = marks[0].getFill().getColor();
                            marks[0].getFill().setColor(newColorExpr);
                        }
                    }else if (symb[0] instanceof LineSymbolizer) {
                        LineSymbolizer ps = (LineSymbolizer) symb[0];
                        Stroke stroke = ps.getStroke();
                        oldColorExpr = stroke.getColor();
                        stroke.setColor(newColorExpr);
                    }
                   
                    if (newColorExpr.equals(oldColorExpr)) {
                        return; //don't bother, same colour
                    }
                        //determine if the palette is already customized
                        if (this.styleThemePage.customPalette == null) {
                            int numClasses = new Integer(this.styleThemePage.getCombo(StyleThemePage.COMBO_CLASSES).getText()).intValue();
                            //create the palette from the current one
                            BrewerPalette pal = (BrewerPalette) ((StructuredSelection) this.styleThemePage.paletteTable.getSelection()).getFirstElement();
                            this.styleThemePage.customPalette = new BrewerPalette();
                            PaletteSuitability suitability = new PaletteSuitability();
                            //suitability.
                            //customPalette.setColors()
                            SampleScheme newScheme = new SampleScheme();
                            int maxColors = pal.getMaxColors();
                            Color[] allColorsArray = pal.getColors();
                            if (maxColors==Integer.MAX_VALUE) {
                                // this means the array is dynamic, so the num is exactly the colors
                                maxColors = numClasses;
                                newScheme = new CustomSampleScheme(maxColors);
                            }
                            if (allColorsArray.length == 0) {
                                allColorsArray = pal.getColors(maxColors);
                            }
                            Color[] colors = new Color[maxColors];
                            List<Color> allColors = new ArrayList<Color>();
                            for (int i = 0; i < allColorsArray.length; i++) {
                                allColors.add(allColorsArray[i]);
                            }
                            String unknown = "?"; //$NON-NLS-1$
                            for (int i = 0; i < maxColors; i++) {
                                if (i > 0) {
                                    //create a simple scheme
                                    int[] scheme = new int[i+1];
                                    for (int j = 0; j < i+1; j++) {
                                        scheme[j] = j;
                                    }
                                    newScheme.setSampleScheme(i+1, scheme);
                                    //set the suitability to unknown
                                    try {
                                        suitability.setSuitability(i+1, new String[] {unknown, unknown, unknown, unknown, unknown, unknown});
                                    } catch (Exception e) {
                                        SLDPlugin.log("setSuitability() failed", e); //$NON-NLS-1$
//                                        return;
                                    }
                                }
                                //copy the color
                                if (i < numClasses) {
                                    //copy the colors directly over
                                    colors[i] = pal.getColor(i, numClasses);
                                    allColors.remove(colors[i]);
                                } else {
                                    //find unique colors to fill in the rest of the palette
                                    colors[i] = allColors.remove(0);
                                }
                            }
                            //newScheme.setSampleScheme(3, new int[] {0,1});
                            this.styleThemePage.customPalette.setPaletteSuitability(suitability);
                            this.styleThemePage.customPalette.setColors(colors);
                            this.styleThemePage.customPalette.setColorScheme(newScheme);
                            this.styleThemePage.customPalette.setName(Messages.StyleEditor_theme_custom);
                            this.styleThemePage.customPalette.setDescription(Messages.StyleEditor_theme_custom_desc);
                            this.styleThemePage.customPalette.setType(pal.getType());
                            if (!this.styleThemePage.getBrewer().hasPalette(Messages.StyleEditor_theme_custom)) {
                                this.styleThemePage.getBrewer().registerPalette(this.styleThemePage.customPalette);
                            }
                        }
                        //seek and destroy the old colour
                        Color[] colors = this.styleThemePage.customPalette.getColors();
                        int expectedIndex = -1;
                        if (rule.getName().toLowerCase().startsWith("rule")) { //$NON-NLS-1$
                            expectedIndex = Integer.parseInt(rule.getName().substring(4))-1;
                        }
                        int actualIndex = -1;
                        for (int i = 0; i < colors.length; i++) {
                            if (sb.literalExpression(SLDs.toHTMLColor(colors[i])).equals(oldColorExpr)) {
                                actualIndex = i;
View Full Code Here

        Style sld = (Style) blackboard.lookup(Style.class); // or
        // blackboard.get(
        // "org.locationtech.udig.style.sld"
        // );
        if (sld != null) {
            Rule rule = getRule(sld);
            return generateStyledIcon(layer, rule);
        }
        if (layer.hasResource(WebMapServer.class)) {
            return null; // do not support styling for wms yet
        }
View Full Code Here

TOP

Related Classes of org.geotools.styling.Rule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.