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.jfree.experimental.chart.swt.editor.SWTTitleEditor.java

/**
 * Standard constructor: builds a panel for displaying/editing the
 * properties of the specified title./*from  w  w  w  .j a va2  s  . com*/
 *
 * @param title  the title, which should be changed.
 */
SWTTitleEditor(Composite parent, int style, Title title) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);

    TextTitle t = (title != null ? (TextTitle) title : new TextTitle(localizationResources.getString("Title")));
    this.showTitle = (title != null);
    this.titleFont = SWTUtils.toSwtFontData(getDisplay(), t.getFont(), true);
    this.titleColor = SWTUtils.toSwtColor(getDisplay(), t.getPaint());

    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));
    // row 1
    Label label = new Label(general, SWT.NONE);
    label.setText(localizationResources.getString("Show_Title"));
    GridData gridData = new GridData();
    gridData.horizontalSpan = 2;
    label.setLayoutData(gridData);
    this.showTitleCheckBox = new Button(general, SWT.CHECK);
    this.showTitleCheckBox.setSelection(this.showTitle);
    this.showTitleCheckBox.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    this.showTitleCheckBox.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            SWTTitleEditor.this.showTitle = SWTTitleEditor.this.showTitleCheckBox.getSelection();
        }
    });
    // row 2
    new Label(general, SWT.NONE).setText(localizationResources.getString("Text"));
    this.titleField = new Text(general, SWT.BORDER);
    this.titleField.setText(t.getText());
    this.titleField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(general, SWT.NONE).setText("");
    // row 3
    new Label(general, SWT.NONE).setText(localizationResources.getString("Font"));
    this.fontField = new Text(general, SWT.BORDER);
    this.fontField.setText(this.titleFont.toString());
    this.fontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    this.selectFontButton = new Button(general, SWT.PUSH);
    this.selectFontButton.setText(localizationResources.getString("Select..."));
    this.selectFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the font-change dialog
            FontDialog dlg = new FontDialog(getShell());
            dlg.setText(localizationResources.getString("Font_Selection"));
            dlg.setFontList(new FontData[] { SWTTitleEditor.this.titleFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTTitleEditor.this.font != null) {
                    SWTTitleEditor.this.font.dispose();
                }
                // Create the new font and set it into the title 
                // label
                SWTTitleEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                //titleField.setFont(font);
                SWTTitleEditor.this.fontField.setText(SWTTitleEditor.this.font.getFontData()[0].toString());
                SWTTitleEditor.this.titleFont = SWTTitleEditor.this.font.getFontData()[0];
            }
        }
    });
    // row 4
    new Label(general, SWT.NONE).setText(localizationResources.getString("Color"));
    // Use a SwtPaintCanvas to show the color, note that we must set the 
    // heightHint.
    final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.titleColor);
    GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    canvasGridData.heightHint = 20;
    colorCanvas.setLayoutData(canvasGridData);
    this.selectColorButton = new Button(general, SWT.PUSH);
    this.selectColorButton.setText(localizationResources.getString("Select..."));
    this.selectColorButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Title_Color"));
            dlg.setRGB(SWTTitleEditor.this.titleColor.getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                // create the new color and set it to the 
                // SwtPaintCanvas
                SWTTitleEditor.this.titleColor = new Color(getDisplay(), rgb);
                colorCanvas.setColor(SWTTitleEditor.this.titleColor);
            }
        }
    });
}

From source file:at.ac.tuwien.inso.subcat.ui.widgets.TimeChartControlPanel.java

