private static List<LegendEntry> createRampEntries(ColorMap colorMap, final Dimension imageSize){
List<LegendEntry> lentries = new ArrayList<LegendEntry>();
final ColorMapEntry[] entries = colorMap.getColorMapEntries();
boolean first = true;
for (int i = 1; i < entries.length; i += 1){
final ColorMapEntry entry = entries[i];
final ColorMapEntry prevEntry = entries[i-1];
if (isNoData(prevEntry)){
//skip no data entries in legend
continue;
}
ImageDescriptor dd = null;
int idx = -1;
if (first){
idx = 0;
}else if (i > entries.length - 2){
idx = 2;
}
final int index = idx;
first = false;
dd = new ImageDescriptor() {
@Override
public ImageData getImageData() {
Display display = PlatformUI.getWorkbench().getDisplay();
Image swtImage = new Image(display, imageSize.width,
imageSize.height);
GC gc = new GC(swtImage);
gc.setAntialias(SWT.ON);
org.eclipse.swt.graphics.Color c1 = getColor(display,
entry.getColor());
org.eclipse.swt.graphics.Color c2 = getColor(display,
prevEntry.getColor());
gc.setAlpha(getAlpha(entry.getOpacity()));
gc.setBackground(c1);
gc.setForeground(c2);
gc.fillGradientRectangle(1, 0, imageSize.width-2,
imageSize.height, true);
gc.setAlpha(150);
gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
gc.drawLine(0, 0, 0, imageSize.height);
gc.drawLine(imageSize.width-1, 0, imageSize.width-1, imageSize.height);
if (index == 0){
gc.drawLine(0, 0, imageSize.width-1, 0);
}else if (index == 2){
gc.drawLine(0, imageSize.height - 1, imageSize.width-1, imageSize.height - 1);
}
c1.dispose();
c2.dispose();
ImageData clone = (ImageData) swtImage.getImageData()
.clone();
swtImage.dispose();
return clone;
}
};
String[] text = null;
String q1 = entry.getQuantity().evaluate(null, String.class);
String q2 = prevEntry.getQuantity().evaluate(null, String.class);
String l1 = entry.getLabel();
String l2 = prevEntry.getLabel();
if (i <= entries.length - 3){
if (l2 == null){
text = new String[]{q2};
}else{
text = new String[]{l2 + " (" + q2 + ")"}; //$NON-NLS-1$ //$NON-NLS-2$