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

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

Introduction

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

Prototype

public void setData(Object data) 

Source Link

Document

Sets the application defined widget data associated with the receiver to be the argument.

Usage

From source file:org.eclipse.swt.snippets.Snippet336.java

public static void main(String[] args) {
    display = new Display();
    shell = new Shell(display);
    shell.setText("Snippet 336");
    shell.setLayout(new GridLayout());
    TabFolder folder = new TabFolder(shell, SWT.NONE);
    folder.setLayoutData(new GridData(GridData.FILL_BOTH));

    //Progress tab
    TabItem item = new TabItem(folder, SWT.NONE);
    item.setText("Progress");
    Composite composite = new Composite(folder, SWT.NONE);
    composite.setLayout(new GridLayout());
    item.setControl(composite);/*w  w  w . j  a  v a  2  s  .  c o  m*/
    Listener listener = event -> {
        Button button = (Button) event.widget;
        if (!button.getSelection())
            return;
        TaskItem item1 = getTaskBarItem();
        if (item1 != null) {
            int state = ((Integer) button.getData()).intValue();
            item1.setProgressState(state);
        }
    };
    Group group = new Group(composite, SWT.NONE);
    group.setText("State");
    group.setLayout(new GridLayout());
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Button button;
    String[] stateLabels = { "SWT.DEFAULT", "SWT.INDETERMINATE", "SWT.NORMAL", "SWT.ERROR", "SWT.PAUSED" };
    int[] states = { SWT.DEFAULT, SWT.INDETERMINATE, SWT.NORMAL, SWT.ERROR, SWT.PAUSED };
    for (int i = 0; i < states.length; i++) {
        button = new Button(group, SWT.RADIO);
        button.setText(stateLabels[i]);
        button.setData(Integer.valueOf(states[i]));
        button.addListener(SWT.Selection, listener);
        if (i == 0)
            button.setSelection(true);
    }
    group = new Group(composite, SWT.NONE);
    group.setText("Value");
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label label = new Label(group, SWT.NONE);
    label.setText("Progress");
    final Scale scale = new Scale(group, SWT.NONE);
    scale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    scale.addListener(SWT.Selection, event -> {
        TaskItem item1 = getTaskBarItem();
        if (item1 != null)
            item1.setProgress(scale.getSelection());
    });

    //Overlay text tab
    item = new TabItem(folder, SWT.NONE);
    item.setText("Text");
    composite = new Composite(folder, SWT.NONE);
    composite.setLayout(new GridLayout());
    item.setControl(composite);
    group = new Group(composite, SWT.NONE);
    group.setText("Enter a short text:");
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    final Text text = new Text(group, SWT.BORDER | SWT.SINGLE);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    text.setLayoutData(data);
    button = new Button(group, SWT.PUSH);
    button.setText("Set");
    button.addListener(SWT.Selection, event -> {
        TaskItem item1 = getTaskBarItem();
        if (item1 != null)
            item1.setOverlayText(text.getText());
    });
    button = new Button(group, SWT.PUSH);
    button.setText("Clear");
    button.addListener(SWT.Selection, event -> {
        text.setText("");
        TaskItem item1 = getTaskBarItem();
        if (item1 != null)
            item1.setOverlayText("");
    });

    //Overlay image tab
    item = new TabItem(folder, SWT.NONE);
    item.setText("Image");
    composite = new Composite(folder, SWT.NONE);
    composite.setLayout(new GridLayout());
    item.setControl(composite);
    Listener listener3 = event -> {
        Button button1 = (Button) event.widget;
        if (!button1.getSelection())
            return;
        TaskItem item1 = getTaskBarItem();
        if (item1 != null) {
            String text1 = button1.getText();
            Image image = null;
            if (!text1.equals("NONE"))
                image = new Image(display, Snippet336.class.getResourceAsStream(text1));
            Image oldImage = item1.getOverlayImage();
            item1.setOverlayImage(image);
            if (oldImage != null)
                oldImage.dispose();
        }
    };
    group = new Group(composite, SWT.NONE);
    group.setText("Images");
    group.setLayout(new GridLayout());
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    button = new Button(group, SWT.RADIO);
    button.setText("NONE");
    button.addListener(SWT.Selection, listener3);
    button.setSelection(true);
    String[] images = { "eclipse.png", "pause.gif", "run.gif", "warning.gif" };
    for (int i = 0; i < images.length; i++) {
        button = new Button(group, SWT.RADIO);
        button.setText(images[i]);
        button.addListener(SWT.Selection, listener3);
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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   www . j  a v 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();
    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  www.  j a va 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();

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

int showBMPDialog() {
    final int[] bmpType = new int[1];
    bmpType[0] = SWT.IMAGE_BMP;//from w  w w.  ja va 2s .  c o  m
    SelectionListener radioSelected = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Button radio = (Button) event.widget;
            if (radio.getSelection())
                bmpType[0] = ((Integer) radio.getData()).intValue();
        }
    };
    // need to externalize strings
    final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);

    dialog.setText("Save_as");
    dialog.setLayout(new GridLayout());

    Label label = new Label(dialog, SWT.NONE);
    label.setText("Save_as");

    Button radio = new Button(dialog, SWT.RADIO);
    radio.setText("Save_as_type_no_compress");
    radio.setSelection(true);
    radio.setData(new Integer(SWT.IMAGE_BMP));
    radio.addSelectionListener(radioSelected);

    radio = new Button(dialog, SWT.RADIO);
    radio.setText("Save_as_type_rle_compress");
    radio.setData(new Integer(SWT.IMAGE_BMP_RLE));
    radio.addSelectionListener(radioSelected);

    radio = new Button(dialog, SWT.RADIO);
    radio.setText("Save_as_type_os2");
    radio.setData(new Integer(SWT.IMAGE_OS2_BMP));
    radio.addSelectionListener(radioSelected);

    label = new Label(dialog, SWT.SEPARATOR | SWT.HORIZONTAL);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Button ok = new Button(dialog, SWT.PUSH);
    ok.setText("OK");
    GridData data = new GridData();
    data.horizontalAlignment = SWT.CENTER;
    data.widthHint = 75;
    ok.setLayoutData(data);
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            dialog.close();
        }
    });

    dialog.pack();
    dialog.open();
    while (!dialog.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    return bmpType[0];
}

