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.LineJoinTab.java

@Override
public void createControlPanel(Composite parent) {

    // create drop down combo for choosing clipping
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("LineJoin")); //$NON-NLS-1$
    joinCb = new Combo(comp, SWT.DROP_DOWN);
    joinCb.add(GraphicsExample.getResourceString("bevel")); //$NON-NLS-1$
    joinCb.add(GraphicsExample.getResourceString("miter")); //$NON-NLS-1$
    joinCb.add(GraphicsExample.getResourceString("round")); //$NON-NLS-1$
    joinCb.select(1);/*from  w w w  . jav a  2 s . c  o  m*/
    joinCb.addListener(SWT.Selection, event -> example.redraw());

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

    // initialize the shape color to the 4th item in the menu (green)
    shapeColor = (GraphicsBackground) menu.getItem(3).getData();

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

    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(shapeColor.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:Sample.java

public Sample() {
    shell.setText("Book Entry Demo");

    GridLayout gridLayout = new GridLayout(4, false);
    gridLayout.verticalSpacing = 8;/* ww  w  . j  av  a2s .c o  m*/

    shell.setLayout(gridLayout);

    // Title
    Label label = new Label(shell, SWT.NULL);
    label.setText("Title: ");

    Text title = new Text(shell, SWT.SINGLE | SWT.BORDER);
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 3;
    title.setLayoutData(gridData);

    // Author(s)
    label = new Label(shell, SWT.NULL);
    label.setText("Author(s): ");

    Text authors = new Text(shell, SWT.SINGLE | SWT.BORDER);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 3;
    authors.setLayoutData(gridData);

    // Cover
    label = new Label(shell, SWT.NULL);
    label.setText("Cover: ");

    gridData = new GridData();
    gridData.verticalSpan = 3;
    label.setLayoutData(gridData);

    CLabel cover = new CLabel(shell, SWT.NULL);

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 1;
    gridData.verticalSpan = 3;
    gridData.heightHint = 100;
    gridData.widthHint = 100;

    cover.setLayoutData(gridData);

    // Details.
    label = new Label(shell, SWT.NULL);
    label.setText("Pages");

    Text pages = new Text(shell, SWT.SINGLE | SWT.BORDER);
    pages.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    label = new Label(shell, SWT.NULL);
    label.setText("Publisher");

    Text pubisher = new Text(shell, SWT.SINGLE | SWT.BORDER);
    pubisher.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    label = new Label(shell, SWT.NULL);
    label.setText("Rating");

    Combo rating = new Combo(shell, SWT.READ_ONLY);
    rating.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    rating.add("5");
    rating.add("4");
    rating.add("3");
    rating.add("2");
    rating.add("1");

    // Abstract.

    label = new Label(shell, SWT.NULL);
    label.setText("Abstract:");

    Text bookAbstract = new Text(shell, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    gridData.horizontalSpan = 3;
    gridData.grabExcessVerticalSpace = true;

    bookAbstract.setLayoutData(gridData);

    // Button.
    Button enter = new Button(shell, SWT.PUSH);
    enter.setText("Enter");

    gridData = new GridData();
    gridData.horizontalSpan = 4;
    gridData.horizontalAlignment = GridData.END;
    enter.setLayoutData(gridData);

    // Fill information.

    title.setText("Professional Java Interfaces with SWT/JFace");
    authors.setText("Jack Li Guojie");
    pages.setText("500pp");
    pubisher.setText("John Wiley & Sons");
    cover.setBackground(new Image(display, "java2s.gif"));
    bookAbstract.setText("This book provides a comprehensive guide for \n"
            + "you to create Java user interfaces with SWT/JFace. ");

    shell.pack();
    shell.open();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

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

/**
 * Creates the widgets used to control the drawing.
 *//*from   w ww . jav  a 2s  .c  om*/
@Override
public void createControlPanel(Composite parent) {
    super.createControlPanel(parent);

    // create drop down combo for choosing clipping
    Composite comp;

    // create spinner for line width
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));
    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Alpha")); //$NON-NLS-1$
    alphaSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    alphaSpinner.setMinimum(0);
    alphaSpinner.setMaximum(255);
    alphaSpinner.setSelection(127);
    alphaSpinner.addListener(SWT.Selection, event -> example.redraw());

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

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

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

    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(background.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:com.rcp.wbw.demo.editor.SWTOtherEditor.java

/**
 * Creates a new instance./*w w w.java  2  s  . c  om*/
 * 
 * @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));
            }
        }
    });
}

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

