Package org.geotools.brewer.color

Examples of org.geotools.brewer.color.SampleScheme


                            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$
View Full Code Here


        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(stream);
        String name = fixToString(document.getElementsByTagName("name").item(0).getFirstChild().toString());
        String description = fixToString(document.getElementsByTagName("description").item(0).getFirstChild().toString());

        SampleScheme scheme = new SampleScheme();

        NodeList samples = document.getElementsByTagName("sample");

        for( int i = 0; i < samples.getLength(); i++ ) {
            Node sample = samples.item(i);
            int size = Integer.parseInt(sample.getAttributes().getNamedItem("size").getNodeValue());
            String values = fixToString(sample.getFirstChild().toString());
            int[] list = new int[size];
            StringTokenizer tok = new StringTokenizer(values);

            for( int j = 0; j < size; j++ ) {
                list[j] = Integer.parseInt(tok.nextToken(","));
            }

            scheme.setSampleScheme(size, list);
        }

        NodeList palettes = document.getElementsByTagName("palette");

        for( int i = 0; i < palettes.getLength(); i++ ) {
            BrewerPalette pal = new BrewerPalette();
            PaletteSuitability suitability = new PaletteSuitability();
            NodeList paletteInfo = palettes.item(i).getChildNodes();

            for( int j = 0; j < paletteInfo.getLength(); j++ ) {
                Node item = paletteInfo.item(j);

                if (item.getNodeName().equals("name")) {
                    pal.setName(fixToString(item.getFirstChild().toString()));
                }

                if (item.getNodeName().equals("description")) {
                    pal.setDescription(fixToString(item.getFirstChild().toString()));
                }

                if (item.getNodeName().equals("colors")) {
                    StringTokenizer oTok = new StringTokenizer(fixToString(item.getFirstChild().toString()));
                    List<Color> colors = new ArrayList<Color>();

                    while( oTok.hasMoreTokens() ) {
                        String entry = oTok.nextToken(":");
                        StringTokenizer iTok = new StringTokenizer(entry);
                        int r = Integer.parseInt(iTok.nextToken(",").trim());
                        int g = Integer.parseInt(iTok.nextToken(",").trim());
                        int b = Integer.parseInt(iTok.nextToken(",").trim());
                        colors.add(new Color(r, g, b));
                    }

                    pal.setColors((Color[]) colors.toArray(new Color[colors.size()]));
                }

                if (item.getNodeName().equals("suitability")) {
                    NodeList schemeSuitability = item.getChildNodes();

                    for( int k = 0; k < schemeSuitability.getLength(); k++ ) {
                        Node palScheme = schemeSuitability.item(k);

                        if (palScheme.getNodeName().equals("scheme")) {
                            int paletteSize = Integer.parseInt(palScheme.getAttributes().getNamedItem("size").getNodeValue());

                            String values = fixToString(palScheme.getFirstChild().toString());
                            String[] list = new String[6];
                            StringTokenizer tok = new StringTokenizer(values);

                            // obtain all 6 values, which should each be
                            // G=GOOD, D=DOUBTFUL, B=BAD, or ?=UNKNOWN.
                            for( int m = 0; m < 6; m++ ) {
                                list[m] = tok.nextToken(",");
                            }

                            suitability.setSuitability(paletteSize, list);
                        }
                    }
                }
            }

            pal.setType(type);

            if (scheme.getMaxCount() == -1) {
                Color[] colors = pal.getColors();
                int length = colors.length;
                CustomSampleScheme scheme2 = new CustomSampleScheme(length);
               
                for( int j = 2; j < length; j++ ) {
View Full Code Here

            customPalette.setColors(colors.toArray(new Color[0]));
        }else{
            customPalette = new BrewerPalette();
            PaletteSuitability suitability = new PaletteSuitability();
   
            SampleScheme newScheme = new SampleScheme();
            String unknown = "?"; //$NON-NLS-1$
            for (int i = 0; i < colors.size(); 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;
                    }
                    try {
                        newScheme.setSampleScheme(i+1, scheme);
                        //set the suitability to unknown
                        suitability.setSuitability(i+1, new String[] {unknown, unknown, unknown, unknown, unknown, unknown});
                    } catch (Exception e) {
                        // SLDPlugin.log("setSuitability() failed", e); //$NON-NLS-1$
                        // don't block here, give an unknown status
View Full Code Here

TOP

Related Classes of org.geotools.brewer.color.SampleScheme

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.