Package org.geotools.styling

Examples of org.geotools.styling.StyleBuilder$EqualClasses


            Item item = (Item) element;
            Object data = item.getData();
            Expression newColorExpr = null;
            Expression oldColorExpr = null;
            Color newColor = null;
            StyleBuilder sb = new StyleBuilder();
            if (value instanceof RGB) {
                RGB rgb = (RGB) value;
                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;
                                if (expectedIndex == i) {
                                    //we found the correct old color where we expected to
                                    break;
                                } //otherwise, keep looking just in case
View Full Code Here


     * @param typeName the TypeName of the feature type the style will style.
     * @param color the color of the style
     * @return a simple style to use in default cases.
     */
    public static Style createLineStyle( String typeName, Color color ) {
        StyleBuilder sb = new StyleBuilder();
        Style linestyle = sb.createStyle();

        LineSymbolizer line = sb.createLineSymbolizer(color);
        linestyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(line));

        FeatureTypeStyle fts = linestyle.getFeatureTypeStyles()[0];
        fts.setName(Messages.Styling_name); //tag as simple
        fts.setFeatureTypeName(SLDs.GENERIC_FEATURE_TYPENAME);
        fts.setSemanticTypeIdentifiers(new String[] {"generic:geometry", "simple"}); //$NON-NLS-1$ //$NON-NLS-2$
View Full Code Here

     * @param line the color of the outlines.
     * @param fill The color of the fills
     * @return a simple style to use in default cases.
     */
    public static Style createPolyStyle( String typeName, Color line, Color fill ) {
        StyleBuilder sb = new StyleBuilder();
        Style polystyle = sb.createStyle();

        PolygonSymbolizer poly = sb.createPolygonSymbolizer(fill, line, 1);
        polystyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(poly));

        polystyle.getFeatureTypeStyles()[0].setFeatureTypeName(SLDs.GENERIC_FEATURE_TYPENAME);
        return polystyle;
    }
View Full Code Here

     *
     * @param typeName the TypeName of the feature type the style will style.
     * @return a simple style to use in default cases.
     */
    public static Style createPointStyle( String typeName ) {
        StyleBuilder sb = new StyleBuilder();
        Style pointstyle = sb.createStyle();
        PointSymbolizer point = sb.createPointSymbolizer(sb.createGraphic());

        pointstyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(point));

        pointstyle.getFeatureTypeStyles()[0].setFeatureTypeName(SLDs.GENERIC_FEATURE_TYPENAME);
        return pointstyle;
    }
View Full Code Here

     *
     * @param typeName the TypeName of the feature type the style will style.
     * @return as simple style to use in default cases.
     */
    public static Style createRasterStyle( String typeName ) {
        StyleBuilder sb = new StyleBuilder();
        Style rasterstyle = sb.createStyle();
        RasterSymbolizer raster = sb.createRasterSymbolizer();

        rasterstyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(raster));
        rasterstyle.getFeatureTypeStyles()[0].setFeatureTypeName(SLDs.GENERIC_FEATURE_TYPENAME);
        return rasterstyle;
    }
View Full Code Here

    Classifier customBreak = null;
   
    public StyleThemePage() {
        //create factories
        ff = (FilterFactory2) CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
        sb = new StyleBuilder(ff);
       
        //suitability icons
        controlNames.put(LABEL_ICON_COLORBLIND, Messages.StyleEditor_theme_suitability_colour);
        controlNames.put(LABEL_ICON_CRT, Messages.StyleEditor_theme_suitability_crt);
        controlNames.put(LABEL_ICON_LCD, Messages.StyleEditor_theme_suitability_lcd);
View Full Code Here

        if (normalizedGeomName == null) {
            normalizedGeomName = geometryType.toLowerCase();
        }
        Style style = this.defaultStyle.get(normalizedGeomName.toLowerCase());
        if (style == null) {
            StyleBuilder builder = new StyleBuilder();
            final Symbolizer symbolizer;
            if (normalizedGeomName.equalsIgnoreCase(Point.class.getSimpleName())) {
                symbolizer = builder.createPointSymbolizer();
            } else if (normalizedGeomName.equalsIgnoreCase(LineString.class.getSimpleName())) {
                symbolizer = builder.createLineSymbolizer(Color.black, 2);
            } else if (normalizedGeomName.equalsIgnoreCase(Polygon.class.getSimpleName())) {
                symbolizer = builder.createPolygonSymbolizer(Color.lightGray, Color.black, 2);
            } else if (normalizedGeomName.equalsIgnoreCase(Constants.Style.Raster.NAME)) {
                symbolizer = builder.createRasterSymbolizer();
            } else if (normalizedGeomName.equalsIgnoreCase(Constants.Style.Grid.NAME)) {
                return createGridStyle(builder);
            } else if (normalizedGeomName.equalsIgnoreCase(Constants.Style.OverviewMap.NAME)) {
                symbolizer = createMapOverviewStyle(builder);
            } else {
                final Style geomStyle = this.defaultStyle.get(Geometry.class.getSimpleName().toLowerCase());
                if (geomStyle != null) {
                    return geomStyle;
                } else {
                    symbolizer = builder.createPointSymbolizer();
                }
            }
            style = builder.createStyle(symbolizer);
        }
        return style;
    }
View Full Code Here

    @Before
    public void setUp() throws Exception {
        Configuration configuration = new Configuration();
        final File file = getFile(MapfishJsonStyleParserPluginTest.class, REQUEST_DATA_STYLE_JSON_V1_STYLE_JSON);
        configuration.setConfigurationFile(file);
        helper = new JsonStyleParserHelper(configuration, new StyleBuilder(), true, Versions.ONE);
    }
View Full Code Here

        assertEquals(16, estimator.getBuffer());
    }
   
    @Test
    public void testMarkNoSizeNoStroke() throws Exception {
        StyleBuilder sb = new StyleBuilder();
        Mark mark = sb.createMark("square");
        mark.setStroke(null);
        Graphic graphic = sb.createGraphic(null, mark, null);
        graphic.setSize(NilExpression.NIL);
        PointSymbolizer ps = sb.createPointSymbolizer(graphic);
        Style style = sb.createStyle(ps);
       
        MetaBufferEstimator estimator = new MetaBufferEstimator();
        style.accept(estimator);
        assertTrue(estimator.isEstimateAccurate());
        assertEquals(16, estimator.getBuffer());
View Full Code Here

        assertEquals(16, estimator.getBuffer());
    }
   
    @Test
    public void testMarkStroke() throws Exception {
        StyleBuilder sb = new StyleBuilder();
        Mark mark = sb.createMark("square");
        mark.getStroke().setWidth(sb.getFilterFactory().literal(10));
        Graphic graphic = sb.createGraphic(null, mark, null);
        graphic.setSize(NilExpression.NIL);
        PointSymbolizer ps = sb.createPointSymbolizer(graphic);
        Style style = sb.createStyle(ps);
       
        MetaBufferEstimator estimator = new MetaBufferEstimator();
        style.accept(estimator);
        assertTrue(estimator.isEstimateAccurate());
        assertEquals(26, estimator.getBuffer());
View Full Code Here

TOP

Related Classes of org.geotools.styling.StyleBuilder$EqualClasses

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.