Example usage for org.eclipse.swt.widgets Button getBounds

List of usage examples for org.eclipse.swt.widgets Button getBounds

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Button getBounds.

Prototype

public Rectangle getBounds() 

Source Link

Document

Returns a rectangle describing the receiver's size and location relative to its parent (or its display if its parent is null), unless the receiver is a shell.

Usage

From source file:org.eclipse.swt.examples.graphics.LineStyleTab.java

@Override
public void createControlPanel(Composite parent) {

    Composite comp;/*from  w  w w .j  av  a2s. co  m*/

    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("LineWidth")); //$NON-NLS-1$
    lineWidthSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    lineWidthSpinner.setSelection(10);
    lineWidthSpinner.setMinimum(1);
    lineWidthSpinner.setMaximum(30);
    lineWidthSpinner.addListener(SWT.Selection, event -> example.redraw());

    ColorMenu cm = new ColorMenu();
    cm.setPatternItems(example.checkAdvancedGraphics());
    menu = cm.createMenu(parent.getParent(), gb -> {
        lineColor = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

    // create color button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    // initialize the foreground to the 5th item in the menu (blue)
    lineColor = (GraphicsBackground) menu.getItem(4).getData();

    // color button
    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(lineColor.getThumbNail());
    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

From source file:org.eclipse.swt.examples.graphics.CustomAlphaTab.java

/**
 * Creates the widgets used to control the drawing.
 *///  w w  w .  j  av a  2  s  .  c  o  m
@Override
public void createControlPanel(Composite parent) {
    super.createControlPanel(parent);

    // create drop down combo for choosing clipping
    Composite comp;

    // create spinner for line width
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));
    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Alpha")); //$NON-NLS-1$
    alphaSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    alphaSpinner.setMinimum(0);
    alphaSpinner.setMaximum(255);
    alphaSpinner.setSelection(127);
    alphaSpinner.addListener(SWT.Selection, event -> example.redraw());

    // color menu
    ColorMenu cm = new ColorMenu();
    cm.setPatternItems(example.checkAdvancedGraphics());
    menu = cm.createMenu(parent.getParent(), gb -> {
        background = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

    // initialize the background to the 5th item in the menu (blue)
    background = (GraphicsBackground) menu.getItem(4).getData();

    // color button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(background.getThumbNail());
    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

From source file:org.eclipse.swt.examples.graphics.TextAntialiasTab.java

@Override
public void createControlPanel(Composite parent) {

    Composite comp;/* w w  w  . j a va2s  . c om*/

    // create drop down combo for antialiasing
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));
    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Antialiasing")); //$NON-NLS-1$
    aliasCombo = new Combo(comp, SWT.DROP_DOWN);
    aliasCombo.add("OFF");
    aliasCombo.add("DEFAULT");
    aliasCombo.add("ON");
    aliasCombo.select(0);
    aliasCombo.addListener(SWT.Selection, event -> example.redraw());

    ColorMenu cm = new ColorMenu();
    cm.setColorItems(true);
    menu = cm.createMenu(parent.getParent(), gb -> {
        textColor = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

    // create color button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    // initialize the color to black
    textColor = (GraphicsBackground) menu.getItem(1).getData();

    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(textColor.getThumbNail());

    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

From source file:org.eclipse.swt.examples.graphics.PathTab.java

@Override
public void createControlPanel(Composite parent) {

    Composite comp;//from ww  w  .  j a  v  a2 s  .  com

    // create draw button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    drawButton = new Button(comp, SWT.TOGGLE);
    drawButton.setText(GraphicsExample.getResourceString("DrawPath")); //$NON-NLS-1$
    drawButton.addListener(SWT.Selection, event -> example.redraw());
    drawButton.setSelection(true);

    // create fill button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    fillButton = new Button(comp, SWT.TOGGLE);
    fillButton.setText(GraphicsExample.getResourceString("FillPath")); //$NON-NLS-1$
    fillButton.addListener(SWT.Selection, event -> example.redraw());

    // create close button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    closeButton = new Button(comp, SWT.TOGGLE);
    closeButton.setText(GraphicsExample.getResourceString("ClosePath")); //$NON-NLS-1$
    closeButton.addListener(SWT.Selection, event -> example.redraw());

    // create color button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    ColorMenu cm = new ColorMenu();
    cm.setPatternItems(example.checkAdvancedGraphics());
    menu = cm.createMenu(parent.getParent(), gb -> {
        fillColor = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

    // initialize the foreground to the 5th item in the menu (green)
    fillColor = (GraphicsBackground) menu.getItem(3).getData();

    // color button
    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("FillColor")); //$NON-NLS-1$
    colorButton.setImage(fillColor.getThumbNail());
    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

From source file:org.eclipse.swt.examples.graphics.PathClippingAnimTab.java

/**
 * Creates the widgets used to control the drawing.
 *///from w ww . j  a v a 2  s  .  co m
@Override
public void createControlPanel(Composite parent) {
    super.createControlPanel(parent);

    // color menu
    ColorMenu cm = new ColorMenu();
    cm.setPatternItems(example.checkAdvancedGraphics());
    menu = cm.createMenu(parent.getParent(), gb -> {
        background = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

    // initialize the background to the 5th item in the menu (blue)
    background = (GraphicsBackground) menu.getItem(4).getData();

    // color button
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(background.getThumbNail());
    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

From source file:org.eclipse.swt.examples.graphics.RegionClippingTab.java

/**
 * Creates the widgets used to control the drawing.
 */// ww w .  j ava2s.com
@Override
public void createControlPanel(Composite parent) {
    // create drop down combo for choosing clipping
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Clipping")); //$NON-NLS-1$
    clippingCb = new Combo(comp, SWT.DROP_DOWN);
    clippingCb.add(GraphicsExample.getResourceString("Region1")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Region2")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Add")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Sub")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Inter")); //$NON-NLS-1$
    clippingCb.select(0);
    clippingCb.addListener(SWT.Selection, event -> example.redraw());

    // color menu
    ColorMenu cm = new ColorMenu();
    menu1 = cm.createMenu(parent.getParent(), gb -> {
        colorGB1 = gb;
        colorButton1.setImage(gb.getThumbNail());
        example.redraw();
    });
    menu2 = cm.createMenu(parent.getParent(), gb -> {
        colorGB2 = gb;
        colorButton2.setImage(gb.getThumbNail());
        example.redraw();
    });

    // initialize the color to blue
    colorGB1 = (GraphicsBackground) menu1.getItem(4).getData();
    // initialize the color to red
    colorGB2 = (GraphicsBackground) menu2.getItem(2).getData();

    // color button 1
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    colorButton1 = new Button(comp, SWT.PUSH);
    colorButton1.setText(GraphicsExample.getResourceString("Color1")); //$NON-NLS-1$
    colorButton1.setImage(colorGB1.getThumbNail());
    colorButton1.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu1.setLocation(point.x, point.y + bounds.height);
        menu1.setVisible(true);
    });

    // color button 2
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    colorButton2 = new Button(comp, SWT.PUSH);
    colorButton2.setText(GraphicsExample.getResourceString("Color2")); //$NON-NLS-1$
    colorButton2.setImage(colorGB2.getThumbNail());
    colorButton2.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu2.setLocation(point.x, point.y + bounds.height);
        menu2.setVisible(true);
    });
}

From source file:org.eclipse.swt.examples.graphics.CustomFontTab.java

@Override
public void createControlPanel(Composite parent) {

    Composite mainComp = new Composite(parent, SWT.NONE);
    mainComp.setLayout(new RowLayout());

    // create combo for font face
    Composite comp = new Composite(mainComp, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.LEFT).setText(GraphicsExample.getResourceString("FontFace")); //$NON-NLS-1$
    fontFaceCb = new Combo(comp, SWT.DROP_DOWN);
    for (String name : fontNames) {
        fontFaceCb.add(name);/* w  ww.  j  av  a2  s  . com*/
    }
    fontFaceCb.select(0);
    fontFaceCb.addListener(SWT.Selection, event -> example.redraw());

    // create combo for font style
    comp = new Composite(mainComp, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.LEFT).setText(GraphicsExample.getResourceString("FontStyle")); //$NON-NLS-1$
    fontStyleCb = new Combo(comp, SWT.DROP_DOWN);
    for (String fontStyle : fontStyles) {
        fontStyleCb.add(fontStyle);
    }
    fontStyleCb.select(0);
    fontStyleCb.addListener(SWT.Selection, event -> example.redraw());

    // create spinner for font size (points)
    comp = new Composite(mainComp, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.LEFT).setText(GraphicsExample.getResourceString("FontSize")); //$NON-NLS-1$
    fontPointSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    fontPointSpinner.setMinimum(1);
    fontPointSpinner.setMaximum(1000);
    fontPointSpinner.setSelection(200);
    fontPointSpinner.addListener(SWT.Selection, event -> example.redraw());

    ColorMenu cm = new ColorMenu();
    cm.setColorItems(true);
    cm.setPatternItems(example.checkAdvancedGraphics());
    menu = cm.createMenu(parent.getParent(), gb -> {
        fontForeground = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

    // initialize the background to the 2nd item in the menu (black)
    fontForeground = (GraphicsBackground) menu.getItem(1).getData();

    // create color button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(fontForeground.getThumbNail());
    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

From source file:LayoutTerms.java

public LayoutTerms() {
    init();/*  www  .j  a v  a2s  .c om*/

    Composite composite;

    System.out.println("Bounds: " + shell.getBounds());
    System.out.println("Client area: " + shell.getClientArea());

    shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

    RowLayout rowLayout = new RowLayout();
    rowLayout.type = SWT.HORIZONTAL;
    rowLayout.wrap = true;

    rowLayout.marginLeft = 15;
    rowLayout.marginTop = 5;
    rowLayout.marginRight = 15;
    rowLayout.marginBottom = 10;

    rowLayout.spacing = 8;

    shell.setLayout(rowLayout);

    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button number 2");

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("3");

    shell.pack();
    shell.open();

    System.out.println("button1: " + button1.getBounds());
    System.out.println("button2: " + button2.getBounds());

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:org.eclipse.swt.examples.graphics.PathClippingTab.java

/**
 * Creates the widgets used to control the drawing.
 *///ww w.  ja va2 s  . co m
@Override
public void createControlPanel(Composite parent) {

    // create drop down combo for choosing clipping
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Clipping")); //$NON-NLS-1$
    clippingCb = new Combo(comp, SWT.DROP_DOWN);
    clippingCb.add(GraphicsExample.getResourceString("Circles")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Rectangle")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Oval")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Word")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Star")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Triangles")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Default")); //$NON-NLS-1$
    clippingCb.select(0);
    clippingCb.addListener(SWT.Selection, event -> example.redraw());

    // color menu
    ColorMenu cm = new ColorMenu();
    cm.setPatternItems(example.checkAdvancedGraphics());
    menu = cm.createMenu(parent.getParent(), gb -> {
        background = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

    // initialize the background to the 5th item in the menu (blue)
    background = (GraphicsBackground) menu.getItem(4).getData();

    // color button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(background.getThumbNail());
    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

From source file:org.eclipse.swt.examples.graphics.GradientDialog.java

/**
 * Creates the controls of the dialog.//from w  ww.  jav a 2 s .c  om
 * */
public void createDialogControls(final Shell parent) {
    final Display display = parent.getDisplay();

    // message
    Label message = new Label(parent, SWT.NONE);
    message.setText(GraphicsExample.getResourceString("GradientDlgMsg"));
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    message.setLayoutData(gridData);

    // default colors are white and black
    if (rgb1 == null || rgb2 == null) {
        rgb1 = display.getSystemColor(SWT.COLOR_WHITE).getRGB();
        rgb2 = display.getSystemColor(SWT.COLOR_BLACK).getRGB();
    }

    // canvas
    canvas = new Canvas(parent, SWT.NONE);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.widthHint = 200;
    gridData.heightHint = 100;
    canvas.setLayoutData(gridData);
    canvas.addListener(SWT.Paint, e -> {
        Image preview = null;
        Point size = canvas.getSize();
        Color color1 = new Color(display, rgb1);
        Color color2 = new Color(display, rgb2);
        preview = GraphicsExample.createImage(display, color1, color2, size.x, size.y);
        if (preview != null) {
            e.gc.drawImage(preview, 0, 0);
        }
        preview.dispose();
        color1.dispose();
        color2.dispose();
    });

    // composite used for both color buttons
    Composite colorButtonComp = new Composite(parent, SWT.NONE);

    // layout buttons
    RowLayout layout = new RowLayout();
    layout.type = SWT.VERTICAL;
    layout.pack = false;
    colorButtonComp.setLayout(layout);

    // position composite
    gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    colorButtonComp.setLayoutData(gridData);

    ColorMenu colorMenu = new ColorMenu();

    // color controls: first color
    colorButton1 = new Button(colorButtonComp, SWT.PUSH);
    colorButton1.setText(GraphicsExample.getResourceString("GradientDlgButton1"));
    Color color1 = new Color(display, rgb1);
    Image img1 = GraphicsExample.createImage(display, color1);
    color1.dispose();
    colorButton1.setImage(img1);
    resources.add(img1);
    menu1 = colorMenu.createMenu(parent.getParent(), gb -> {
        rgb1 = gb.getBgColor1().getRGB();
        colorButton1.setImage(gb.getThumbNail());
        if (canvas != null)
            canvas.redraw();
    });
    colorButton1.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu1.setLocation(point.x, point.y + bounds.height);
        menu1.setVisible(true);
    });

    // color controls: second color
    colorButton2 = new Button(colorButtonComp, SWT.PUSH);
    colorButton2.setText(GraphicsExample.getResourceString("GradientDlgButton2"));
    Color color2 = new Color(display, rgb2);
    Image img2 = GraphicsExample.createImage(display, color2);
    color2.dispose();
    colorButton2.setImage(img2);
    resources.add(img2);
    menu2 = colorMenu.createMenu(parent.getParent(), gb -> {
        rgb2 = gb.getBgColor1().getRGB();
        colorButton2.setImage(gb.getThumbNail());
        if (canvas != null)
            canvas.redraw();
    });
    colorButton2.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu2.setLocation(point.x, point.y + bounds.height);
        menu2.setVisible(true);
    });

    // composite used for ok and cancel buttons
    Composite okCancelComp = new Composite(parent, SWT.NONE);

    // layout buttons
    RowLayout rowLayout = new RowLayout();
    rowLayout.pack = false;
    rowLayout.marginTop = 5;
    okCancelComp.setLayout(rowLayout);

    // position composite
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
    gridData.horizontalSpan = 2;
    okCancelComp.setLayoutData(gridData);

    // OK button
    okButton = new Button(okCancelComp, SWT.PUSH);
    okButton.setText("&OK");
    okButton.addListener(SWT.Selection, event -> {
        returnVal = SWT.OK;
        parent.close();
    });

    // cancel button
    cancelButton = new Button(okCancelComp, SWT.PUSH);
    cancelButton.setText("&Cancel");
    cancelButton.addListener(SWT.Selection, event -> parent.close());
}