Example usage for org.eclipse.swt.widgets Composite Composite

List of usage examples for org.eclipse.swt.widgets Composite Composite

Introduction

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

Prototype

public Composite(Composite parent, int style) 

Source Link

Document

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Usage

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

/**
 * This method creates a spinner for specifying the number of petals. The call to the
 * createControlPanel method in the super class create the controls that are
 * defined in the super class.// w  ww.  j  av a2 s  .  c o  m
 *
 * @param parent The parent composite
 */
@Override
public void createControlPanel(Composite parent) {
    super.createControlPanel(parent);

    // create spinner number of petals
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Petals")); //$NON-NLS-1$
    petalSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    petalSpinner.setSelection(8);
    petalSpinner.setMinimum(3);
    petalSpinner.setMaximum(20);
    petalSpinner.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 -> {
        foreground = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

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

    // color button
    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(foreground.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 www . j  av a2  s .  c  o m

    // 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:SWTBrowser.java

public SWTBrowser() {
    shell.setLayout(new GridLayout());

    ToolBar toolBar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT);
    final ToolBarManager manager = new ToolBarManager(toolBar);

    Composite compositeLocation = new Composite(shell, SWT.NULL);
    compositeLocation.setLayout(new GridLayout(3, false));
    compositeLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Label labelAddress = new Label(compositeLocation, SWT.NULL);
    labelAddress.setText("Address");

    textLocation = new Text(compositeLocation, SWT.SINGLE | SWT.BORDER);
    textLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Button buttonGo = new Button(compositeLocation, SWT.NULL);
    buttonGo.setImage(new Image(shell.getDisplay(), "java2s.gif"));

    browser = new Browser(shell, SWT.BORDER);
    browser.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite compositeStatus = new Composite(shell, SWT.NULL);
    compositeStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    compositeStatus.setLayout(new GridLayout(2, false));

    labelStatus = new Label(compositeStatus, SWT.NULL);
    labelStatus.setText("Ready");
    labelStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final ProgressBar progressBar = new ProgressBar(compositeStatus, SWT.SMOOTH);

    Listener openURLListener = new Listener() {
        public void handleEvent(Event event) {
            browser.setUrl(textLocation.getText());
        }/*from   w w w.  j a  va2s.c o m*/
    };

    buttonGo.addListener(SWT.Selection, openURLListener);
    textLocation.addListener(SWT.DefaultSelection, openURLListener);

    // Adds tool bar items using actions.
    final Action actionBackward = new Action("&Backword", ImageDescriptor.createFromFile(null, "java2s.gif")) {
        public void run() {
            browser.back();
        }
    };
    actionBackward.setEnabled(false); // action is disabled at start up.

    final Action actionForward = new Action("&Forward",
            ImageDescriptor.createFromFile(null, "icons/web/forward.gif")) {
        public void run() {
            browser.forward();
        }
    };
    actionForward.setEnabled(false); // action is disabled at start up.

    Action actionStop = new Action("&Stop", ImageDescriptor.createFromFile(null, "icons/web/stop.gif")) {
        public void run() {
            browser.stop();
        }
    };

    Action actionRefresh = new Action("&Refresh",
            ImageDescriptor.createFromFile(null, "icons/web/refresh.gif")) {
        public void run() {
            browser.refresh();
        }
    };

    Action actionHome = new Action("&Home", ImageDescriptor.createFromFile(null, "icons/web/home.gif")) {
        public void run() {
            browser.setUrl("http://www.eclipse.org");
        }
    };

    manager.add(actionBackward);
    manager.add(actionForward);
    manager.add(actionStop);
    manager.add(actionRefresh);
    manager.add(actionHome);

    manager.update(true);
    toolBar.pack();

    browser.addLocationListener(new LocationListener() {
        public void changing(LocationEvent event) {
            // Displays the new location in the text field.
            textLocation.setText(event.location);
        }

        public void changed(LocationEvent event) {
            // Update tool bar items.
            actionBackward.setEnabled(browser.isBackEnabled());
            actionForward.setEnabled(browser.isForwardEnabled());
            manager.update(false);
        }
    });

    browser.addProgressListener(new ProgressListener() {
        public void changed(ProgressEvent event) {
            progressBar.setMaximum(event.total);
            progressBar.setSelection(event.current);
        }

        public void completed(ProgressEvent event) {
            progressBar.setSelection(0);
        }
    });

    browser.addStatusTextListener(new StatusTextListener() {
        public void changed(StatusTextEvent event) {
            labelStatus.setText(event.text);
        }
    });

    browser.addTitleListener(new TitleListener() {
        public void changed(TitleEvent event) {
            shell.setText(event.title + " - powered by SWT");
        }
    });

    initialize(display, browser);

    shell.setSize(500, 400);
    shell.open();
    //textUser.forceFocus();

    //browser.setText(
    //   "<html><body>" + "<h1>SWT &amp; JFace </h1>" + "</body/html>");

    // 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.LineJoinTab.java

@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("LineJoin")); //$NON-NLS-1$
    joinCb = new Combo(comp, SWT.DROP_DOWN);
    joinCb.add(GraphicsExample.getResourceString("bevel")); //$NON-NLS-1$
    joinCb.add(GraphicsExample.getResourceString("miter")); //$NON-NLS-1$
    joinCb.add(GraphicsExample.getResourceString("round")); //$NON-NLS-1$
    joinCb.select(1);/*  w ww  . j a  v a2 s  .c om*/
    joinCb.addListener(SWT.Selection, event -> example.redraw());

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

    // initialize the shape color to the 4th item in the menu (green)
    shapeColor = (GraphicsBackground) menu.getItem(3).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(shapeColor.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.GraphicAntialiasTab.java

@Override
public void createControlPanel(Composite parent) {

    Composite comp;/*from  ww  w. ja  v  a  2s. c  o m*/

    // 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 -> {
        ovalColorGB = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

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

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

    // color button
    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(ovalColorGB.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:CoolBarExamples.java

public CoolBarExamples() {
    shell.setLayout(new GridLayout());

    final CoolBar coolBar = new CoolBar(shell, SWT.NONE);

    coolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // cool item with a text field.
    CoolItem textItem = new CoolItem(coolBar, SWT.NONE);

    Text text = new Text(coolBar, SWT.BORDER | SWT.DROP_DOWN);
    text.setText("TEXT");
    text.pack();/*from   w  w w .  j av a  2  s.c o m*/

    Point size = text.getSize();
    textItem.setControl(text);
    textItem.setSize(textItem.computeSize(size.x, size.y));

    // cool item with a label.
    CoolItem labelItem = new CoolItem(coolBar, SWT.NONE);

    Label label = new Label(coolBar, SWT.NONE);
    label.setText("LABEL");
    label.pack();

    size = label.getSize();
    labelItem.setControl(label);
    labelItem.setSize(textItem.computeSize(size.x, size.y));

    // cool item with a button.
    CoolItem buttonItem = new CoolItem(coolBar, SWT.NONE | SWT.DROP_DOWN);

    Composite composite = new Composite(coolBar, SWT.NONE);
    composite.setLayout(new GridLayout(2, true));

    Button button1 = new Button(composite, SWT.PUSH);
    button1.setText("Button 1");
    button1.pack();

    Button button2 = new Button(composite, SWT.PUSH);
    button2.setText("Button 2");
    button2.pack();

    composite.pack();

    size = composite.getSize();
    buttonItem.setControl(composite);
    buttonItem.setSize(buttonItem.computeSize(size.x, size.y));

    //      // Test cool item adding method.
    //      Label label2 = new Label(coolBar, SWT.NONE);
    //      label2.setText("label2");
    //      addControlToCoolBar(label2, SWT.DROP_DOWN, coolBar);

    try {
        setState(coolBar, new File("coolbar.state"));
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    shell.addListener(SWT.Close, new Listener() {
        public void handleEvent(Event event) {
            try {
                saveState(coolBar, new File("coolbar.state"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    shell.setSize(300, 120);
    // shell.pack();
    shell.open();

    // 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.talend.dataprofiler.chart.util.ChartUtils.java

/**
 * Create a AWT_SWT bridge composite for displaying the <CODE>ChartPanel</CODE>.
 * //w  ww. java2  s . c  o m
 * @param composite
 * @param gd
 * @param chartPanel
 */
public static ChartPanel createAWTSWTComp(Composite composite, GridData gd, JFreeChart chart) {

    ChartPanel chartPanel = new ChartPanel(chart);
    Composite frameComp = new Composite(composite, SWT.EMBEDDED);
    frameComp.setLayout(new GridLayout());
    frameComp.setLayoutData(gd);
    frameComp.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));

    Frame frame = SWT_AWT.new_Frame(frameComp);
    frame.setLayout(new java.awt.GridLayout());
    frame.add(chartPanel);
    frame.validate();

    return chartPanel;
}

From source file:org.eclipse.swt.examples.controlexample.ExpandBarTab.java

/**
 * Creates the "Example" widgets./*from  w  w  w . java 2s .  c o  m*/
 */
@Override
void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (borderButton.getSelection())
        style |= SWT.BORDER;
    if (verticalButton.getSelection())
        style |= SWT.V_SCROLL;

    /* Create the example widgets */
    expandBar1 = new ExpandBar(expandBarGroup, style);

    // First item
    Composite composite = new Composite(expandBar1, SWT.NONE);
    composite.setLayout(new GridLayout());
    new Button(composite, SWT.PUSH).setText("SWT.PUSH");
    new Button(composite, SWT.RADIO).setText("SWT.RADIO");
    new Button(composite, SWT.CHECK).setText("SWT.CHECK");
    new Button(composite, SWT.TOGGLE).setText("SWT.TOGGLE");
    ExpandItem item = new ExpandItem(expandBar1, SWT.NONE, 0);
    item.setText(ControlExample.getResourceString("Item1_Text"));
    item.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    item.setControl(composite);
    item.setImage(instance.images[ControlExample.ciClosedFolder]);

    // Second item
    composite = new Composite(expandBar1, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_ERROR));
    new Label(composite, SWT.NONE).setText("SWT.ICON_ERROR");
    new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_INFORMATION));
    new Label(composite, SWT.NONE).setText("SWT.ICON_INFORMATION");
    new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_WARNING));
    new Label(composite, SWT.NONE).setText("SWT.ICON_WARNING");
    new Label(composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_QUESTION));
    new Label(composite, SWT.NONE).setText("SWT.ICON_QUESTION");
    item = new ExpandItem(expandBar1, SWT.NONE, 1);
    item.setText(ControlExample.getResourceString("Item2_Text"));
    item.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    item.setControl(composite);
    item.setImage(instance.images[ControlExample.ciOpenFolder]);
    item.setExpanded(true);
}

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

@Override
public void createControlPanel(Composite parent) {

    Composite comp;/*from w  w  w.j av a  2s . 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.PathClippingTab.java

/**
 * Creates the widgets used to control the drawing.
 *//*ww w.j  a  v  a  2s  .  c  om*/
@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);
    });
}