colorRulesEditor = new ColorEditor(parent, SWT.NONE);
String[] mapsetPathAndMapName = JGrassCatalogUtilities
.getMapsetpathAndMapnameFromJGrassMapGeoResource(resource);
GrassColorTable ctable = null;
Enumeration<ColorRule> rules = null;
try {
while( rules == null || !rules.hasMoreElements() ) {
try {
ctable = new GrassColorTable(mapsetPathAndMapName[0],
mapsetPathAndMapName[1], null);
} catch (IOException e1) {
JGrassrasterStyleActivator.log("JGrassrasterStyleActivator problem", e1); //$NON-NLS-1$
e1.printStackTrace();
}
rules = ctable.getColorRules();
// create a default color file
if (rules == null || !rules.hasMoreElements()) {
ctable.createDefaultColorRulesString(null, true);
}
}
} catch (Exception e) {
JGrassrasterStyleActivator
.log(
"JGrassrasterStyleActivator problem: eu.hydrologis.jgrass.style.jgrassraster.colors#JGrassRasterStyleEditorPage#createPageContent", e); //$NON-NLS-1$
e.printStackTrace();
}
ArrayList<Rule> listOfRules = new ArrayList<Rule>();
while( rules.hasMoreElements() ) {
ColorRule element = (ColorRule) rules.nextElement();
float lowvalue = element.getLowCategoryValue();
float highvalue = element.getLowCategoryValue() + element.getCategoryRange();
byte[] lowcatcol = element.getColor(lowvalue);
byte[] highcatcol = element.getColor(highvalue);
float[] lowHigh = new float[]{lowvalue, highvalue};
Color lowColor = new Color(Display.getDefault(), (int) (lowcatcol[0] & 0xff),
(int) (lowcatcol[1] & 0xff), (int) (lowcatcol[2] & 0xff));
Color highColor = new Color(Display.getDefault(), (int) (highcatcol[0] & 0xff),
(int) (highcatcol[1] & 0xff), (int) (highcatcol[2] & 0xff));
listOfRules.add(new Rule(lowHigh, lowColor, highColor, true));
}
colorRulesEditor.setLayer(layer);
colorRulesEditor.setAlphaValue(ctable.getAlpha());
colorRulesEditor.setRulesList(listOfRules);
} else {
Label problemLabel = new Label(parent, SWT.NONE);
problemLabel.setText("No support for map styling of map type: \"" + type + "\"");