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

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

Introduction

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

Prototype

public Label(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:AddressBookDemo.java

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);/*from w w  w .jav a 2s . co  m*/
    layout.numColumns = 2;
    layout.verticalSpacing = 9;

    Label label = new Label(container, SWT.NULL);
    label.setText("&Given Name:");

    givenNameText = new Text(container, SWT.BORDER | SWT.SINGLE);

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    givenNameText.setLayoutData(gd);
    givenNameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });

    label = new Label(container, SWT.NULL);
    label.setText("&Family Name:");

    familyNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    familyNameText.setLayoutData(gd);
    familyNameText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });

    label = new Label(container, SWT.NULL);
    label.setText("&Nickname:");

    nickNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    nickNameText.setLayoutData(gd);

    createLine(container, layout.numColumns);

    label = new Label(container, SWT.NULL);
    label.setText("&Business Phone:");

    businessPhoneText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    businessPhoneText.setLayoutData(gd);

    label = new Label(container, SWT.NULL);
    label.setText("&Home Phone:");

    homePhoneText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    homePhoneText.setLayoutData(gd);

    createLine(container, layout.numColumns);

    label = new Label(container, SWT.NULL);
    label.setText("&E-Mail Address:");

    emailText = new Text(container, SWT.BORDER | SWT.SINGLE);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    emailText.setLayoutData(gd);
    emailText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            dialogChanged();
        }
    });

    // dialogChanged();
    setControl(container);
}

From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java

void createFileTransfer(Composite copyParent, Composite pasteParent) {
    //File Transfer
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("FileTransfer:"); //$NON-NLS-1$
    GridData data = new GridData();
    data.verticalSpan = 3;//from  w w w . j a va2s  .co  m
    l.setLayoutData(data);

    final Table copyFileTable = new Table(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    data.verticalSpan = 3;
    copyFileTable.setLayoutData(data);

    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Select file(s)");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
        String result = dialog.open();
        if (result != null && result.length() > 0) {
            String path = dialog.getFilterPath();
            String[] names = dialog.getFileNames();
            for (String name : names) {
                TableItem item = new TableItem(copyFileTable, SWT.NONE);
                item.setText(path + File.separator + name);
            }
        }
    }));
    b = new Button(copyParent, SWT.PUSH);
    b.setText("Select directory");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
        String result = dialog.open();
        if (result != null && result.length() > 0) {
            //copyFileTable.removeAll();
            TableItem item = new TableItem(copyFileTable, SWT.NONE);
            item.setText(result);
        }
    }));

    b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        TableItem[] items = copyFileTable.getItems();
        if (items.length > 0) {
            status.setText("");
            String[] itemsData = new String[items.length];
            for (int i = 0; i < itemsData.length; i++) {
                itemsData[i] = items[i].getText();
            }
            clipboard.setContents(new Object[] { itemsData }, new Transfer[] { FileTransfer.getInstance() });
        } else {
            status.setText("No file to copy");
        }
    }));

    l = new Label(pasteParent, SWT.NONE);
    l.setText("FileTransfer:"); //$NON-NLS-1$
    final Table pasteFileTable = new Table(pasteParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    pasteFileTable.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        String[] textData = (String[]) clipboard.getContents(FileTransfer.getInstance());
        if (textData != null && textData.length > 0) {
            status.setText("");
            pasteFileTable.removeAll();
            for (String element : textData) {
                TableItem item = new TableItem(pasteFileTable, SWT.NONE);
                item.setText(element);
            }
        } else {
            status.setText("No file to paste");
        }
    }));
}

From source file:org.eclipse.swt.examples.paint.PaintExample.java

/**
 * Creates the GUI.//  ww w.j a  v  a 2s .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() {
        @Override
        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 = 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(widgetSelectedAdapter(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(widgetSelectedAdapter(e -> {
        toolSettings.airbrushIntensity = airbrushIntensityScale.getSelection();
        updateToolSettings();
    }));
}

From source file:org.pentaho.di.ui.spoon.trans.TransPerfDelegate.java

/**
 * Tell the user that the transformation is not running or that there is no monitoring configured.
 *//*from  www . j a va 2s.c  o  m*/
