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

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

Introduction

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

Prototype

public Label(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:DNDExample.java

private void createDropOperations(Composite parent) {
    parent.setLayout(new RowLayout(SWT.VERTICAL));
    final Button moveButton = new Button(parent, SWT.CHECK);
    moveButton.setText("DND.DROP_MOVE");
    moveButton.setSelection(true);//from w w  w.  j a  v  a2  s  .  c o  m
    dropOperation = DND.DROP_MOVE;
    moveButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropOperation |= DND.DROP_MOVE;
            } else {
                dropOperation = dropOperation & ~DND.DROP_MOVE;
                if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_MOVE) != 0) {
                    dropOperation |= DND.DROP_MOVE;
                    moveButton.setSelection(true);
                }
            }
            if (dropEnabled) {
                createDropTarget();
            }
        }
    });

    final Button copyButton = new Button(parent, SWT.CHECK);
    copyButton.setText("DND.DROP_COPY");
    copyButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropOperation |= DND.DROP_COPY;
            } else {
                dropOperation = dropOperation & ~DND.DROP_COPY;
                if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_COPY) != 0) {
                    dropOperation = DND.DROP_COPY;
                    copyButton.setSelection(true);
                }
            }
            if (dropEnabled) {
                createDropTarget();
            }
        }
    });

    final Button linkButton = new Button(parent, SWT.CHECK);
    linkButton.setText("DND.DROP_LINK");
    linkButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropOperation |= DND.DROP_LINK;
            } else {
                dropOperation = dropOperation & ~DND.DROP_LINK;
                if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_LINK) != 0) {
                    dropOperation = DND.DROP_LINK;
                    linkButton.setSelection(true);
                }
            }
            if (dropEnabled) {
                createDropTarget();
            }
        }
    });

    Button b = new Button(parent, SWT.CHECK);
    b.setText("DND.DROP_DEFAULT");
    defaultParent = new Composite(parent, SWT.NONE);
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropOperation |= DND.DROP_DEFAULT;
                defaultParent.setVisible(true);
            } else {
                dropOperation = dropOperation & ~DND.DROP_DEFAULT;
                defaultParent.setVisible(false);
            }
            if (dropEnabled) {
                createDropTarget();
            }
        }
    });

    defaultParent.setVisible(false);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 20;
    defaultParent.setLayout(layout);
    Label label = new Label(defaultParent, SWT.NONE);
    label.setText("Value for default operation is:");
    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_MOVE");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropDefaultOperation = DND.DROP_MOVE;
                dropOperation |= DND.DROP_MOVE;
                moveButton.setSelection(true);
                if (dropEnabled) {
                    createDropTarget();
                }
            }
        }
    });

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_COPY");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropDefaultOperation = DND.DROP_COPY;
                dropOperation |= DND.DROP_COPY;
                copyButton.setSelection(true);
                if (dropEnabled) {
                    createDropTarget();
                }
            }
        }
    });

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_LINK");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropDefaultOperation = DND.DROP_LINK;
                dropOperation |= DND.DROP_LINK;
                linkButton.setSelection(true);
                if (dropEnabled) {
                    createDropTarget();
                }
            }
        }
    });

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_NONE");
    b.setSelection(true);
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b.getSelection()) {
                dropDefaultOperation = DND.DROP_NONE;
                dropOperation &= ~DND.DROP_DEFAULT;
                if (dropEnabled) {
                    createDropTarget();
                }
            }
        }
    });
}

From source file:au.gov.ansto.bragg.kakadu.ui.plot.FitPlotPropertiesComposite.java