public TimeChartControlPanel(Composite parent, int style) {
    super(parent, SWT.NONE);
    setLayout(new GridLayout(3, false));

    Composite composite = new Composite(this, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    GridLayout gl_composite = new GridLayout(3, false);
    gl_composite.verticalSpacing = 0;//from   w  ww .j a v  a  2  s. com
    gl_composite.marginWidth = 0;
    gl_composite.marginHeight = 0;
    gl_composite.horizontalSpacing = 0;
    composite.setLayout(gl_composite);

    // Chart, Top Panel:
    new Label(composite, SWT.NONE);
    ;

    Composite chartTopComposite = new Composite(composite, SWT.NONE);
    GridLayout chartBottomLayout = new GridLayout(3, true);
    chartTopComposite.setLayout(chartBottomLayout);
    chartBottomLayout.verticalSpacing = 0;
    chartBottomLayout.marginWidth = 0;
    chartBottomLayout.marginHeight = 0;
    chartBottomLayout.horizontalSpacing = 0;

    chartTopComposite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
    yearSelector = new Combo(chartTopComposite, SWT.READ_ONLY);

    chartTopComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    chartSelector = new Combo(chartTopComposite, SWT.READ_ONLY);
    chartSelector.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));

    chartTopComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    Button saveButton = new Button(chartTopComposite, SWT.NONE);
    saveButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
    saveButton.setText("Save");

    new Label(composite, SWT.NONE);

    // Chart Row:
    btnPrev = new Button(composite, SWT.NONE);
    btnPrev.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    btnPrev.setText("<");

    // TODO: drop scrolledComposite 
    scrolledComposite = new ScrolledComposite(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setLayout(new FillLayout());

    chartComposite = new ChartComposite(scrolledComposite, SWT.NONE, null);
    chartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    chartComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
    scrolledComposite.setContent(chartComposite);

    btnNext = new Button(composite, SWT.NONE);
    btnNext.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    btnNext.setText(">");

    // ** Event handling:

    chartSelector.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            for (TimeChartControlPanelListener listener : listeners) {
                listener.chartSelectionChanged();
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    // *** Year Setting:
    yearSelector.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            btnPrev.setEnabled(hasPrevChart());
            btnNext.setEnabled(hasNextChart());

            triggerChartSelected();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    btnPrev.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            yearSelector.select(yearSelector.getSelectionIndex() - 1);
            btnPrev.setEnabled(hasPrevChart());
            btnNext.setEnabled(hasNextChart());

            triggerChartSelected();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    btnNext.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            yearSelector.select(yearSelector.getSelectionIndex() + 1);
            btnPrev.setEnabled(hasPrevChart());
            btnNext.setEnabled(hasNextChart());

            triggerChartSelected();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    saveButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(TimeChartControlPanel.this.getShell(), SWT.SAVE);
            fd.setText("Save Chart");
            String[] filterExt = { "*.png", "*.jpg" };
            fd.setFilterExtensions(filterExt);
            String selectedPath = fd.open();
            if (selectedPath == null) {
                return;
            }

            for (TimeChartControlPanelListener listener : listeners) {
                listener.chartSaveRequest(selectedPath);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}

From source file:BugTracker.java

public BugTracker() {
    GridLayout gridLayout = new GridLayout();
    shell.setLayout(gridLayout);/*  ww w  . j a  v  a 2s . c om*/
    shell.setText("Bug Tracking System");

    // Action.
    Action actionAddNew = new Action("New bug") {
        public void run() {
            // Append.
            TableItem item = new TableItem(table, SWT.NULL);
            item.setImage(bugIcon);
            table.select(table.getItemCount() - 1);
        }
    };

    Action actionDelete = new Action("Delete selected") {
        public void run() {
            int index = table.getSelectionIndex();
            if (index < 0) {
                System.out.println("Please select an item first. ");
                return;
            }
            MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO);
            messageBox.setText("Confirmation");
            messageBox.setMessage("Are you sure to remove the bug with id #" + table.getItem(index).getText(0));
            if (messageBox.open() == SWT.YES) {
                table.remove(index);
            }
        }
    };

    Action actionSave = new Action("Save") {
        public void run() {
            saveBugs();
        }
    };

    ToolBar toolBar = new ToolBar(shell, SWT.RIGHT | SWT.FLAT);

    ToolBarManager manager = new ToolBarManager(toolBar);
    manager.add(actionAddNew);
    manager.add(actionDelete);
    manager.add(new Separator());
    manager.add(actionSave);
    manager.update(true);

    table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
    table.setLayoutData(new GridData(GridData.FILL_BOTH));

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

    TableColumn tcID = new TableColumn(table, SWT.LEFT);
    tcID.setText("ID");

    TableColumn tcSummary = new TableColumn(table, SWT.NULL);
    tcSummary.setText("Summary");

    TableColumn tcAssignedTo = new TableColumn(table, SWT.NULL);
    tcAssignedTo.setText("Assigned to");

    TableColumn tcSolved = new TableColumn(table, SWT.NULL);
    tcSolved.setText("Solved");

    tcID.setWidth(60);
    tcSummary.setWidth(200);
    tcAssignedTo.setWidth(80);
    tcSolved.setWidth(50);

    table.pack();

    // Table editor.
    final TableEditor editor = new TableEditor(table);

    table.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event event) {
            // Locate the cell position.
            Point point = new Point(event.x, event.y);
            final TableItem item = table.getItem(point);
            if (item == null)
                return;
            int column = -1;
            for (int i = 0; i < table.getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(point))
                    column = i;
            }
            if (column != 3)
                return;

            // Cell position located, now open the table editor.

            final Button button = new Button(table, SWT.CHECK);
            button.setSelection(item.getText(column).equalsIgnoreCase("YES"));

            editor.horizontalAlignment = SWT.LEFT;
            editor.grabHorizontal = true;

            editor.setEditor(button, item, column);

            final int selectedColumn = column;
            Listener buttonListener = new Listener() {
                public void handleEvent(final Event e) {
                    switch (e.type) {
                    case SWT.FocusOut:
                        item.setText(selectedColumn, button.getSelection() ? "YES" : "NO");
                        button.dispose();
                        break;
                    case SWT.Traverse:
                        switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                            item.setText(selectedColumn, button.getSelection() ? "YES" : "NO");
                            //FALL THROUGH
                        case SWT.TRAVERSE_ESCAPE:
                            button.dispose();
                            e.doit = false;
                        }
                        break;
                    }
                }
            };

            button.addListener(SWT.FocusOut, buttonListener);
            button.addListener(SWT.Traverse, buttonListener);

            button.setFocus();

        }
    });

    table.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event event) {
            // Locate the cell position.
            Point point = new Point(event.x, event.y);
            final TableItem item = table.getItem(point);
            if (item == null)
                return;
            int column = -1;
            for (int i = 0; i < table.getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(point))
                    column = i;
            }
            if (column < 0 || column >= 3)
                return;

            // Cell position located, now open the table editor.

            final Text text = new Text(table, SWT.NONE);
            text.setText(item.getText(column));

            editor.horizontalAlignment = SWT.LEFT;
            editor.grabHorizontal = true;

            editor.setEditor(text, item, column);

            final int selectedColumn = column;
            Listener textListener = new Listener() {
                public void handleEvent(final Event e) {
                    switch (e.type) {
                    case SWT.FocusOut:
                        item.setText(selectedColumn, text.getText());
                        text.dispose();
                        break;
                    case SWT.Traverse:
                        switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                            item.setText(selectedColumn, text.getText());
                            //FALL THROUGH
                        case SWT.TRAVERSE_ESCAPE:
                            text.dispose();
                            e.doit = false;
                        }
                        break;
                    }
                }
            };

            text.addListener(SWT.FocusOut, textListener);
            text.addListener(SWT.Traverse, textListener);

            text.setFocus();
        }

    });

    loadBugs();

    table.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            System.out.println("Selected: " + table.getSelection()[0]);
        }
    });

    Listener sortListener = new Listener() {
        public void handleEvent(Event event) {
            if (!(event.widget instanceof TableColumn))
                return;
            TableColumn tc = (TableColumn) event.widget;
            sortTable(table, table.indexOf(tc));
            System.out.println("The table is sorted by column #" + table.indexOf(tc));
        }
    };

    for (int i = 0; i < table.getColumnCount(); i++)
        ((TableColumn) table.getColumn(i)).addListener(SWT.Selection, sortListener);

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // 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:com.rcp.wbw.demo.editor.SWTTitleEditor.java