private void showEmptyGraph() {
    if (perfComposite.isDisposed()) {
        return;
    }

    emptyGraph = true;

    Label label = new Label(perfComposite, SWT.CENTER);
    label.setText(BaseMessages.getString(PKG, "TransLog.Dialog.PerformanceMonitoringNotEnabled.Message"));
    label.setBackground(perfComposite.getBackground());
    label.setFont(GUIResource.getInstance().getFontMedium());

    FormData fdLabel = new FormData();
    fdLabel.left = new FormAttachment(5, 0);
    fdLabel.right = new FormAttachment(95, 0);
    fdLabel.top = new FormAttachment(5, 0);
    label.setLayoutData(fdLabel);

    Button button = new Button(perfComposite, SWT.CENTER);
    button.setText(BaseMessages.getString(PKG, "TransLog.Dialog.PerformanceMonitoring.Button"));
    button.setBackground(perfComposite.getBackground());
    button.setFont(GUIResource.getInstance().getFontMedium());

    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            TransGraph.editProperties(spoon.getActiveTransformation(), spoon, spoon.rep, true,
                    TransDialog.Tabs.MONITOR_TAB);
        }
    });

    FormData fdButton = new FormData();
    fdButton.left = new FormAttachment(40, 0);
    fdButton.right = new FormAttachment(60, 0);
    fdButton.top = new FormAttachment(label, 5);
    button.setLayoutData(fdButton);

    perfComposite.layout(true, true);
}

From source file:ReservationData.java

public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout gridLayout = new GridLayout(2, false);
    composite.setLayout(gridLayout);//from   www .ja  v  a2 s.c o m

    new Label(composite, SWT.NULL).setText("Arrival date: ");

    Composite compositeArrival = new Composite(composite, SWT.NULL);
    compositeArrival.setLayout(new RowLayout());

    String[] months = new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
            "Nov", "Dec" };

    Calendar calendar = new GregorianCalendar(); // today.
    ((ReservationWizard) getWizard()).data.arrivalDate = calendar.getTime();

    comboArrivalMonth = new Combo(compositeArrival, SWT.BORDER | SWT.READ_ONLY);
    for (int i = 0; i < months.length; i++)
        comboArrivalMonth.add(months[i]);
    comboArrivalMonth.select(calendar.get(Calendar.MONTH));

    comboArrivalDay = new Combo(compositeArrival, SWT.BORDER | SWT.READ_ONLY);
    for (int i = 0; i < 31; i++)
        comboArrivalDay.add("" + (i + 1));
    comboArrivalDay.select(calendar.get(Calendar.DAY_OF_MONTH) - 1);

    comboArrivalYear = new Combo(compositeArrival, SWT.BORDER | SWT.READ_ONLY);
    for (int i = 2004; i < 2010; i++)
        comboArrivalYear.add("" + i);
    comboArrivalYear.select(calendar.get(Calendar.YEAR) - 2004);

    calendar.add(Calendar.DATE, 1); // tomorrow. 
    ((ReservationWizard) getWizard()).data.departureDate = calendar.getTime();

    new Label(composite, SWT.NULL).setText("Departure date: ");

    Composite compositeDeparture = new Composite(composite, SWT.NULL | SWT.READ_ONLY);
    compositeDeparture.setLayout(new RowLayout());

    comboDepartureMonth = new Combo(compositeDeparture, SWT.NULL | SWT.READ_ONLY);
    for (int i = 0; i < months.length; i++)
        comboDepartureMonth.add(months[i]);
    comboDepartureMonth.select(calendar.get(Calendar.MONTH));

    comboDepartureDay = new Combo(compositeDeparture, SWT.NULL | SWT.READ_ONLY);
    for (int i = 0; i < 31; i++)
        comboDepartureDay.add("" + (i + 1));
    comboDepartureDay.select(calendar.get(Calendar.DAY_OF_MONTH) - 1);

    comboDepartureYear = new Combo(compositeDeparture, SWT.NULL | SWT.READ_ONLY);
    for (int i = 2004; i < 2010; i++)
        comboDepartureYear.add("" + i);
    comboDepartureYear.select(calendar.get(Calendar.YEAR) - 2004);

    // draws a line. 
    Label line = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);

    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    line.setLayoutData(gridData);

    new Label(composite, SWT.NULL).setText("Room type: ");
    comboRoomTypes = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
    comboRoomTypes.add("Standard room (rate: $198)");
    comboRoomTypes.add("Deluxe room (rate: $298)");
    comboRoomTypes.select(0);

    Listener selectionListener = new Listener() {
        public void handleEvent(Event event) {
            int arrivalDay = comboArrivalDay.getSelectionIndex() + 1;
            int arrivalMonth = comboArrivalMonth.getSelectionIndex();
            int arrivalYear = comboArrivalYear.getSelectionIndex() + 2004;

            int departureDay = comboDepartureDay.getSelectionIndex() + 1;
            int departureMonth = comboDepartureMonth.getSelectionIndex();
            int departureYear = comboDepartureYear.getSelectionIndex() + 2004;

            setDates(arrivalDay, arrivalMonth, arrivalYear, departureDay, departureMonth, departureYear);
        }
    };

    comboArrivalDay.addListener(SWT.Selection, selectionListener);
    comboArrivalMonth.addListener(SWT.Selection, selectionListener);
    comboArrivalYear.addListener(SWT.Selection, selectionListener);
    comboDepartureDay.addListener(SWT.Selection, selectionListener);
    comboDepartureMonth.addListener(SWT.Selection, selectionListener);
    comboDepartureYear.addListener(SWT.Selection, selectionListener);

    comboRoomTypes.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            ((ReservationWizard) getWizard()).data.roomType = comboRoomTypes.getSelectionIndex();
        }
    });

    setControl(composite);

}

