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

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

Introduction

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

Prototype

public Composite(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.SWTAxisEditor.java

/**
 * Standard constructor: builds a composite for displaying/editing 
 * the properties of the specified axis.
 *
 * @param parent The parent composite./*from   w  ww  .j a v a  2  s  . c  o m*/
 * @param style The SWT style of the SwtAxisEditor.
 * @param axis  the axis whose properties are to be displayed/edited  
 *              in the composite.
 */
public SWTAxisEditor(Composite parent, int style, Axis axis) {
    super(parent, style);
    this.labelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getLabelFont(), true);
    this.labelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getLabelPaint());
    this.tickLabelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getTickLabelFont(), true);
    this.tickLabelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getTickLabelPaint());

    FillLayout layout = new FillLayout(SWT.VERTICAL);
    layout.marginHeight = layout.marginWidth = 4;
    this.setLayout(layout);
    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));
    // row 1
    new Label(general, SWT.NONE).setText(localizationResources.getString("Label"));
    this.label = new Text(general, SWT.BORDER);
    if (axis.getLabel() != null) {
        this.label.setText(axis.getLabel());
    }
    this.label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(general, SWT.NONE).setText(""); //empty cell
    // row 2
    new Label(general, SWT.NONE).setText(localizationResources.getString("Font"));
    this.labelFontField = new Text(general, SWT.BORDER);
    this.labelFontField.setText(this.labelFont.toString());
    this.labelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button selectFontButton = new Button(general, SWT.PUSH);
    selectFontButton.setText(localizationResources.getString("Select..."));
    selectFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            FontDialog dlg = new FontDialog(getShell());
            dlg.setText(localizationResources.getString("Font_Selection"));
            dlg.setFontList(new FontData[] { SWTAxisEditor.this.labelFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTAxisEditor.this.font != null) {
                    SWTAxisEditor.this.font.dispose();
                }
                // Create the new font and set it into the title 
                // label
                SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                //label.setFont( font );
                SWTAxisEditor.this.labelFontField.setText(SWTAxisEditor.this.font.getFontData()[0].toString());
                SWTAxisEditor.this.labelFont = SWTAxisEditor.this.font.getFontData()[0];
            }
        }
    });
    // row 3
    new Label(general, SWT.NONE).setText(localizationResources.getString("Paint"));
    // Use a colored text field to show the color
    final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.labelPaintColor);
    GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    canvasGridData.heightHint = 20;
    colorCanvas.setLayoutData(canvasGridData);
    Button selectColorButton = new Button(general, SWT.PUSH);
    selectColorButton.setText(localizationResources.getString("Select..."));
    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(SWTAxisEditor.this.labelPaintColor.getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                // create the new color and set it to the 
                // SwtPaintCanvas
                SWTAxisEditor.this.labelPaintColor = new Color(getDisplay(), rgb);
                colorCanvas.setColor(SWTAxisEditor.this.labelPaintColor);
            }
        }
    });
    Group other = new Group(this, SWT.NONE);
    FillLayout tabLayout = new FillLayout();
    tabLayout.marginHeight = tabLayout.marginWidth = 4;
    other.setLayout(tabLayout);
    other.setText(localizationResources.getString("Other"));

    this.otherTabs = new TabFolder(other, SWT.NONE);
    TabItem item1 = new TabItem(this.otherTabs, SWT.NONE);
    item1.setText(" " + localizationResources.getString("Ticks") + " ");
    Composite ticks = new Composite(this.otherTabs, SWT.NONE);
    ticks.setLayout(new GridLayout(3, false));
    this.showTickLabelsCheckBox = new Button(ticks, SWT.CHECK);
    this.showTickLabelsCheckBox.setText(localizationResources.getString("Show_tick_labels"));
    this.showTickLabelsCheckBox.setSelection(axis.isTickLabelsVisible());
    this.showTickLabelsCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    new Label(ticks, SWT.NONE).setText(localizationResources.getString("Tick_label_font"));
    this.tickLabelFontField = new Text(ticks, SWT.BORDER);
    this.tickLabelFontField.setText(this.tickLabelFont.toString());
    //tickLabelFontField.setFont(SwtUtils.toSwtFontData(getDisplay(), 
    // axis.getTickLabelFont()));
    this.tickLabelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button selectTickLabelFontButton = new Button(ticks, SWT.PUSH);
    selectTickLabelFontButton.setText(localizationResources.getString("Select..."));
    selectTickLabelFontButton.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[] { SWTAxisEditor.this.tickLabelFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTAxisEditor.this.font != null) {
                    SWTAxisEditor.this.font.dispose();
                }
                // Create the new font and set it into the title 
                // label
                SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                //tickLabelFontField.setFont(font);
                SWTAxisEditor.this.tickLabelFontField
                        .setText(SWTAxisEditor.this.font.getFontData()[0].toString());
                SWTAxisEditor.this.tickLabelFont = SWTAxisEditor.this.font.getFontData()[0];
            }
        }
    });
    this.showTickMarksCheckBox = new Button(ticks, SWT.CHECK);
    this.showTickMarksCheckBox.setText(localizationResources.getString("Show_tick_marks"));
    this.showTickMarksCheckBox.setSelection(axis.isTickMarksVisible());
    this.showTickMarksCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    item1.setControl(ticks);
}

From source file:PaintExample.java

/**
 * Creates the GUI./*  w  ww .  j  a v a2  s .c  o m*/
 */