From source file:org.eclipse.swt.examples.imageanalyzer.ImageAnalyzer.java

int showBMPDialog() {
    final int[] bmpType = new int[1];
    bmpType[0] = SWT.IMAGE_BMP;//  www  . jav a 2 s.c  o m
    SelectionListener radioSelected = widgetSelectedAdapter(event -> {
        Button radio = (Button) event.widget;
        if (radio.getSelection())
            bmpType[0] = ((Integer) radio.getData()).intValue();
    });
    // need to externalize strings
    final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM);

    dialog.setText(bundle.getString("Save_as_type"));
    dialog.setLayout(new GridLayout());

    Label label = new Label(dialog, SWT.NONE);
    label.setText(bundle.getString("Save_as_type_label"));

    Button radio = new Button(dialog, SWT.RADIO);
    radio.setText(bundle.getString("Save_as_type_no_compress"));
    radio.setSelection(true);
    radio.setData(Integer.valueOf(SWT.IMAGE_BMP));
    radio.addSelectionListener(radioSelected);

    radio = new Button(dialog, SWT.RADIO);
    radio.setText(bundle.getString("Save_as_type_rle_compress"));
    radio.setData(Integer.valueOf(SWT.IMAGE_BMP_RLE));
    radio.addSelectionListener(radioSelected);

    radio = new Button(dialog, SWT.RADIO);
    radio.setText(bundle.getString("Save_as_type_os2"));
    radio.setData(Integer.valueOf(SWT.IMAGE_OS2_BMP));
    radio.addSelectionListener(radioSelected);

    label = new Label(dialog, SWT.SEPARATOR | SWT.HORIZONTAL);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Button ok = new Button(dialog, SWT.PUSH);
    ok.setText(bundle.getString("OK"));
    GridData data = new GridData();
    data.horizontalAlignment = SWT.CENTER;
    data.widthHint = 75;
    ok.setLayoutData(data);
    ok.addSelectionListener(widgetSelectedAdapter(e -> dialog.close()));

    dialog.pack();
    dialog.open();
    while (!dialog.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    return bmpType[0];
}