Search in sources :

Example 1 with RuleFieldAccessor

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);
        }
    };
}
Also used : Listener(org.eclipse.swt.widgets.Listener) RuleFieldAccessor(net.sourceforge.pmd.eclipse.ui.preferences.br.RuleFieldAccessor) TreeItem(org.eclipse.swt.widgets.TreeItem) Color(org.eclipse.swt.graphics.Color) Tree(org.eclipse.swt.widgets.Tree) Event(org.eclipse.swt.widgets.Event) RGB(org.eclipse.swt.graphics.RGB) Map(java.util.Map)

Example 2 with RuleFieldAccessor

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;
                    }
                }
            });
        }
    };
}
Also used : Listener(org.eclipse.swt.widgets.Listener) RuleFieldAccessor(net.sourceforge.pmd.eclipse.ui.preferences.br.RuleFieldAccessor) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Tree(org.eclipse.swt.widgets.Tree) Event(org.eclipse.swt.widgets.Event) Region(org.eclipse.swt.graphics.Region) GC(org.eclipse.swt.graphics.GC) Map(java.util.Map) CellPainterBuilder(net.sourceforge.pmd.eclipse.ui.preferences.br.CellPainterBuilder) Display(org.eclipse.swt.widgets.Display)

Aggregations

Map (java.util.Map)2 RuleFieldAccessor (net.sourceforge.pmd.eclipse.ui.preferences.br.RuleFieldAccessor)2 Color (org.eclipse.swt.graphics.Color)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 Tree (org.eclipse.swt.widgets.Tree)2 CellPainterBuilder (net.sourceforge.pmd.eclipse.ui.preferences.br.CellPainterBuilder)1 GC (org.eclipse.swt.graphics.GC)1 RGB (org.eclipse.swt.graphics.RGB)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Region (org.eclipse.swt.graphics.Region)1 Display (org.eclipse.swt.widgets.Display)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1