public void createGUI(Composite parent) {
    GridLayout gridLayout;
    GridData gridData;

    /*** Create principal GUI layout elements ***/
    Composite displayArea = new Composite(parent, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    displayArea.setLayout(gridLayout);

    // Creating these elements here avoids the need to instantiate the GUI elements
    // in strict layout order.  The natural layout ordering is an artifact of using
    // SWT layouts, but unfortunately it is not the same order as that required to
    // instantiate all of the non-GUI application elements to satisfy referential
    // dependencies.  It is possible to reorder the initialization to some extent, but
    // this can be very tedious.

    // paint canvas
    final Canvas paintCanvas = new Canvas(displayArea,
            SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    paintCanvas.setLayoutData(gridData);
    paintCanvas.setBackground(paintColorWhite);

    // color selector frame
    final Composite colorFrame = new Composite(displayArea, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    colorFrame.setLayoutData(gridData);

    // tool settings frame
    final Composite toolSettingsFrame = new Composite(displayArea, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    toolSettingsFrame.setLayoutData(gridData);

    // status text
    final Text statusText = new Text(displayArea, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    statusText.setLayoutData(gridData);

    /*** Create the remaining application elements inside the principal GUI layout elements ***/
    // paintSurface
    paintSurface = new PaintSurface(paintCanvas, statusText, paintColorWhite);

    // finish initializing the tool data
    tools[Pencil_tool].data = new PencilTool(toolSettings, paintSurface);
    tools[Airbrush_tool].data = new AirbrushTool(toolSettings, paintSurface);
    tools[Line_tool].data = new LineTool(toolSettings, paintSurface);
    tools[PolyLine_tool].data = new PolyLineTool(toolSettings, paintSurface);
    tools[Rectangle_tool].data = new RectangleTool(toolSettings, paintSurface);
    tools[RoundedRectangle_tool].data = new RoundedRectangleTool(toolSettings, paintSurface);
    tools[Ellipse_tool].data = new EllipseTool(toolSettings, paintSurface);
    tools[Text_tool].data = new TextTool(toolSettings, paintSurface);

    // colorFrame      
    gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    colorFrame.setLayout(gridLayout);

    // activeForegroundColorCanvas, activeBackgroundColorCanvas
    activeForegroundColorCanvas = new Canvas(colorFrame, SWT.BORDER);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.heightHint = 24;
    gridData.widthHint = 24;
    activeForegroundColorCanvas.setLayoutData(gridData);

    activeBackgroundColorCanvas = new Canvas(colorFrame, SWT.BORDER);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.heightHint = 24;
    gridData.widthHint = 24;
    activeBackgroundColorCanvas.setLayoutData(gridData);

    // paletteCanvas
    final Canvas paletteCanvas = new Canvas(colorFrame, SWT.BORDER | SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.heightHint = 24;
    paletteCanvas.setLayoutData(gridData);
    paletteCanvas.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event e) {
            Rectangle bounds = paletteCanvas.getClientArea();
            Color color = getColorAt(bounds, e.x, e.y);

            if (e.button == 1)
                setForegroundColor(color);
            else
                setBackgroundColor(color);
        }

        private Color getColorAt(Rectangle bounds, int x, int y) {
            if (bounds.height <= 1 && bounds.width <= 1)
                return paintColorWhite;
            final int row = (y - bounds.y) * numPaletteRows / bounds.height;
            final int col = (x - bounds.x) * numPaletteCols / bounds.width;
            return paintColors[Math.min(Math.max(row * numPaletteCols + col, 0), paintColors.length - 1)];
        }
    });
    Listener refreshListener = new Listener() {
        public void handleEvent(Event e) {
            if (e.gc == null)
                return;
            Rectangle bounds = paletteCanvas.getClientArea();
            for (int row = 0; row < numPaletteRows; ++row) {
                for (int col = 0; col < numPaletteCols; ++col) {
                    final int x = bounds.width * col / numPaletteCols;
                    final int y = bounds.height * row / numPaletteRows;
                    final int width = Math.max(bounds.width * (col + 1) / numPaletteCols - x, 1);
                    final int height = Math.max(bounds.height * (row + 1) / numPaletteRows - y, 1);
                    e.gc.setBackground(paintColors[row * numPaletteCols + col]);
                    e.gc.fillRectangle(bounds.x + x, bounds.y + y, width, height);
                }
            }
        }
    };
    paletteCanvas.addListener(SWT.Resize, refreshListener);
    paletteCanvas.addListener(SWT.Paint, refreshListener);
    //paletteCanvas.redraw();

    // toolSettingsFrame
    gridLayout = new GridLayout();
    gridLayout.numColumns = 4;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    toolSettingsFrame.setLayout(gridLayout);

    Label label = new Label(toolSettingsFrame, SWT.NONE);
    label.setText(getResourceString("settings.AirbrushRadius.text"));

    final Scale airbrushRadiusScale = new Scale(toolSettingsFrame, SWT.HORIZONTAL);
    airbrushRadiusScale.setMinimum(5);
    airbrushRadiusScale.setMaximum(50);
    airbrushRadiusScale.setSelection(toolSettings.airbrushRadius);
    airbrushRadiusScale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    airbrushRadiusScale.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            toolSettings.airbrushRadius = airbrushRadiusScale.getSelection();
            updateToolSettings();
        }
    });

    label = new Label(toolSettingsFrame, SWT.NONE);
    label.setText(getResourceString("settings.AirbrushIntensity.text"));

    final Scale airbrushIntensityScale = new Scale(toolSettingsFrame, SWT.HORIZONTAL);
    airbrushIntensityScale.setMinimum(1);
    airbrushIntensityScale.setMaximum(100);
    airbrushIntensityScale.setSelection(toolSettings.airbrushIntensity);
    airbrushIntensityScale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    airbrushIntensityScale.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            toolSettings.airbrushIntensity = airbrushIntensityScale.getSelection();
            updateToolSettings();
        }
    });
}

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

/**
 * Standard constructor: builds a composite for displaying/editing
 * the properties of the specified axis.
 * //from  www .ja va2  s  .  c  o  m
 * @param parent
 *            The parent composite.
 * @param style
 *            The SWT style of the SwtAxisEditor.
 * @param axis
 *            the axis whose properties are to be displayed/edited
 *            in the composite.
 */
