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