Search in sources :

Example 26 with Region

use of org.eclipse.swt.graphics.Region in project tdi-studio-se by Talend.

the class Marker method disposeHovers.

/**
     * Disposes the hovers.
     */
private void disposeHovers() {
    for (Shell hover : hovers.values()) {
        Region region = hover.getRegion();
        if (region != null) {
            region.dispose();
        }
        hover.dispose();
    }
    hovers.clear();
    texts.clear();
    if (lineHover != null && !lineHover.isDisposed()) {
        lineHover.setVisible(false);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Region(org.eclipse.swt.graphics.Region)

Example 27 with Region

use of org.eclipse.swt.graphics.Region in project tdi-studio-se by Talend.

the class Marker method configureHover.

/**
     * Configures the hover.
     * 
     * @param hover The hover
     * @param text The hover text
     * @param x The x coordinate in pixels
     * @param y The y coordinate in pixels
     * @param showBelow <tt>true</tt> to show hover below data point
     */
private void configureHover(Shell hover, String text, final int x, int y, boolean showBelow) {
    // set size
    Point textExtent = getExtent(hover, text);
    Point hoverSize = new Point(textExtent.x + MARGIN * 2 + OFFSET * 2, textExtent.y + OFFSET * 2);
    hover.setSize(hoverSize);
    // set location
    //        boolean showOnRight = Display.getDefault().map(chart.getPlotArea(), null, x + hoverSize.x, y).x < (Display.getDefault()
    //                .getBounds().width - x);
    boolean showOnRight = chart.getPlotArea().getSize().x - hoverSize.x > x;
    int hoverX = showOnRight ? x : x - hoverSize.x;
    int hoverY = showBelow ? y : y - hoverSize.y;
    hover.setLocation(chart.getPlotArea().toDisplay(hoverX, hoverY));
    // set region
    Region region = hover.getRegion();
    if (region != null) {
        region.dispose();
    }
    region = getHoverRegion(textExtent, showOnRight, showBelow);
    hover.setRegion(region);
    hover.redraw();
    hover.setVisible(true);
}
Also used : Region(org.eclipse.swt.graphics.Region) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 28 with Region

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

the class KNIMECTabFolderRenderer method drawTabBody.

void drawTabBody(final GC gc, final Rectangle bounds, final int state) {
    int[] points = new int[1024];
    int index = 0;
    int radius = cornerSize / 2;
    int marginWidth = parent.marginWidth;
    int marginHeight = parent.marginHeight;
    int delta = INNER_KEYLINE + OUTER_KEYLINE + 2 * (shadowEnabled ? SIDE_DROP_WIDTH : 0) + 2 * marginWidth;
    int width = bounds.width - delta;
    int height = Math.max(parent.getTabHeight() + INNER_KEYLINE + OUTER_KEYLINE + (shadowEnabled ? BOTTOM_DROP_WIDTH : 0), bounds.height - INNER_KEYLINE - OUTER_KEYLINE - 2 * marginHeight - (shadowEnabled ? BOTTOM_DROP_WIDTH : 0));
    int circX = bounds.x + delta / 2 + radius;
    int circY = bounds.y + radius;
    // Body
    index = 0;
    int[] ltt = drawCircle(circX, circY, radius, LEFT_TOP);
    System.arraycopy(ltt, 0, points, index, ltt.length);
    index += ltt.length;
    int[] lbb = drawCircle(circX, circY + height - (radius * 2), radius, LEFT_BOTTOM);
    System.arraycopy(lbb, 0, points, index, lbb.length);
    index += lbb.length;
    int[] rb = drawCircle(circX + width - (radius * 2), circY + height - (radius * 2), radius, RIGHT_BOTTOM);
    System.arraycopy(rb, 0, points, index, rb.length);
    index += rb.length;
    int[] rt = drawCircle(circX + width - (radius * 2), circY, radius, RIGHT_TOP);
    System.arraycopy(rt, 0, points, index, rt.length);
    index += rt.length;
    points[index++] = circX;
    points[index++] = circY - radius;
    int[] tempPoints = new int[index];
    System.arraycopy(points, 0, tempPoints, 0, index);
    gc.fillPolygon(tempPoints);
    // Fill in parent background for non-rectangular shape
    Region r = new Region();
    r.add(bounds);
    r.subtract(tempPoints);
    gc.setBackground(parent.getParent().getBackground());
    Display display = parent.getDisplay();
    Region clipping = new Region();
    gc.getClipping(clipping);
    r.intersect(clipping);
    gc.setClipping(r);
    Rectangle mappedBounds = display.map(parent, parent.getParent(), bounds);
    parent.getParent().drawBackground(gc, bounds.x, bounds.y, bounds.width, bounds.height, mappedBounds.x, mappedBounds.y);
    // Shadow
    if (shadowEnabled) {
        drawShadow(display, bounds, gc);
    }
    gc.setClipping(clipping);
    clipping.dispose();
    r.dispose();
    // Remember for use in header drawing
    shape = tempPoints;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Point(org.eclipse.swt.graphics.Point) Display(org.eclipse.swt.widgets.Display)

Example 29 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_equalsLjava_lang_Object.

@Test
public void test_equalsLjava_lang_Object() {
    Rectangle rect1 = new Rectangle(25, 100, 200, 780);
    Rectangle rect2 = new Rectangle(30, 105, 205, 785);
    Region reg1 = new Region(display);
    reg1.add(rect1);
    Region reg2 = reg1;
    if (!reg1.equals(reg2)) {
        reg1.dispose();
        reg2.dispose();
        fail("references to the same instance of Region should be considered equal");
    }
    reg2 = new Region(display);
    reg2.add(rect1);
    // Currently, Regions are only "equal" if they have the same handle.
    // This is so that identical objects are properly hashed.
    // We are considering adding a new method that will compare Regions for the same area.
    // if (!reg1.equals(reg2)) {
    // reg1.dispose();
    // reg2.dispose();
    // fail("two instances of Region representing the same area should be considered equal");
    // }
    reg2.dispose();
    reg2 = new Region(display);
    if (reg1.equals(reg2)) {
        reg1.dispose();
        reg2.dispose();
        fail("Non empty region considered equal to empty one");
    }
    reg2.add(rect2);
    if (reg1.equals(reg2)) {
        reg1.dispose();
        reg2.dispose();
        fail("two different regions considered equal");
    }
    reg1.dispose();
    reg2.dispose();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.swt.graphics.Region) Test(org.junit.Test)

Example 30 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_Rectangle.

@Test
public void test_addLorg_eclipse_swt_graphics_Rectangle() {
    Region reg = new Region(display);
    // add a rectangle
    reg.add(new Rectangle(0, 0, 100, 50));
    // add a second rectangle
    reg.add(new Rectangle(200, 200, 10, 10));
    try {
        reg.add((Rectangle) null);
        fail("no exception thrown for adding a null rectangle");
    } catch (IllegalArgumentException e) {
    }
    reg.dispose();
    try {
        reg.add(new Rectangle(20, 30, 10, 5));
        fail("no exception thrown for adding a rectangle after Region got disposed");
    } catch (SWTException e) {
    }
}
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