private void updateParameterGroup(Map<String, Double> parameters, Double quality) {
    inverseButton.setSelection(fitter.isInverse());
    inverseButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }//from  www .j  ava 2 s .c o  m

        public void widgetSelected(SelectionEvent arg0) {
            if (fitter.isInverseAllowed())
                inverseButton.setEnabled(isEnabled());
            if (inverseButton.getSelection() != fitter.isInverse())
                setInverseValue(inverseButton.getSelection());
        }

    });
    parameterList.clear();
    GridData data;
    parameterGroup.dispose();
    if (removeButton != null)
        removeButton.dispose();
    parameterGroup = new Group(this, SWT.NONE);
    parameterGroup.setText("Parameters");
    GridLayout propertiesGridLayout = new GridLayout();
    propertiesGridLayout.numColumns = 2;
    propertiesGridLayout.marginHeight = 3;
    propertiesGridLayout.marginWidth = 3;
    propertiesGridLayout.horizontalSpacing = 3;
    propertiesGridLayout.verticalSpacing = 3;
    parameterGroup.setLayout(propertiesGridLayout);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    data.grabExcessHorizontalSpace = true;
    parameterGroup.setLayoutData(data);

    Label functionLabel = new Label(parameterGroup, SWT.NONE);
    functionLabel.setText("Function");
    data = new GridData();
    data.verticalAlignment = GridData.BEGINNING;
    data.verticalIndent = 3;
    functionLabel.setLayoutData(data);

    Text functionText = new Text(parameterGroup, SWT.NONE);
    functionText.setText(fitter.getFunctionText());
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    functionText.setLayoutData(data);
    functionText.setEditable(false);

    for (Entry<String, Double> entry : parameters.entrySet()) {
        Label label = new Label(parameterGroup, SWT.NONE);
        label.setText(entry.getKey());
        data = new GridData();
        data.verticalAlignment = GridData.BEGINNING;
        data.verticalIndent = 3;
        label.setLayoutData(data);

        Text text = new Text(parameterGroup, SWT.BORDER);
        text.setData(entry.getKey());
        text.setText(String.valueOf(entry.getValue()));
        data = new GridData();
        data.horizontalAlignment = GridData.FILL;
        data.grabExcessHorizontalSpace = true;
        text.setLayoutData(data);

        parameterList.add(text);
    }
    Label resolutionlabel = new Label(parameterGroup, SWT.NONE);
    resolutionlabel.setText("resolution");
    data = new GridData();
    data.verticalAlignment = GridData.BEGINNING;
    data.verticalIndent = 3;
    resolutionlabel.setLayoutData(data);

    resolutionText = new Text(parameterGroup, SWT.BORDER);
    resolutionText.setText(String.valueOf(fitter.getResolutionMultiple()));
    //      resolutionText.
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    resolutionText.setLayoutData(data);

    if (!quality.isNaN()) {
        Label label = new Label(parameterGroup, SWT.NONE);
        label.setText("Quality(" + fitter.getFitterType().getValue() + ")");
        data = new GridData();
        data.verticalAlignment = GridData.BEGINNING;
        data.verticalIndent = 3;
        label.setLayoutData(data);

        Text text = new Text(parameterGroup, SWT.BORDER);
        text.setText(String.valueOf(quality));
        data = new GridData();
        data.horizontalAlignment = GridData.FILL;
        data.grabExcessHorizontalSpace = true;
        text.setLayoutData(data);
    }
    if (fitter.getFunctionType() == FunctionType.AddFunction) {
        removeButton = new Button(this, SWT.PUSH);
        removeButton
                .setText("Remove Function " + fitFunctionCombo.getItem(fitFunctionCombo.getSelectionIndex()));
        data = new GridData();
        data.horizontalAlignment = GridData.FILL;
        data.verticalAlignment = GridData.FILL;
        data.horizontalSpan = 2;
        data.grabExcessHorizontalSpace = true;
        data.grabExcessVerticalSpace = true;
        removeButton.setLayoutData(data);
        removeButton.addSelectionListener(new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent arg0) {
            }

            public void widgetSelected(SelectionEvent arg0) {
                try {
                    removeFunction(fitFunctionCombo.getItem(fitFunctionCombo.getSelectionIndex()));
                } catch (Exception e) {
                    plot.handleException(e);
                }
            }

        });
    }
    //      parameterGroup.redraw();
    //      this.redraw();
    //      parent.redraw();
    //      redraw();
    layout();
    if (expandItem != null) {
        expandItem.setHeight(this.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    }
    parent.update();
    parent.redraw();
    //      parent.layout();
}

From source file:org.eclipse.swt.examples.dnd.DNDExample.java

