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

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

Introduction

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

Prototype

public void setLayout(Layout layout) 

Source Link

Document

Sets the layout which is associated with the receiver to be the argument which may be null.

Usage

From source file:ClipboardExample.java

void createFileTransfer(Composite copyParent, Composite pasteParent) {
    // File Transfer
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("FileTransfer:"); //$NON-NLS-1$

    Composite c = new Composite(copyParent, SWT.NONE);
    c.setLayout(new GridLayout(2, false));
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    c.setLayoutData(data);//from  ww w. j a v  a  2s.  com

    copyFileTable = new Table(c, SWT.MULTI | SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    data.horizontalSpan = 2;
    copyFileTable.setLayoutData(data);

    Button b = new Button(c, SWT.PUSH);
    b.setText("Select file(s)");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
            String result = dialog.open();
            if (result != null && result.length() > 0) {
                // copyFileTable.removeAll();
                String separator = System.getProperty("file.separator");
                String path = dialog.getFilterPath();
                String[] names = dialog.getFileNames();
                for (int i = 0; i < names.length; i++) {
                    TableItem item = new TableItem(copyFileTable, SWT.NONE);
                    item.setText(path + separator + names[i]);
                }
            }
        }
    });
    b = new Button(c, SWT.PUSH);
    b.setText("Select directory");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
            String result = dialog.open();
            if (result != null && result.length() > 0) {
                // copyFileTable.removeAll();
                TableItem item = new TableItem(copyFileTable, SWT.NONE);
                item.setText(result);
            }
        }
    });

    b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = copyFileTable.getItems();
            if (items.length > 0) {
                status.setText("");
                String[] data = new String[items.length];
                for (int i = 0; i < data.length; i++) {
                    data[i] = items[i].getText();
                }
                clipboard.setContents(new Object[] { data }, new Transfer[] { FileTransfer.getInstance() });
            } else {
                status.setText("nothing to copy");
            }
        }
    });

    l = new Label(pasteParent, SWT.NONE);
    l.setText("FileTransfer:"); //$NON-NLS-1$
    pasteFileTable = new Table(pasteParent, SWT.MULTI | SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    pasteFileTable.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String[] data = (String[]) clipboard.getContents(FileTransfer.getInstance());
            if (data != null && data.length > 0) {
                status.setText("");
                pasteFileTable.removeAll();
                for (int i = 0; i < data.length; i++) {
                    TableItem item = new TableItem(pasteFileTable, SWT.NONE);
                    item.setText(data[i]);
                }
            } else {
                status.setText("nothing to paste");
            }
        }
    });
}

From source file:ClipboardExample.java

public void open(Display display) {
    clipboard = new Clipboard(display);
    shell = new Shell(display);
    shell.setText("SWT Clipboard");
    shell.setLayout(new FillLayout());

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);//  www .j  a va  2  s . c om
    parent.setLayout(new GridLayout(2, true));

    Group copyGroup = new Group(parent, SWT.NONE);
    copyGroup.setText("Copy From:");
    GridData data = new GridData(GridData.FILL_BOTH);
    copyGroup.setLayoutData(data);
    copyGroup.setLayout(new GridLayout(3, false));

    Group pasteGroup = new Group(parent, SWT.NONE);
    pasteGroup.setText("Paste To:");
    data = new GridData(GridData.FILL_BOTH);
    pasteGroup.setLayoutData(data);
    pasteGroup.setLayout(new GridLayout(3, false));

    Group controlGroup = new Group(parent, SWT.NONE);
    controlGroup.setText("Control API:");
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    controlGroup.setLayoutData(data);
    controlGroup.setLayout(new GridLayout(5, false));

    Group typesGroup = new Group(parent, SWT.NONE);
    typesGroup.setText("Available Types");
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    typesGroup.setLayoutData(data);
    typesGroup.setLayout(new GridLayout(2, false));

    status = new Label(parent, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.heightHint = 60;
    status.setLayoutData(data);

    createTextTransfer(copyGroup, pasteGroup);
    createRTFTransfer(copyGroup, pasteGroup);
    createHTMLTransfer(copyGroup, pasteGroup);
    createFileTransfer(copyGroup, pasteGroup);
    createMyTransfer(copyGroup, pasteGroup);
    createControlTransfer(controlGroup);
    createAvailableTypes(typesGroup);

    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    clipboard.dispose();
}

