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

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

Introduction

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

Prototype

public void setText(String text) 

Source Link

Document

Sets the receiver's text.

Usage

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

public void open(Display display) {
    Shell shell = new Shell(display);
    shell.setText("OLE Example");
    shell.setLayout(new FillLayout());

    Composite parent = new Composite(shell, SWT.NONE);
    parent.setLayout(new GridLayout(4, true));

    Composite buttons = new Composite(parent, SWT.NONE);
    buttons.setLayout(new GridLayout());
    GridData gridData = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    buttons.setLayoutData(gridData);//from   w w  w  .ja va 2 s  .c o  m

    Composite displayArea = new Composite(parent, SWT.BORDER);
    displayArea.setLayout(new FillLayout());
    displayArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));

    Button excelButton = new Button(buttons, SWT.RADIO);
    excelButton.setText("New Excel Sheet");
    excelButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        if (((Button) e.widget).getSelection())
            newClientSite("Excel.Sheet");
    }));
    Button mediaPlayerButton = new Button(buttons, SWT.RADIO);
    mediaPlayerButton.setText("New MPlayer");
    mediaPlayerButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        if (((Button) e.widget).getSelection())
            newClientSite("MPlayer");
    }));
    Button powerPointButton = new Button(buttons, SWT.RADIO);
    powerPointButton.setText("New PowerPoint Slide");
    powerPointButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        if (((Button) e.widget).getSelection())
            newClientSite("PowerPoint.Slide");
    }));
    Button wordButton = new Button(buttons, SWT.RADIO);
    wordButton.setText("New Word Document");
    wordButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        if (((Button) e.widget).getSelection())
            newClientSite("Word.Document");
    }));
    new Label(buttons, SWT.NONE);
    Button openButton = new Button(buttons, SWT.RADIO);
    openButton.setText("Open file...");
    openButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        if (((Button) e.widget).getSelection())
            fileOpen();
    }));
    new Label(buttons, SWT.NONE);
    closeButton = new Button(buttons, SWT.RADIO);
    closeButton.setText("Close file");
    closeButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        if (((Button) e.widget).getSelection())
            disposeClient();
    }));
    closeButton.setSelection(true);

    oleFrame = new OleFrame(displayArea, SWT.NONE);
    addFileMenu(oleFrame);

    shell.setSize(800, 600);
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java

public SWTInstanceToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver,
        NetworkNode networkNode, int x, int y) {
    super(parent, x, y);

    this.networkNode = networkNode;

    final Color backgroundColor = getShell().getBackground();
    final Color foregroundColor = getShell().getForeground();

    boolean isProfilingEnabled = false;
    final InstanceVisualizationData instanceVisualizationData = (InstanceVisualizationData) networkNode
            .getAttachment();// ww w  . j  a v  a  2  s.c o  m
    if (instanceVisualizationData != null) {
        isProfilingEnabled = instanceVisualizationData.isProfilingEnabledForJob();
    }

    int height;

    // Set the title
    setTitle(networkNode.getName());

    // Only create chart if profiling is enabled
    if (isProfilingEnabled) {
        this.cpuChart = createCPUChart(instanceVisualizationData, backgroundColor);
        this.cpuChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        this.memoryChart = createMemoryChart(instanceVisualizationData, backgroundColor);
        this.memoryChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        this.networkChart = createNetworkChart(instanceVisualizationData, backgroundColor);
        this.networkChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        height = 460;
    } else {
        this.cpuChart = null;
        this.memoryChart = null;
        this.networkChart = null;
        height = 75;
    }

    // Available instance actions
    final Composite instanceActionComposite = new Composite(getShell(), SWT.NONE);
    instanceActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
    instanceActionComposite.setBackground(backgroundColor);
    instanceActionComposite.setForeground(foregroundColor);

    final Button killInstanceButton = new Button(instanceActionComposite, SWT.PUSH);
    final String instanceName = this.networkNode.getName();
    killInstanceButton.setText("Kill instance...");
    killInstanceButton.setEnabled(this.networkNode.isLeafNode());
    killInstanceButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            commandReceiver.killInstance(instanceName);
        }

    });

    getShell().setSize(WIDTH, height);

    finishInstantiation(x, y, WIDTH, false);
}

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