private void createDropOperations(Composite parent) {
    parent.setLayout(new RowLayout(SWT.VERTICAL));
    final Button moveButton = new Button(parent, SWT.CHECK);
    moveButton.setText("DND.DROP_MOVE");
    moveButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b = (Button) e.widget;
        if (b.getSelection()) {
            dropOperation |= DND.DROP_MOVE;
        } else {//  w ww.j  a  v  a2 s  .c  o m
            dropOperation = dropOperation & ~DND.DROP_MOVE;
            if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_MOVE) != 0) {
                dropOperation |= DND.DROP_MOVE;
                moveButton.setSelection(true);
            }
        }
        if (dropEnabled) {
            createDropTarget();
        }
    }));

    final Button copyButton = new Button(parent, SWT.CHECK);
    copyButton.setText("DND.DROP_COPY");
    copyButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button b = (Button) e.widget;
        if (b.getSelection()) {
            dropOperation |= DND.DROP_COPY;
        } else {
            dropOperation = dropOperation & ~DND.DROP_COPY;
            if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_COPY) != 0) {
                dropOperation = DND.DROP_COPY;
                copyButton.setSelection(true);
            }
        }
        if (dropEnabled) {
            createDropTarget();
        }
    }));

    final Button linkButton = new Button(parent, SWT.CHECK);
    linkButton.setText("DND.DROP_LINK");
    linkButton.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropOperation |= DND.DROP_LINK;
        } else {
            dropOperation = dropOperation & ~DND.DROP_LINK;
            if (dropOperation == 0 || (dropDefaultOperation & DND.DROP_LINK) != 0) {
                dropOperation = DND.DROP_LINK;
                linkButton.setSelection(true);
            }
        }
        if (dropEnabled) {
            createDropTarget();
        }
    }));

    Button b = new Button(parent, SWT.CHECK);
    b.setText("DND.DROP_DEFAULT");
    defaultParent = new Composite(parent, SWT.NONE);
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropOperation |= DND.DROP_DEFAULT;
            defaultParent.setVisible(true);
        } else {
            dropOperation = dropOperation & ~DND.DROP_DEFAULT;
            defaultParent.setVisible(false);
        }
        if (dropEnabled) {
            createDropTarget();
        }
    }));

    defaultParent.setVisible(false);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 20;
    defaultParent.setLayout(layout);
    Label label = new Label(defaultParent, SWT.NONE);
    label.setText("Value for default operation is:");
    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_MOVE");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropDefaultOperation = DND.DROP_MOVE;
            dropOperation |= DND.DROP_MOVE;
            moveButton.setSelection(true);
            if (dropEnabled) {
                createDropTarget();
            }
        }
    }));

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_COPY");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropDefaultOperation = DND.DROP_COPY;
            dropOperation |= DND.DROP_COPY;
            copyButton.setSelection(true);
            if (dropEnabled) {
                createDropTarget();
            }
        }
    }));

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_LINK");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropDefaultOperation = DND.DROP_LINK;
            dropOperation |= DND.DROP_LINK;
            linkButton.setSelection(true);
            if (dropEnabled) {
                createDropTarget();
            }
        }
    }));

    b = new Button(defaultParent, SWT.RADIO);
    b.setText("DND.DROP_NONE");
    b.setSelection(true);
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        Button eb = (Button) e.widget;
        if (eb.getSelection()) {
            dropDefaultOperation = DND.DROP_NONE;
            dropOperation &= ~DND.DROP_DEFAULT;
            if (dropEnabled) {
                createDropTarget();
            }
        }
    }));

    // initialize state
    moveButton.setSelection(true);
    copyButton.setSelection(true);
    linkButton.setSelection(true);
    dropOperation = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
}

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

