Search in sources :

Example 36 with Region

use of org.eclipse.swt.graphics.Region in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_graphics_Region method test_intersectsLorg_eclipse_swt_graphics_Rectangle.

@Test
public void test_intersectsLorg_eclipse_swt_graphics_Rectangle() {
    Rectangle rect1 = new Rectangle(10, 20, 50, 30);
    Rectangle rectInter1 = new Rectangle(59, 49, 10, 20);
    Rectangle rectNotInter1 = new Rectangle(0, 5, 10, 15);
    Rectangle rect2 = new Rectangle(30, 40, 10, 100);
    Rectangle rectInter2 = new Rectangle(39, 139, 1, 5);
    Rectangle rectNotInter12 = new Rectangle(40, 50, 5, 15);
    Region reg = new Region(display);
    reg.dispose();
    try {
        reg.intersects(rectInter1);
        fail("no exception thrown on disposed region");
    } catch (Exception e) {
    }
    reg = new Region(display);
    if (reg.intersects(rect1)) {
        reg.dispose();
        fail("intersects can't return true on empty region");
    }
    reg.add(rect1);
    if (!reg.intersects(rect1)) {
        reg.dispose();
        fail("intersects didn't return true");
    }
    if (!reg.intersects(rectInter1)) {
        reg.dispose();
        fail("intersects didn't return true ");
    }
    if (reg.intersects(rectNotInter1)) {
        reg.dispose();
        fail("intersects return true on rectangle not intersecting with region");
    }
    reg.add(rect2);
    if (!reg.intersects(rect2)) {
        reg.dispose();
        fail("intersects didn't return true");
    }
    if (!reg.intersects(rectInter2)) {
        reg.dispose();
        fail("intersects didn't return true ");
    }
    if (reg.intersects(rectNotInter12)) {
        reg.dispose();
        fail("intersects return true on rectangle not intersecting with region");
    }
    reg.dispose();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) SWTException(org.eclipse.swt.SWTException) Test(org.junit.Test)

Example 37 with Region

use of org.eclipse.swt.graphics.Region in project eclipse.platform.swt by eclipse.

the class PaintSurface method clearRubberbandSelection.

/**
 * Clears the active rubberband selection.
 * <p>
 * Erases any rubberband objects on the screen then clears the selection.
 * </p>
 */
public void clearRubberbandSelection() {
    if (!isRubberbandHidden()) {
        Region region = new Region();
        rubberband.addDamagedRegion(displayFDC, region);
        Rectangle r = region.getBounds();
        paintCanvas.redraw(r.x, r.y, r.width, r.height, true);
        region.dispose();
    }
    rubberband.clear();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region)

Example 38 with Region

use of org.eclipse.swt.graphics.Region in project netxms by netxms.

the class Sleak method refreshLabel.

void refreshLabel() {
    int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0;
    for (final Object object : objects) {
        if (object instanceof Color) {
            colors++;
        }
        if (object instanceof Cursor) {
            cursors++;
        }
        if (object instanceof Font) {
            fonts++;
        }
        if (object instanceof GC) {
            gcs++;
        }
        if (object instanceof Image) {
            images++;
        }
        if (object instanceof Region) {
        }
    }
    // $NON-NLS-1$
    String string = "";
    if (colors != 0) {
        // $NON-NLS-1$
        string += colors + " Color(s)\n";
    }
    if (cursors != 0) {
        // $NON-NLS-1$
        string += cursors + " Cursor(s)\n";
    }
    if (fonts != 0) {
        // $NON-NLS-1$
        string += fonts + " Font(s)\n";
    }
    if (gcs != 0) {
        // $NON-NLS-1$
        string += gcs + " GC(s)\n";
    }
    if (images != 0) {
        // $NON-NLS-1$
        string += images + " Image(s)\n";
    }
    // if (regions != 0) string += regions + " Region(s)\n";
    if (string.length() != 0) {
        string = string.substring(0, string.length() - 1);
    }
    label.setText(string);
}
Also used : Color(org.eclipse.swt.graphics.Color) Region(org.eclipse.swt.graphics.Region) Cursor(org.eclipse.swt.graphics.Cursor) GC(org.eclipse.swt.graphics.GC) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 39 with Region

use of org.eclipse.swt.graphics.Region in project janrufmonitor by tbrandt77.

the class BalloonWindow method prepareForOpen.