public SWTAxisEditor(Composite parent, int style, Axis axis) {
    super(parent, style);
    this.labelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getLabelFont(), true);
    this.labelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getLabelPaint());
    this.tickLabelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getTickLabelFont(), true);
    this.tickLabelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getTickLabelPaint());

    FillLayout layout = new FillLayout(SWT.VERTICAL);
    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
    new Label(general, SWT.NONE).setText(localizationResources.getString("Label"));
    this.label = new Text(general, SWT.BORDER);
    if (axis.getLabel() != null) {
        this.label.setText(axis.getLabel());
    }
    this.label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(general, SWT.NONE).setText(""); // empty cell
    // row 2
    new Label(general, SWT.NONE).setText(localizationResources.getString("Font"));
    this.labelFontField = new Text(general, SWT.BORDER);
    this.labelFontField.setText(this.labelFont.toString());
    this.labelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button selectFontButton = new Button(general, SWT.PUSH);
    selectFontButton.setText(localizationResources.getString("Select..."));
    selectFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            FontDialog dlg = new FontDialog(getShell());
            dlg.setText(localizationResources.getString("Font_Selection"));
            dlg.setFontList(new FontData[] { SWTAxisEditor.this.labelFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTAxisEditor.this.font != null) {
                    SWTAxisEditor.this.font.dispose();
                }
                // Create the new font and set it into the title
                // label
                SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                // label.setFont(font);
                SWTAxisEditor.this.labelFontField.setText(SWTAxisEditor.this.font.getFontData()[0].toString());
                SWTAxisEditor.this.labelFont = SWTAxisEditor.this.font.getFontData()[0];
            }
        }
    });
    // row 3
    new Label(general, SWT.NONE).setText(localizationResources.getString("Paint"));
    // Use a colored text field to show the color
    final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.labelPaintColor);
    GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    canvasGridData.heightHint = 20;
    colorCanvas.setLayoutData(canvasGridData);
    Button selectColorButton = new Button(general, SWT.PUSH);
    selectColorButton.setText(localizationResources.getString("Select..."));
    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(SWTAxisEditor.this.labelPaintColor.getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                // create the new color and set it to the
                // SwtPaintCanvas
                SWTAxisEditor.this.labelPaintColor = new Color(getDisplay(), rgb);
                colorCanvas.setColor(SWTAxisEditor.this.labelPaintColor);
            }
        }
    });
    Group other = new Group(this, SWT.NONE);
    FillLayout tabLayout = new FillLayout();
    tabLayout.marginHeight = tabLayout.marginWidth = 4;
    other.setLayout(tabLayout);
    other.setText(localizationResources.getString("Other"));

    this.otherTabs = new TabFolder(other, SWT.NONE);
    TabItem item1 = new TabItem(this.otherTabs, SWT.NONE);
    item1.setText(" " + localizationResources.getString("Ticks") + " ");
    Composite ticks = new Composite(this.otherTabs, SWT.NONE);
    ticks.setLayout(new GridLayout(3, false));
    this.showTickLabelsCheckBox = new Button(ticks, SWT.CHECK);
    this.showTickLabelsCheckBox.setText(localizationResources.getString("Show_tick_labels"));
    this.showTickLabelsCheckBox.setSelection(axis.isTickLabelsVisible());
    this.showTickLabelsCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    new Label(ticks, SWT.NONE).setText(localizationResources.getString("Tick_label_font"));
    this.tickLabelFontField = new Text(ticks, SWT.BORDER);
    this.tickLabelFontField.setText(this.tickLabelFont.toString());
    // tickLabelFontField.setFont(SwtUtils.toSwtFontData(getDisplay(),
    // axis.getTickLabelFont()));
    this.tickLabelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button selectTickLabelFontButton = new Button(ticks, SWT.PUSH);
    selectTickLabelFontButton.setText(localizationResources.getString("Select..."));
    selectTickLabelFontButton.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[] { SWTAxisEditor.this.tickLabelFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTAxisEditor.this.font != null) {
                    SWTAxisEditor.this.font.dispose();
                }
                // Create the new font and set it into the title
                // label
                SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                // tickLabelFontField.setFont(font);
                SWTAxisEditor.this.tickLabelFontField
                        .setText(SWTAxisEditor.this.font.getFontData()[0].toString());
                SWTAxisEditor.this.tickLabelFont = SWTAxisEditor.this.font.getFontData()[0];
            }
        }
    });
    this.showTickMarksCheckBox = new Button(ticks, SWT.CHECK);
    this.showTickMarksCheckBox.setText(localizationResources.getString("Show_tick_marks"));
    this.showTickMarksCheckBox.setSelection(axis.isTickMarksVisible());
    this.showTickMarksCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    item1.setControl(ticks);
}

From source file:org.ietr.preesm.mapper.ui.BestCostPlotter.java

public void display(Composite parentComposite) {

    Composite composite = new Composite(parentComposite, SWT.EMBEDDED | SWT.FILL);
    parentComposite.setLayout(new FillLayout());
    Frame frame = SWT_AWT.new_Frame(composite);
    frame.add(this.getContentPane());

    MouseClickedListener listener = new MouseClickedListener(frame);
    chartPanel.addChartMouseListener(listener);
    chartPanel.addMouseMotionListener(listener);
    chartPanel.addMouseListener(listener);
}

From source file:net.sf.smbt.ui.btc.views.AbstractBTCMarketView.java

@Override
public void createPartControl(Composite parent) {
    contributeToActionBars();/*www.  j  av a2  s  .co  m*/

    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FillLayout());
    container.setLayoutData(GridDataFactory.fillDefaults().create());

    addCharts(container);
}

From source file:AddressBook.java