void createEditEventDialog(Shell parent, int x, int y, final int index) {
    final Shell dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
    dialog.setLayout(new GridLayout());
    dialog.setText(ControlExample.getResourceString("Edit_Event"));
    Label label = new Label(dialog, SWT.NONE);
    label.setText(ControlExample.getResourceString("Edit_Event_Fields", EVENT_INFO[index].name));

    Group group = new Group(dialog, SWT.NONE);
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final int fields = EVENT_INFO[index].settableFields;
    final int eventType = EVENT_INFO[index].type;
    setFieldsMask = EVENT_INFO[index].setFields;
    setFieldsEvent = EVENT_INFO[index].event;

    if ((fields & DOIT) != 0) {
        new Label(group, SWT.NONE).setText("doit");
        final Combo doitCombo = new Combo(group, SWT.READ_ONLY);
        doitCombo.setItems("", "true", "false");
        if ((setFieldsMask & DOIT) != 0)
            doitCombo.setText(Boolean.toString(setFieldsEvent.doit));
        doitCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        doitCombo.addSelectionListener(widgetSelectedAdapter(e -> {
            String newValue = doitCombo.getText();
            if (newValue.length() == 0) {
                setFieldsMask &= ~DOIT;
            } else {
                setFieldsEvent.type = eventType;
                setFieldsEvent.doit = newValue.equals("true");
                setFieldsMask |= DOIT;//from  www  .  ja  va  2  s . c  om
            }
        }));
    }

    if ((fields & DETAIL) != 0) {
        new Label(group, SWT.NONE).setText("detail");
        int detailType = fields & 0xFF;
        final Combo detailCombo = new Combo(group, SWT.READ_ONLY);
        detailCombo.setItems(DETAIL_CONSTANTS[detailType]);
        detailCombo.add("", 0);
        detailCombo.setVisibleItemCount(detailCombo.getItemCount());
        if ((setFieldsMask & DETAIL) != 0)
            detailCombo.setText(DETAIL_CONSTANTS[detailType][setFieldsEvent.detail]);
        detailCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        detailCombo.addSelectionListener(widgetSelectedAdapter(e -> {
            String newValue = detailCombo.getText();
            if (newValue.length() == 0) {
                setFieldsMask &= ~DETAIL;
            } else {
                setFieldsEvent.type = eventType;
                for (int i = 0; i < DETAIL_VALUES.length; i += 2) {
                    if (newValue.equals(DETAIL_VALUES[i])) {
                        setFieldsEvent.detail = ((Integer) DETAIL_VALUES[i + 1]).intValue();
                        break;
                    }
                }
                setFieldsMask |= DETAIL;
            }
        }));
    }

    if ((fields & TEXT) != 0) {
        new Label(group, SWT.NONE).setText("text");
        final Text textText = new Text(group, SWT.BORDER);
        if ((setFieldsMask & TEXT) != 0)
            textText.setText(setFieldsEvent.text);
        textText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        textText.addModifyListener(e -> {
            String newValue = textText.getText();
            if (newValue.length() == 0) {
                setFieldsMask &= ~TEXT;
            } else {
                setFieldsEvent.type = eventType;
                setFieldsEvent.text = newValue;
                setFieldsMask |= TEXT;
            }
        });
    }

    if ((fields & X) != 0) {
        new Label(group, SWT.NONE).setText("x");
        final Text xText = new Text(group, SWT.BORDER);
        if ((setFieldsMask & X) != 0)
            xText.setText(Integer.toString(setFieldsEvent.x));
        xText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        xText.addModifyListener(e -> {
            String newValue = xText.getText();
            try {
                int newIntValue = Integer.parseInt(newValue);
                setFieldsEvent.type = eventType;
                setFieldsEvent.x = newIntValue;
                setFieldsMask |= X;
            } catch (NumberFormatException ex) {
                setFieldsMask &= ~X;
            }
        });
    }

    if ((fields & Y) != 0) {
        new Label(group, SWT.NONE).setText("y");
        final Text yText = new Text(group, SWT.BORDER);
        if ((setFieldsMask & Y) != 0)
            yText.setText(Integer.toString(setFieldsEvent.y));
        yText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        yText.addModifyListener(e -> {
            String newValue = yText.getText();
            try {
                int newIntValue = Integer.parseInt(newValue);
                setFieldsEvent.type = eventType;
                setFieldsEvent.y = newIntValue;
                setFieldsMask |= Y;
            } catch (NumberFormatException ex) {
                setFieldsMask &= ~Y;
            }
        });
    }

    if ((fields & WIDTH) != 0) {
        new Label(group, SWT.NONE).setText("width");
        final Text widthText = new Text(group, SWT.BORDER);
        if ((setFieldsMask & WIDTH) != 0)
            widthText.setText(Integer.toString(setFieldsEvent.width));
        widthText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        widthText.addModifyListener(e -> {
            String newValue = widthText.getText();
            try {
                int newIntValue = Integer.parseInt(newValue);
                setFieldsEvent.type = eventType;
                setFieldsEvent.width = newIntValue;
                setFieldsMask |= WIDTH;
            } catch (NumberFormatException ex) {
                setFieldsMask &= ~WIDTH;
            }
        });
    }

    if ((fields & HEIGHT) != 0) {
        new Label(group, SWT.NONE).setText("height");
        final Text heightText = new Text(group, SWT.BORDER);
        if ((setFieldsMask & HEIGHT) != 0)
            heightText.setText(Integer.toString(setFieldsEvent.height));
        heightText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        heightText.addModifyListener(e -> {
            String newValue = heightText.getText();
            try {
                int newIntValue = Integer.parseInt(newValue);
                setFieldsEvent.type = eventType;
                setFieldsEvent.height = newIntValue;
                setFieldsMask |= HEIGHT;
            } catch (NumberFormatException ex) {
                setFieldsMask &= ~HEIGHT;
            }
        });
    }

    Button ok = new Button(dialog, SWT.PUSH);
    ok.setText(ControlExample.getResourceString("OK"));
    GridData data = new GridData(70, SWT.DEFAULT);
    data.horizontalAlignment = SWT.RIGHT;
    ok.setLayoutData(data);
    ok.addSelectionListener(widgetSelectedAdapter(e -> {
        EVENT_INFO[index].setFields = setFieldsMask;
        EVENT_INFO[index].event = setFieldsEvent;
        dialog.dispose();
    }));

    dialog.setDefaultButton(ok);
    dialog.pack();
    dialog.setLocation(x, y);
    dialog.open();
}