/**
 * Standard constructor: builds a panel for displaying/editing the
 * properties of the specified title.//from   ww w .  j a  v a  2s. c o  m
 * 
 * @param parent
 *            the parent.
 * @param style
 *            the style.
 * @param title
 *            the title, which should be changed.
 * 
 */
SWTTitleEditor(Composite parent, int style, Title title) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);

    TextTitle t = (title != null ? (TextTitle) title : new TextTitle(localizationResources.getString("Title")));
    this.showTitle = (title != null);
    this.titleFont = SWTUtils.toSwtFontData(getDisplay(), t.getFont(), true);
    this.titleColor = SWTUtils.toSwtColor(getDisplay(), t.getPaint());

    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));
    // row 1
    Label label = new Label(general, SWT.NONE);
    label.setText(localizationResources.getString("Show_Title"));
    GridData gridData = new GridData();
    gridData.horizontalSpan = 2;
    label.setLayoutData(gridData);
    this.showTitleCheckBox = new Button(general, SWT.CHECK);
    this.showTitleCheckBox.setSelection(this.showTitle);
    this.showTitleCheckBox.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    this.showTitleCheckBox.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            SWTTitleEditor.this.showTitle = SWTTitleEditor.this.showTitleCheckBox.getSelection();
        }
    });
    // row 2
    new Label(general, SWT.NONE).setText(localizationResources.getString("Text"));
    this.titleField = new Text(general, SWT.BORDER);
    this.titleField.setText(t.getText());
    this.titleField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(general, SWT.NONE).setText("");
    // row 3
    new Label(general, SWT.NONE).setText(localizationResources.getString("Font"));
    this.fontField = new Text(general, SWT.BORDER);
    this.fontField.setText(this.titleFont.toString());
    this.fontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    this.selectFontButton = new Button(general, SWT.PUSH);
    this.selectFontButton.setText(localizationResources.getString("Select..."));
    this.selectFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the font-change dialog
            FontDialog dlg = new FontDialog(getShell());
            dlg.setText(localizationResources.getString("Font_Selection"));
            dlg.setFontList(new FontData[] { SWTTitleEditor.this.titleFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTTitleEditor.this.font != null) {
                    SWTTitleEditor.this.font.dispose();
                }
                // Create the new font and set it into the title
                // label
                SWTTitleEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                // titleField.setFont(font);
                SWTTitleEditor.this.fontField.setText(SWTTitleEditor.this.font.getFontData()[0].toString());
                SWTTitleEditor.this.titleFont = SWTTitleEditor.this.font.getFontData()[0];
            }
        }
    });
    // row 4
    new Label(general, SWT.NONE).setText(localizationResources.getString("Color"));
    // Use a SwtPaintCanvas to show the color, note that we must set the
    // heightHint.
    final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.titleColor);
    GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    canvasGridData.heightHint = 20;
    colorCanvas.setLayoutData(canvasGridData);
    this.selectColorButton = new Button(general, SWT.PUSH);
    this.selectColorButton.setText(localizationResources.getString("Select..."));
    this.selectColorButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Title_Color"));
            dlg.setRGB(SWTTitleEditor.this.titleColor.getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                // create the new color and set it to the
                // SwtPaintCanvas
                SWTTitleEditor.this.titleColor = new Color(getDisplay(), rgb);
                colorCanvas.setColor(SWTTitleEditor.this.titleColor);
            }
        }
    });
}