SWTPlotAppearanceEditor(Composite parent, int style, Plot plot) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    this.setLayout(layout);

    Group general = new Group(this, SWT.NONE);
    GridLayout groupLayout = new GridLayout(3, false);
    groupLayout.marginHeight = groupLayout.marginWidth = 4;
    general.setLayout(groupLayout);/*from  w w  w  .  j a  va 2s. c  o  m*/
    general.setText(localizationResources.getString("General"));

    // row 1: stroke
    new Label(general, SWT.NONE).setText(localizationResources.getString("Outline_stroke"));
    this.strokeCanvas = new SWTStrokeCanvas(general, SWT.NONE);
    this.strokeCanvas.setStroke(plot.getOutlineStroke());
    GridData strokeGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    strokeGridData.heightHint = 20;
    this.strokeCanvas.setLayoutData(strokeGridData);
    this.selectStroke = new Spinner(general, SWT.BORDER);
    this.selectStroke.setMinimum(1);
    this.selectStroke.setMaximum(3);
    this.selectStroke.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    this.selectStroke.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int w = SWTPlotAppearanceEditor.this.selectStroke.getSelection();
            if (w > 0) {
                SWTPlotAppearanceEditor.this.strokeCanvas.setStroke(new BasicStroke(w));
                SWTPlotAppearanceEditor.this.strokeCanvas.redraw();
            }
        }
    });
    // row 2: outline color
    new Label(general, SWT.NONE).setText(localizationResources.getString("Outline_Paint"));
    this.outlinePaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), plot.getOutlinePaint()));
    GridData outlineGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    outlineGridData.heightHint = 20;
    this.outlinePaintCanvas.setLayoutData(outlineGridData);
    Button selectOutlineColor = new Button(general, SWT.PUSH);
    selectOutlineColor.setText(localizationResources.getString("Select..."));
    selectOutlineColor.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectOutlineColor.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Outline_Paint"));
            dlg.setRGB(SWTPlotAppearanceEditor.this.outlinePaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTPlotAppearanceEditor.this.outlinePaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
    // row 3: background paint
    new Label(general, SWT.NONE).setText(localizationResources.getString("Background_paint"));
    this.backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), plot.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(SWTPlotAppearanceEditor.this.backgroundPaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTPlotAppearanceEditor.this.backgroundPaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
    // row 4: orientation
    if (plot instanceof CategoryPlot) {
        this.plotOrientation = ((CategoryPlot) plot).getOrientation();
    } else if (plot instanceof XYPlot) {
        this.plotOrientation = ((XYPlot) plot).getOrientation();
    }
    if (this.plotOrientation != null) {
        boolean isVertical = this.plotOrientation.equals(PlotOrientation.VERTICAL);
        int index = isVertical ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL;
        new Label(general, SWT.NONE).setText(localizationResources.getString("Orientation"));
        this.orientation = new Combo(general, SWT.DROP_DOWN);
        this.orientation.setItems(orientationNames);
        this.orientation.select(index);
        this.orientation.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 2, 1));
        this.orientation.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                switch (SWTPlotAppearanceEditor.this.orientation.getSelectionIndex()) {
                case ORIENTATION_VERTICAL:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.VERTICAL;
                    break;
                case ORIENTATION_HORIZONTAL:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.HORIZONTAL;
                    break;
                default:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.VERTICAL;
                }
            }
        });
    }
}

From source file:BackupFiles.java

/**
 * Helper method to create the label/text/button for a directory
 * //  w w  w  .j  a  v  a 2 s  .  c  o  m
 * @param composite
 *            the parent composite
 * @param label
 *            the text for the label
 * @return Text
 */
private Text createFilePanelHelper(Composite composite, String label) {
    // Create the composite to hold the controls
    Composite panel = new Composite(composite, SWT.BORDER);
    panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    panel.setLayout(new GridLayout(3, false));

    // Create the controls
    new Label(panel, SWT.LEFT).setText(label);
    Text text = new Text(panel, SWT.BORDER);
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Button browse = new Button(panel, SWT.PUSH);

    // Add browsing
    browse.setText("...");
    browse.addSelectionListener(new DirectoryBrowser(text));

    // Return the Text that holds the directory
    return text;
}

From source file:com.rcp.wbw.demo.editor.SWTPlotAppearanceEditor.java