From source file:org.eclipse.swt.examples.layoutexample.Tab.java

/**
 * Refreshes the composite and draws all controls
 * in the layout example./*from ww  w  .j  a v  a2 s.  c om*/
 */
void refreshLayoutComposite() {
    /* Remove children that are already laid out */
    children = layoutComposite.getChildren();
    for (Control child : children) {
        child.dispose();
    }
    /* Add all children listed in the table */
    TableItem[] items = table.getItems();
    children = new Control[items.length];
    String[] itemValues = new String[] { LayoutExample.getResourceString("Item", new String[] { "1" }),
            LayoutExample.getResourceString("Item", new String[] { "2" }),
            LayoutExample.getResourceString("Item", new String[] { "3" }) };
    for (int i = 0; i < items.length; i++) {
        String control = items[i].getText(1);
        String controlName = items[i].getText(0);
        if (control.equals("Button")) {
            Button button = new Button(layoutComposite, SWT.PUSH);
            button.setText(controlName);
            children[i] = button;
        } else if (control.equals("Canvas")) {
            Canvas canvas = new Canvas(layoutComposite, SWT.BORDER);
            children[i] = canvas;
        } else if (control.equals("Combo")) {
            Combo combo = new Combo(layoutComposite, SWT.NONE);
            combo.setItems(itemValues);
            combo.setText(controlName);
            children[i] = combo;
        } else if (control.equals("Composite")) {
            Composite composite = new Composite(layoutComposite, SWT.BORDER);
            children[i] = composite;
        } else if (control.equals("CoolBar")) {
            CoolBar coolBar = new CoolBar(layoutComposite, SWT.NONE);
            ToolBar toolBar = new ToolBar(coolBar, SWT.BORDER);
            ToolItem item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            CoolItem coolItem1 = new CoolItem(coolBar, 0);
            coolItem1.setControl(toolBar);
            toolBar = new ToolBar(coolBar, SWT.BORDER);
            item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "3" }));
            item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "4" }));
            CoolItem coolItem2 = new CoolItem(coolBar, 0);
            coolItem2.setControl(toolBar);
            Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            coolItem1.setSize(coolItem1.computeSize(size.x, size.y));
            coolItem2.setSize(coolItem2.computeSize(size.x, size.y));
            coolBar.setSize(coolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            children[i] = coolBar;
        } else if (control.equals("Group")) {
            Group group = new Group(layoutComposite, SWT.NONE);
            group.setText(controlName);
            children[i] = group;
        } else if (control.equals("Label")) {
            Label label = new Label(layoutComposite, SWT.NONE);
            label.setText(controlName);
            children[i] = label;
        } else if (control.equals("Link")) {
            Link link = new Link(layoutComposite, SWT.NONE);
            link.setText(controlName);
            children[i] = link;
        } else if (control.equals("List")) {
            org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(layoutComposite, SWT.BORDER);
            list.setItems(itemValues);
            children[i] = list;
        } else if (control.equals("ProgressBar")) {
            ProgressBar progress = new ProgressBar(layoutComposite, SWT.NONE);
            progress.setSelection(50);
            children[i] = progress;
        } else if (control.equals("Scale")) {
            Scale scale = new Scale(layoutComposite, SWT.NONE);
            children[i] = scale;
        } else if (control.equals("Slider")) {
            Slider slider = new Slider(layoutComposite, SWT.NONE);
            children[i] = slider;
        } else if (control.equals("StyledText")) {
            StyledText styledText = new StyledText(layoutComposite,
                    SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
            styledText.setText(controlName);
            children[i] = styledText;
        } else if (control.equals("Table")) {
            Table table = new Table(layoutComposite, SWT.BORDER);
            table.setLinesVisible(true);
            TableItem item1 = new TableItem(table, 0);
            item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            TableItem item2 = new TableItem(table, 0);
            item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            children[i] = table;
        } else if (control.equals("Text")) {
            Text text = new Text(layoutComposite, SWT.BORDER);
            text.setText(controlName);
            children[i] = text;
        } else if (control.equals("ToolBar")) {
            ToolBar toolBar = new ToolBar(layoutComposite, SWT.BORDER);
            ToolItem item1 = new ToolItem(toolBar, 0);
            item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            ToolItem item2 = new ToolItem(toolBar, 0);
            item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            children[i] = toolBar;
        } else {
            Tree tree = new Tree(layoutComposite, SWT.BORDER);
            TreeItem item1 = new TreeItem(tree, 0);
            item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            TreeItem item2 = new TreeItem(tree, 0);
            item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            children[i] = tree;
        }
    }
}

