Search in sources :

Example 11 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_containsII.

@Test
public void test_containsII() {
    Rectangle rect1 = new Rectangle(10, 10, 200, 100);
    Point pointInRect1 = new Point(10, 10);
    Rectangle rect2 = new Rectangle(50, 50, 1000, 1000);
    Point pointInRect2 = new Point(1049, 1009);
    Point pointNotInRect12 = new Point(49, 110);
    Region reg = new Region(display);
    reg.dispose();
    try {
        reg.contains(pointInRect1.x, pointInRect1.y);
        fail("no exception thrown on disposed region");
    } catch (Exception e) {
    }
    reg = new Region(display);
    if (reg.contains(pointInRect1.x, pointInRect1.y)) {
        reg.dispose();
        fail("Empty region should not contain point");
    }
    reg.add(rect1);
    if (!reg.contains(pointInRect1.x, pointInRect1.y)) {
        reg.dispose();
        fail("Region should contain point");
    }
    reg.add(rect2);
    if (!reg.contains(pointInRect1.x, pointInRect1.y) || !reg.contains(pointInRect2.x, pointInRect2.y)) {
        reg.dispose();
        fail("Region should contain point");
    }
    if (reg.contains(pointNotInRect12.x, pointNotInRect12.y)) {
        reg.dispose();
        fail("Region should not contain point");
    }
    reg.dispose();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Point(org.eclipse.swt.graphics.Point) SWTException(org.eclipse.swt.SWTException) Test(org.junit.Test)

Example 12 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_containsLorg_eclipse_swt_graphics_Point.

@Test
public void test_containsLorg_eclipse_swt_graphics_Point() {
    Rectangle rect1 = new Rectangle(10, 10, 200, 100);
    Point pointInRect1 = new Point(10, 10);
    Rectangle rect2 = new Rectangle(50, 50, 1000, 1000);
    Point pointInRect2 = new Point(1049, 1009);
    Point pointNotInRect12 = new Point(49, 110);
    Region reg = new Region(display);
    reg.dispose();
    try {
        reg.contains(pointInRect1);
        fail("no exception thrown on disposed region");
    } catch (Exception e) {
    }
    reg = new Region(display);
    if (reg.contains(pointInRect1)) {
        reg.dispose();
        fail("Empty region should not contain point");
    }
    reg.add(rect1);
    if (!reg.contains(pointInRect1)) {
        reg.dispose();
        fail("Region should contain point");
    }
    reg.add(rect2);
    if (!reg.contains(pointInRect1) || !reg.contains(pointInRect2)) {
        reg.dispose();
        fail("Region should contain point");
    }
    if (reg.contains(pointNotInRect12)) {
        reg.dispose();
        fail("Region should not contain point");
    }
    reg.dispose();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Point(org.eclipse.swt.graphics.Point) SWTException(org.eclipse.swt.SWTException) Test(org.junit.Test)

Example 13 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_getBounds.

@Test
public void test_getBounds() {
    Region reg = new Region(display);
    reg.dispose();
    try {
        reg.getBounds();
        fail("Region disposed should throw Exception");
    } catch (Exception e) {
    }
    Rectangle rect1 = new Rectangle(10, 10, 50, 30);
    Rectangle rect2 = new Rectangle(100, 100, 10, 10);
    // the rectangle enclosing the two preceding rectangles
    Rectangle rect12Bounds = new Rectangle(10, 10, 100, 100);
    reg = new Region(display);
    reg.add(rect1);
    Rectangle rect1Bis = reg.getBounds();
    if (rect1Bis.x != rect1.x || rect1Bis.y != rect1.y || rect1Bis.height != rect1.height || rect1Bis.width != rect1.width) {
        reg.dispose();
        fail("getBounds doesn't return the borders of the rectangle area which was set up");
    }
    reg.add(rect2);
    Rectangle rect12 = reg.getBounds();
    if (rect12.x != rect12Bounds.x || rect12.y != rect12Bounds.y || rect12.height != rect12Bounds.height || rect12.width != rect12Bounds.width) {
        reg.dispose();
        fail("getBounds doesn't return the borders of the resulting rectangle area which was set up");
    }
    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 14 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_intersectLorg_eclipse_swt_graphics_Rectangle.

@Test
public void test_intersectLorg_eclipse_swt_graphics_Rectangle() {
    Rectangle rect1 = new Rectangle(0, 0, 48, 24);
    Rectangle rect2 = new Rectangle(0, 0, 48, 24);
    Rectangle rect3 = new Rectangle(10, 10, 10, 10);
    Rectangle rect4 = new Rectangle(48, 24, 10, 10);
    Rectangle rect5 = new Rectangle(24, 20, 24, 10);
    Region reg = new Region(display);
    reg.dispose();
    try {
        reg.intersect(rect1);
        fail("no exception thrown on disposed region");
    } catch (SWTException e) {
    }
    reg = new Region(display);
    reg.intersect(rect1);
    if (!reg.isEmpty()) {
        reg.dispose();
        fail("intersect failed for empty region");
    }
    reg.add(rect1);
    reg.intersect(rect2);
    Rectangle box = reg.getBounds();
    if (!box.equals(rect1)) {
        reg.dispose();
        fail("intersect failed 1");
    }
    reg.intersect(rect3);
    box = reg.getBounds();
    if (!box.equals(rect3)) {
        reg.dispose();
        fail("intersect failed 2");
    }
    reg.intersect(rect4);
    if (!reg.isEmpty()) {
        reg.dispose();
        fail("intersect failed 3");
    }
    reg.add(rect1.union(rect4));
    reg.intersect(rect5);
    box = reg.getBounds();
    if (!box.equals(rect5)) {
        reg.dispose();
        fail("intersect failed 4");
    }
    reg.dispose();
    reg = new Region(display);
    reg.add(rect1);
    reg.add(rect4);
    reg.intersect(rect5);
    box = reg.getBounds();
    if (!box.equals(new Rectangle(24, 20, 24, 4))) {
        reg.dispose();
        fail("intersect failed 5");
    }
    reg.dispose();
}
Also used : SWTException(org.eclipse.swt.SWTException) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Example 15 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_subtractLorg_eclipse_swt_graphics_Region.

@Test
public void test_subtractLorg_eclipse_swt_graphics_Region() {
    Region reg1 = new Region(display);
    reg1.add(new Rectangle(0, 0, 50, 25));
    Region reg = new Region(display);
    reg.dispose();
    try {
        reg.subtract(reg1);
        reg1.dispose();
        fail("no exception thrown on disposed region");
    } catch (SWTException e) {
    }
    reg = new Region(display);
    reg.subtract(reg1);
    if (!reg.isEmpty()) {
        reg.dispose();
        reg1.dispose();
        fail("subtract failed for empty region");
    }
    Region reg2 = new Region(display);
    reg2.add(new Rectangle(0, 0, 50, 25));
    reg.add(reg1);
    reg.subtract(reg2);
    if (!reg.isEmpty()) {
        reg.dispose();
        reg1.dispose();
        reg2.dispose();
        fail("subtract failed 1");
    }
    reg2.dispose();
    Region reg3 = new Region(display);
    reg3.add(new Rectangle(10, 10, 10, 10));
    reg.add(reg1);
    reg.subtract(reg3);
    Rectangle box = reg.getBounds();
    if (!box.equals(reg1.getBounds())) {
        reg.dispose();
        reg1.dispose();
        reg3.dispose();
        fail("subtract failed 2");
    }
    reg3.dispose();
    Region reg4 = new Region(display);
    reg4.add(new Rectangle(50, 25, 10, 10));
    reg.subtract(reg4);
    box = reg.getBounds();
    if (!box.equals(reg1.getBounds())) {
        reg.dispose();
        reg1.dispose();
        reg4.dispose();
        fail("subtract failed 3");
    }
    Region reg5 = new Region(display);
    reg5.add(new Rectangle(0, 0, 60, 20));
    reg.add(reg1.getBounds().union(reg4.getBounds()));
    reg.subtract(reg5);
    box = reg.getBounds();
    if (!box.equals(new Rectangle(0, 20, 60, 15))) {
        reg.dispose();
        reg1.dispose();
        reg4.dispose();
        reg5.dispose();
        fail("subtract failed 4");
    }
    reg.dispose();
    reg = new Region(display);
    reg.add(reg1);
    reg.add(reg4);
    reg.subtract(reg5);
    box = reg.getBounds();
    if (!box.equals(new Rectangle(0, 20, 60, 15))) {
        reg.dispose();
        reg1.dispose();
        reg4.dispose();
        reg5.dispose();
        fail("subtract failed 5");
    }
    reg.dispose();
    reg1.dispose();
    reg4.dispose();
    reg5.dispose();
}
Also used : SWTException(org.eclipse.swt.SWTException) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

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