Search in sources :

Example 41 with Region

use of org.eclipse.swt.graphics.Region in project xtext-eclipse by eclipse.

the class RenameRefactoringPopup method packPopup.

protected void packPopup() {
    popupLayout.marginTop = HAH;
    popupLayout.marginBottom = 0;
    popup.pack();
    Region oldRegion = region;
    region = new Region();
    region.add(getPolygon(false));
    popup.setRegion(region);
    Rectangle bounds = region.getBounds();
    popup.setSize(bounds.width, bounds.height + 2);
    if (oldRegion != null) {
        oldRegion.dispose();
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region)

Example 42 with Region

use of org.eclipse.swt.graphics.Region 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

Region (org.eclipse.swt.graphics.Region)42 Rectangle (org.eclipse.swt.graphics.Rectangle)29 Test (org.junit.Test)21 SWTException (org.eclipse.swt.SWTException)13 Point (org.eclipse.swt.graphics.Point)12 Color (org.eclipse.swt.graphics.Color)8 GC (org.eclipse.swt.graphics.GC)6 Font (org.eclipse.swt.graphics.Font)5 Image (org.eclipse.swt.graphics.Image)5 Cursor (org.eclipse.swt.graphics.Cursor)4 Path (org.eclipse.swt.graphics.Path)4 Display (org.eclipse.swt.widgets.Display)4 Shell (org.eclipse.swt.widgets.Shell)4 FontData (org.eclipse.swt.graphics.FontData)3 Pattern (org.eclipse.swt.graphics.Pattern)3 TextLayout (org.eclipse.swt.graphics.TextLayout)2 Transform (org.eclipse.swt.graphics.Transform)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 Tree (org.eclipse.swt.widgets.Tree)2