From source file:PaintExample.java

/**
 * Creates the GUI./*from ww w  . j a va  2  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:ClipboardExample.java

void createControlTransfer(Composite parent) {
    Label l = new Label(parent, SWT.NONE);
    l.setText("Text:");
    Button b = new Button(parent, SWT.PUSH);
    b.setText("Cut");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            text.cut();//from   w  w  w .  j a  v a  2 s  .co  m
        }
    });
    b = new Button(parent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            text.copy();
        }
    });
    b = new Button(parent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            text.paste();
        }
    });
    text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    text.setLayoutData(data);

    l = new Label(parent, SWT.NONE);
    l.setText("Combo:");
    b = new Button(parent, SWT.PUSH);
    b.setText("Cut");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            combo.cut();
        }
    });
    b = new Button(parent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            combo.copy();
        }
    });
    b = new Button(parent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            combo.paste();
        }
    });
    combo = new Combo(parent, SWT.NONE);
    combo.setItems(new String[] { "Item 1", "Item 2", "Item 3", "A longer Item" });

    l = new Label(parent, SWT.NONE);
    l.setText("StyledText:");
    l = new Label(parent, SWT.NONE);
    l.setVisible(false);
    b = new Button(parent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            styledText.copy();
        }
    });
    b = new Button(parent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            styledText.paste();
        }
    });
    styledText = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    styledText.setLayoutData(data);
}

From source file:org.eclipse.swt.snippets.SnippetExplorer.java

/** Initialize the SnippetExplorer controls.
 *
 * @param shell parent shell//from w w w .  j a va  2 s .c om
 */
