Package org.geotools.brewer.color

Examples of org.geotools.brewer.color.BrewerPalette


//        gridData.widthHint = 175;

        paletteTable.setLabelProvider(new LabelProvider() {
            public Image getImage(Object element) {
                if (element instanceof BrewerPalette) {
                    BrewerPalette palette = (BrewerPalette) element;
                    return Glyph.palette(palette.getColors(palette.getMaxColors())).createImage();
                }
                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;
            }
        });

        paletteTable.setContentProvider(new IStructuredContentProvider() {
           
            public Object[] getElements(Object inputElement) {
                if (inputElement instanceof ColorBrewer) {
                    ColorBrewer brewer = (ColorBrewer) inputElement;
                    return brewer.getPalettes();
                } else {
                    return new Object[0];
                }
            }

            public void dispose() {
            }

            public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            }
        });

        paletteTable.setSorter(new ViewerSorter() {

            @Override
            public int compare( Viewer viewer, Object e1, Object e2 ) {
                if (e1 instanceof BrewerPalette && e2 instanceof BrewerPalette) {
                    BrewerPalette p1 = (BrewerPalette) e1;
                    BrewerPalette p2 = (BrewerPalette) e2;
                    //alphabetical by name
                    return p1.getName().compareTo(p2.getName());
                } else return super.compare(viewer, e1, e2);
            }
           
        });
       
View Full Code Here


    private void select(String paletteName) {
        ColorBrewer brewer = PlatformGIS.getColorBrewer();
        if (paletteName == null || !brewer.hasPalette(paletteName))
            return;
        BrewerPalette palette = brewer.getPalette(paletteName);
        palettes.setSelection(new StructuredSelection(palette));
    }
View Full Code Here

        ISelection select = palettes.getSelection();
        if (select == null) {
            getPreferenceStore().setToDefault(getPreferenceName());
            return;
        }
        BrewerPalette palette = (BrewerPalette) ((StructuredSelection) select).getFirstElement();
        getPreferenceStore().setValue(getPreferenceName(), palette.getName());
    }
View Full Code Here

                 * When a new palette is selected: get the palette String and then we want to
                 * repaint all paletteCombos to have new colours
                 */
                int index = paletteSelectionCombo.getSelectionIndex();
                String name = paletteSelectionCombo.getItem(index);
                BrewerPalette palette = PlatformGIS.getColorBrewer().getPalette(name);
                //ColourScheme scheme = map.getColourScheme();
                //scheme.setColourPalette(palette);
                //map.setColorPalette(palette);
                //map.setColourScheme(scheme);
                mapScheme = new ColourScheme(palette,  Integer.parseInt(quantityCombo.getItem(quantityCombo.getSelectionIndex())) );
View Full Code Here

                break;
            }
        }
       
        String name = paletteSelectionCombo.getItem(paletteSelectionCombo.getSelectionIndex());
        BrewerPalette palette = PlatformGIS.getColorBrewer().getPalette(name);
        mapScheme = new ColourScheme(palette,  Integer.parseInt(quantityCombo.getItem(quantityCombo.getSelectionIndex())) );
        updateLayerDisplay();
    }
View Full Code Here

    /**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * @generated
     */
    public void setColorPalette(BrewerPalette newColorPalette) {
        BrewerPalette oldColorPalette = colorPalette;
        colorPalette = newColorPalette;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET,
                    ProjectPackage.MAP__COLOR_PALETTE, oldColorPalette, colorPalette));
    }
View Full Code Here

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

  }

  @Override
  public boolean select( Viewer viewer, Object parentElement, Object element ) {
      if (element instanceof BrewerPalette) {
          BrewerPalette pal = (BrewerPalette) element;
          int numClasses = new Integer(this.styleThemePage.getCombo(StyleThemePage.COMBO_CLASSES).getText()).intValue();
          int maxColors = pal.getMaxColors();
            if (maxColors!=-1 && maxColors < numClasses) {
              return false;
          }
          if (this.styleThemePage.getButton(StyleThemePage.BUTTON_COLORBLIND).getSelection()) {
              if (pal.getPaletteSuitability().getSuitability(numClasses, PaletteSuitability.VIEWER_COLORBLIND) != PaletteSuitability.QUALITY_GOOD)
                  return false;
          }
          if (this.styleThemePage.getButton(StyleThemePage.BUTTON_CRT).getSelection()) {
              if (pal.getPaletteSuitability().getSuitability(numClasses, PaletteSuitability.VIEWER_CRT) != PaletteSuitability.QUALITY_GOOD)
                  return false;
          }
          if (this.styleThemePage.getButton(StyleThemePage.BUTTON_LCD).getSelection()) {
              if (pal.getPaletteSuitability().getSuitability(numClasses, PaletteSuitability.VIEWER_LCD) != PaletteSuitability.QUALITY_GOOD)
                  return false;
          }
          if (this.styleThemePage.getButton(StyleThemePage.BUTTON_PHOTOCOPY).getSelection()) {
              if (pal.getPaletteSuitability().getSuitability(numClasses, PaletteSuitability.VIEWER_PHOTOCOPY) != PaletteSuitability.QUALITY_GOOD)
                  return false;
          }
          if (this.styleThemePage.getButton(StyleThemePage.BUTTON_PRINT).getSelection()) {
              if (pal.getPaletteSuitability().getSuitability(numClasses, PaletteSuitability.VIEWER_PRINT) != PaletteSuitability.QUALITY_GOOD)
                  return false;
          }
          if (this.styleThemePage.getButton(StyleThemePage.BUTTON_PROJECTOR).getSelection()) {
              if (pal.getPaletteSuitability().getSuitability(numClasses, PaletteSuitability.VIEWER_PROJECTOR) != PaletteSuitability.QUALITY_GOOD)
                  return false;
          }
      }
      return true;
  }
View Full Code Here

final class BrewerPaletteViewerSorter extends ViewerSorter {
  @Override
  public int compare( Viewer viewer, Object e1, Object e2 ) {
      if (e1 instanceof BrewerPalette && e2 instanceof BrewerPalette) {
          BrewerPalette p1 = (BrewerPalette) e1;
          BrewerPalette p2 = (BrewerPalette) e2;
          //alphabetical by name
          return p1.getName().compareTo(p2.getName());
          //TODO: alternatives (colour hue?)
      } else return super.compare(viewer, e1, e2);
  }
View Full Code Here

import org.geotools.brewer.color.BrewerPalette;

public class BrewerPaletteLabelProvider extends LabelProvider {
  public Image getImage(Object element) {
    if (element instanceof BrewerPalette) {
      BrewerPalette palette = (BrewerPalette) element;
      int maxColors = palette.getMaxColors();
            Color[] colors;
            try{
                colors = palette.getColors(maxColors);
            }catch (Exception e) {
                colors = palette.getColors();
                palette = new CustomDynamicPalette(palette.getName(), palette.getDescription(), colors);
                colors = palette.getColors(maxColors);
            }
            return Glyph.palette(colors).createImage();
    }
    return 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.