From source file:KalendarDialog.java

public Object open() {
    Shell parent = getParent();//w  ww .java 2 s  .co m
    display = Display.getDefault();
    shell = new Shell(parent, SWT.TITLE | SWT.PRIMARY_MODAL);
    shell.setText("Calendar ver0.02");
    shell.setSize(230, 220);

    gridLayout = new GridLayout();
    gridLayout.numColumns = 7;
    shell.setLayout(gridLayout);

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    yearUp = new Button(shell, SWT.PUSH | SWT.FLAT);
    yearUp.setText("<");
    yearUp.setLayoutData(gridData);
    yearUp.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            previousYear();
        }
    });

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    monthUp = new Button(shell, SWT.PUSH | SWT.FLAT);
    monthUp.setText("<<");
    monthUp.setLayoutData(gridData);
    monthUp.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            previousMonth();
        }
    });

    nowLabel = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    nowLabel.setLayoutData(gridData);
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
    nowLabel.setText(formatter.format(new Date()));

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    monthNext = new Button(shell, SWT.PUSH | SWT.FLAT);
    monthNext.setText(">>");
    monthNext.setLayoutData(gridData);
    monthNext.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            nextMonth();
        }
    });

    gridData = new GridData(GridData.FILL_HORIZONTAL);
    yearNext = new Button(shell, SWT.PUSH | SWT.FLAT);
    yearNext.setText(">");
    yearNext.setLayoutData(gridData);
    yearNext.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            nextYear();
        }
    });

    sunday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    sunday.setLayoutData(gridData);
    sunday.setText("Sun");

    monday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    monday.setLayoutData(gridData);
    monday.setText("Mon");

    tuesday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    tuesday.setLayoutData(gridData);
    tuesday.setText("Tue");

    wednesday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    wednesday.setLayoutData(gridData);
    wednesday.setText("Wed");

    thursday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    thursday.setLayoutData(gridData);
    thursday.setText("Thu");

    friday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    friday.setLayoutData(gridData);
    friday.setText("Fri");

    saturday = new CLabel(shell, SWT.CENTER | SWT.SHADOW_OUT);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gridData.widthHint = 20;
    gridData.heightHint = 20;
    saturday.setLayoutData(gridData);
    saturday.setText("Sat");

    for (int i = 0; i < 42; i++) {
        days[i] = new CLabel(shell, SWT.FLAT | SWT.CENTER);
        gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
        days[i].setLayoutData(gridData);
        days[i].setBackground(display.getSystemColor(SWT.COLOR_WHITE));
        days[i].addMouseListener(this);
        days[i].setToolTipText("double click get current date.");
    }

    Calendar now = Calendar.getInstance(); //
    nowDate = new Date(now.getTimeInMillis());
    setDayForDisplay(now);

    shell.open();
    Display display = parent.getDisplay();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    return selectedDate;
}

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