public void prepareForOpen() {
    Point contentsSize = contents.getSize();
    Point titleSize = new Point(0, 0);
    boolean showTitle = ((style & (SWT.CLOSE | SWT.TITLE)) != 0);
    if (showTitle) {
        if (titleLabel == null) {
            titleLabel = new Label(shell, SWT.NONE);
            titleLabel.setBackground(shell.getBackground());
            titleLabel.setForeground(shell.getForeground());
            FontData[] fds = shell.getFont().getFontData();
            for (int i = 0; i < fds.length; i++) {
                fds[i].setStyle(fds[i].getStyle() | SWT.BOLD);
            }
            final Font font = new Font(shell.getDisplay(), fds);
            titleLabel.addListener(SWT.Dispose, new Listener() {

                public void handleEvent(Event event) {
                    font.dispose();
                }
            });
            titleLabel.setFont(font);
            selectionControls.add(titleLabel);
        }
        String titleText = shell.getText();
        titleLabel.setText(titleText == null ? "" : titleText);
        titleLabel.pack();
        titleSize = titleLabel.getSize();
        final Image titleImage = shell.getImage();
        if (titleImageLabel == null && shell.getImage() != null) {
            titleImageLabel = new Canvas(shell, SWT.NONE);
            titleImageLabel.setBackground(shell.getBackground());
            titleImageLabel.setBounds(titleImage.getBounds());
            titleImageLabel.addListener(SWT.Paint, new Listener() {

                public void handleEvent(Event event) {
                    event.gc.drawImage(titleImage, 0, 0);
                }
            });
            Point tilSize = titleImageLabel.getSize();
            titleSize.x += tilSize.x + titleWidgetSpacing;
            if (tilSize.y > titleSize.y)
                titleSize.y = tilSize.y;
            selectionControls.add(titleImageLabel);
        }
        if (systemControlsBar == null && (style & SWT.CLOSE) != 0) {
            // Color closeFG = shell.getForeground(), closeBG = shell.getBackground();
            // Color closeFG = shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY), closeBG = shell.getBackground();
            Color closeFG = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND), closeBG = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
            final Image closeImage = createCloseImage(shell.getDisplay(), closeBG, closeFG);
            shell.addListener(SWT.Dispose, new Listener() {

                public void handleEvent(Event event) {
                    closeImage.dispose();
                }
            });
            systemControlsBar = new ToolBar(shell, SWT.FLAT);
            systemControlsBar.setBackground(closeBG);
            systemControlsBar.setForeground(closeFG);
            ToolItem closeItem = new ToolItem(systemControlsBar, SWT.PUSH);
            closeItem.setImage(closeImage);
            closeItem.addListener(SWT.Selection, new Listener() {

                public void handleEvent(Event event) {
                    shell.close();
                }
            });
            systemControlsBar.pack();
            Point closeSize = systemControlsBar.getSize();
            titleSize.x += closeSize.x + titleWidgetSpacing;
            if (closeSize.y > titleSize.y)
                titleSize.y = closeSize.y;
        }
        titleSize.y += titleSpacing;
        if (titleSize.x > contentsSize.x) {
            contentsSize.x = titleSize.x;
            contents.setSize(contentsSize.x, contentsSize.y);
        }
        contentsSize.y += titleSize.y;
    }
    Rectangle screen = shell.getDisplay().getClientArea();
    int anchor = preferredAnchor;
    if (anchor != SWT.NONE && autoAnchor && locX != Integer.MIN_VALUE) {
        if ((anchor & SWT.LEFT) != 0) {
            if (locX + contentsSize.x + marginLeft + marginRight - 16 >= screen.x + screen.width)
                anchor = anchor - SWT.LEFT + SWT.RIGHT;
        } else // RIGHT
        {
            if (locX - contentsSize.x - marginLeft - marginRight + 16 < screen.x)
                anchor = anchor - SWT.RIGHT + SWT.LEFT;
        }
        if ((anchor & SWT.TOP) != 0) {
            if (locY + contentsSize.y + 20 + marginTop + marginBottom >= screen.y + screen.height)
                anchor = anchor - SWT.TOP + SWT.BOTTOM;
        } else // BOTTOM
        {
            if (locY - contentsSize.y - 20 - marginTop - marginBottom < screen.y)
                anchor = anchor - SWT.BOTTOM + SWT.TOP;
        }
    }
    final Point shellSize = (anchor == SWT.NONE) ? new Point(contentsSize.x + marginLeft + marginRight, contentsSize.y + marginTop + marginBottom) : new Point(contentsSize.x + marginLeft + marginRight, contentsSize.y + marginTop + marginBottom + 20);
    if (shellSize.x < 54 + marginLeft + marginRight)
        shellSize.x = 54 + marginLeft + marginRight;
    if (anchor == SWT.NONE) {
        if (shellSize.y < 10 + marginTop + marginBottom)
            shellSize.y = 10 + marginTop + marginBottom;
    } else {
        if (shellSize.y < 30 + marginTop + marginBottom)
            shellSize.y = 30 + marginTop + marginBottom;
    }
    shell.setSize(shellSize);
    int titleLocY = marginTop + (((anchor & SWT.TOP) != 0) ? 20 : 0);
    contents.setLocation(marginLeft, titleSize.y + titleLocY);
    if (showTitle) {
        int realTitleHeight = titleSize.y - titleSpacing;
        if (titleImageLabel != null) {
            titleImageLabel.setLocation(marginLeft, titleLocY + (realTitleHeight - titleImageLabel.getSize().y) / 2);
            titleLabel.setLocation(marginLeft + titleImageLabel.getSize().x + titleWidgetSpacing, titleLocY + (realTitleHeight - titleLabel.getSize().y) / 2);
        } else
            titleLabel.setLocation(marginLeft, titleLocY + (realTitleHeight - titleLabel.getSize().y) / 2);
        if (systemControlsBar != null)
            systemControlsBar.setLocation(shellSize.x - marginRight - systemControlsBar.getSize().x, titleLocY + (realTitleHeight - systemControlsBar.getSize().y) / 2);
    }
    final Region region = new Region();
    region.add(createOutline(shellSize, anchor, true));
    shell.setRegion(region);
    shell.addListener(SWT.Dispose, new Listener() {

        public void handleEvent(Event event) {
            region.dispose();
        }
    });
    final int[] outline = createOutline(shellSize, anchor, false);
    shell.addListener(SWT.Paint, new Listener() {

        public void handleEvent(Event event) {
            event.gc.drawPolygon(outline);
        }
    });
    if (locX != Integer.MIN_VALUE) {
        Point shellLoc = new Point(locX, locY);
        if ((anchor & SWT.BOTTOM) != 0)
            shellLoc.y = shellLoc.y - shellSize.y + 1;
        if ((anchor & SWT.LEFT) != 0)
            shellLoc.x -= 15;
        else if ((anchor & SWT.RIGHT) != 0)
            shellLoc.x = shellLoc.x - shellSize.x + 16;
        if (autoAnchor) {
            if (shellLoc.x < screen.x)
                shellLoc.x = screen.x;
            else if (shellLoc.x > screen.x + screen.width - shellSize.x)
                shellLoc.x = screen.x + screen.width - shellSize.x;
            if (anchor == SWT.NONE) {
                if (shellLoc.y < screen.y)
                    shellLoc.y = screen.y;
                else if (shellLoc.y > screen.y + screen.height - shellSize.y)
                    shellLoc.y = screen.y + screen.height - shellSize.y;
            }
        }
        shell.setLocation(shellLoc);
    }
}
Also used : Listener(org.eclipse.swt.widgets.Listener) FontData(org.eclipse.swt.graphics.FontData) Canvas(org.eclipse.swt.widgets.Canvas) Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) ToolBar(org.eclipse.swt.widgets.ToolBar) Event(org.eclipse.swt.widgets.Event) Region(org.eclipse.swt.graphics.Region) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 40 with Region

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

