Package org.geotools.brewer.color

Examples of org.geotools.brewer.color.BrewerPalette


    return null;
  }

  public String getText(Object element) {
    if (element instanceof BrewerPalette) {
      BrewerPalette palette = (BrewerPalette) element;
      String text = null;
            text = palette.getName() + ": " + palette.getDescription(); //$NON-NLS-1$
            if (text == null) text = palette.getName();
            return text;
    }
    return null;
  }
View Full Code Here


     */
    public ColourScheme createColourSchemeFromString(EDataType eDataType, String initialValue) {
        String[] parts = initialValue.split(";"); //$NON-NLS-1$
        if (parts.length != 4) {
            //something is wrong...
            BrewerPalette palette = PlatformGIS.getColorBrewer().getPalette("Dark2"); //$NON-NLS-1$
            return new ColourScheme(palette, 0);
        }
        String[] strap = parts[2].split(","); //$NON-NLS-1$
        BrewerPalette palette = PlatformGIS.getColorBrewer().getPalette(parts[0]);
        HashMap<Integer, Integer> colourMapping = new HashMap<Integer, Integer>();
        for (int i = 0; i < strap.length; i++) {
            colourMapping.put(i, Integer.parseInt(strap[i]));
        }
        String[] strap2 = parts[3].split(","); //$NON-NLS-1$
View Full Code Here

        }

        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++ ) {
                    int[] list = new int[j];
                    for( int k = 0; k < list.length; k++ ) {
                        list[k] = k;
                    }
                    scheme2.setSampleScheme(j, list);
                }
                pal.setColorScheme(scheme2);
            }

            pal.setPaletteSuitability(suitability);
            PALETTESLIST.add(pal);
        }
    }
