Example usage for org.eclipse.swt.widgets Composite getShell

List of usage examples for org.eclipse.swt.widgets Composite getShell

Introduction

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

Prototype

public Shell getShell() 

Source Link

Document

Returns the receiver's shell.

Usage

From source file:widgetTest3.java

/** * Printing ** */

public static void createPrintButton(final Composite composite) {
    //       Create button for starting printing process
    final Button printButton = new Button(composite, SWT.PUSH);
    printButton.setText("Print");
    //       React to clicks
    printButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            // Get Shell instance
            Shell shell = composite.getShell();
            // Create printer selection dialog
            PrintDialog printDialog = new PrintDialog(shell);
            // and open it
            PrinterData printerData = printDialog.open();
            // Check if OK was pressed
            if (printerData != null) {
                // Create new Printer instance
                Printer printer = new Printer(printerData);
                // Create graphics context for this printer
                GC gc = new GC(printer);
                // Open printing task
                if (!printer.startJob("Hello"))
                    System.out.println("Starting printer task failed");
                else {
                    // Print first page
                    if (!printer.startPage())
                        System.out.println("Printing of page 1 failed");
                    else {
                        // Get green system color from printer
                        // and set it as text color
                        Color green = printer.getSystemColor(SWT.COLOR_DARK_GREEN);
                        gc.setForeground(green);
                        // Draw text
                        gc.drawText("Hello World", 4, 4, true);
                        // Close page
                        printer.endPage();
                    }//from w w  w  . j a v a  2  s. com
                    // Print second page
                    if (!printer.startPage())
                        System.out.println("Printing of page 2 failed");
                    else {
                        // Get blue system color from printer
                        // and set it as text color
                        Color blue = printer.getSystemColor(SWT.COLOR_BLUE);
                        gc.setForeground(blue);
                        // Draw text
                        gc.drawText("Hello Eclipse", 4, 4, true);
                        // Close page
                        printer.endPage();
                    }
                    // Close printing task
                    printer.endJob();
                }
                // Release operating system resources
                gc.dispose();
                printer.dispose();
            }
        }
    });
}

From source file:DumbUser.java

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

    // Create the button
    Button show = new Button(composite, SWT.NONE);
    show.setText("Show");

    final Shell shell = parent.getShell();

    // Display the dialog
    show.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create and show the dialog
            DumbMessageDialog dlg = new DumbMessageDialog(shell);
            dlg.open();
        }
    });

    parent.pack();
    return composite;
}

From source file:ShowMyTitleAreaDialog.java

/**
 * Creates the main window's contents//from  w w  w.  j  ava2  s  .com
 * 
 * @param parent the main window
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));

    // Create the button
    Button show = new Button(composite, SWT.NONE);
    show.setText("Show");

    final Shell shell = parent.getShell();

    // Display the TitleAreaDialog
    show.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create and show the dialog
            MyTitleAreaDialog dlg = new MyTitleAreaDialog(shell);
            dlg.open();
        }
    });

    parent.pack();
    return composite;
}

From source file:HoverHelp.java

/**
 * Creates the example/*  w w  w . ja v  a 2  s. c  om*/
 */
public void createPartControl(Composite frame) {
    final ToolTipHandler tooltip = new ToolTipHandler(frame.getShell());

    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    frame.setLayout(layout);

    ToolBar bar = new ToolBar(frame, SWT.BORDER);
    for (int i = 0; i < 5; i++) {
        ToolItem item = new ToolItem(bar, SWT.PUSH);
        item.setText(getResourceString("ToolItem.text", new Object[] { new Integer(i) }));
        item.setData("TIP_TEXT", getResourceString("ToolItem.tooltip", new Object[] { item.getText() }));
        item.setData("TIP_HELPTEXTHANDLER", new ToolTipHelpTextHandler() {
            public String getHelpText(Widget widget) {
                Item item = (Item) widget;
                return getResourceString("ToolItem.help", new Object[] { item.getText() });
            }
        });
    }
    GridData gridData = new GridData();
    gridData.horizontalSpan = 3;
    bar.setLayoutData(gridData);
    tooltip.activateHoverHelp(bar);

    Table table = new Table(frame, SWT.BORDER);
    for (int i = 0; i < 4; i++) {
        TableItem item = new TableItem(table, SWT.PUSH);
        item.setText(getResourceString("Item", new Object[] { new Integer(i) }));
        item.setData("TIP_IMAGE", images[hhiInformation]);
        item.setText(getResourceString("TableItem.text", new Object[] { new Integer(i) }));
        item.setData("TIP_TEXT", getResourceString("TableItem.tooltip", new Object[] { item.getText() }));
        item.setData("TIP_HELPTEXTHANDLER", new ToolTipHelpTextHandler() {
            public String getHelpText(Widget widget) {
                Item item = (Item) widget;
                return getResourceString("TableItem.help", new Object[] { item.getText() });
            }
        });
    }
    table.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));
    tooltip.activateHoverHelp(table);

    Tree tree = new Tree(frame, SWT.BORDER);
    for (int i = 0; i < 4; i++) {
        TreeItem item = new TreeItem(tree, SWT.PUSH);
        item.setText(getResourceString("Item", new Object[] { new Integer(i) }));
        item.setData("TIP_IMAGE", images[hhiWarning]);
        item.setText(getResourceString("TreeItem.text", new Object[] { new Integer(i) }));
        item.setData("TIP_TEXT", getResourceString("TreeItem.tooltip", new Object[] { item.getText() }));
        item.setData("TIP_HELPTEXTHANDLER", new ToolTipHelpTextHandler() {
            public String getHelpText(Widget widget) {
                Item item = (Item) widget;
                return getResourceString("TreeItem.help", new Object[] { item.getText() });
            }
        });
    }
    tree.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));
    tooltip.activateHoverHelp(tree);

    Button button = new Button(frame, SWT.PUSH);
    button.setText(getResourceString("Hello.text"));
    button.setData("TIP_TEXT", getResourceString("Hello.tooltip"));
    tooltip.activateHoverHelp(button);
}