/**
 * Creates the page contents//from  ww  w.  j  av a 2s.c om
 * 
 * @param parent
 *            the parent composite
 */
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new FillLayout(SWT.VERTICAL));
    new Label(composite, SWT.CENTER).setText("Welcome to the Address Book Entry Wizard!");
    new Label(composite, SWT.LEFT).setText("This wizard guides you through creating an Address Book entry.");
    new Label(composite, SWT.LEFT).setText("Click Next to continue.");
    setControl(composite);
}

From source file:ReservationData.java

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new GridLayout(2, false));

    new Label(composite, SWT.NULL).setText("Full name: ");
    textName = new Text(composite, SWT.SINGLE | SWT.BORDER);
    textName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(composite, SWT.NULL).setText("Phone Number: ");
    textPhone = new Text(composite, SWT.SINGLE | SWT.BORDER);
    textPhone.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(composite, SWT.NULL).setText("Email address: ");
    textEmail = new Text(composite, SWT.SINGLE | SWT.BORDER);
    textEmail.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(composite, SWT.NULL).setText("Address: ");
    textAddress = new Text(composite, SWT.MULTI | SWT.BORDER);
    textAddress.setText("\r\n\r\n\r\n");
    textAddress.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            if (event.widget == null || !(event.widget instanceof Text))
                return;

            String string = ((Text) event.widget).getText();

            if (event.widget == textName) {
                ((ReservationWizard) getWizard()).data.customerName = string;

            } else if (event.widget == textPhone) {
                ((ReservationWizard) getWizard()).data.customerPhone = string;

            } else if (event.widget == textEmail) {
                if (string.indexOf('@') < 0) {
                    setErrorMessage("Invalid email address: " + string);
                    ((ReservationWizard) getWizard()).data.customerEmail = null;
                } else {
                    setErrorMessage(null);
                    ((ReservationWizard) getWizard()).data.customerEmail = string;
                }//w  w w .  ja v a 2s  . co  m
            } else if (event.widget == textAddress) {
                ((ReservationWizard) getWizard()).data.customerAddress = string;
            }

            ReservationData data = ((ReservationWizard) getWizard()).data;
            if (data.customerName != null && data.customerPhone != null && data.customerEmail != null
                    && data.customerAddress != null) {
                setPageComplete(true);
            } else {
                setPageComplete(false);
            }
        }
    };

    textName.addListener(SWT.Modify, listener);
    textPhone.addListener(SWT.Modify, listener);
    textEmail.addListener(SWT.Modify, listener);
    textAddress.addListener(SWT.Modify, listener);

    if (getDialogSettings() != null && validDialogSettings()) {

        textName.setText(getDialogSettings().get(ReservationWizard.KEY_CUSTOMER_NAME));

        textPhone.setText(getDialogSettings().get(ReservationWizard.KEY_CUSTOMER_PHONE));

        textEmail.setText(getDialogSettings().get(ReservationWizard.KEY_CUSTOMER_EMAIL));

        textAddress.setText(getDialogSettings().get(ReservationWizard.KEY_CUSTOMER_ADDRESS));

    }

    setControl(composite);
}

From source file:org.eclipse.swt.examples.accessibility.ControlsWithAccessibleNamesExample.java