private void createControls(Shell shell) {
    shell.setLayout(new FormLayout());

    if (listUpdater == null) {
        listUpdater = new ListUpdater();
        listUpdater.start();
    }

    final Composite leftContainer = new Composite(shell, SWT.NONE);
    leftContainer.setLayout(new GridLayout());

    final Sash splitter = new Sash(shell, SWT.BORDER | SWT.VERTICAL);
    final int splitterWidth = 3;
    splitter.addListener(SWT.Selection, e -> splitter.setBounds(e.x, e.y, e.width, e.height));

    final Composite rightContainer = new Composite(shell, SWT.NONE);
    rightContainer.setLayout(new GridLayout());

    FormData formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.right = new FormAttachment(splitter, 0);
    formData.top = new FormAttachment(0, 0);
    formData.bottom = new FormAttachment(100, 0);
    leftContainer.setLayoutData(formData);

    formData = new FormData();
    formData.left = new FormAttachment(50, 0);
    formData.right = new FormAttachment(50, splitterWidth);
    formData.top = new FormAttachment(0, 0);
    formData.bottom = new FormAttachment(100, 0);
    splitter.setLayoutData(formData);
    splitter.addListener(SWT.Selection, event -> {
        final FormData splitterFormData = (FormData) splitter.getLayoutData();
        splitterFormData.left = new FormAttachment(0, event.x);
        splitterFormData.right = new FormAttachment(0, event.x + splitterWidth);
        shell.layout();
    });

    formData = new FormData();
    formData.left = new FormAttachment(splitter, 0);
    formData.right = new FormAttachment(100, 0);
    formData.top = new FormAttachment(0, 0);
    formData.bottom = new FormAttachment(100, 0);
    rightContainer.setLayoutData(formData);

    filterField = new Text(leftContainer,
            SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
    filterField.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    filterField.setMessage(FILTER_HINT);
    filterField.addListener(SWT.Modify, event -> {
        listUpdater.updateInMs(FILTER_DELAY_MS);
    });
    snippetTable = new Table(leftContainer, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
    snippetTable.setLinesVisible(true);
    snippetTable.setHeaderVisible(true);
    final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.heightHint = 500;
    snippetTable.setLayoutData(data);
    snippetTable.addListener(SWT.MouseDoubleClick, event -> {
        final Point clickPoint = new Point(event.x, event.y);
        launchSnippet(snippetTable.getItem(clickPoint));
    });
    snippetTable.addListener(SWT.KeyUp, event -> {
        if (event.keyCode == '\r' || event.keyCode == '\n') {
            launchSnippet(snippetTable.getSelection());
        }
    });

    final Composite buttonRow = new Composite(leftContainer, SWT.NONE);
    buttonRow.setLayout(new GridLayout(3, false));
    buttonRow.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));

    startSelectedButton = new Button(buttonRow, SWT.LEAD);
    startSelectedButton.setText("  Start &selected Snippets");
    snippetTable.addListener(SWT.Selection, event -> {
        startSelectedButton.setEnabled(snippetTable.getSelectionCount() > 0);
        updateInfoTab(snippetTable.getSelection());
    });
    startSelectedButton.setEnabled(snippetTable.getSelectionCount() > 0);
    startSelectedButton.addListener(SWT.Selection, event -> {
        launchSnippet(snippetTable.getSelection());
    });

    final Label runnerLabel = new Label(buttonRow, SWT.NONE);
    runnerLabel.setText("Snippet Runner:");
    runnerLabel.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false));

    runnerCombo = new Combo(buttonRow, SWT.TRAIL | SWT.DROP_DOWN | SWT.READ_ONLY);
    runnerMapping.clear();
    if (multiDisplaySupport) {
        runnerCombo.add("Thread");
        runnerMapping.add(THREAD_RUNNER);
    }
    if (javaCommand != null) {
        runnerCombo.add("Process");
        runnerMapping.add(PROCESS_RUNNER);
    }
    runnerCombo.add("Serial");
    runnerMapping.add(null);
    runnerCombo.setData(runnerMapping);
    runnerCombo.addListener(SWT.Modify, event -> {
        if (runnerMapping.size() > runnerCombo.getSelectionIndex()) {
            snippetRunner = runnerMapping.get(runnerCombo.getSelectionIndex());
        } else {
            System.err.println("Unknown runner index " + runnerCombo.getSelectionIndex());
        }
    });
    runnerCombo.select(0);

    infoTabs = new TabFolder(rightContainer, SWT.TOP);
    infoTabs.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    descriptionView = new StyledText(infoTabs, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY | SWT.V_SCROLL);

    sourceView = new StyledText(infoTabs, SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    setMonospaceFont(sourceView);

    final ScrolledComposite previewContainer = new ScrolledComposite(infoTabs, SWT.V_SCROLL | SWT.H_SCROLL);
    previewImageLabel = new Label(previewContainer, SWT.NONE);
    previewContainer.setContent(previewImageLabel);

    final TabItem descriptionTab = new TabItem(infoTabs, SWT.NONE);
    descriptionTab.setText("Description");
    descriptionTab.setControl(descriptionView);
    final TabItem sourceTab = new TabItem(infoTabs, SWT.NONE);
    sourceTab.setText("Source");
    sourceTab.setControl(sourceView);
    final TabItem previewTab = new TabItem(infoTabs, SWT.NONE);
    previewTab.setText("Preview");
    previewTab.setControl(previewContainer);

    updateInfoTab(null, true);
    updateInfoTab(snippetTable.getSelection());
}

From source file:CalculatorMichaelSchmidt.java

