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:FoodList.java

/**
 * Creates the main window's contents//from  w  ww . ja v a2  s. co  m
 * 
 * @param parent
 *            the main window
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    // Add a checkbox to toggle filter
    Button filterHealthy = new Button(composite, SWT.CHECK);
    filterHealthy.setText("&Show only healthy");

    final ListViewer lv = new ListViewer(composite);
    lv.setContentProvider(new FoodContentProvider());
    lv.setLabelProvider(new FoodLabelProvider());
    lv.setInput(new GroceryList());

    // When user checks the checkbox, toggle the filter
    filterHealthy.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            if (((Button) event.widget).getSelection())
                lv.addFilter(filter);
            else
                lv.removeFilter(filter);
        }
    });

    parent.pack();
    return composite;
}

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

@Override
public void createControlPanel(Composite parent) {

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

    // 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 3rd item in the menu (red)
    foreground = (GraphicsBackground) menu.getItem(2).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.addressbook.DataEntryDialog.java

private void createControlButtons() {
    Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;// w  w  w.  j ava  2  s. c  o  m
    composite.setLayout(layout);

    Button okButton = new Button(composite, SWT.PUSH);
    okButton.setText(resAddressBook.getString("OK"));
    okButton.addSelectionListener(widgetSelectedAdapter(e -> shell.close()));

    Button cancelButton = new Button(composite, SWT.PUSH);
    cancelButton.setText(resAddressBook.getString("Cancel"));
    cancelButton.addSelectionListener(widgetSelectedAdapter(e -> {
        values = null;
        shell.close();
    }));

    shell.setDefaultButton(okButton);
}

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

@Override
public void createControlPanel(Composite parent) {

    Composite comp;//from  w  ww  .j  a  va  2s.  c  om
    GridLayout gridLayout = new GridLayout(2, false);

    // create drop down combo
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(gridLayout);
    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Image")); //$NON-NLS-1$
    imageCb = new Combo(comp, SWT.DROP_DOWN);
    imageCb.add(GraphicsExample.getResourceString("House")); //$NON-NLS-1$
    imageCb.add(GraphicsExample.getResourceString("Question")); //$NON-NLS-1$
    imageCb.add(GraphicsExample.getResourceString("Task")); //$NON-NLS-1$
    imageCb.add(GraphicsExample.getResourceString("Font")); //$NON-NLS-1$
    imageCb.add(GraphicsExample.getResourceString("Cube")); //$NON-NLS-1$
    imageCb.add(GraphicsExample.getResourceString("SWT")); //$NON-NLS-1$
    imageCb.add(GraphicsExample.getResourceString("Ovals")); //$NON-NLS-1$
    imageCb.select(0);
    imageCb.addListener(SWT.Selection, event -> example.redraw());
}

From source file:MainClass.java

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, true));

    new Label(composite, SWT.LEFT).setText("Do you have complaints?");
    Composite yesNo = new Composite(composite, SWT.NONE);
    yesNo.setLayout(new FillLayout(SWT.VERTICAL));

    yes = new Button(yesNo, SWT.RADIO);
    yes.setText("Yes");

    no = new Button(yesNo, SWT.RADIO);
    no.setText("No");

    setControl(composite);/*from   www .  j  a v  a2s. c  om*/
}

From source file:Survey.java

/**
 * Creates the page controls//from w w  w  .j a  v a  2 s  .  c  om
 */
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, true));

    new Label(composite, SWT.LEFT).setText("Do you have complaints?");
    Composite yesNo = new Composite(composite, SWT.NONE);
    yesNo.setLayout(new FillLayout(SWT.VERTICAL));

    yes = new Button(yesNo, SWT.RADIO);
    yes.setText("Yes");

    no = new Button(yesNo, SWT.RADIO);
    no.setText("No");

    setControl(composite);
}

From source file:MainClass.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    Button newPerson = new Button(composite, SWT.PUSH);
    newPerson.setText("Create New Person");

    final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
    tv.setContentProvider(new PersonContentProvider());
    tv.setLabelProvider(new StudentLabelProvider());
    tv.setInput(studentList);/*  ww w  .  j  av  a 2 s . c om*/
    Table table = tv.getTable();
    table.setLayoutData(new GridData(GridData.FILL_BOTH));

    new TableColumn(table, SWT.CENTER).setText(NAME);
    new TableColumn(table, SWT.CENTER).setText(MALE);
    new TableColumn(table, SWT.CENTER).setText(AGE);
    new TableColumn(table, SWT.CENTER).setText(SHIRT_COLOR);

    for (int i = 0, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }

    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    newPerson.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Student p = new Student();
            p.setName("Name");
            p.setMale(true);
            p.setAgeRange(Integer.valueOf("0"));
            p.setShirtColor(new RGB(255, 0, 0));
            studentList.add(p);
            tv.refresh();
        }
    });

    CellEditor[] editors = new CellEditor[4];
    editors[0] = new TextCellEditor(table);
    editors[1] = new CheckboxCellEditor(table);
    editors[2] = new ComboBoxCellEditor(table, AgeRange.INSTANCES, SWT.READ_ONLY);
    editors[3] = new ColorCellEditor(table);

    tv.setColumnProperties(PROPS);
    tv.setCellModifier(new StudentCellModifier(tv));
    tv.setCellEditors(editors);

    return composite;
}