public static void main(String[] args) {
    display = new Display();
    shell = new Shell(display);
    shell.setLayout(new GridLayout(4, true));
    shell.setText("Override Accessibility Test");

    largeImage = new Image(display,
            ControlsWithAccessibleNamesExample.class.getResourceAsStream("run_wiz.gif"));
    smallImage = new Image(display, ControlsWithAccessibleNamesExample.class.getResourceAsStream("run.gif"));
    ImageData source = smallImage.getImageData();
    ImageData mask = source.getTransparencyMask();
    transparentImage = new Image(display, source, mask);

    new Label(shell, SWT.NONE).setText("Use Platform Name");
    new Label(shell, SWT.NONE).setText("Override Platform Name");
    new Label(shell, SWT.NONE).setText("Use Platform Name");
    new Label(shell, SWT.NONE).setText("Override Platform Name");

    AccessibleAdapter overrideAccessibleAdapter = new AccessibleAdapter() {
        @Override//from  w w w  .j  a v a  2  s  .  c o m
        public void getName(AccessibleEvent e) {
            Control control = ((Accessible) e.getSource()).getControl();
            if (e.childID == ACC.CHILDID_SELF) {
                e.result = "Overriding Platform Name For " + control.getData("name") + " (was " + e.result
                        + ")";
            } else {
                e.result = "Overriding Platform Name For " + control.getData("child") + ": " + e.childID
                        + " (was " + e.result + ")";
            }
        }

        @Override
        public void getHelp(AccessibleEvent e) {
            Control control = ((Accessible) e.getSource()).getControl();
            if (e.childID == ACC.CHILDID_SELF) {
                e.result = "Overriding Platform Help For " + control.getData("name") + " (was " + e.result
                        + ")";
            } else {
                e.result = "Overriding Platform Help For " + control.getData("child") + ": " + e.childID
                        + " (was " + e.result + ")";
            }
        }
    };

    //      Shell shell;
    shell.setData("name", "Shell");
    shell.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Label label, overrideLabel;
    label = new Label(shell, SWT.BORDER);
    label.setText("Label");
    label.setToolTipText("Label ToolTip");

    overrideLabel = new Label(shell, SWT.BORDER);
    overrideLabel.setText("Label");
    overrideLabel.setToolTipText("Label ToolTip");
    overrideLabel.setData("name", "Label");
    overrideLabel.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Label imageLabel, overrideImageLabel;
    imageLabel = new Label(shell, SWT.BORDER);
    imageLabel.setImage(largeImage);
    imageLabel.setToolTipText("Image Label ToolTip");

    overrideImageLabel = new Label(shell, SWT.BORDER);
    overrideImageLabel.setImage(largeImage);
    overrideImageLabel.setToolTipText("Image Label ToolTip");
    overrideImageLabel.setData("name", "Image Label");
    overrideImageLabel.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Button button, overrideButton;
    button = new Button(shell, SWT.PUSH);
    button.setText("Button");
    button.setToolTipText("Button ToolTip");

    overrideButton = new Button(shell, SWT.PUSH);
    overrideButton.setText("Button");
    overrideButton.setToolTipText("Button ToolTip");
    overrideButton.setData("name", "Button");
    overrideButton.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Button imageButton, overrideImageButton;
    imageButton = new Button(shell, SWT.PUSH);
    imageButton.setImage(smallImage);
    imageButton.setToolTipText("Image Button ToolTip");

    overrideImageButton = new Button(shell, SWT.PUSH);
    overrideImageButton.setImage(smallImage);
    overrideImageButton.setToolTipText("Image Button ToolTip");
    overrideImageButton.setData("name", "Image Button");
    overrideImageButton.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Combo combo, overrideCombo;
    combo = new Combo(shell, SWT.BORDER);
    for (int i = 0; i < 5; i++) {
        combo.add("item" + i);
    }
    combo.setText("Combo");
    combo.setToolTipText("Combo ToolTip");

    overrideCombo = new Combo(shell, SWT.BORDER);
    for (int i = 0; i < 5; i++) {
        overrideCombo.add("item" + i);
    }
    overrideCombo.setText("Combo");
    overrideCombo.setToolTipText("Combo ToolTip");
    overrideCombo.setData("name", "Combo");
    overrideCombo.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Spinner spinner, overrideSpinner;
    spinner = new Spinner(shell, SWT.BORDER);
    spinner.setSelection(5);
    spinner.setToolTipText("Spinner ToolTip");

    overrideSpinner = new Spinner(shell, SWT.BORDER);
    overrideSpinner.setSelection(5);
    overrideSpinner.setToolTipText("Spinner ToolTip");
    overrideSpinner.setData("name", "Spinner");
    overrideSpinner.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Text text, overrideText;
    text = new Text(shell, SWT.SINGLE | SWT.BORDER);
    text.setText("Contents of single-line Text");

    overrideText = new Text(shell, SWT.SINGLE | SWT.BORDER);
    overrideText.setText("Contents of single-line Text");
    overrideText.setData("name", "Text");
    overrideText.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Text multiLineText, overrideMultiLineText;
    multiLineText = new Text(shell, SWT.MULTI | SWT.BORDER);
    multiLineText.setText("Contents of multi-line Text\nLine 2\nLine 3\nLine 4");

    overrideMultiLineText = new Text(shell, SWT.MULTI | SWT.BORDER);
    overrideMultiLineText.setText("Contents of multi-line Text\nLine 2\nLine 3\nLine 4");
    overrideMultiLineText.setData("name", "MultiLineText");
    overrideMultiLineText.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      List list, overrideList;
    list = new List(shell, SWT.SINGLE | SWT.BORDER);
    list.setItems("Item0", "Item1", "Item2");

    overrideList = new List(shell, SWT.SINGLE | SWT.BORDER);
    overrideList.setItems("Item0", "Item1", "Item2");
    overrideList.setData("name", "List");
    overrideList.setData("child", "List Item");
    overrideList.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Table table, overrideTable;
    table = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    for (int col = 0; col < 3; col++) {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText("Col " + col);
        column.pack();
    }
    for (int row = 0; row < 3; row++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(new String[] { "C0R" + row, "C1R" + row, "C2R" + row });
    }

    overrideTable = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    overrideTable.setHeaderVisible(true);
    overrideTable.setLinesVisible(true);
    for (int col = 0; col < 3; col++) {
        TableColumn column = new TableColumn(overrideTable, SWT.NONE);
        column.setText("Col " + col);
        column.pack();
    }
    for (int row = 0; row < 3; row++) {
        TableItem item = new TableItem(overrideTable, SWT.NONE);
        item.setText(new String[] { "C0R" + row, "C1R" + row, "C2R" + row });
    }
    overrideTable.setData("name", "Table");
    overrideTable.setData("child", "Table Item");
    overrideTable.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Tree tree, overrideTree;
    tree = new Tree(shell, SWT.BORDER | SWT.MULTI);
    for (int i = 0; i < 3; i++) {
        TreeItem item = new TreeItem(tree, SWT.NONE);
        item.setText("Item" + i);
        for (int j = 0; j < 4; j++) {
            new TreeItem(item, SWT.NONE).setText("Item" + i + j);
        }
    }

    overrideTree = new Tree(shell, SWT.BORDER | SWT.MULTI);
    for (int i = 0; i < 3; i++) {
        TreeItem item = new TreeItem(overrideTree, SWT.NONE);
        item.setText("Item" + i);
        for (int j = 0; j < 4; j++) {
            new TreeItem(item, SWT.NONE).setText("Item" + i + j);
        }
    }
    overrideTree.setData("name", "Tree");
    overrideTree.setData("child", "Tree Item");
    overrideTree.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Tree treeTable, overrideTreeTable;
    treeTable = new Tree(shell, SWT.BORDER | SWT.MULTI);
    treeTable.setHeaderVisible(true);
    treeTable.setLinesVisible(true);
    for (int col = 0; col < 3; col++) {
        TreeColumn column = new TreeColumn(treeTable, SWT.NONE);
        column.setText("Col " + col);
        column.pack();
    }
    for (int i = 0; i < 3; i++) {
        TreeItem item = new TreeItem(treeTable, SWT.NONE);
        item.setText(new String[] { "I" + i + "C0", "I" + i + "C1", "I" + i + "C2" });
        for (int j = 0; j < 4; j++) {
            new TreeItem(item, SWT.NONE)
                    .setText(new String[] { "I" + i + j + "C0", "I" + i + j + "C1", "I" + i + j + "C2" });
        }
    }

    overrideTreeTable = new Tree(shell, SWT.BORDER | SWT.MULTI);
    overrideTreeTable.setHeaderVisible(true);
    overrideTreeTable.setLinesVisible(true);
    for (int col = 0; col < 3; col++) {
        TreeColumn column = new TreeColumn(overrideTreeTable, SWT.NONE);
        column.setText("Col " + col);
        column.pack();
    }
    for (int i = 0; i < 3; i++) {
        TreeItem item = new TreeItem(overrideTreeTable, SWT.NONE);
        item.setText(new String[] { "I" + i + "C0", "I" + i + "C1", "I" + i + "C2" });
        for (int j = 0; j < 4; j++) {
            new TreeItem(item, SWT.NONE)
                    .setText(new String[] { "I" + i + j + "C0", "I" + i + j + "C1", "I" + i + j + "C2" });
        }
    }
    overrideTreeTable.setData("name", "Tree Table");
    overrideTreeTable.setData("child", "Tree Table Item");
    overrideTreeTable.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      ToolBar toolBar, overrideToolBar;
    toolBar = new ToolBar(shell, SWT.FLAT);
    for (int i = 0; i < 3; i++) {
        ToolItem item = new ToolItem(toolBar, SWT.PUSH);
        item.setText("Item" + i);
        item.setToolTipText("ToolItem ToolTip" + i);
    }

    overrideToolBar = new ToolBar(shell, SWT.FLAT);
    for (int i = 0; i < 3; i++) {
        ToolItem item = new ToolItem(overrideToolBar, SWT.PUSH);
        item.setText("Item" + i);
        item.setToolTipText("ToolItem ToolTip" + i);
    }
    overrideToolBar.setData("name", "ToolBar");
    overrideToolBar.setData("child", "ToolBar Item");
    overrideToolBar.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      ToolBar imageToolBar, overrideImageToolBar;
    imageToolBar = new ToolBar(shell, SWT.FLAT);
    for (int i = 0; i < 3; i++) {
        ToolItem item = new ToolItem(imageToolBar, SWT.PUSH);
        item.setImage(transparentImage);
        item.setToolTipText("Image ToolItem ToolTip" + i);
    }

    overrideImageToolBar = new ToolBar(shell, SWT.FLAT);
    for (int i = 0; i < 3; i++) {
        ToolItem item = new ToolItem(overrideImageToolBar, SWT.PUSH);
        item.setImage(transparentImage);
        item.setToolTipText("Image ToolItem ToolTip" + i);
    }
    overrideImageToolBar.setData("name", "Image ToolBar");
    overrideImageToolBar.setData("child", "Image ToolBar Item");
    overrideImageToolBar.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      CoolBar coolBar, overrideCoolBar;
    coolBar = new CoolBar(shell, SWT.FLAT);
    for (int i = 0; i < 2; i++) {
        CoolItem coolItem = new CoolItem(coolBar, SWT.PUSH);
        ToolBar coolItemToolBar = new ToolBar(coolBar, SWT.FLAT);
        int toolItemWidth = 0;
        for (int j = 0; j < 2; j++) {
            ToolItem item = new ToolItem(coolItemToolBar, SWT.PUSH);
            item.setText("I" + i + j);
            item.setToolTipText("ToolItem ToolTip" + i + j);
            if (item.getWidth() > toolItemWidth)
                toolItemWidth = item.getWidth();
        }
        coolItem.setControl(coolItemToolBar);
        Point size = coolItemToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        Point coolSize = coolItem.computeSize(size.x, size.y);
        coolItem.setMinimumSize(toolItemWidth, coolSize.y);
        coolItem.setPreferredSize(coolSize);
        coolItem.setSize(coolSize);
    }

    overrideCoolBar = new CoolBar(shell, SWT.FLAT);
    for (int i = 0; i < 2; i++) {
        CoolItem coolItem = new CoolItem(overrideCoolBar, SWT.PUSH);
        ToolBar coolItemToolBar = new ToolBar(overrideCoolBar, SWT.FLAT);
        int toolItemWidth = 0;
        for (int j = 0; j < 2; j++) {
            ToolItem item = new ToolItem(coolItemToolBar, SWT.PUSH);
            item.setText("I" + i + j);
            item.setToolTipText("ToolItem ToolTip" + i + j);
            if (item.getWidth() > toolItemWidth)
                toolItemWidth = item.getWidth();
        }
        coolItem.setControl(coolItemToolBar);
        Point size = coolItemToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        Point coolSize = coolItem.computeSize(size.x, size.y);
        coolItem.setMinimumSize(toolItemWidth, coolSize.y);
        coolItem.setPreferredSize(coolSize);
        coolItem.setSize(coolSize);
    }
    overrideCoolBar.setData("name", "CoolBar");
    overrideCoolBar.setData("child", "CoolBar Item");
    overrideCoolBar.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Canvas canvas, overrideCanvas;
    canvas = new Canvas(shell, SWT.BORDER);
    canvas.addPaintListener(e -> e.gc.drawString("Canvas", 15, 25));
    /* Set a caret into the canvas so that it will take focus. */
    Caret caret = new Caret(canvas, SWT.NONE);
    caret.setBounds(15, 25, 2, 20);
    canvas.setCaret(caret);
    /* Hook key listener so canvas will take focus during traversal in. */
    canvas.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            e.doit = true;
        }

        @Override
        public void keyReleased(KeyEvent e) {
            e.doit = true;
        }
    });
    /* Hook traverse listener to make canvas give up focus during traversal out. */
    canvas.addTraverseListener(e -> e.doit = true);

    overrideCanvas = new Canvas(shell, SWT.BORDER);
    overrideCanvas.addPaintListener(e -> e.gc.drawString("Canvas", 15, 25));
    /* Set a caret into the canvas so that it will take focus. */
    caret = new Caret(overrideCanvas, SWT.NONE);
    caret.setBounds(15, 25, 2, 20);
    overrideCanvas.setCaret(caret);
    /* Hook key listener so canvas will take focus during traversal in. */
    overrideCanvas.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            e.doit = true;
        }

        @Override
        public void keyReleased(KeyEvent e) {
            e.doit = true;
        }
    });
    /* Hook traverse listener to make canvas give up focus during traversal out. */
    overrideCanvas.addTraverseListener(e -> e.doit = true);
    overrideCanvas.setData("name", "Canvas");
    overrideCanvas.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Composite composite, overrideComposite;
    composite = new Composite(shell, SWT.BORDER);
    composite.setLayout(new GridLayout());
    new Button(composite, SWT.RADIO).setText("Child 1");
    new Button(composite, SWT.RADIO).setText("Child 2");

    overrideComposite = new Composite(shell, SWT.BORDER);
    overrideComposite.setLayout(new GridLayout());
    new Button(overrideComposite, SWT.RADIO).setText("Child 1");
    new Button(overrideComposite, SWT.RADIO).setText("Child 2");
    overrideComposite.setData("name", "Composite");
    overrideComposite.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Group group, overrideGroup;
    group = new Group(shell, SWT.NONE);
    group.setText("Group");
    group.setLayout(new FillLayout());
    new Text(group, SWT.SINGLE).setText("Text in Group");

    overrideGroup = new Group(shell, SWT.NONE);
    overrideGroup.setText("Group");
    overrideGroup.setLayout(new FillLayout());
    new Text(overrideGroup, SWT.SINGLE).setText("Text in Group");
    overrideGroup.setData("name", "Group");
    overrideGroup.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      TabFolder tabFolder, overrideTabFolder;
    tabFolder = new TabFolder(shell, SWT.NONE);
    for (int i = 0; i < 3; i++) {
        TabItem item = new TabItem(tabFolder, SWT.NONE);
        item.setText("TabItem &" + i);
        item.setToolTipText("TabItem ToolTip" + i);
        Text itemText = new Text(tabFolder, SWT.MULTI | SWT.BORDER);
        itemText.setText("\nText for TabItem " + i + "\n\n");
        item.setControl(itemText);
    }

    overrideTabFolder = new TabFolder(shell, SWT.NONE);
    for (int i = 0; i < 3; i++) {
        TabItem item = new TabItem(overrideTabFolder, SWT.NONE);
        item.setText("TabItem &" + i);
        item.setToolTipText("TabItem ToolTip" + i);
        Text itemText = new Text(overrideTabFolder, SWT.MULTI | SWT.BORDER);
        itemText.setText("\nText for TabItem " + i + "\n\n");
        item.setControl(itemText);
    }
    overrideTabFolder.setData("name", "TabFolder");
    overrideTabFolder.setData("child", "TabItem");
    overrideTabFolder.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      CLabel cLabel, overrideCLabel;
    cLabel = new CLabel(shell, SWT.BORDER);
    cLabel.setText("CLabel");
    cLabel.setToolTipText("CLabel ToolTip");
    cLabel.setLayoutData(new GridData(100, SWT.DEFAULT));

    overrideCLabel = new CLabel(shell, SWT.BORDER);
    overrideCLabel.setText("CLabel");
    overrideCLabel.setToolTipText("CLabel ToolTip");
    overrideCLabel.setLayoutData(new GridData(100, SWT.DEFAULT));
    overrideCLabel.setData("name", "CLabel");
    overrideCLabel.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      CCombo cCombo, overrideCCombo;
    cCombo = new CCombo(shell, SWT.BORDER);
    for (int i = 0; i < 5; i++) {
        cCombo.add("item" + i);
    }
    cCombo.setText("CCombo");
    cCombo.setToolTipText("CCombo ToolTip");

    // Note: This doesn't work well because CCombo has Control children
    overrideCCombo = new CCombo(shell, SWT.BORDER);
    for (int i = 0; i < 5; i++) {
        overrideCCombo.add("item" + i);
    }
    overrideCCombo.setText("CCombo");
    overrideCCombo.setToolTipText("CCombo ToolTip");
    overrideCCombo.setData("name", "CCombo");
    overrideCCombo.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      CTabFolder cTabFolder, overrideCTabFolder;
    cTabFolder = new CTabFolder(shell, SWT.NONE);
    for (int i = 0; i < 3; i++) {
        CTabItem item = new CTabItem(cTabFolder, SWT.NONE);
        item.setText("CTabItem &" + i);
        item.setToolTipText("TabItem ToolTip" + i);
        Text itemText = new Text(cTabFolder, SWT.MULTI | SWT.BORDER);
        itemText.setText("\nText for CTabItem " + i + "\n\n");
        item.setControl(itemText);
    }
    cTabFolder.setSelection(cTabFolder.getItem(0));

    overrideCTabFolder = new CTabFolder(shell, SWT.NONE);
    for (int i = 0; i < 3; i++) {
        CTabItem item = new CTabItem(overrideCTabFolder, SWT.NONE);
        item.setText("CTabItem &" + i);
        item.setToolTipText("TabItem ToolTip" + i);
        Text itemText = new Text(overrideCTabFolder, SWT.MULTI | SWT.BORDER);
        itemText.setText("\nText for CTabItem " + i + "\n\n");
        item.setControl(itemText);
    }
    overrideCTabFolder.setSelection(overrideCTabFolder.getItem(0));
    overrideCTabFolder.setData("name", "CTabFolder");
    overrideCTabFolder.setData("child", "CTabItem");
    overrideCTabFolder.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      StyledText styledText, overrideStyledText;
    styledText = new StyledText(shell, SWT.SINGLE | SWT.BORDER);
    styledText.setText("Contents of single-line StyledText");

    overrideStyledText = new StyledText(shell, SWT.SINGLE | SWT.BORDER);
    overrideStyledText.setText("Contents of single-line StyledText");
    overrideStyledText.setData("name", "StyledText");
    overrideStyledText.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      StyledText multiLineStyledText, overrideMultiLineStyledText;
    multiLineStyledText = new StyledText(shell, SWT.MULTI | SWT.BORDER);
    multiLineStyledText.setText("Contents of multi-line StyledText\nLine 2\nLine 3\nLine 4");

    overrideMultiLineStyledText = new StyledText(shell, SWT.MULTI | SWT.BORDER);
    overrideMultiLineStyledText.setText("Contents of multi-line StyledText\nLine 2\nLine 3\nLine 4");
    overrideMultiLineStyledText.setData("name", "MultiLineStyledText");
    overrideMultiLineStyledText.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Scale scale, overrideScale;
    scale = new Scale(shell, SWT.NONE);
    scale.setToolTipText("Scale ToolTip");

    overrideScale = new Scale(shell, SWT.NONE);
    overrideScale.setToolTipText("Scale ToolTip");
    overrideScale.setData("name", "Scale");
    overrideScale.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Slider slider, overrideSlider;
    slider = new Slider(shell, SWT.NONE);
    slider.setToolTipText("Slider ToolTip");

    overrideSlider = new Slider(shell, SWT.NONE);
    overrideSlider.setToolTipText("Slider ToolTip");
    overrideSlider.setData("name", "Slider");
    overrideSlider.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      ProgressBar progressBar, overrideProgressBar;
    if (!SWT.getPlatform().equals("cocoa")) {
        progressBar = new ProgressBar(shell, SWT.NONE);
        progressBar.setSelection(50);
        progressBar.setToolTipText("ProgressBar ToolTip");

        overrideProgressBar = new ProgressBar(shell, SWT.NONE);
        overrideProgressBar.setSelection(50);
        overrideProgressBar.setToolTipText("ProgressBar ToolTip");
        overrideProgressBar.setData("name", "ProgressBar");
        overrideProgressBar.getAccessible().addAccessibleListener(overrideAccessibleAdapter);
    }

    //      Sash sash, overrideSash;
    sash = new Sash(shell, SWT.BORDER);
    sash.setToolTipText("Sash ToolTip");

    overrideSash = new Sash(shell, SWT.BORDER);
    overrideSash.setToolTipText("Sash ToolTip");
    overrideSash.setData("name", "Sash");
    overrideSash.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    //      Link link, overrideLink;
    link = new Link(shell, SWT.NONE);
    link.setText("<a>This is a link</a>");
    link.setToolTipText("Link ToolTip");

    overrideLink = new Link(shell, SWT.NONE);
    overrideLink.setText("<a>This is a link</a>");
    overrideLink.setToolTipText("Link ToolTip");
    overrideLink.setData("name", "Link");
    overrideLink.getAccessible().addAccessibleListener(overrideAccessibleAdapter);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    largeImage.dispose();
    smallImage.dispose();
    transparentImage.dispose();
    display.dispose();
}