/**
 * Creates the control widgets./*from w w w.ja  v  a  2s . c o m*/
 */
@Override
void createControlWidgets() {
    /* Controls the topControl in the StackLayout */
    Group columnGroup = new Group(controlGroup, SWT.NONE);
    columnGroup.setText("topControl");//(LayoutExample.getResourceString ("Top_Control"));
    columnGroup.setLayout(new GridLayout(3, false));
    columnGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    backButton = new Button(columnGroup, SWT.PUSH);
    backButton.setText("<<");
    backButton.setEnabled(false);
    backButton.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
    backButton.addSelectionListener(
            SelectionListener.widgetSelectedAdapter(e -> setTopControl(currentLayer - 1)));
    topControl = new Label(columnGroup, SWT.BORDER);
    topControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    advanceButton = new Button(columnGroup, SWT.PUSH);
    advanceButton.setText(">>");
    advanceButton.setEnabled(false);
    advanceButton.addSelectionListener(
            SelectionListener.widgetSelectedAdapter(e -> setTopControl(currentLayer + 1)));

    /* Controls the margins of the StackLayout */
    Group marginGroup = new Group(controlGroup, SWT.NONE);
    marginGroup.setText(LayoutExample.getResourceString("Margins"));
    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);

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

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

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

    /* Create the extra widgets */
    wrapButton = new Button(styleGroup, SWT.CHECK);
    wrapButton.setText("SWT.WRAP");
    readOnlyButton = new Button(styleGroup, SWT.CHECK);
    readOnlyButton.setText("SWT.READ_ONLY");
    passwordButton = new Button(styleGroup, SWT.CHECK);
    passwordButton.setText("SWT.PASSWORD");
    searchButton = new Button(styleGroup, SWT.CHECK);
    searchButton.setText("SWT.SEARCH");
    iconCancelButton = new Button(styleGroup, SWT.CHECK);
    iconCancelButton.setText("SWT.ICON_CANCEL");
    iconSearchButton = new Button(styleGroup, SWT.CHECK);
    iconSearchButton.setText("SWT.ICON_SEARCH");

    Composite alignmentGroup = new Composite(styleGroup, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginWidth = layout.marginHeight = 0;
    alignmentGroup.setLayout(layout);
    alignmentGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    leftButton = new Button(alignmentGroup, SWT.RADIO);
    leftButton.setText("SWT.LEFT");
    centerButton = new Button(alignmentGroup, SWT.RADIO);
    centerButton.setText("SWT.CENTER");
    rightButton = new Button(alignmentGroup, SWT.RADIO);
    rightButton.setText("SWT.RIGHT");
}

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

/**
 * Creates a new editor./*from  w  w w  .  ja v a  2 s .c  o  m*/
 * 
 * @param parent  the parent.
 * @param style  the style.
 * @param axis  the axis.
 */