From source file:org.eclipse.swt.examples.browser.demos.views.EditorTab.java

public EditorTab(TabItem item) {
    final Composite parent = new Composite(item.getParent(), SWT.NONE);
    item.setText("Editor");
    item.setControl(parent);/*from  w w  w.java 2s. c  om*/

    try {
        browser = new Browser(parent, SWT.NONE);
    } catch (SWTError e) {
        e.printStackTrace();
        return;
    }
    final Sash sash = new Sash(parent, SWT.VERTICAL);
    Composite panel = new Composite(parent, SWT.NONE);
    final FormLayout form = new FormLayout();
    parent.setLayout(form);

    FormData data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(sash, 0);
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    browser.setLayoutData(data);

    final FormData sashData = new FormData();
    sashData.left = new FormAttachment(50, 0);
    sashData.top = new FormAttachment(0, 0);
    sashData.bottom = new FormAttachment(100, 0);
    sash.setLayoutData(sashData);
    sash.addListener(SWT.Selection, e -> {
        Rectangle rect = sash.getBounds();
        Rectangle parentRect = sash.getParent().getClientArea();
        int right = parentRect.width - rect.width - 20;
        e.x = Math.max(Math.min(e.x, right), 20);
        if (e.x != rect.x) {
            sashData.left = new FormAttachment(0, e.x);
            parent.layout();
        }
    });
    data = new FormData();
    data.left = new FormAttachment(sash, 0);
    data.right = new FormAttachment(100, 0);
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    panel.setLayoutData(data);

    /* Initialize Panel */
    panel.setLayout(new FillLayout(SWT.VERTICAL));
    Group htmlGroup = new Group(panel, SWT.NONE);
    htmlGroup.setText("setText");
    htmlText = new Text(htmlGroup, SWT.MULTI);
    htmlButton = new Button(htmlGroup, SWT.PUSH);
    htmlButton.setText("setText");
    GridLayout gridLayout = new GridLayout();
    htmlGroup.setLayout(gridLayout);
    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    htmlText.setLayoutData(gridData);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    htmlButton.setLayoutData(gridData);
    htmlGroup.layout();

    Group scriptGroup = new Group(panel, SWT.NONE);
    scriptGroup.setText("execute");
    scriptText = new Text(scriptGroup, SWT.MULTI);
    scriptButton = new Button(scriptGroup, SWT.PUSH);
    scriptButton.setText("execute");
    gridLayout = new GridLayout();
    scriptGroup.setLayout(gridLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    scriptText.setLayoutData(gridData);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    scriptButton.setLayoutData(gridData);
    scriptGroup.layout();

    browser.setText(html);
    htmlText.setText(html);
    scriptText.setText(script);
    parent.layout();

    Listener listener = e -> {
        Widget w = e.widget;
        if (w == htmlButton)
            browser.setText(htmlText.getText());
        if (w == scriptButton)
            browser.execute(scriptText.getText());
    };

    htmlButton.addListener(SWT.Selection, listener);
    scriptButton.addListener(SWT.Selection, listener);
}

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);// www.j  a  v  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:AddressBookDemo.java

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;//from w w w.  ja  v a  2s. co  m
    layout.verticalSpacing = 9;

    Label label = new Label(container, SWT.NULL);
    label.setText("&Address Line 1:");

    addressLine1Text = new Text(container, SWT.BORDER | SWT.MULTI);

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    addressLine1Text.setLayoutData(gd);
    addressLine1Text.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });

    label = new Label(container, SWT.NULL);
    label.setText("&Address Line 2:");

    addressLine2Text = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    addressLine2Text.setLayoutData(gd);
    addressLine2Text.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });

    label = new Label(container, SWT.NULL);
    label.setText("&City:");

    cityText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    cityText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&State:");

    stateCombo = new Combo(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    stateCombo.setLayoutData(gd);
    stateCombo.setItems(STATES);

    label = new Label(container, SWT.NULL);
    label.setText("&Zip Code:");

    zipCodeText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    zipCodeText.setLayoutData(gd);

    // dialogChanged();
    setControl(container);
}