@Override
protected Control createDialogArea(final Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    final GridLayout calculatorGridLayout = new GridLayout();
    calculatorGridLayout.marginRight = 5;
    calculatorGridLayout.marginLeft = 5;
    calculatorGridLayout.marginBottom = 5;
    calculatorGridLayout.marginTop = 5;//from  w  ww  . j a v  a 2 s.  c o m
    calculatorGridLayout.marginWidth = 10;
    calculatorGridLayout.marginHeight = 2;
    calculatorGridLayout.numColumns = 4;
    calculatorGridLayout.verticalSpacing = 2;
    calculatorGridLayout.makeColumnsEqualWidth = true;
    calculatorGridLayout.horizontalSpacing = 2;
    container.setLayout(calculatorGridLayout);

    // The display.  Note that it has a limit of 30 characters, 
    // much greater than the length of a double-precision number. 
    displayText = new Text(container, SWT.RIGHT | SWT.BORDER);
    displayText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    displayText.setEditable(false);
    displayText.setDoubleClickEnabled(false);
    displayText.setTextLimit(30);
    displayText.setText(displayString);
    displayText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 4, 1));

    final Button msButton = new Button(container, SWT.NONE);
    msButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateMemory('S');
        }
    });
    msButton.setToolTipText("Save value to Memory");
    msButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    msButton.setText("MS");

    final Button mcButton = new Button(container, SWT.NONE);
    mcButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('D');
        }
    });
    mcButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    mcButton.setToolTipText("Clear Memory");
    mcButton.setText("MC");

    final Button clearButton = new Button(container, SWT.NONE);
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('C');
        }
    });
    clearButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    clearButton.setToolTipText("Clear all Calculator Registers");
    clearButton.setText("C");

    final Button ceButton = new Button(container, SWT.NONE);
    ceButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('E');
        }
    });
    ceButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    ceButton.setToolTipText("Clear Entry");
    ceButton.setText("CE");

    final Button memAddButton = new Button(container, SWT.NONE);
    memAddButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateMemory('+');
        }
    });
    memAddButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    memAddButton.setToolTipText("Add value to Memory");
    memAddButton.setText("M+");

    final Button mrButton = new Button(container, SWT.NONE);
    mrButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('R');
        }
    });
    mrButton.setToolTipText("Recall value in Memory");
    mrButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    mrButton.setText("MR");

    final Button backButton = new Button(container, SWT.NONE);
    backButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('B');
        }
    });
    backButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    backButton.setToolTipText("Backspace");
    backButton.setText("BACK");

    final Button divideButton = new Button(container, SWT.NONE);
    divideButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateCalc('/');
        }
    });
    divideButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    divideButton.setToolTipText("Divide");
    divideButton.setText("/");

    final Button memSubtractButton = new Button(container, SWT.NONE);
    memSubtractButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateMemory('-');
        }
    });
    memSubtractButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    memSubtractButton.setToolTipText("Subtract value from Memory");
    memSubtractButton.setText("M-");

    final Button inverseButton = new Button(container, SWT.NONE);
    inverseButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('I');
        }
    });
    inverseButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    inverseButton.setToolTipText("Inverse of value");
    inverseButton.setText("1/X");

    final Button sqrtButton = new Button(container, SWT.NONE);
    sqrtButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('Q');
        }
    });
    sqrtButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    sqrtButton.setToolTipText("Square Root of value");
    sqrtButton.setText("SQRT");

    final Button multiplyButton = new Button(container, SWT.NONE);
    multiplyButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateCalc('*');
        }
    });
    multiplyButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    multiplyButton.setToolTipText("Multiply");
    multiplyButton.setText("*");

    final Button num7Button = new Button(container, SWT.NONE);
    num7Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('7');
        }
    });
    num7Button.setToolTipText("Numeric Pad");
    num7Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num7Button.setText("7");

    final Button num8Button = new Button(container, SWT.NONE);
    num8Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('8');
        }
    });
    num8Button.setToolTipText("Numeric Pad");
    num8Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num8Button.setText("8");

    final Button num9Button = new Button(container, SWT.NONE);
    num9Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('9');
        }
    });
    num9Button.setToolTipText("Numeric Pad");
    num9Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num9Button.setText("9");

    final Button SubtractButton = new Button(container, SWT.NONE);
    SubtractButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateCalc('-');
        }
    });
    SubtractButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    SubtractButton.setToolTipText("Subtract");
    SubtractButton.setText("-");

    final Button num4Button = new Button(container, SWT.NONE);
    num4Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('4');
        }
    });
    num4Button.setToolTipText("Numeric Pad");
    num4Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num4Button.setText("4");

    final Button num5Button = new Button(container, SWT.NONE);
    num5Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('5');
        }
    });
    num5Button.setToolTipText("Numeric Pad");
    num5Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num5Button.setText("5");

    final Button num6Button = new Button(container, SWT.NONE);
    num6Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('6');
        }
    });
    num6Button.setToolTipText("Numeric Pad");
    num6Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num6Button.setText("6");

    final Button AdditionButton = new Button(container, SWT.NONE);
    AdditionButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateCalc('+');
        }
    });
    AdditionButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    AdditionButton.setToolTipText("Add");
    AdditionButton.setText("+");

    final Button num1Button = new Button(container, SWT.NONE);
    num1Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('1');
        }
    });
    num1Button.setCapture(true);
    num1Button.setToolTipText("Numeric Pad");
    num1Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num1Button.setText("1");

    final Button num2Button = new Button(container, SWT.NONE);
    num2Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('2');
        }
    });
    num2Button.setToolTipText("Numeric Pad");
    num2Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num2Button.setText("2");

    final Button num3Button = new Button(container, SWT.NONE);
    num3Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('3');
        }
    });
    num3Button.setToolTipText("Numeric Pad");
    num3Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num3Button.setText("3");

    final Button equalsButton = new Button(container, SWT.NONE);
    equalsButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateCalc('=');
        }
    });
    equalsButton.setToolTipText("Equals (get result)");
    equalsButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 2));
    equalsButton.setText("=");

    final Button num0Button = new Button(container, SWT.NONE);
    num0Button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('0');
        }
    });
    num0Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    num0Button.setToolTipText("Numeric Pad");
    num0Button.setText("0");

    final Button decimalButton = new Button(container, SWT.NONE);
    decimalButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('.');
        }
    });
    decimalButton.setToolTipText("Numeric Pad");
    decimalButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    decimalButton.setText(".");

    final Button signButton = new Button(container, SWT.NONE);
    signButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            updateDisplay('-');
        }
    });
    signButton.setToolTipText("Change sign of value");
    signButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    signButton.setText("+/-");
    new Label(container, SWT.NONE);
    //
    return container;
}