From source file:org.eclipse.swt.examples.ole.win32.OleBrowserView.java

/**
 * Creates the example./*  w w  w  .j a  va 2 s . co m*/
 * 
 * @see ViewPart#createPartControl
 */
@Override
public void createPartControl(Composite parent) {
    displayArea = new Composite(parent, SWT.NONE);

    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    displayArea.setLayout(gridLayout);

    createToolbar();
    createBrowserFrame();
    createStatusArea();
    createBrowserControl();
}

From source file:org.mwc.debrief.dis.views.DisListenerView.java

@Override
public void createPartControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    composite.setLayoutData(gd);//from w w  w .  j av  a 2  s . c o m
    GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);

    Composite buttonComposite = new Composite(composite, SWT.NONE);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    gd.widthHint = 300;
    buttonComposite.setLayoutData(gd);
    layout = new GridLayout(4, false);
    layout.marginWidth = 5;
    layout.marginHeight = 5;
    buttonComposite.setLayout(layout);

    connectButton = createButton(buttonComposite, "Connect", 2);
    connectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME connect
        }

    });
    disconnectButton = createButton(buttonComposite, "Disconnect", 2);
    disconnectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME disconnect
        }

    });

    final Link link = new Link(buttonComposite, SWT.NONE);
    gd = new GridData(SWT.END, SWT.FILL, false, false);
    gd.horizontalSpan = 4;
    link.setLayoutData(gd);
    link.setText("<a href=\"id\">Server Prefs</a>");
    link.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(link.getShell(), DisPrefs.ID,
                    null, null);
            dialog.open();
        }
    });
    link.setToolTipText("Dis Preferences");

    stopButton = createButton(buttonComposite, "Stop");
    stopButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME stop
        }

    });

    pauseButton = createButton(buttonComposite, "Pause");
    pauseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME pause
        }

    });

    resumeButton = createButton(buttonComposite, "Resume");
    resumeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME resume
        }

    });

    playButton = createButton(buttonComposite, "Play");
    playButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME play
        }

    });

    stopButton.setEnabled(false);
    pauseButton.setEnabled(false);
    resumeButton.setEnabled(false);
    disconnectButton.setEnabled(false);

    Label label = new Label(buttonComposite, SWT.NONE);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    label.setLayoutData(gd);
    label.setText("Path to input file:");

    Text text = new Text(buttonComposite, SWT.SINGLE | SWT.BORDER);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    gd.horizontalSpan = 2;
    gd.widthHint = 150;
    text.setLayoutData(gd);

    final Button browseButton = new Button(buttonComposite, SWT.PUSH);
    gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    browseButton.setLayoutData(gd);
    browseButton.setText("Browse...");
    browseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getSite().getShell(), SWT.SINGLE);
            String value = pathText.getText();
            if (value.trim().length() == 0) {
                value = Platform.getLocation().toOSString();
            }
            dialog.setFilterPath(value);

            String result = dialog.open();
            if (result == null || result.trim().length() == 0) {
                return;
            }
            pathText.setText(result);

        }

    });

    Composite chartWrapperComposite = new Composite(composite, SWT.BORDER);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    chartWrapperComposite.setLayoutData(gd);
    layout = new GridLayout(1, false);
    chartWrapperComposite.setLayout(layout);

    chartComposite = new ChartComposite(chartWrapperComposite, SWT.NONE, null, 400, 600, 300, 200, 1800, 1800,
            true, true, true, true, true, true) {
        @Override
        public void mouseUp(MouseEvent event) {
            super.mouseUp(event);
            JFreeChart c = getChart();
            if (c != null) {
                c.setNotify(true); // force redraw
            }
        }
    };

    Composite checkboxComposite = new Composite(composite, SWT.NONE);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    checkboxComposite.setLayoutData(gd);
    layout = new GridLayout(2, false);
    layout.marginWidth = 5;
    layout.marginHeight = 5;
    checkboxComposite.setLayout(layout);

    newPlotButton = new Button(checkboxComposite, SWT.CHECK);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    newPlotButton.setLayoutData(gd);
    newPlotButton.setText("New plot per replication");
    newPlotButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME new plot ...
        }

    });
    liveUpdatesButton = new Button(checkboxComposite, SWT.CHECK);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    liveUpdatesButton.setLayoutData(gd);
    liveUpdatesButton.setText("Live updates");
    liveUpdatesButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // FIXME Live updates.
        }

    });
    liveUpdatesButton.setSelection(true);

}

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

@Override
public void createControlPanel(Composite parent) {

    Composite comp;//w  w w . j  a va2  s. c  om

    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);
    });
}