From source file:ReservationData.java

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout gridLayout = new GridLayout(2, false);
    composite.setLayout(gridLayout);

    new Label(composite, SWT.NULL).setText("Arrival date: ");

    Composite compositeArrival = new Composite(composite, SWT.NULL);
    compositeArrival.setLayout(new RowLayout());

    String[] months = new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
            "Nov", "Dec" };

    Calendar calendar = new GregorianCalendar(); // today.
    ((ReservationWizard) getWizard()).data.arrivalDate = calendar.getTime();

    comboArrivalMonth = new Combo(compositeArrival, SWT.BORDER | SWT.READ_ONLY);
    for (int i = 0; i < months.length; i++)
        comboArrivalMonth.add(months[i]);
    comboArrivalMonth.select(calendar.get(Calendar.MONTH));

    comboArrivalDay = new Combo(compositeArrival, SWT.BORDER | SWT.READ_ONLY);
    for (int i = 0; i < 31; i++)
        comboArrivalDay.add("" + (i + 1));
    comboArrivalDay.select(calendar.get(Calendar.DAY_OF_MONTH) - 1);

    comboArrivalYear = new Combo(compositeArrival, SWT.BORDER | SWT.READ_ONLY);
    for (int i = 2004; i < 2010; i++)
        comboArrivalYear.add("" + i);
    comboArrivalYear.select(calendar.get(Calendar.YEAR) - 2004);

    calendar.add(Calendar.DATE, 1); // tomorrow. 
    ((ReservationWizard) getWizard()).data.departureDate = calendar.getTime();

    new Label(composite, SWT.NULL).setText("Departure date: ");

    Composite compositeDeparture = new Composite(composite, SWT.NULL | SWT.READ_ONLY);
    compositeDeparture.setLayout(new RowLayout());

    comboDepartureMonth = new Combo(compositeDeparture, SWT.NULL | SWT.READ_ONLY);
    for (int i = 0; i < months.length; i++)
        comboDepartureMonth.add(months[i]);
    comboDepartureMonth.select(calendar.get(Calendar.MONTH));

    comboDepartureDay = new Combo(compositeDeparture, SWT.NULL | SWT.READ_ONLY);
    for (int i = 0; i < 31; i++)
        comboDepartureDay.add("" + (i + 1));
    comboDepartureDay.select(calendar.get(Calendar.DAY_OF_MONTH) - 1);

    comboDepartureYear = new Combo(compositeDeparture, SWT.NULL | SWT.READ_ONLY);
    for (int i = 2004; i < 2010; i++)
        comboDepartureYear.add("" + i);
    comboDepartureYear.select(calendar.get(Calendar.YEAR) - 2004);

    // draws a line. 
    Label line = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);

    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;/*from  www . ja va 2  s.  c  om*/
    line.setLayoutData(gridData);

    new Label(composite, SWT.NULL).setText("Room type: ");
    comboRoomTypes = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
    comboRoomTypes.add("Standard room (rate: $198)");
    comboRoomTypes.add("Deluxe room (rate: $298)");
    comboRoomTypes.select(0);

    Listener selectionListener = new Listener() {
        public void handleEvent(Event event) {
            int arrivalDay = comboArrivalDay.getSelectionIndex() + 1;
            int arrivalMonth = comboArrivalMonth.getSelectionIndex();
            int arrivalYear = comboArrivalYear.getSelectionIndex() + 2004;

            int departureDay = comboDepartureDay.getSelectionIndex() + 1;
            int departureMonth = comboDepartureMonth.getSelectionIndex();
            int departureYear = comboDepartureYear.getSelectionIndex() + 2004;

            setDates(arrivalDay, arrivalMonth, arrivalYear, departureDay, departureMonth, departureYear);
        }
    };

    comboArrivalDay.addListener(SWT.Selection, selectionListener);
    comboArrivalMonth.addListener(SWT.Selection, selectionListener);
    comboArrivalYear.addListener(SWT.Selection, selectionListener);
    comboDepartureDay.addListener(SWT.Selection, selectionListener);
    comboDepartureMonth.addListener(SWT.Selection, selectionListener);
    comboDepartureYear.addListener(SWT.Selection, selectionListener);

    comboRoomTypes.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            ((ReservationWizard) getWizard()).data.roomType = comboRoomTypes.getSelectionIndex();
        }
    });

    setControl(composite);

}