SWTPlotAppearanceEditor(Composite parent, int style, Plot plot) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);/*from   w ww.  ja v a  2  s  .c o  m*/

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

    // row 1: stroke
    new Label(general, SWT.NONE).setText(localizationResources.getString("Outline_stroke"));
    this.strokeCanvas = new SWTStrokeCanvas(general, SWT.NONE);
    this.strokeCanvas.setStroke(plot.getOutlineStroke());
    GridData strokeGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    strokeGridData.heightHint = 20;
    this.strokeCanvas.setLayoutData(strokeGridData);
    this.selectStroke = new Spinner(general, SWT.BORDER);
    this.selectStroke.setMinimum(1);
    this.selectStroke.setMaximum(3);
    this.selectStroke.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    this.selectStroke.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int w = SWTPlotAppearanceEditor.this.selectStroke.getSelection();
            if (w > 0) {
                SWTPlotAppearanceEditor.this.strokeCanvas.setStroke(new BasicStroke(w));
                SWTPlotAppearanceEditor.this.strokeCanvas.redraw();
            }
        }
    });
    // row 2: outline color
    new Label(general, SWT.NONE).setText(localizationResources.getString("Outline_Paint"));
    this.outlinePaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), plot.getOutlinePaint()));
    GridData outlineGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    outlineGridData.heightHint = 20;
    this.outlinePaintCanvas.setLayoutData(outlineGridData);
    Button selectOutlineColor = new Button(general, SWT.PUSH);
    selectOutlineColor.setText(localizationResources.getString("Select..."));
    selectOutlineColor.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectOutlineColor.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Outline_Paint"));
            dlg.setRGB(SWTPlotAppearanceEditor.this.outlinePaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTPlotAppearanceEditor.this.outlinePaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
    // row 3: background paint
    new Label(general, SWT.NONE).setText(localizationResources.getString("Background_paint"));
    this.backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), plot.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(SWTPlotAppearanceEditor.this.backgroundPaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTPlotAppearanceEditor.this.backgroundPaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
    // row 4: orientation
    if (plot instanceof CategoryPlot) {
        this.plotOrientation = ((CategoryPlot) plot).getOrientation();
    } else if (plot instanceof XYPlot) {
        this.plotOrientation = ((XYPlot) plot).getOrientation();
    }
    if (this.plotOrientation != null) {
        boolean isVertical = this.plotOrientation.equals(PlotOrientation.VERTICAL);
        int index = isVertical ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL;
        new Label(general, SWT.NONE).setText(localizationResources.getString("Orientation"));
        this.orientation = new Combo(general, SWT.DROP_DOWN);
        this.orientation.setItems(orientationNames);
        this.orientation.select(index);
        this.orientation.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 2, 1));
        this.orientation.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                switch (SWTPlotAppearanceEditor.this.orientation.getSelectionIndex()) {
                case ORIENTATION_VERTICAL:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.VERTICAL;
                    break;
                case ORIENTATION_HORIZONTAL:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.HORIZONTAL;
                    break;
                default:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.VERTICAL;
                }
            }
        });
    }
}

From source file:PICalculator.java

public Thread getTask2(Button button) {
    final Button theButton = button;
    return new Thread() {

        public void run() {
            final double pi = calculatePI(9999999);

            display.asyncExec(new Runnable() {
                public void run() {

                    // Update UI.

                    theButton.setText("PI = " + pi);

                }/*from   w w  w.  j  ava2  s  .  co  m*/
            });
        }
    };
}

From source file:BackupFiles.java

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

    // 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:CheckFileTree.java

/**
 * Creates the main window's contents//from  w  w w .ja v  a2 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 checkbox to toggle whether the labels preserve case
    Button preserveCase = new Button(composite, SWT.CHECK);
    preserveCase.setText("&Preserve case");

    // Create the tree viewer to display the file tree
    final TreeViewer tv = new TreeViewer(composite);
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput("root"); // pass a non-null that will be ignored

    // When user checks the checkbox, toggle the preserve case attribute
    // of the label provider
    preserveCase.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            boolean preserveCase = ((Button) event.widget).getSelection();
            FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv.getLabelProvider();
            ftlp.setPreserveCase(preserveCase);
        }
    });
    return composite;
}

From source file:org.amanzi.awe.charts.ui.ChartsView.java

/**
 * Creates radio button with the text specified and assigns the layout data
 * //from  ww  w.  j av a 2 s . co m
 * @param parent parent composite
 * @param chartType TODO
 */
private Button createRadioButton(final Composite parent, final String text, final boolean selected,
        final ChartType chartType) {
    Button radioButton = new Button(parent, SWT.RADIO);
    radioButton.setText(text);
    radioButton.setSelection(selected);

    GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    radioButton.setLayoutData(layoutData);
    radioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            type = chartType;
            onItemSelected();
        }
    });
    return radioButton;
}

From source file:CheckFileTree.java

/**
 * Creates the main window's contents/*from ww w .  j a  v  a  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));

    // Add a checkbox to toggle whether the labels preserve case
    Button preserveCase = new Button(composite, SWT.CHECK);
    preserveCase.setText("&Preserve case");

    // Create the tree viewer to display the file tree
    final CheckboxTreeViewer tv = new CheckboxTreeViewer(composite);
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput("root"); // pass a non-null that will be ignored

    // When user checks the checkbox, toggle the preserve case attribute
    // of the label provider
    preserveCase.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            boolean preserveCase = ((Button) event.widget).getSelection();
            FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv.getLabelProvider();
            ftlp.setPreserveCase(preserveCase);
        }
    });

    // When user checks a checkbox in the tree, check all its children
    tv.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            // If the item is checked . . .
            if (event.getChecked()) {
                // . . . check all its children
                tv.setSubtreeChecked(event.getElement(), true);
            }
        }
    });
    return composite;
}