From source file:MainClass.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));

    final Button indeterminate = new Button(composite, SWT.CHECK);
    indeterminate.setText("Indeterminate");
    Button showProgress = new Button(composite, SWT.NONE);
    showProgress.setText("Show Progress");

    final Shell shell = parent.getShell();

    showProgress.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            try {
                new ProgressMonitorDialog(shell).run(true, true,
                        new LongRunningOperation(indeterminate.getSelection()));
            } catch (InvocationTargetException e) {
                MessageDialog.openError(shell, "Error", e.getMessage());
            } catch (InterruptedException e) {
                MessageDialog.openInformation(shell, "Cancelled", e.getMessage());
            }/*from w  ww. j a  va  2 s .  co  m*/
        }
    });

    parent.pack();
    return composite;
}

From source file:org.eclipse.swt.examples.hoverhelp.HoverHelp.java

/**
 * Creates the example/* ww  w.j  av a  2 s.c  o m*/
 */
public void createPartControl(Composite frame) {
    final ToolTipHandler tooltip = new ToolTipHandler(frame.getShell());

    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    frame.setLayout(layout);

    String platform = SWT.getPlatform();
    String helpKey = "F1";
    if (platform.equals("gtk"))
        helpKey = "Ctrl+F1";
    if (platform.equals("cocoa"))
        helpKey = "Help";

    ToolBar bar = new ToolBar(frame, SWT.BORDER);
    for (int i = 0; i < 5; i++) {
        ToolItem item = new ToolItem(bar, SWT.PUSH);
        item.setText(getResourceString("ToolItem.text", new Object[] { Integer.valueOf(i) }));
        item.setData("TIP_TEXT",
                getResourceString("ToolItem.tooltip", new Object[] { item.getText(), helpKey }));
        item.setData("TIP_HELPTEXTHANDLER", (ToolTipHelpTextHandler) widget -> {
            Item item1 = (Item) widget;
            return getResourceString("ToolItem.help", new Object[] { item1.getText() });
        });
    }
    GridData gridData = new GridData();
    gridData.horizontalSpan = 3;
    bar.setLayoutData(gridData);
    tooltip.activateHoverHelp(bar);

    Table table = new Table(frame, SWT.BORDER);
    for (int i = 0; i < 4; i++) {
        TableItem item = new TableItem(table, SWT.PUSH);
        item.setText(getResourceString("Item", new Object[] { Integer.valueOf(i) }));
        item.setData("TIP_IMAGE", images[hhiInformation]);
        item.setText(getResourceString("TableItem.text", new Object[] { Integer.valueOf(i) }));
        item.setData("TIP_TEXT",
                getResourceString("TableItem.tooltip", new Object[] { item.getText(), helpKey }));
        item.setData("TIP_HELPTEXTHANDLER", (ToolTipHelpTextHandler) widget -> {
            Item item1 = (Item) widget;
            return getResourceString("TableItem.help", new Object[] { item1.getText() });
        });
    }
    table.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));
    tooltip.activateHoverHelp(table);

    Tree tree = new Tree(frame, SWT.BORDER);
    for (int i = 0; i < 4; i++) {
        TreeItem item = new TreeItem(tree, SWT.PUSH);
        item.setText(getResourceString("Item", new Object[] { Integer.valueOf(i) }));
        item.setData("TIP_IMAGE", images[hhiWarning]);
        item.setText(getResourceString("TreeItem.text", new Object[] { Integer.valueOf(i) }));
        item.setData("TIP_TEXT",
                getResourceString("TreeItem.tooltip", new Object[] { item.getText(), helpKey }));
        item.setData("TIP_HELPTEXTHANDLER", (ToolTipHelpTextHandler) widget -> {
            Item item1 = (Item) widget;
            return getResourceString("TreeItem.help", new Object[] { item1.getText() });
        });
    }
    tree.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL));
    tooltip.activateHoverHelp(tree);

    Button button = new Button(frame, SWT.PUSH);
    button.setText(getResourceString("Hello.text"));
    button.setData("TIP_TEXT", getResourceString("Hello.tooltip"));
    tooltip.activateHoverHelp(button);
}