From source file:at.ac.tuwien.inso.subcat.ui.widgets.TrendView.java

public void addConfiguration(TrendChartConfigData config) {
    assert (config != null);

    LinkedList<Combo> combos = new LinkedList<Combo>();

    // Title Row:
    Label lblGrpTitle = new Label(optionComposite, SWT.NONE);
    lblGrpTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    Helper.setLabelStyle(lblGrpTitle, SWT.BOLD);
    lblGrpTitle.setText(config.getName());

    Composite topOptions = new Composite(optionComposite, SWT.NONE);
    topOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    topOptions.setLayout(new GridLayout(config.getDropDowns().size(), true));

    for (DropDownData dropData : config.getDropDowns()) {
        Combo comboDropDown = new Combo(topOptions, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
        comboDropDown.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
        comboDropDown.setData(dropData);
        combos.add(comboDropDown);//from w  w  w  .ja v  a 2 s.  c  o m

        for (DropDownData.Pair data : dropData.getData()) {
            comboDropDown.add(data.name);
        }

        comboDropDown.select(0);

        comboDropDown.addSelectionListener(this.comboListener);
    }

    // Separator:
    Helper.separator(optionComposite, 3);

    // Left Option Labels:
    new Label(optionComposite, SWT.NONE);

    Composite leftOptions = new Composite(optionComposite, SWT.NONE);
    leftOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    leftOptions.setLayout(new GridLayout(1, true));
    for (OptionListConfigData.Pair pair : config.getOptionList().getData()) {
        Label lblOpt = new Label(leftOptions, SWT.NONE);
        lblOpt.setText(pair.name);
    }

    // Check Boxes:
    Composite selectionComposite = new Composite(optionComposite, SWT.NONE);
    selectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    selectionComposite.setLayout(new GridLayout(combos.size(), true));

    OptionListConfig leftConfig = config.getOptionList().getConfig();
    int x = 0;

    for (Combo combo : combos) {
        TrendChartPlotConfig topConfig = (TrendChartPlotConfig) config.getDropDowns().get(x).getConfig();

        for (OptionListConfigData.Pair pair : config.getOptionList().getData()) {
            Button button = new Button(selectionComposite, SWT.CHECK);
            button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
            button.setData(new ChartIdentifier(topConfig, combo, leftConfig, pair.id, boxWeight++));
            button.addSelectionListener(boxListener);
        }

        x++;
    }

    // Scrolling area size update:
    scrolledComposite.setMinSize(optionComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}

From source file:at.ac.tuwien.inso.subcat.ui.widgets.TrendChart.java

public void addConfiguration(TrendChartConfigData config, List<String> flags) {
    assert (config != null);

    ArrayList<Combo> combos = new ArrayList<Combo>();

    // Title Row:
    Label lblGrpTitle = new Label(optionComposite, SWT.NONE);
    lblGrpTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    Helper.setLabelStyle(lblGrpTitle, SWT.BOLD);
    lblGrpTitle.setText(config.getName());

    Composite topOptions = new Composite(optionComposite, SWT.NONE);
    topOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    topOptions.setLayout(new GridLayout(config.getDropDowns().size(), true));

    for (DropDownData dropData : config.getDropDowns()) {
        if (dropData.getConfig().show(flags)) {
            Combo comboDropDown = new Combo(topOptions, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
            comboDropDown.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
            comboDropDown.setData(dropData);
            combos.add(comboDropDown);/*from   w  w  w  .  j av  a 2 s .co  m*/

            for (DropDownData.Pair data : dropData.getData()) {
                comboDropDown.add(data.name);
            }

            comboDropDown.select(0);

            comboDropDown.addSelectionListener(this.comboListener);
        }
    }

    // Separator:
    Helper.separator(optionComposite, 3);

    // Left Option Labels:
    new Label(optionComposite, SWT.NONE);

    Composite leftOptions = new Composite(optionComposite, SWT.NONE);
    leftOptions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    leftOptions.setLayout(new GridLayout(1, true));
    for (OptionListConfigData.Pair pair : config.getOptionList().getData()) {
        Label lblOpt = new Label(leftOptions, SWT.NONE);
        lblOpt.setText(pair.name);
    }

    // Check Boxes:
    Composite selectionComposite = new Composite(optionComposite, SWT.NONE);
    selectionComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    selectionComposite.setLayout(new GridLayout(combos.size(), true));

    OptionListConfig leftConfig = config.getOptionList().getConfig();

    for (OptionListConfigData.Pair pair : config.getOptionList().getData()) {
        int x = 0;
        for (Combo combo : combos) {
            TrendChartPlotConfig topConfig = (TrendChartPlotConfig) config.getDropDowns().get(x).getConfig();

            Button button = new Button(selectionComposite, SWT.CHECK);
            button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
            button.setData(new ChartIdentifier(topConfig, combo, leftConfig, pair.id, boxWeight++));
            button.addSelectionListener(boxListener);
            x++;
        }
    }

    // Scrolling area size update:
    scrolledComposite.setMinSize(optionComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}

From source file:AddressBookDemo.java

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;// ww w.j av a 2 s.  c o  m
    layout.verticalSpacing = 9;

    Label label = new Label(container, SWT.NULL);
    label.setText("&Given Name:");

    givenNameText = new Text(container, SWT.BORDER | SWT.SINGLE);

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    givenNameText.setLayoutData(gd);
    givenNameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });

    label = new Label(container, SWT.NULL);
    label.setText("&Family Name:");

    familyNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    familyNameText.setLayoutData(gd);
    familyNameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });

    label = new Label(container, SWT.NULL);
    label.setText("&Nickname:");

    nickNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    nickNameText.setLayoutData(gd);

    createLine(container, layout.numColumns);

    label = new Label(container, SWT.NULL);
    label.setText("&Business Phone:");

    businessPhoneText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    businessPhoneText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Home Phone:");

    homePhoneText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    homePhoneText.setLayoutData(gd);

    createLine(container, layout.numColumns);

    label = new Label(container, SWT.NULL);
    label.setText("&E-Mail Address:");

    emailText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    emailText.setLayoutData(gd);
    emailText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });

    // dialogChanged();
    setControl(container);
}