public SWTNumberAxisEditor(Composite parent, int style, NumberAxis axis) {
    super(parent, style, axis);
    this.autoRange = axis.isAutoRange();
    this.minimumValue = axis.getLowerBound();
    this.maximumValue = axis.getUpperBound();

    TabItem item2 = new TabItem(getOtherTabs(), SWT.NONE);
    item2.setText(" " + localizationResources.getString("Range") + " ");
    Composite range = new Composite(getOtherTabs(), SWT.NONE);
    range.setLayout(new GridLayout(2, true));
    item2.setControl(range);

    this.autoRangeCheckBox = new Button(range, SWT.CHECK);
    this.autoRangeCheckBox.setText(localizationResources.getString("Auto-adjust_range"));
    this.autoRangeCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    this.autoRangeCheckBox.setSelection(this.autoRange);
    this.autoRangeCheckBox.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            toggleAutoRange();
        }
    });
    new Label(range, SWT.NONE).setText(localizationResources.getString("Minimum_range_value"));
    this.minimumRangeValue = new Text(range, SWT.BORDER);
    this.minimumRangeValue.setText(String.valueOf(this.minimumValue));
    this.minimumRangeValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    this.minimumRangeValue.setEnabled(!this.autoRange);
    //this.minimumRangeValue.addModifyListener(this);
    //this.minimumRangeValue.addVerifyListener(this);
    this.minimumRangeValue.addFocusListener(this);
    new Label(range, SWT.NONE).setText(localizationResources.getString("Maximum_range_value"));
    this.maximumRangeValue = new Text(range, SWT.BORDER);
    this.maximumRangeValue.setText(String.valueOf(this.maximumValue));
    this.maximumRangeValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    this.maximumRangeValue.setEnabled(!this.autoRange);
    //this.maximumRangeValue.addModifyListener(this);
    //this.maximumRangeValue.addVerifyListener(this);
    this.maximumRangeValue.addFocusListener(this);
}

From source file:ShowPrograms.java

/**
 * Creates the main window's contents/*from w ww.j  a v  a  2 s. c  om*/
 * 
 * @param shell the main window
 */
private void createContents(Shell shell) {
    shell.setLayout(new GridLayout(2, false));

    // Create the label and combo for the extensions
    new Label(shell, SWT.NONE).setText("Extension:");
    Combo extensionsCombo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
    extensionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the label and the
    new Label(shell, SWT.NONE).setText("Program:");
    final Label programName = new Label(shell, SWT.NONE);
    programName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Fill the combo with the extensions on the system
    String[] extensions = Program.getExtensions();
    for (int i = 0, n = extensions.length; i < n; i++) {
        extensionsCombo.add(extensions[i]);
    }

    // Add a handler to get the selected extension, look up the associated
    // program, and display the program's name
    extensionsCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Combo combo = (Combo) event.widget;

            // Get the program for the extension
            Program program = Program.findProgram(combo.getText());

            // Display the program's name
            programName.setText(program == null ? "(None)" : program.getName());
        }
    });

    // Create a list box to show all the programs on the system
    List allPrograms = new List(shell, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    allPrograms.setLayoutData(data);

    // Put all the known programs into the list box
    Program[] programs = Program.getPrograms();
    for (int i = 0, n = programs.length; i < n; i++) {
        String name = programs[i].getName();
        allPrograms.add(name);
        allPrograms.setData(name, programs[i]);
    }

    // Add a field for a data file
    new Label(shell, SWT.NONE).setText("Data File:");
    final Text dataFile = new Text(shell, SWT.BORDER);
    dataFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Double-clicking a program in the list launches the program
    allPrograms.addMouseListener(new MouseAdapter() {
        public void mouseDoubleClick(MouseEvent event) {
            List list = (List) event.widget;
            if (list.getSelectionCount() > 0) {
                String programName = list.getSelection()[0];
                Program program = (Program) list.getData(programName);
                program.execute(dataFile.getText());
            }
        }
    });

    // Let them use launch instead of execute
    Button launch = new Button(shell, SWT.PUSH);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    launch.setLayoutData(data);
    launch.setText("Use Program.launch() instead of Program.execute()");
    launch.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Use launch
            Program.launch(dataFile.getText());
        }
    });
}

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();/*from   w ww .jav a 2 s . c om*/
    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.eclipse.swt.examples.controlexample.SashFormTab.java

/**
 * Creates the "Style" group./*from  w w w.  j  a v a2s.  c  o  m*/
 */
@Override
void createStyleGroup() {
    super.createStyleGroup();

    /* Create the extra widgets */
    horizontalButton = new Button(styleGroup, SWT.RADIO);
    horizontalButton.setText("SWT.HORIZONTAL");
    horizontalButton.setSelection(true);
    verticalButton = new Button(styleGroup, SWT.RADIO);
    verticalButton.setText("SWT.VERTICAL");
    verticalButton.setSelection(false);
    smoothButton = new Button(styleGroup, SWT.CHECK);
    smoothButton.setText("SWT.SMOOTH");
    smoothButton.setSelection(false);
}