From source file:ShowProgress.java

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

    // Create the indeterminate checkbox
    final Button indeterminate = new Button(composite, SWT.CHECK);
    indeterminate.setText("Indeterminate");

    // Create the ShowProgress button
    Button showProgress = new Button(composite, SWT.NONE);
    showProgress.setText("Show Progress");

    final Shell shell = parent.getShell();

    // Display the ProgressMonitorDialog
    showProgress.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            try {
                new ProgressMonitorDialog(shell).run(true, true,
                        new LongRunningOperation(indeterminate.getSelection()));
            } catch (InvocationTargetException e) {
                MessageDialog.openError(shell, "Error", e.getMessage());
            } catch (InterruptedException e) {
                MessageDialog.openInformation(shell, "Cancelled", e.getMessage());
            }
        }
    });

    parent.pack();
    return composite;
}

From source file:Ch11WizardComposite.java

protected void buildControls() {
    final Composite parent = this;
    FillLayout layout = new FillLayout();
    parent.setLayout(layout);/*w w w.  j a va2s. com*/

    Button dialogBtn = new Button(parent, SWT.PUSH);
    dialogBtn.setText("Wizard Dialog...");
    dialogBtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            WizardDialog dialog = new WizardDialog(parent.getShell(), new ProjectWizard());
            dialog.open();
        }

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

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

@Override
public void createPartControl(final Composite parent) {
    parent.setLayout(new GridLayout(1, false));

    controlsComposite = new Composite(parent, SWT.NONE);
    controlsComposite.setLayout(new GridLayout(1, false));
    controlsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Composite buttonsContainer = new Composite(controlsComposite, SWT.NONE);
    buttonsContainer.setLayout(new GridLayout(4, true));
    buttonsContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    createRadioButton(buttonsContainer, "Line", true, ChartType.TIME_CHART);
    createRadioButton(buttonsContainer, "Bar", false, ChartType.BAR_CHART);
    createRadioButton(buttonsContainer, "Stacked", false, ChartType.STACKED_CHART);
    createRadioButton(buttonsContainer, "Pie", false, ChartType.PIE_CHART);

    Composite filteringContainer = new Composite(controlsComposite, SWT.BORDER);
    filteringContainer.setLayout(new GridLayout(2, true));
    filteringContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    groupSelectorWidget = new ItemsSelectorWidget(filteringContainer, this, GROUPS_LABEL);
    columnsSelectorWidget = new ItemsSelectorWidget(filteringContainer, this, CELLS_LABEL);

    groupSelectorWidget.initializeWidget();
    columnsSelectorWidget.initializeWidget();
    int width = parent.getShell().getSize().x;

    chartComposite = new ChartComposite(parent, SWT.FILL, null, ChartComposite.DEFAULT_WIDTH,
            ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH,
            ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, width, ChartComposite.DEFAULT_MAXIMUM_DRAW_HEIGHT, true,
            true, true, true, true, true);

    chartComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    chartComposite.setVisible(false);//from w  w  w .j a va  2s. co m
    chartComposite.addChartMouseListener(this);
}

From source file:SendMessage.java

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

    // Create a big text box for the message text
    final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 5;
    text.setLayoutData(data);

    // Create the Confirm button
    Button confirm = new Button(composite, SWT.PUSH);
    confirm.setText("Confirm");
    confirm.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the Error button
    Button error = new Button(composite, SWT.PUSH);
    error.setText("Error");
    error.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the Information button
    Button information = new Button(composite, SWT.PUSH);
    information.setText("Information");
    information.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the Question button
    Button question = new Button(composite, SWT.PUSH);
    question.setText("Question");
    question.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the Warning button
    Button warning = new Button(composite, SWT.PUSH);
    warning.setText("Warning");
    warning.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the label to display the return value
    final Label label = new Label(composite, SWT.NONE);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 5;
    label.setLayoutData(data);

    // Save ourselves some typing
    final Shell shell = parent.getShell();

    // Display a Confirmation dialog
    confirm.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            boolean b = MessageDialog.openConfirm(shell, "Confirm", text.getText());
            label.setText("Returned " + Boolean.toString(b));
        }
    });

    // Display an Error dialog
    error.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            MessageDialog.openError(shell, "Error", text.getText());
            label.setText("Returned void");
        }
    });

    // Display an Information dialog
    information.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            MessageDialog.openInformation(shell, "Information", text.getText());
            label.setText("Returned void");
        }
    });

    // Display a Question dialog
    question.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            boolean b = MessageDialog.openQuestion(shell, "Question", text.getText());
            label.setText("Returned " + Boolean.toString(b));
        }
    });

    // Display a Warning dialog
    warning.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            MessageDialog.openWarning(shell, "Warning", text.getText());
            label.setText("Returned void");
        }
    });

    return composite;
}