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.controlexample.CoolBarTab.java

/**
 * Creates the "Other" group.//from www.  j a  v a  2 s  .c o  m
 */
@Override
void createOtherGroup() {
    super.createOtherGroup();

    /* Create display controls specific to this example */
    lockedButton = new Button(otherGroup, SWT.CHECK);
    lockedButton.setText(ControlExample.getResourceString("Locked"));

    /* Add the listeners */
    lockedButton.addSelectionListener(widgetSelectedAdapter(event -> setWidgetLocked()));
}

From source file:SWT2D.java

private void run() {
    // Create top level shell
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Java 2D Example");
    // GridLayout for canvas and button
    shell.setLayout(new GridLayout());
    // Create container for AWT canvas
    final Composite canvasComp = new Composite(shell, SWT.EMBEDDED);
    // Set preferred size
    GridData data = new GridData();
    data.widthHint = 600;//from  w w  w  .  j  a v  a2s  .  c om
    data.heightHint = 500;
    canvasComp.setLayoutData(data);
    // Create AWT Frame for Canvas
    java.awt.Frame canvasFrame = SWT_AWT.new_Frame(canvasComp);
    // Create Canvas and add it to the Frame
    final java.awt.Canvas canvas = new java.awt.Canvas();
    canvasFrame.add(canvas);
    // Get graphical context and cast to Java2D
    final java.awt.Graphics2D g2d = (java.awt.Graphics2D) canvas.getGraphics();
    // Enable antialiasing
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Remember initial transform
    final java.awt.geom.AffineTransform origTransform = g2d.getTransform();
    // Create Clear button and position it
    Button clearButton = new Button(shell, SWT.PUSH);
    clearButton.setText("Clear");
    data = new GridData();
    data.horizontalAlignment = GridData.CENTER;
    clearButton.setLayoutData(data);
    // Event processing for Clear button
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            // Delete word list and redraw canvas
            wordList.clear();
            canvasComp.redraw();
        }
    });
    // Process canvas mouse clicks
    canvas.addMouseListener(new java.awt.event.MouseListener() {
        public void mouseClicked(java.awt.event.MouseEvent e) {
        }

        public void mouseEntered(java.awt.event.MouseEvent e) {
        }

        public void mouseExited(java.awt.event.MouseEvent e) {
        }

        public void mousePressed(java.awt.event.MouseEvent e) {
            // Manage pop-up editor
            display.syncExec(new Runnable() {
                public void run() {
                    if (eShell == null) {
                        // Create new Shell: non-modal!
                        eShell = new Shell(shell, SWT.NO_TRIM | SWT.MODELESS);
                        eShell.setLayout(new FillLayout());
                        // Text input field
                        eText = new Text(eShell, SWT.BORDER);
                        eText.setText("Text rotation in the SWT?");
                        eShell.pack();
                        // Set position (Display coordinates)
                        java.awt.Rectangle bounds = canvas.getBounds();
                        org.eclipse.swt.graphics.Point pos = canvasComp.toDisplay(bounds.width / 2,
                                bounds.height / 2);
                        Point size = eShell.getSize();
                        eShell.setBounds(pos.x, pos.y, size.x, size.y);
                        // Open Shell
                        eShell.open();
                    } else if (!eShell.isVisible()) {
                        // Editor versteckt, sichtbar machen
                        eShell.setVisible(true);
                    } else {
                        // Editor is visible - get text
                        String t = eText.getText();
                        // set editor invisible
                        eShell.setVisible(false);
                        // Add text to list and redraw canvas
                        wordList.add(t);
                        canvasComp.redraw();
                    }
                }
            });
        }

        public void mouseReleased(java.awt.event.MouseEvent e) {
        }
    });
    // Redraw the canvas
    canvasComp.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            // Pass the redraw task to AWT event queue
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    // Compute canvas center
                    java.awt.Rectangle bounds = canvas.getBounds();
                    int originX = bounds.width / 2;
                    int originY = bounds.height / 2;
                    // Reset canvas
                    g2d.setTransform(origTransform);
                    g2d.setColor(java.awt.Color.WHITE);
                    g2d.fillRect(0, 0, bounds.width, bounds.height);
                    // Set font
                    g2d.setFont(new java.awt.Font("Myriad", java.awt.Font.PLAIN, 32));
                    double angle = 0d;
                    // Prepare star shape
                    double increment = Math.toRadians(30);
                    Iterator iter = wordList.iterator();
                    while (iter.hasNext()) {
                        // Determine text colors in RGB color cycle
                        float red = (float) (0.5 + 0.5 * Math.sin(angle));
                        float green = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(120)));
                        float blue = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(240)));
                        g2d.setColor(new java.awt.Color(red, green, blue));
                        // Redraw text
                        String text = (String) iter.next();
                        g2d.drawString(text, originX + 50, originY);
                        // Rotate for next text output
                        g2d.rotate(increment, originX, originY);
                        angle += increment;
                    }
                }
            });
        }
    });
    // Finish shell and open it
    shell.pack();
    shell.open();
    // SWT event processing
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

/**
 * Creates the "Style" group./*from  w  w w.ja va 2  s .  co m*/
 */