/**
 * Creates the "Example" widgets./*from  ww  w.j a  v a2  s . com*/
 */
@Override
void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (pushButton.getSelection())
        style |= SWT.PUSH;
    if (checkButton.getSelection())
        style |= SWT.CHECK;
    if (radioButton.getSelection())
        style |= SWT.RADIO;
    if (toggleButton.getSelection())
        style |= SWT.TOGGLE;
    if (flatButton.getSelection())
        style |= SWT.FLAT;
    if (wrapButton.getSelection())
        style |= SWT.WRAP;
    if (borderButton.getSelection())
        style |= SWT.BORDER;
    if (leftButton.getSelection())
        style |= SWT.LEFT;
    if (rightButton.getSelection())
        style |= SWT.RIGHT;
    if (arrowButton.getSelection()) {
        style |= SWT.ARROW;
        if (upButton.getSelection())
            style |= SWT.UP;
        if (downButton.getSelection())
            style |= SWT.DOWN;
    } else {
        if (centerButton.getSelection())
            style |= SWT.CENTER;
    }

    /* Create the example widgets */
    button1 = new Button(textButtonGroup, style);
    button1.setText(ControlExample.getResourceString("One"));
    button2 = new Button(textButtonGroup, style);
    button2.setText(ControlExample.getResourceString("Two"));
    button3 = new Button(textButtonGroup, style);
    if (wrapButton.getSelection()) {
        button3.setText(ControlExample.getResourceString("Wrap_Text"));
    } else {
        button3.setText(ControlExample.getResourceString("Three"));
    }
    button4 = new Button(imageButtonGroup, style);
    button4.setImage(instance.images[ControlExample.ciClosedFolder]);
    button5 = new Button(imageButtonGroup, style);
    button5.setImage(instance.images[ControlExample.ciOpenFolder]);
    button6 = new Button(imageButtonGroup, style);
    button6.setImage(instance.images[ControlExample.ciTarget]);
    button7 = new Button(imagetextButtonGroup, style);
    button7.setText(ControlExample.getResourceString("One"));
    button7.setImage(instance.images[ControlExample.ciClosedFolder]);
    button8 = new Button(imagetextButtonGroup, style);
    button8.setText(ControlExample.getResourceString("Two"));
    button8.setImage(instance.images[ControlExample.ciOpenFolder]);
    button9 = new Button(imagetextButtonGroup, style);
    if (wrapButton.getSelection()) {
        button9.setText(ControlExample.getResourceString("Wrap_Text"));
    } else {
        button9.setText(ControlExample.getResourceString("Three"));
    }
    button9.setImage(instance.images[ControlExample.ciTarget]);
}

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