From source file:PaintExample.java

/**
 * Handles a mouseDown event./*from   w  ww.  jav  a2  s  .  c  o m*/
 * 
 * @param event the mouse event detail information
 */
public void mouseDown(MouseEvent event) {
    if (event.button == 1) {
        // draw with left mouse button
        getPaintSurface().commitRubberbandSelection();
    } else {
        // set text with right mouse button
        getPaintSurface().clearRubberbandSelection();
        Shell shell = getPaintSurface().getShell();
        final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
        dialog.setText(PaintExample.getResourceString("tool.Text.dialog.title"));
        dialog.setLayout(new GridLayout());
        Label label = new Label(dialog, SWT.NONE);
        label.setText(PaintExample.getResourceString("tool.Text.dialog.message"));
        label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
        final Text field = new Text(dialog, SWT.SINGLE | SWT.BORDER);
        field.setText(drawText);
        field.selectAll();
        field.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        Composite buttons = new Composite(dialog, SWT.NONE);
        GridLayout layout = new GridLayout(2, true);
        layout.marginWidth = 0;
        buttons.setLayout(layout);
        buttons.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
        Button ok = new Button(buttons, SWT.PUSH);
        ok.setText(PaintExample.getResourceString("OK"));
        ok.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
        ok.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                drawText = field.getText();
                dialog.dispose();
            }
        });
        Button cancel = new Button(buttons, SWT.PUSH);
        cancel.setText(PaintExample.getResourceString("Cancel"));
        cancel.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                dialog.dispose();
            }
        });
        dialog.setDefaultButton(ok);
        dialog.pack();
        dialog.open();
        Display display = dialog.getDisplay();
        while (!shell.isDisposed() && !dialog.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }
}

From source file:org.eclipse.swt.examples.fileviewer.FileViewer.java

/**
 * Creates the file details table.//w  w w .j  ava 2  s .  c om
 *
 * @param parent the parent control
 */
private void createTableView(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    gridLayout.marginHeight = gridLayout.marginWidth = 2;
    gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
    composite.setLayout(gridLayout);
    tableContentsOfLabel = new Label(composite, SWT.BORDER);
    tableContentsOfLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));

    table = new Table(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));

    for (int i = 0; i < tableTitles.length; ++i) {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText(tableTitles[i]);
        column.setWidth(tableWidths[i]);
    }
    table.setHeaderVisible(true);
    table.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            notifySelectedFiles(getSelectedFiles());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
            doDefaultFileAction(getSelectedFiles());
        }

        private File[] getSelectedFiles() {
            final TableItem[] items = table.getSelection();
            final File[] files = new File[items.length];

            for (int i = 0; i < items.length; ++i) {
                files[i] = (File) items[i].getData(TABLEITEMDATA_FILE);
            }
            return files;
        }
    });

    createTableDragSource(table);
    createTableDropTarget(table);
}