View Full Code Here

                } else {
                    expr = attr;
                }
               
                StructuredSelection structuredSelection = (StructuredSelection) paletteTable.getSelection();
                BrewerPalette pal = (BrewerPalette) structuredSelection.getFirstElement();
                if (pal == null) {
                    // get it from the last memento used
                    StyleBlackboard bb = getSelectedLayer().getStyleBlackboard();
                    IMemento memento = (IMemento) bb.get(DialogSettingsStyleContent.EXTENSION_ID);
                    String paletteName = memento.getString(PALETTE_KEY);
                    pal = getBrewer().getPalette(paletteName);
                }
                String paletteName = pal.getName();
                Combo combo = getCombo(COMBO_CLASSES);
                int numClasses = new Integer(combo.getText()).intValue();
                int[] suitability =null;
                try{
                    suitability = pal.getPaletteSuitability().getSuitability(numClasses);
                }catch (Exception e) {
                    suitability = CustomUnknownPaletteSuitability.getInstance().getSuitability(numClasses);
                }
               
                //check for custom classifier
                if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_custom)) {
                    classifier = customBreak;
                }
               
                boolean classifierModified = false;
                if (classifier == null) {
                    classifierModified = true;
                } else {
                    //determine if the classifier needs recalculation
                    if (function.getClasses() != new Integer(getCombo(COMBO_CLASSES).getText()).intValue()) {
                        if (getCombo(COMBO_ELSE).getSelectionIndex() == 0) classifierModified = true;
                        if (function.getClasses() != new Integer(getCombo(COMBO_CLASSES).getText()).intValue()-1)
                            classifierModified = true;
                    }
                    if (getCombo(COMBO_ELSE).getSelectionIndex() > 0)
                        classifierModified = true;
                    else if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_custom)) 
                        classifierModified = true;
                    else if ((getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_equalInterval)) && !(function instanceof EqualIntervalFunction))
                        classifierModified = true;
                    else if ((getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_quantile)) && !(function instanceof QuantileFunction))
                        classifierModified = true;
                    else if ((getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_standardDeviation)) && !(function instanceof StandardDeviationFunction))
                        classifierModified = true;
                    else if ((getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_uniques)) && !(function instanceof UniqueIntervalFunction))
                        classifierModified = true;
                    else if (!function.getExpression().equals(expr))
                        classifierModified = true;
                }
               
                String semanticTypeIdentifier;
                //break type:palette
                if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_uniques))
                    semanticTypeIdentifier = "unique:"; //$NON-NLS-1$
                else if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_equalInterval))
                    semanticTypeIdentifier = "equalinterval:"; //$NON-NLS-1$
                else if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_quantile))
                    semanticTypeIdentifier = "quantile:"; //$NON-NLS-1$
                else if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase("standard deviation")) //$NON-NLS-1$
                    semanticTypeIdentifier = "standarddeviation:"; //$NON-NLS-1$
                else if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_custom))
                    semanticTypeIdentifier = "custom:"; //$NON-NLS-1$
                else {
                    semanticTypeIdentifier = "default:"; //$NON-NLS-1$
                }
                semanticTypeIdentifier = semanticTypeIdentifier.concat(paletteName.toLowerCase());
               
                //create the classification function, if necessary
                if (classifierModified) {
                    //TODO: add other classifiers
                  FunctionName fn = null;
                    boolean createClassifier = true;
                    if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_uniques))
                      fn = UniqueIntervalFunction.NAME;
                    else if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_equalInterval))
                      fn = EqualIntervalFunction.NAME;
                    else if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_quantile))
                      fn = QuantileFunction.NAME;
                    else if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_standardDeviation))
                      fn = StandardDeviationFunction.NAME;
                    else if (getCombo(COMBO_BREAKTYPE).getText().equalsIgnoreCase(Messages.StyleEditor_theme_custom)){
                        classifier = customBreak;
                        createClassifier = false;
                    }else{
                        return;
                    }
                   
          if (createClassifier) {
            function = (ClassificationFunction) ff.function(fn.getFunctionName(), new Expression[fn.getArgumentCount()]);
           
            ProgressListener cancelProgress = ((StyleEditorDialog) getContainer()).getProgressListener();
            function.setProgressListener((org.geotools.util.ProgressListener) cancelProgress);
            numClasses = new Integer(getCombo(COMBO_CLASSES).getText()).intValue();

            if (getCombo(COMBO_ELSE).getSelectionIndex() == 0) {
              // function.setNumberOfClasses(numClasses);
              function.setClasses(numClasses);
            } else {
              // function.setNumberOfClasses(numClasses-1);
              function.setClasses(numClasses - 1);
            }
            // function.setCollection(collection);
            function.getParameters().set(0, expr); // set the expression last, since it causes the calculation
            // function.setExpression(expr);
            classifier = (Classifier) function.evaluate(collection,Classifier.class);
          }
                }

                //generate the style
                BrewerPalette palette = getBrewer().getPalette(paletteName);
               
                Color[] colors = null;
                try{
                    colors = palette.getColors(numClasses);
                }catch (Exception e) {
                    colors = palette.getColors();
                    palette = new CustomDynamicPalette(palette.getName(), palette.getDescription(), colors);
                    colors = palette.getColors(numClasses);
                }
                if (reverseColours) {
                    for (int i = 0; i < colors.length / 2; i++) {
                        Color tempColor = colors[i];
                        int j = colors.length-i-1;
View Full Code Here

        }
        if( getBrewer().hasPalette(Messages.StyleEditor_theme_custom)){
            customPalette = getBrewer().getPalette(Messages.StyleEditor_theme_custom);
            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++) {
View Full Code Here

    private void storePalette(IMemento memento) {
        ISelection selection = paletteTable.getSelection();
        if (!selection.isEmpty()) {
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            BrewerPalette palette = (BrewerPalette) (structuredSelection).getFirstElement();
            memento.putString(PALETTE_KEY, palette.getName());
        }
    }
View Full Code Here

      public void widgetSelected(SelectionEvent e) {
        reverseColors = !reverseColors;
        if (getCurrentSelection() != null){
          Object x = ((IStructuredSelection)cmbPalette.getSelection()).getFirstElement();
          if (x instanceof BrewerPalette){
            BrewerPalette palette = (BrewerPalette) ((IStructuredSelection)cmbPalette.getSelection()).getFirstElement();
            getCurrentSelection().setColorPalette(palette, reverseColors);
          }else if (x instanceof PredefinedColorRule){
            ColorMap cm = ((PredefinedColorRule)x).getColorMap();
            if (cm != null && getCurrentSelection() != null){
              //flip colors
              if (reverseColors){
                ColorMap reverse = new ColorMapImpl();
                for (int i = 0; i < cm.getColorMapEntries().length; i ++){
                  ColorMapEntry entry = cm.getColorMapEntries()[i];
                  ColorMapEntry clone = new ColorMapEntryImpl();
                  clone.setColor(cm.getColorMapEntry(cm.getColorMapEntries().length - 1 - i).getColor());
                  clone.setLabel(entry.getLabel());
                  clone.setQuantity(entry.getQuantity());
                  clone.setOpacity(entry.getOpacity());
                  reverse.addColorMapEntry(clone);
                 
                }
                cm = reverse;
              }
             
              getCurrentSelection().init(cm);
            }
          }
        }
      }
    });
   
    Label lblSep = new Label(linkPnl, SWT.SEPARATOR | SWT.VERTICAL);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    gd.heightHint = 10;
    lblSep.setLayoutData(gd);
   
    lnk = new Link(linkPnl, SWT.NONE);
    lnk.setText("<a>" + Messages.SingleBandEditorPage_FormatExportLink + "</a>")//$NON-NLS-1$ //$NON-NLS-2$
    lnk.addSelectionListener(new SelectionAdapter() {
     
      @Override
      public void widgetSelected(SelectionEvent e) {
        getFormat();
      }
    });
   
    Link lnk2 = new Link(linkPnl, SWT.NONE);
    lnk2.setText("<a>" + Messages.SingleBandEditorPage_OneClickExportLink + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$
    lnk2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
    lnk2.setToolTipText(Messages.SingleBandEditorPage_OneClickTooltip);
    lnk2.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        oneClickExport();
      }
    });
   
   
    cmbThemingStyle.getCombo().addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        IColorMapTypePanel panel = getCurrentSelection();
        if (panel != null){
          ((StackLayout)tableComp.getLayout()).topControl = stacks.get(panel);
          tableComp.layout();
          btnTest.setText(panel.getComputeValuesLabel());
          btnTest.getParent().layout();
         

          Object x = ((IStructuredSelection)cmbPalette.getSelection()).getFirstElement();;
          if (x instanceof BrewerPalette){
            BrewerPalette palette = (BrewerPalette) x;
            getCurrentSelection().setInitialColorPalette(palette);
          }else if (x instanceof PredefinedColorRule){
            ColorMap cm = ((PredefinedColorRule)x).getColorMap();
            if (cm != null && getCurrentSelection() != null){
              getCurrentSelection().init(cm);
            }
           
          }
        }
      }
    });
   
   
    cmbPalette.addSelectionChangedListener(new ISelectionChangedListener() {     
      @Override
      public void selectionChanged(SelectionChangedEvent event) {
        Object x = ((IStructuredSelection)cmbPalette.getSelection()).getFirstElement();;
        if (x instanceof BrewerPalette){
          BrewerPalette palette = (BrewerPalette) x;
          if (getCurrentSelection() != null){
            getCurrentSelection().setColorPalette(palette, reverseColors);
          }
        }else if (x instanceof PredefinedColorRule){
          ColorMap cm = ((PredefinedColorRule)x).getColorMap();
View Full Code Here

        styleBlackboard.put(SLDContent.ID, newStyle);
        styleBlackboard.setSelected(new String[]{SLDContent.ID});
       
        Object x = ((IStructuredSelection)cmbPalette.getSelection()).getFirstElement();
        if (x instanceof BrewerPalette){
          BrewerPalette palette = (BrewerPalette) x;
          if (palette != null){
            styleBlackboard.put("org.locationtech.udig.style.raster.palette", palette.getName()); //$NON-NLS-1$
          }
        }else if (x instanceof PredefinedColorRule){
          styleBlackboard.put("org.locationtech.udig.style.raster.palette", ((PredefinedColorRule) x).getName()); //$NON-NLS-1$
        }
 
View Full Code Here

   
    /* reselect based on blackboard setting */
    String paletteName = (String) l.getStyleBlackboard().get("org.locationtech.udig.style.raster.palette"); //$NON-NLS-1$
    if (paletteName != null){
      ColorBrewer cb = getBrewer();
      BrewerPalette palette = cb.getPalette(paletteName);
      if (palette != null){
        cmbPalette.setSelection(new StructuredSelection(cb.getPalette(paletteName)));
      }else{
        PredefinedColorRule cm = colorRules.getPredefinedRule(paletteName);
        if (cm != null){
View Full Code Here

TOP

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

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.