From source file:net.bioclipse.plugins.views.ChartView.java

/**
 * Displays a chart in ChartView and sets up its mouse listener
 * @param chart//from   ww w  . j a  va2s .com
 */
public void display(JFreeChart chart) {
    final ChartDescriptor cd = ChartUtils.getChartDescriptor(chart);

    JFreeChartTab chartTab = new JFreeChartTab(tabFolder, SWT.CLOSE);
    chartTab.setText(chart.getTitle().getText());
    chartTab.setChart(chart);

    Composite composite = new Composite(tabFolder, SWT.EMBEDDED | SWT.NO_BACKGROUND);
    chartTab.setControl(composite);

    frame = SWT_AWT.new_Frame(composite);

    final ChartPanel chartPanel = new ChartPanel(chart);

    //Since methods are called on a java.awt.Frame it has to be called on the swing/awt thread 
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            frame.removeAll();
            frame.add(chartPanel);
            frame.setVisible(true);

            if (cd.getPlotType() == ChartConstants.SCATTER_PLOT) {
                //Listens for mouseclicks on points
                XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
                plot.setRenderer(new ScatterPlotRenderer(false, true));

                if (ChartView.IS_MACOS) {
                    frame.addMouseListener(pmh);
                    frame.addMouseMotionListener(pmh);
                } else {
                    chartPanel.addMouseListener(pmh);
                    frame.addMouseMotionListener(pmh);
                }
            }
        }
    });
    tabFolder.setSelection(chartTab);
    tabFolder.forceFocus();
    tabFolder.layout();
    ChartUtils.setActiveChart(chart);

    //Make sure actions are enabled when the chart has been created
    saveImageActionJPG.setEnabled(true);
    saveImageActionPNG.setEnabled(true);
    saveImageActionSVG.setEnabled(true);
}

From source file:AddressBook.java

/**
 * Creates the page contents//w w  w . j  a v  a  2 s . co m
 * 
 * @param parent
 *            the parent composite
 */
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));

    // Create the label and text field for first name
    new Label(composite, SWT.LEFT).setText("First Name:");
    final Text first = new Text(composite, SWT.BORDER);
    first.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Create the label and text field for last name
    new Label(composite, SWT.LEFT).setText("Last Name:");
    final Text last = new Text(composite, SWT.BORDER);
    last.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Add the handler to update the first name based on input
    first.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            firstName = first.getText();
            setPageComplete(firstName.length() > 0 && lastName.length() > 0);
        }
    });

    // Add the handler to update the last name based on input
    last.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            lastName = last.getText();
            setPageComplete(firstName.length() > 0 && lastName.length() > 0);
        }
    });

    setControl(composite);
}