@Override
void createOtherGroup() {
    /* Create the group */
    otherGroup = new Group(controlGroup, SWT.NONE);
    otherGroup.setLayout(new GridLayout());
    otherGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    otherGroup.setText(ControlExample.getResourceString("Other"));

    /* Create the controls */
    autoHideButton = new Button(otherGroup, SWT.CHECK);
    autoHideButton.setText(ControlExample.getResourceString("AutoHide"));
    showInTrayButton = new Button(otherGroup, SWT.CHECK);
    showInTrayButton.setText(ControlExample.getResourceString("Show_In_Tray"));
    tray = display.getSystemTray();//from w ww  .ja  va2 s  .  c o  m
    showInTrayButton.setEnabled(tray != null);

    /* Add the listeners */
    autoHideButton.addSelectionListener(widgetSelectedAdapter(event -> setExampleWidgetAutoHide()));
    showInTrayButton.addSelectionListener(widgetSelectedAdapter(event -> showExampleWidgetInTray()));
    shell.addDisposeListener(event -> disposeTrayItem());

    /* Set the default state */
    autoHideButton.setSelection(true);
}

From source file:au.gov.ansto.bragg.kakadu.ui.plot.FitPlotPropertiesComposite.java

private void initialise() {
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;//ww  w .ja  va2  s . c o m
    gridLayout.marginHeight = 3;
    gridLayout.marginWidth = 3;
    gridLayout.horizontalSpacing = 3;
    gridLayout.verticalSpacing = 3;
    setLayout(gridLayout);

    fitEnabledButton = new Button(this, SWT.CHECK);
    fitEnabledButton.setText("Fitting Enabled");
    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    data.horizontalSpan = 2;
    data.grabExcessHorizontalSpace = true;
    fitEnabledButton.setLayoutData(data);

    fitFunctionCombo = new Combo(this, SWT.READ_ONLY);
    fitFunctionCombo.setEnabled(false);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    data.verticalIndent = 3;
    data.grabExcessHorizontalSpace = true;
    fitFunctionCombo.setLayoutData(data);

    //      inverseLabel = new Label(this, SWT.NONE);
    //      inverseLabel.setText("inverse function");
    //      data = new GridData ();
    //      data.verticalAlignment = GridData.BEGINNING;
    //      data.verticalIndent = 3;
    //      inverseLabel.setLayoutData(data);
    //      inverseLabel.setEnabled(false);

    inverseButton = new Button(this, SWT.CHECK);
    inverseButton.setText("Inverted Model");
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalIndent = 3;
    data.grabExcessHorizontalSpace = true;
    inverseButton.setLayoutData(data);
    inverseButton.setEnabled(false);
    //      fitFunctionCombo.setLayoutData (data);

    Composite xComposite = new Composite(this, SWT.NULL);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 4;
    //      gridLayout.marginHeight = 3;
    gridLayout.marginWidth = 0;
    //      gridLayout.horizontalSpacing = 3;
    //      gridLayout.verticalSpacing = 3;
    xComposite.setLayout(gridLayout);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    data.grabExcessHorizontalSpace = true;
    xComposite.setLayoutData(data);

    minXButton = new Button(xComposite, SWT.TOGGLE);
    minXButton.setText("X min");
    minXButton.setToolTipText("Click to enable grabing a point from the plot as the beginning of fitting data");
    data = new GridData();
    //      data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    //      data.grabExcessHorizontalSpace = true;
    //      data.grabExcessVerticalSpace = true;
    minXButton.setLayoutData(data);
    minXButton.setEnabled(false);

    minXText = new Text(xComposite, SWT.BORDER);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    data.grabExcessHorizontalSpace = true;
    //      data.grabExcessVerticalSpace = true;
    minXText.setLayoutData(data);
    minXText.setEnabled(false);

    maxXButton = new Button(xComposite, SWT.TOGGLE);
    maxXButton.setText("X max");
    maxXButton.setToolTipText("Click to enable grabing a point from the plot as the end of fitting data");
    data = new GridData();
    //      data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    //      data.grabExcessHorizontalSpace = true;
    //      data.grabExcessVerticalSpace = true;
    maxXButton.setLayoutData(data);
    maxXButton.setEnabled(false);

    maxXText = new Text(xComposite, SWT.BORDER);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    data.grabExcessHorizontalSpace = true;
    //      data.grabExcessVerticalSpace = true;
    maxXText.setLayoutData(data);
    maxXText.setEnabled(false);

    doFitButton = new Button(this, SWT.PUSH);
    doFitButton.setText("Fit");
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    data.grabExcessHorizontalSpace = true;
    //      data.grabExcessVerticalSpace = true;
    doFitButton.setLayoutData(data);
    doFitButton.setEnabled(false);

    resetButton = new Button(this, SWT.PUSH);
    resetButton.setText("Reset");
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.BEGINNING;
    data.grabExcessHorizontalSpace = true;
    resetButton.setLayoutData(data);
    resetButton.setEnabled(false);

    parameterGroup = new Group(this, SWT.NONE);
    parameterGroup.setText("Parameters");
    GridLayout propertiesGridLayout = new GridLayout();
    propertiesGridLayout.numColumns = 2;
    propertiesGridLayout.marginHeight = 3;
    propertiesGridLayout.marginWidth = 3;
    propertiesGridLayout.horizontalSpacing = 3;
    propertiesGridLayout.verticalSpacing = 3;
    parameterGroup.setLayout(propertiesGridLayout);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.horizontalSpan = 2;
    data.grabExcessHorizontalSpace = true;
    data.verticalAlignment = GridData.BEGINNING;
    parameterGroup.setLayoutData(data);

}

