Search in sources :

Example 31 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_toString.

@Test
public void test_toString() {
    Region reg = new Region(display);
    String s = reg.toString();
    if (s == null || s.length() == 0) {
        fail("toString returns null or empty string");
    }
    reg.add(new Rectangle(1, 1, 10, 20));
    s = reg.toString();
    if (s == null || s.length() == 0) {
        fail("toString returns null or empty string");
    }
    reg.dispose();
    s = reg.toString();
    if (s == null || s.length() == 0) {
        fail("toString returns null or empty string");
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Example 32 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_ConstructorLorg_eclipse_swt_graphics_Device.

@Test
public void test_ConstructorLorg_eclipse_swt_graphics_Device() {
    Region reg = new Region(display);
    if (reg.isDisposed()) {
        fail("Constructor for Region didn't initialize");
    }
    reg.dispose();
}
Also used : Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Example 33 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_addLorg_eclipse_swt_graphics_Region.

@Test
public void test_addLorg_eclipse_swt_graphics_Region() {
    Region reg1 = new Region(display);
    // make a second region and add it to the first one
    Region reg2 = new Region(display);
    reg2.add(new Rectangle(40, 50, 10, 20));
    reg1.add(reg2);
    reg2.dispose();
    try {
        reg1.add((Region) null);
        fail("no exception thrown for adding a null region");
    } catch (IllegalArgumentException e) {
    }
    try {
        reg2 = new Region(display);
        reg2.add(new Rectangle(1, 1, 100, 200));
        reg2.dispose();
        reg1.add(reg2);
        fail("no exception thrown for adding to a Region a Region which got disposed");
    } catch (IllegalArgumentException e) {
    }
    reg1.dispose();
    try {
        reg2 = new Region(display);
        reg2.add(new Rectangle(1, 1, 100, 200));
        reg1.add(reg2);
        fail("no exception thrown for adding a Region to a Region which got disposed");
    } catch (SWTException e) {
    } finally {
        if (reg2 != null)
            reg2.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 34 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_dispose.

@Test
public void test_dispose() {
    Region reg = new Region(display);
    reg.add(new Rectangle(1, 1, 50, 100));
    if (reg.isDisposed()) {
        fail("Region should not be in the disposed state");
    }
    // dispose twice as this is allowed
    for (int i = 0; i < 2; i++) {
        reg.dispose();
        if (!reg.isDisposed()) {
            fail("Region should be in the disposed state");
        }
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Point(org.eclipse.swt.graphics.Point) Test(org.junit.Test)

Example 35 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_intersectsIIII.

@Test
public void test_intersectsIIII() {
    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.x, rectInter1.y, rectInter1.width, rectInter1.height);
        fail("no exception thrown on disposed region");
    } catch (Exception e) {
    }
    reg = new Region(display);
    if (reg.intersects(rect1.x, rect1.y, rect1.width, rect1.height)) {
        reg.dispose();
        fail("intersects can't return true on empty region");
    }
    reg.add(rect1);
    if (!reg.intersects(rect1.x, rect1.y, rect1.width, rect1.height)) {
        reg.dispose();
        fail("intersects didn't return true");
    }
    if (!reg.intersects(rectInter1.x, rectInter1.y, rectInter1.width, rectInter1.height)) {
        reg.dispose();
        fail("intersects didn't return true ");
    }
    if (reg.intersects(rectNotInter1.x, rectNotInter1.y, rectNotInter1.width, rectNotInter1.height)) {
        reg.dispose();
        fail("intersects return true on rectangle not intersecting with region");
    }
    reg.add(rect2);
    if (!reg.intersects(rect2.x, rect2.y, rect2.width, rect2.height)) {
        reg.dispose();
        fail("intersects didn't return true");
    }
    if (!reg.intersects(rectInter2.x, rectInter2.y, rectInter2.width, rectInter2.height)) {
        reg.dispose();
        fail("intersects didn't return true ");
    }
    if (reg.intersects(rectNotInter12.x, rectNotInter12.y, rectNotInter12.width, rectNotInter12.height)) {
        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)

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