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

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

Introduction

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

Prototype


public Button(Composite parent, int style) 

Source Link

Document

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

Usage

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

@Override
public void createControlPanel(Composite parent) {

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

    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("LineWidth")); //$NON-NLS-1$
    lineWidthSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    lineWidthSpinner.setSelection(10);
    lineWidthSpinner.setMinimum(1);
    lineWidthSpinner.setMaximum(30);
    lineWidthSpinner.addListener(SWT.Selection, event -> example.redraw());

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

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

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

    // color button
    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(lineColor.getThumbNail());
    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

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

/**
 * Creates the "Style" group./*w w w.j  a  v  a 2 s .c om*/
 */
@Override
void createStyleGroup() {
    super.createStyleGroup();

    /* Create the extra widgets */
    shadowEtchedInButton = new Button(styleGroup, SWT.RADIO);
    shadowEtchedInButton.setText("SWT.SHADOW_ETCHED_IN");
    shadowEtchedInButton.setSelection(true);
    shadowEtchedOutButton = new Button(styleGroup, SWT.RADIO);
    shadowEtchedOutButton.setText("SWT.SHADOW_ETCHED_OUT");
    shadowInButton = new Button(styleGroup, SWT.RADIO);
    shadowInButton.setText("SWT.SHADOW_IN");
    shadowOutButton = new Button(styleGroup, SWT.RADIO);
    shadowOutButton.setText("SWT.SHADOW_OUT");
    shadowNoneButton = new Button(styleGroup, SWT.RADIO);
    shadowNoneButton.setText("SWT.SHADOW_NONE");
    borderButton = new Button(styleGroup, SWT.CHECK);
    borderButton.setText("SWT.BORDER");
}

From source file:MainClass.java

public RowComposite(Composite c) {
    super(c, SWT.NO_FOCUS);
    RowLayout rl = new RowLayout();
    rl.wrap = false;//from   ww  w  .j  a  v a  2 s. co  m
    rl.pack = false;
    this.setLayout(rl);
    okBtn = new Button(this, SWT.BORDER | SWT.PUSH);
    okBtn.setText("OK");
    okBtn.setSize(30, 20);
    cancelBtn = new Button(this, SWT.BORDER | SWT.PUSH);
    cancelBtn.setText("Cancel");
    cancelBtn.setSize(30, 20);
    cancelBtn.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println("Cancel was clicked");
        }
    });
}

From source file:PersonEditor.java

/**
 * Creates the main window's contents/*w w  w .j  a  v  a  2  s  .c  om*/
 * 
 * @param parent
 *            the main window
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    // Add a button to create the new person
    Button newPerson = new Button(composite, SWT.PUSH);
    newPerson.setText("Create New Person");

    // Add the TableViewer
    final TableViewer tv = new TableViewer(composite, SWT.FULL_SELECTION);
    tv.setContentProvider(new PersonContentProvider());
    tv.setLabelProvider(new PersonLabelProvider());
    tv.setInput(people);

    // Set up the table
    Table table = tv.getTable();
    table.setLayoutData(new GridData(GridData.FILL_BOTH));

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

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

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

    // Add a new person when the user clicks button
    newPerson.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Person p = new Person();
            p.setName("Name");
            p.setMale(true);
            p.setAgeRange(Integer.valueOf("0"));
            p.setShirtColor(new RGB(255, 0, 0));
            people.add(p);
            tv.refresh();
        }
    });

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

    // Set the editors, cell modifier, and column properties
    tv.setColumnProperties(PROPS);
    tv.setCellModifier(new PersonCellModifier(tv));
    tv.setCellEditors(editors);

    return composite;
}

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

@Override
public void createControlPanel(Composite parent) {

    Composite comp;// www  .jav  a2s  . com

    // create drop down combo for antialiasing
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));
    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Antialiasing")); //$NON-NLS-1$
    aliasCombo = new Combo(comp, SWT.DROP_DOWN);
    aliasCombo.add("OFF");
    aliasCombo.add("DEFAULT");
    aliasCombo.add("ON");
    aliasCombo.select(0);
    aliasCombo.addListener(SWT.Selection, event -> example.redraw());

    ColorMenu cm = new ColorMenu();
    cm.setColorItems(true);
    menu = cm.createMenu(parent.getParent(), gb -> {
        ovalColorGB = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

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

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

    // color button
    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(ovalColorGB.getThumbNail());
    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

From source file:BackupFiles.java

/**
 * Creates the main window's contents/*from  w ww .j  a  va  2  s.c o  m*/
 * 
 * @param parent
 *            the main window
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    // Create the source directory panel and its controls
    final Text sourceDir = createFilePanelHelper(composite, "Source Dir:");

    // Create the CheckboxTableViewer to display the files in the source dir
    final CheckboxTableViewer ctv = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
    ctv.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    ctv.setContentProvider(new BackupFilesContentProvider());
    ctv.setLabelProvider(new BackupFilesLabelProvider());

    // Create the destination directory panel and its controls
    final Text destDir = createFilePanelHelper(composite, "Dest Dir:");

    // Create the Copy button
    Button copy = new Button(composite, SWT.PUSH);
    copy.setText("Copy");

    // Create the status field
    status = new Label(composite, SWT.NONE);
    status.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // When the source directory changes, change the input for the viewer
    sourceDir.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            ctv.setInput(((Text) event.widget).getText());
        }
    });

    // When copy is pressed, copy the files
    copy.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Get the checked elements
            Object[] files = ctv.getCheckedElements();
            if (files.length > 0) {
                // Some files are checked; make sure we have a valid
                // destination
                File dest = new File(destDir.getText());
                if (dest.isDirectory()) {
                    // Go through each file
                    for (int i = 0, n = files.length; i < n; i++) {
                        copyFile((File) files[i], dest);
                    }
                } else
                    showMessage("You must select a valid destination directory");
            } else
                showMessage("You must select some files to copy");
        }
    });

    return composite;
}

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