From source file:org.eclipse.swt.examples.imageanalyzer.ImageAnalyzer.java

void createWidgets() {
    // Add the widgets to the shell in a grid layout.
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;//w w  w  .  ja  v a  2  s  .c o m
    layout.numColumns = 2;
    shell.setLayout(layout);

    // Add a composite to contain some control widgets across the top.
    Composite controls = new Composite(shell, SWT.NONE);
    RowLayout rowLayout = new RowLayout();
    rowLayout.marginTop = 5;
    rowLayout.marginBottom = 5;
    rowLayout.spacing = 8;
    controls.setLayout(rowLayout);
    GridData gridData = new GridData();
    gridData.horizontalSpan = 2;
    controls.setLayoutData(gridData);

    // Combo to change the background.
    Group group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("Background"));
    backgroundCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    backgroundCombo.setItems(bundle.getString("None"), bundle.getString("White"), bundle.getString("Black"),
            bundle.getString("Red"), bundle.getString("Green"), bundle.getString("Blue"));
    backgroundCombo.select(backgroundCombo.indexOf(bundle.getString("White")));
    backgroundCombo.addSelectionListener(widgetSelectedAdapter(event -> changeBackground()));

    // Combo to change the compression ratio.
    group = new Group(controls, SWT.NONE);
    group.setLayout(new GridLayout(3, true));
    group.setText(bundle.getString("Save_group"));
    imageTypeCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    String[] types = { "JPEG", "PNG", "GIF", "ICO", "TIFF", "BMP" };
    for (String type : types) {
        imageTypeCombo.add(type);
    }
    imageTypeCombo.select(imageTypeCombo.indexOf("JPEG"));
    imageTypeCombo.addSelectionListener(widgetSelectedAdapter(event -> {
        int index = imageTypeCombo.getSelectionIndex();
        switch (index) {
        case 0:
            compressionCombo.setEnabled(true);
            compressionRatioLabel.setEnabled(true);
            if (compressionCombo.getItemCount() == 100)
                break;
            compressionCombo.removeAll();
            for (int i = 0; i < 100; i++) {
                compressionCombo.add(String.valueOf(i + 1));
            }
            compressionCombo.select(compressionCombo.indexOf("75"));
            break;
        case 1:
            compressionCombo.setEnabled(true);
            compressionRatioLabel.setEnabled(true);
            if (compressionCombo.getItemCount() == 10)
                break;
            compressionCombo.removeAll();
            for (int i = 0; i < 4; i++) {
                compressionCombo.add(String.valueOf(i));
            }
            compressionCombo.select(0);
            break;
        case 2:
        case 3:
        case 4:
        case 5:
            compressionCombo.setEnabled(false);
            compressionRatioLabel.setEnabled(false);
            break;
        }
    }));
    imageTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    compressionRatioLabel = new Label(group, SWT.NONE);
    compressionRatioLabel.setText(bundle.getString("Compression"));
    compressionRatioLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    compressionCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    for (int i = 0; i < 100; i++) {
        compressionCombo.add(String.valueOf(i + 1));
    }
    compressionCombo.select(compressionCombo.indexOf("75"));
    compressionCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Combo to change the x scale.
    String[] values = { "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1", "1.1", "1.2", "1.3",
            "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2", "3", "4", "5", "6", "7", "8", "9", "10", };
    group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("X_scale"));
    scaleXCombo = new Combo(group, SWT.DROP_DOWN);
    for (String value : values) {
        scaleXCombo.add(value);
    }
    scaleXCombo.select(scaleXCombo.indexOf("1"));
    scaleXCombo.addSelectionListener(widgetSelectedAdapter(event -> scaleX()));

    // Combo to change the y scale.
    group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("Y_scale"));
    scaleYCombo = new Combo(group, SWT.DROP_DOWN);
    for (String value : values) {
        scaleYCombo.add(value);
    }
    scaleYCombo.select(scaleYCombo.indexOf("1"));
    scaleYCombo.addSelectionListener(widgetSelectedAdapter(event -> scaleY()));

    // Combo to change the alpha value.
    group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("Alpha_K"));
    alphaCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    for (int i = 0; i <= 255; i += 5) {
        alphaCombo.add(String.valueOf(i));
    }
    alphaCombo.select(alphaCombo.indexOf("255"));
    alphaCombo.addSelectionListener(widgetSelectedAdapter(event -> alpha()));

    // Check box to request incremental display.
    group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("Display"));
    incrementalCheck = new Button(group, SWT.CHECK);
    incrementalCheck.setText(bundle.getString("Incremental"));
    incrementalCheck.setSelection(incremental);
    incrementalCheck.addSelectionListener(
            widgetSelectedAdapter(event -> incremental = ((Button) event.widget).getSelection()));

    // Check box to request transparent display.
    transparentCheck = new Button(group, SWT.CHECK);
    transparentCheck.setText(bundle.getString("Transparent"));
    transparentCheck.setSelection(transparent);
    transparentCheck.addSelectionListener(widgetSelectedAdapter(event -> {
        transparent = ((Button) event.widget).getSelection();
        if (image != null) {
            imageCanvas.redraw();
        }
    }));

    // Check box to request mask display.
    maskCheck = new Button(group, SWT.CHECK);
    maskCheck.setText(bundle.getString("Mask"));
    maskCheck.setSelection(showMask);
    maskCheck.addSelectionListener(widgetSelectedAdapter(event -> {
        showMask = ((Button) event.widget).getSelection();
        if (image != null) {
            imageCanvas.redraw();
        }
    }));

    // Check box to request background display.
    backgroundCheck = new Button(group, SWT.CHECK);
    backgroundCheck.setText(bundle.getString("Background"));
    backgroundCheck.setSelection(showBackground);
    backgroundCheck.addSelectionListener(
            widgetSelectedAdapter(event -> showBackground = ((Button) event.widget).getSelection()));

    // Group the animation buttons.
    group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("Animation"));

    // Push button to display the previous image in a multi-image file.
    previousButton = new Button(group, SWT.PUSH);
    previousButton.setText(bundle.getString("Previous"));
    previousButton.setEnabled(false);
    previousButton.addSelectionListener(widgetSelectedAdapter(event -> previous()));

    // Push button to display the next image in a multi-image file.
    nextButton = new Button(group, SWT.PUSH);
    nextButton.setText(bundle.getString("Next"));
    nextButton.setEnabled(false);
    nextButton.addSelectionListener(widgetSelectedAdapter(event -> next()));

    // Push button to toggle animation of a multi-image file.
    animateButton = new Button(group, SWT.PUSH);
    animateButton.setText(bundle.getString("Animate"));
    animateButton.setEnabled(false);
    animateButton.addSelectionListener(widgetSelectedAdapter(event -> animate()));

    // Label to show the image file type.
    typeLabel = new Label(shell, SWT.NONE);
    typeLabel.setText(bundle.getString("Type_initial"));
    typeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Canvas to show the image.
    imageCanvas = new Canvas(shell, SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
    imageCanvas.setBackground(whiteColor);
    imageCanvas.setCursor(crossCursor);
    gridData = new GridData();
    gridData.verticalSpan = 15;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    imageCanvas.setLayoutData(gridData);
    imageCanvas.addPaintListener(event -> {
        if (image == null) {
            Rectangle bounds = imageCanvas.getBounds();
            event.gc.fillRectangle(0, 0, bounds.width, bounds.height);
        } else {
            paintImage(event);
        }
    });
    imageCanvas.addMouseMoveListener(event -> {
        if (image != null) {
            showColorAt(event.x, event.y);
        }
    });

    // Set up the image canvas scroll bars.
    ScrollBar horizontal = imageCanvas.getHorizontalBar();
    horizontal.setVisible(true);
    horizontal.setMinimum(0);
    horizontal.setEnabled(false);
    horizontal
            .addSelectionListener(widgetSelectedAdapter(event -> scrollHorizontally((ScrollBar) event.widget)));
    ScrollBar vertical = imageCanvas.getVerticalBar();
    vertical.setVisible(true);
    vertical.setMinimum(0);
    vertical.setEnabled(false);
    vertical.addSelectionListener(widgetSelectedAdapter(event -> scrollVertically((ScrollBar) event.widget)));

    // Label to show the image size.
    sizeLabel = new Label(shell, SWT.NONE);
    sizeLabel.setText(bundle.getString("Size_initial"));
    sizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image depth.
    depthLabel = new Label(shell, SWT.NONE);
    depthLabel.setText(bundle.getString("Depth_initial"));
    depthLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the transparent pixel.
    transparentPixelLabel = new Label(shell, SWT.NONE);
    transparentPixelLabel.setText(bundle.getString("Transparent_pixel_initial"));
    transparentPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the time to load.
    timeToLoadLabel = new Label(shell, SWT.NONE);
    timeToLoadLabel.setText(bundle.getString("Time_to_load_initial"));
    timeToLoadLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Separate the animation fields from the rest of the fields.
    Label separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the logical screen size for animation.
    screenSizeLabel = new Label(shell, SWT.NONE);
    screenSizeLabel.setText(bundle.getString("Animation_size_initial"));
    screenSizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the background pixel.
    backgroundPixelLabel = new Label(shell, SWT.NONE);
    backgroundPixelLabel.setText(bundle.getString("Background_pixel_initial"));
    backgroundPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image location (x, y).
    locationLabel = new Label(shell, SWT.NONE);
    locationLabel.setText(bundle.getString("Image_location_initial"));
    locationLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image disposal method.
    disposalMethodLabel = new Label(shell, SWT.NONE);
    disposalMethodLabel.setText(bundle.getString("Disposal_initial"));
    disposalMethodLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image delay time.
    delayTimeLabel = new Label(shell, SWT.NONE);
    delayTimeLabel.setText(bundle.getString("Delay_initial"));
    delayTimeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the background pixel.
    repeatCountLabel = new Label(shell, SWT.NONE);
    repeatCountLabel.setText(bundle.getString("Repeats_initial"));
    repeatCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Separate the animation fields from the palette.
    separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show if the image has a direct or indexed palette.
    paletteLabel = new Label(shell, SWT.NONE);
    paletteLabel.setText(bundle.getString("Palette_initial"));
    paletteLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Canvas to show the image's palette.
    paletteCanvas = new Canvas(shell, SWT.BORDER | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE);
    paletteCanvas.setFont(fixedWidthFont);
    paletteCanvas.getVerticalBar().setVisible(true);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    GC gc = new GC(paletteLabel);
    paletteWidth = gc.stringExtent(bundle.getString("Max_length_string")).x;
    gc.dispose();
    gridData.widthHint = paletteWidth;
    gridData.heightHint = 16 * 11; // show at least 16 colors
    paletteCanvas.setLayoutData(gridData);
    paletteCanvas.addPaintListener(event -> {
        if (image != null)
            paintPalette(event);
    });

    // Set up the palette canvas scroll bar.
    vertical = paletteCanvas.getVerticalBar();
    vertical.setVisible(true);
    vertical.setMinimum(0);
    vertical.setIncrement(10);
    vertical.setEnabled(false);
    vertical.addSelectionListener(widgetSelectedAdapter(event -> scrollPalette((ScrollBar) event.widget)));

    // Sash to see more of image or image data.
    sash = new Sash(shell, SWT.HORIZONTAL);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    sash.setLayoutData(gridData);
    sash.addSelectionListener(widgetSelectedAdapter(event -> {
        if (event.detail != SWT.DRAG) {
            ((GridData) paletteCanvas.getLayoutData()).heightHint = SWT.DEFAULT;
            Rectangle paletteCanvasBounds = paletteCanvas.getBounds();
            int minY = paletteCanvasBounds.y + 20;
            Rectangle dataLabelBounds = dataLabel.getBounds();
            int maxY = statusLabel.getBounds().y - dataLabelBounds.height - 20;
            if (event.y > minY && event.y < maxY) {
                Rectangle oldSash = sash.getBounds();
                sash.setBounds(event.x, event.y, event.width, event.height);
                int diff = event.y - oldSash.y;
                Rectangle bounds = imageCanvas.getBounds();
                imageCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
                bounds = paletteCanvasBounds;
                paletteCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
                bounds = dataLabelBounds;
                dataLabel.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height);
                bounds = dataText.getBounds();
                dataText.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height - diff);
                //shell.layout(true);
            }
        }
    }));

    // Label to show data-specific fields.
    dataLabel = new Label(shell, SWT.NONE);
    dataLabel.setText(bundle.getString("Pixel_data_initial"));
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    dataLabel.setLayoutData(gridData);

    // Text to show a dump of the data.
    dataText = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    dataText.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    dataText.setFont(fixedWidthFont);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.heightHint = 128;
    gridData.grabExcessVerticalSpace = true;
    dataText.setLayoutData(gridData);
    dataText.addMouseListener(MouseListener.mouseDownAdapter(event -> {
        if (image != null && event.button == 1) {
            showColorForData();
        }
    }));
    dataText.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent event) {
            if (image != null) {
                showColorForData();
            }
        }
    });

    // Label to show status and cursor location in image.
    statusLabel = new Label(shell, SWT.NONE);
    statusLabel.setText("");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    statusLabel.setLayoutData(gridData);
}