the class Sleak method paintCanvas.

void paintCanvas(Event event) {
    canvas.setCursor(null);
    int index = list.getSelectionIndex();
    if (index == -1) {
        return;
    }
    GC gc = event.gc;
    Object object = objects[index];
    if (object instanceof Color) {
        if (((Color) object).isDisposed()) {
            return;
        }
        gc.setBackground((Color) object);
        gc.fillRectangle(canvas.getClientArea());
        return;
    }
    if (object instanceof Cursor) {
        if (((Cursor) object).isDisposed()) {
            return;
        }
        canvas.setCursor((Cursor) object);
        return;
    }
    if (object instanceof Font) {
        if (((Font) object).isDisposed()) {
            return;
        }
        gc.setFont((Font) object);
        FontData[] array = gc.getFont().getFontData();
        String string = "";
        String lf = text.getLineDelimiter();
        for (int i = 0; i < array.length; i++) {
            FontData data = array[i];
            String style = "NORMAL";
            int bits = data.getStyle();
            if (bits != 0) {
                if ((bits & SWT.BOLD) != 0) {
                    style = "BOLD ";
                }
                if ((bits & SWT.ITALIC) != 0) {
                    style += "ITALIC";
                }
            }
            string += data.getName() + " " + data.getHeight() + " " + style + lf;
        }
        gc.drawString(string, 0, 0);
        return;
    }
    // }
    if (object instanceof Image) {
        if (((Image) object).isDisposed()) {
            return;
        }
        gc.drawImage((Image) object, 0, 0);
        return;
    }
    if (object instanceof Path) {
        if (((Path) object).isDisposed()) {
            return;
        }
        gc.drawPath((Path) object);
        return;
    }
    if (object instanceof Pattern) {
        if (((Pattern) object).isDisposed()) {
            return;
        }
        gc.setBackgroundPattern((Pattern) object);
        gc.fillRectangle(canvas.getClientArea());
        gc.setBackgroundPattern(null);
        return;
    }
    if (object instanceof Region) {
        if (((Region) object).isDisposed()) {
            return;
        }
        String string = ((Region) object).getBounds().toString();
        gc.drawString(string, 0, 0);
        return;
    }
    if (object instanceof TextLayout) {
        if (((TextLayout) object).isDisposed()) {
            return;
        }
        ((TextLayout) object).draw(gc, 0, 0);
        return;
    }
    if (object instanceof Transform) {
        if (((Transform) object).isDisposed()) {
            return;
        }
        String string = ((Transform) object).toString();
        gc.drawString(string, 0, 0);
        return;
    }
}
Also used : Path(org.eclipse.swt.graphics.Path) Pattern(org.eclipse.swt.graphics.Pattern) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) Cursor(org.eclipse.swt.graphics.Cursor) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) TextLayout(org.eclipse.swt.graphics.TextLayout) Region(org.eclipse.swt.graphics.Region) GC(org.eclipse.swt.graphics.GC) Transform(org.eclipse.swt.graphics.Transform)

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