From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java

public void open(Display display) {
    clipboard = new Clipboard(display);
    shell = new Shell(display);
    shell.setText("SWT Clipboard");
    shell.setLayout(new FillLayout());

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);/*from   ww w. ja v a2s .c o m*/
    parent.setLayout(new GridLayout(2, true));

    Group copyGroup = new Group(parent, SWT.NONE);
    copyGroup.setText("Copy From:");
    GridData data = new GridData(GridData.FILL_BOTH);
    copyGroup.setLayoutData(data);
    copyGroup.setLayout(new GridLayout(3, false));

    Group pasteGroup = new Group(parent, SWT.NONE);
    pasteGroup.setText("Paste To:");
    data = new GridData(GridData.FILL_BOTH);
    pasteGroup.setLayoutData(data);
    pasteGroup.setLayout(new GridLayout(3, false));

    Group controlGroup = new Group(parent, SWT.NONE);
    controlGroup.setText("Control API:");
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    controlGroup.setLayoutData(data);
    controlGroup.setLayout(new GridLayout(5, false));

    Group typesGroup = new Group(parent, SWT.NONE);
    typesGroup.setText("Available Types");
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    typesGroup.setLayoutData(data);
    typesGroup.setLayout(new GridLayout(2, false));

    status = new Label(parent, SWT.NONE);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    status.setLayoutData(data);

    createTextTransfer(copyGroup, pasteGroup);
    createRTFTransfer(copyGroup, pasteGroup);
    createHTMLTransfer(copyGroup, pasteGroup);
    createFileTransfer(copyGroup, pasteGroup);
    createImageTransfer(copyGroup, pasteGroup);
    createMyTransfer(copyGroup, pasteGroup);
    createControlTransfer(controlGroup);
    createAvailableTypes(typesGroup);

    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    clipboard.dispose();
}