/**
 * Creates the control widgets./*w  w w.  j  av  a2s .c om*/
 */
@Override
void createControlWidgets() {
    /* Controls the type of FillLayout */
    Group typeGroup = new Group(controlGroup, SWT.NONE);
    typeGroup.setText(LayoutExample.getResourceString("Type"));
    typeGroup.setLayout(new GridLayout());
    typeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    horizontal = new Button(typeGroup, SWT.RADIO);
    horizontal.setText("SWT.HORIZONTAL");
    horizontal.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    horizontal.setSelection(true);
    horizontal.addSelectionListener(selectionListener);
    vertical = new Button(typeGroup, SWT.RADIO);
    vertical.setText("SWT.VERTICAL");
    vertical.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    vertical.addSelectionListener(selectionListener);

    /* Controls the margins and spacing of the FillLayout */
    Group marginGroup = new Group(controlGroup, SWT.NONE);
    marginGroup.setText(LayoutExample.getResourceString("Margins_Spacing"));
    marginGroup.setLayout(new GridLayout(2, false));
    marginGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    new Label(marginGroup, SWT.NONE).setText("marginWidth");
    marginWidth = new Spinner(marginGroup, SWT.BORDER);
    marginWidth.setSelection(0);
    marginWidth.addSelectionListener(selectionListener);
    new Label(marginGroup, SWT.NONE).setText("marginHeight");
    marginHeight = new Spinner(marginGroup, SWT.BORDER);
    marginHeight.setSelection(0);
    marginHeight.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    marginHeight.addSelectionListener(selectionListener);
    new Label(marginGroup, SWT.NONE).setText("spacing");
    spacing = new Spinner(marginGroup, SWT.BORDER);
    spacing.setSelection(0);
    spacing.addSelectionListener(selectionListener);

    /* Add common controls */
    super.createControlWidgets();
}

From source file:org.eclipse.swt.examples.addressbook.SearchDialog.java

/**
 * Class constructor that sets the parent shell and the table widget that
 * the dialog will search./*from w ww. j a  v a2s.c  om*/
 *
 * @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(resAddressBook.getString("Search_dialog_title"));
    shell.addShellListener(ShellListener.shellClosedAdapter(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(resAddressBook.getString("Dialog_find_what"));
    searchText = new Text(shell, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchText.setLayoutData(gridData);
    searchText.addModifyListener(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(resAddressBook.getString("Dialog_match_case"));
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchCase.setLayoutData(gridData);

    matchWord = new Button(shell, SWT.CHECK);
    matchWord.setText(resAddressBook.getString("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(resAddressBook.getString("Dialog_direction"));

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

    down = new Button(direction, SWT.RADIO);
    down.setText(resAddressBook.getString("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(resAddressBook.getString("Dialog_find"));
    findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    findButton.setEnabled(false);
    findButton.addSelectionListener(widgetSelectedAdapter(e -> {
        if (!findHandler.find()) {
            MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL);
            box.setText(shell.getText());
            box.setMessage(resAddressBook.getString("Cannot_find") + "\"" + searchText.getText() + "\"");
            box.open();
        }
    }));

    Button cancelButton = new Button(composite, SWT.PUSH);
    cancelButton.setText(resAddressBook.getString("Cancel"));
    cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    cancelButton.addSelectionListener(widgetSelectedAdapter(e -> shell.setVisible(false)));
    shell.pack();
}

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

@Override
public void createControlPanel(Composite parent) {

    Composite comp;/*from  w w  w.j a  v  a  2 s. c om*/

    // create drop down combo for antialiasing
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));
    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Antialiasing")); //$NON-NLS-1$
    aliasCombo = new Combo(comp, SWT.DROP_DOWN);
    aliasCombo.add("OFF");
    aliasCombo.add("DEFAULT");
    aliasCombo.add("ON");
    aliasCombo.select(0);
    aliasCombo.addListener(SWT.Selection, event -> example.redraw());

    ColorMenu cm = new ColorMenu();
    cm.setColorItems(true);
    menu = cm.createMenu(parent.getParent(), gb -> {
        textColor = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

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

    // initialize the color to black
    textColor = (GraphicsBackground) menu.getItem(1).getData();

    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(textColor.getThumbNail());

    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

From source file:org.jfree.experimental.chart.swt.editor.SWTOtherEditor.java

/**
 * Creates a new instance./*from  w ww  .  j  a  v a 2s .c o  m*/
 * 
 * @param parent  the parent.
 * @param style  the style.
 * @param chart  the chart.
 */
public SWTOtherEditor(Composite parent, int style, JFreeChart chart) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);

    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));

    // row 1: antialiasing
    this.antialias = new Button(general, SWT.CHECK);
    this.antialias.setText(localizationResources.getString("Draw_anti-aliased"));
    this.antialias.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
    this.antialias.setSelection(chart.getAntiAlias());

    //row 2: background paint for the chart
    new Label(general, SWT.NONE).setText(localizationResources.getString("Background_paint"));
    this.backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), chart.getBackgroundPaint()));
    GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    bgGridData.heightHint = 20;
    this.backgroundPaintCanvas.setLayoutData(bgGridData);
    Button selectBgPaint = new Button(general, SWT.PUSH);
    selectBgPaint.setText(localizationResources.getString("Select..."));
    selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectBgPaint.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Background_paint"));
            dlg.setRGB(SWTOtherEditor.this.backgroundPaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTOtherEditor.this.backgroundPaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
}