}
//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