From source file:LayoutExample.java

/**
 * Refreshes the composite and draws all controls in the layout example.
 *//*from  www .  jav a  2  s .  c  o m*/
void refreshLayoutComposite() {
    /* Remove children that are already laid out */
    children = layoutComposite.getChildren();
    for (int i = 0; i < children.length; i++) {
        children[i].dispose();
    }
    /* Add all children listed in the table */
    TableItem[] items = table.getItems();
    children = new Control[items.length];
    String[] itemValues = new String[] { LayoutExample.getResourceString("Item", new String[] { "1" }),
            LayoutExample.getResourceString("Item", new String[] { "2" }),
            LayoutExample.getResourceString("Item", new String[] { "3" }) };
    for (int i = 0; i < items.length; i++) {
        String control = items[i].getText(1);
        if (control.equals("Button")) {
            Button button = new Button(layoutComposite, SWT.PUSH);
            button.setText(LayoutExample.getResourceString("Button_Index",
                    new String[] { new Integer(i).toString() }));
            children[i] = button;
        } else if (control.equals("Canvas")) {
            Canvas canvas = new Canvas(layoutComposite, SWT.BORDER);
            children[i] = canvas;
        } else if (control.equals("Combo")) {
            Combo combo = new Combo(layoutComposite, SWT.NONE);
            combo.setItems(itemValues);
            combo.setText(
                    LayoutExample.getResourceString("Combo_Index", new String[] { new Integer(i).toString() }));
            children[i] = combo;
        } else if (control.equals("Composite")) {
            Composite composite = new Composite(layoutComposite, SWT.BORDER);
            children[i] = composite;
        } else if (control.equals("CoolBar")) {
            CoolBar coolBar = new CoolBar(layoutComposite, SWT.NONE);
            ToolBar toolBar = new ToolBar(coolBar, SWT.BORDER);
            ToolItem item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            CoolItem coolItem1 = new CoolItem(coolBar, 0);
            coolItem1.setControl(toolBar);
            toolBar = new ToolBar(coolBar, SWT.BORDER);
            item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "3" }));
            item = new ToolItem(toolBar, 0);
            item.setText(LayoutExample.getResourceString("Item", new String[] { "4" }));
            CoolItem coolItem2 = new CoolItem(coolBar, 0);
            coolItem2.setControl(toolBar);
            Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            coolItem1.setSize(coolItem1.computeSize(size.x, size.y));
            coolItem2.setSize(coolItem2.computeSize(size.x, size.y));
            coolBar.setSize(coolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            children[i] = coolBar;
        } else if (control.equals("Group")) {
            Group group = new Group(layoutComposite, SWT.NONE);
            group.setText(
                    LayoutExample.getResourceString("Group_Index", new String[] { new Integer(i).toString() }));
            children[i] = group;
        } else if (control.equals("Label")) {
            Label label = new Label(layoutComposite, SWT.NONE);
            label.setText(
                    LayoutExample.getResourceString("Label_Index", new String[] { new Integer(i).toString() }));
            children[i] = label;
        } else if (control.equals("List")) {
            List list = new List(layoutComposite, SWT.BORDER);
            list.setItems(itemValues);
            children[i] = list;
        } else if (control.equals("ProgressBar")) {
            ProgressBar progress = new ProgressBar(layoutComposite, SWT.NONE);
            progress.setSelection(50);
            children[i] = progress;
        } else if (control.equals("Scale")) {
            Scale scale = new Scale(layoutComposite, SWT.NONE);
            children[i] = scale;
        } else if (control.equals("Slider")) {
            Slider slider = new Slider(layoutComposite, SWT.NONE);
            children[i] = slider;
        } else if (control.equals("StyledText")) {
            StyledText styledText = new StyledText(layoutComposite,
                    SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
            styledText.setText(LayoutExample.getResourceString("StyledText_Index",
                    new String[] { new Integer(i).toString() }));
            children[i] = styledText;
        } else if (control.equals("Table")) {
            Table table = new Table(layoutComposite, SWT.BORDER);
            table.setLinesVisible(true);
            TableItem item1 = new TableItem(table, 0);
            item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            TableItem item2 = new TableItem(table, 0);
            item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            children[i] = table;
        } else if (control.equals("Text")) {
            Text text = new Text(layoutComposite, SWT.BORDER);
            text.setText(
                    LayoutExample.getResourceString("Text_Index", new String[] { new Integer(i).toString() }));
            children[i] = text;
        } else if (control.equals("ToolBar")) {
            ToolBar toolBar = new ToolBar(layoutComposite, SWT.BORDER);
            ToolItem item1 = new ToolItem(toolBar, 0);
            item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            ToolItem item2 = new ToolItem(toolBar, 0);
            item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            children[i] = toolBar;
        } else {
            Tree tree = new Tree(layoutComposite, SWT.BORDER);
            TreeItem item1 = new TreeItem(tree, 0);
            item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" }));
            TreeItem item2 = new TreeItem(tree, 0);
            item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" }));
            children[i] = tree;
        }
    }
}

