use of net.sourceforge.pmd.eclipse.ui.preferences.br.RuleFieldAccessor in project pmd-eclipse-plugin by pmd.
the class Util method itemAsShapeFor.
public static CellPainterBuilder itemAsShapeFor(final int width, final int height, final Shape shapeId, final int horizAlignment, final Map<Object, RGB> coloursByItem) {
return new AbstractCellPainterBuilder() {
private Color getterColorIn(TreeItem tItem, RuleFieldAccessor getter) {
Object value = valueFor(tItem, getter);
RGB color = coloursByItem.get(value);
return color == null ? null : colorManager().colourFor(color);
}
public void addPainterFor(final Tree tree, final int columnIndex, final RuleFieldAccessor getter, Map<Integer, List<Listener>> listenersByEventCode) {
final int xBoundary = 3;
Listener paintListener = new Listener() {
public void handleEvent(Event event) {
if (event.index != columnIndex) {
return;
}
Color clr = getterColorIn((TreeItem) event.item, getter);
if (clr == null) {
return;
}
Color original = event.gc.getBackground();
event.gc.setBackground(clr);
int xOffset = 0;
final int cellWidth = widthOf(columnIndex, tree);
switch(horizAlignment) {
case SWT.CENTER:
xOffset = (cellWidth / 2) - (width / 2) - xBoundary;
break;
case SWT.RIGHT:
xOffset = cellWidth - width - xBoundary;
break;
case SWT.LEFT:
xOffset = 0;
break;
default:
}
ShapePainter.drawShape(width, height, shapeId, event.gc, event.x + xOffset, event.y, null);
event.gc.setBackground(original);
}
};
Listener measureListener = new Listener() {
public void handleEvent(Event e) {
if (e.index != columnIndex) {
return;
}
e.width = width;
e.height = height;
}
};
addListener(tree, SWT.PaintItem, paintListener, listenersByEventCode);
addListener(tree, SWT.MeasureItem, measureListener, listenersByEventCode);
}
};
}
use of net.sourceforge.pmd.eclipse.ui.preferences.br.RuleFieldAccessor in project pmd-eclipse-plugin by pmd.
the class Util method backgroundBuilderFor.
public static CellPainterBuilder backgroundBuilderFor(final int systemColourIndex) {
return new CellPainterBuilder() {
public void addPainterFor(final Tree tree, final int columnIndex, final RuleFieldAccessor getter, Map<Integer, List<Listener>> paintListeners) {
final Display display = tree.getDisplay();
tree.addListener(SWT.EraseItem, new Listener() {
public void handleEvent(Event event) {
if (event.index != columnIndex) {
return;
}
event.detail &= ~SWT.HOT;
if ((event.detail & SWT.SELECTED) != 0) {
GC gc = event.gc;
Rectangle area = tree.getClientArea();
/*
* If you wish to paint the selection beyond the end of last column, you must change the
* clipping region.
*/
int columnCount = tree.getColumnCount();
if (event.index == columnCount - 1 || columnCount == 0) {
int width = area.x + area.width - event.x;
if (width > 0) {
Region region = new Region();
gc.getClipping(region);
region.add(event.x, event.y, width, event.height);
gc.setClipping(region);
region.dispose();
}
}
gc.setAdvanced(true);
if (gc.getAdvanced()) {
gc.setAlpha(127);
}
Rectangle rect = event.getBounds();
Color foreground = gc.getForeground();
Color background = gc.getBackground();
gc.setForeground(display.getSystemColor(systemColourIndex));
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
gc.fillGradientRectangle(event.x, rect.y, 500, rect.height, false);
gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
gc.drawLine(event.x, rect.y, event.x + 20, rect.y + 20);
// restore colors for subsequent drawing
gc.setForeground(foreground);
gc.setBackground(background);
event.detail &= ~SWT.SELECTED;
}
}
});
}
};
}
Aggregations