@Override
void createStyleGroup() {
    super.createStyleGroup();

    /* Create the extra widgets */
    readOnlyButton = new Button(styleGroup, SWT.CHECK);
    readOnlyButton.setText("SWT.READ_ONLY");
    borderButton = new Button(styleGroup, SWT.CHECK);
    borderButton.setText("SWT.BORDER");
    flatButton = new Button(styleGroup, SWT.CHECK);
    flatButton.setText("SWT.FLAT");
}

From source file:WidgetTest2.java

public static Button createImageButton(Composite composite) {
    final Button button = new Button(composite, SWT.PUSH);
    Display display = composite.getDisplay();
    final Image image = new Image(display, "images/button1.gif");
    button.setImage(image);/*from   w  ww  .ja v  a 2s .c  o  m*/
    //       React to click events
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println("Key was pressed");
        }
    });
    //       Dispose image when button is disposed
    button.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            image.dispose();
        }
    });
    return button;
}

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

/**
 * Creates the "Style" group.//from  www . j ava2s .co m
 */
@Override
void createStyleGroup() {
    super.createStyleGroup();

    /* Create the extra widgets */
    dateButton = new Button(styleGroup, SWT.RADIO);
    dateButton.setText("SWT.DATE");
    timeButton = new Button(styleGroup, SWT.RADIO);
    timeButton.setText("SWT.TIME");
    calendarButton = new Button(styleGroup, SWT.RADIO);
    calendarButton.setText("SWT.CALENDAR");
    Group formatGroup = new Group(styleGroup, SWT.NONE);
    formatGroup.setLayout(new GridLayout());
    shortButton = new Button(formatGroup, SWT.RADIO);
    shortButton.setText("SWT.SHORT");
    mediumButton = new Button(formatGroup, SWT.RADIO);
    mediumButton.setText("SWT.MEDIUM");
    longButton = new Button(formatGroup, SWT.RADIO);
    longButton.setText("SWT.LONG");
    dropDownButton = new Button(styleGroup, SWT.CHECK);
    dropDownButton.setText("SWT.DROP_DOWN");
    weekNumbersButton = new Button(styleGroup, SWT.CHECK);
    weekNumbersButton.setText("SWT.CALENDAR_WEEKNUMBERS");
    borderButton = new Button(styleGroup, SWT.CHECK);
    borderButton.setText("SWT.BORDER");
}

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

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

    // 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
    Composite 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:msi.gama.hpc.gui.perspective.chart.HeadlessChart.java

private void createDataset() {
    lstvarname_flag = new ArrayList<String>();
    lsttimestep = new ArrayList<Integer>();
    lstchkbox = new ArrayList<Button>();
    readDataset();//from   w  ww  .  java2s  .  c  om
    ArrayList<Result> listres = sim.result;
    int n = 0;
    series = new ArrayList<XYSeries>();
    for (int i = 0; i < listres.size(); i++) {
        String varname = listres.get(i).getName();
        if (lstvarname_flag.contains(varname)) {
            int idx = lstvarname_flag.indexOf(varname);
            lsttimestep.set(idx, lsttimestep.get(idx) + 1);
            series.get(idx).add(lsttimestep.get(idx), listres.get(i).getValue());
        } else {
            lstvarname_flag.add(varname);
            Button b1 = new Button(comp.getParent(), SWT.CHECK);
            b1.setText("Show " + varname);
            b1.setSelection(true);
            b1.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    // TODO Auto-generated method stub
                    showChart();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                    // TODO Auto-generated method stub

                }

            });
            lstchkbox.add(b1);
            lsttimestep.add(new Integer(0));
            XYSeries ss = new XYSeries(varname);
            series.add(ss);
        }
        // System.out.println(" " + listres.get(i).getName()+" " + listres.get(i).getValue());
    }

}

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

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

    /* Create the extra widgets */
    shadowNoneButton = new Button(styleGroup, SWT.RADIO);
    shadowNoneButton.setText("SWT.SHADOW_NONE");
    shadowInButton = new Button(styleGroup, SWT.RADIO);
    shadowInButton.setText("SWT.SHADOW_IN");
    shadowOutButton = new Button(styleGroup, SWT.RADIO);
    shadowOutButton.setText("SWT.SHADOW_OUT");
}

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

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

    /* Create the extra widgets */
    topButton = new Button(styleGroup, SWT.RADIO);
    topButton.setText("SWT.TOP");
    topButton.setSelection(true);
    bottomButton = new Button(styleGroup, SWT.RADIO);
    bottomButton.setText("SWT.BOTTOM");
    borderButton = new Button(styleGroup, SWT.CHECK);
    borderButton.setText("SWT.BORDER");
}

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

/**
 * This method creates a spinner for specifying the number of petals. The call to the
 * createControlPanel method in the super class create the controls that are
 * defined in the super class./* w  w  w . j a v  a 2s.c o m*/
 *
 * @param parent The parent composite
 */
@Override
public void createControlPanel(Composite parent) {
    super.createControlPanel(parent);

    // create spinner number of petals
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Petals")); //$NON-NLS-1$
    petalSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    petalSpinner.setSelection(8);
    petalSpinner.setMinimum(3);
    petalSpinner.setMaximum(20);
    petalSpinner.addListener(SWT.Selection, event -> example.redraw());

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

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

    // initialize the foreground to the 2nd item in the menu
    foreground = (GraphicsBackground) menu.getItem(1).getData();

    // color button
    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(foreground.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);
    });
}