From source file:SWTFileViewerDemo.java

/**
 * Creates the file details table.//from   w  w w  .  j av  a 2  s . co m
 * 
 * @param parent
 *            the parent control
 */
private void createTableView(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    gridLayout.marginHeight = gridLayout.marginWidth = 2;
    gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
    composite.setLayout(gridLayout);
    tableContentsOfLabel = new Label(composite, SWT.BORDER);
    tableContentsOfLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));

    table = new Table(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));

    for (int i = 0; i < tableTitles.length; ++i) {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText(tableTitles[i]);
        column.setWidth(tableWidths[i]);
    }
    table.setHeaderVisible(true);
    table.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            notifySelectedFiles(getSelectedFiles());
        }

        public void widgetDefaultSelected(SelectionEvent event) {
            doDefaultFileAction(getSelectedFiles());
        }

        private File[] getSelectedFiles() {
            final TableItem[] items = table.getSelection();
            final File[] files = new File[items.length];

            for (int i = 0; i < items.length; ++i) {
                files[i] = (File) items[i].getData(TABLEITEMDATA_FILE);
            }
            return files;
        }
    });

    createTableDragSource(table);
    createTableDropTarget(table);
}

From source file:SWTAddressBook.java

/**
 * Class constructor that sets the parent shell and the table widget that
 * the dialog will search./*from  www  .  ja  va2s . c  o  m*/
 * 
 * @param parent
 *            Shell The shell that is the parent of the dialog.
 */
public SearchDialog(Shell parent) {
    shell = new Shell(parent, SWT.CLOSE | SWT.BORDER | SWT.TITLE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    shell.setLayout(layout);
    shell.setText("Search");
    shell.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent e) {
            // don't dispose of the shell, just hide it for later use
            e.doit = false;
            shell.setVisible(false);
        }
    });

    Label label = new Label(shell, SWT.LEFT);
    label.setText("Dialog_find_what");
    searchText = new Text(shell, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchText.setLayoutData(gridData);
    searchText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            boolean enableFind = (searchText.getCharCount() != 0);
            findButton.setEnabled(enableFind);
        }
    });

    searchAreaLabel = new Label(shell, SWT.LEFT);
    searchArea = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchArea.setLayoutData(gridData);

    matchCase = new Button(shell, SWT.CHECK);
    matchCase.setText("Dialog_match_case");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchCase.setLayoutData(gridData);

    matchWord = new Button(shell, SWT.CHECK);
    matchWord.setText("Dialog_match_word");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchWord.setLayoutData(gridData);

    Group direction = new Group(shell, SWT.NONE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    direction.setLayoutData(gridData);
    direction.setLayout(new FillLayout());
    direction.setText("Dialog_direction");

    Button up = new Button(direction, SWT.RADIO);
    up.setText("Dialog_dir_up");
    up.setSelection(false);

    down = new Button(direction, SWT.RADIO);
    down.setText("Dialog_dir_down");
    down.setSelection(true);

    Composite composite = new Composite(shell, SWT.NONE);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    composite.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    composite.setLayout(layout);

    findButton = new Button(composite, SWT.PUSH);
    findButton.setText("Dialog_find");
    findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    findButton.setEnabled(false);
    findButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (!findHandler.find()) {
                MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL);
                box.setText(shell.getText());
                box.setMessage("Cannot_find" + "\"" + searchText.getText() + "\"");
                box.open();
            }
        }
    });

    Button cancelButton = new Button(composite, SWT.PUSH);
    cancelButton.setText("Cancel");
    cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    cancelButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            shell.setVisible(false);
        }
    });

    shell.pack();
}