From source file:SampleListViewer.java

private void addButtons() {
    Composite composite = new Composite(shell, SWT.NULL);
    FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
    fillLayout.spacing = 2;//  ww w.j ava2 s.co m

    composite.setLayout(fillLayout);

    buttonAdd = new Button(composite, SWT.PUSH);
    buttonAdd.setText("Add");

    buttonModify = new Button(composite, SWT.PUSH);
    buttonModify.setText("Modify");

    buttonRemove = new Button(composite, SWT.PUSH);
    buttonRemove.setText("Remove");

    buttonAdd.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            //            String text = OptionPane.showInputDialog(shell, "New language genre: ", "Add new element", null);
            //         if(text != null) {
            //         languages.add(new Language(text, true));
            //   }

            listViewer.refresh(false);
        }
    });

    buttonModify.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection();
            Language language = (Language) selection.getFirstElement();
            if (language == null) {
                System.out.println("Please select a language first.");
                return;
            }

            //            String text = OptionPane.showInputDialog(shell, "Rename: ", "Modify genre", language.genre);
            //         if(text != null) {
            //         language.genre = text;
            //   }

            listViewer.update(language, null);
        }
    });

    buttonRemove.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection();
            Language language = (Language) selection.getFirstElement();
            if (language == null) {
                System.out.println("Please select a language first.");
                return;
            }

            languages.remove(language);
            System.out.println("Removed: " + language);

            listViewer.refresh(false);
        }
    });
}

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

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

    /* Create the extra widgets */
    webKitButton = new Button(styleGroup, SWT.CHECK);
    webKitButton.setText("SWT.WEBKIT");
    borderButton = new Button(styleGroup, SWT.CHECK);
    borderButton.setText("SWT.BORDER");
}