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

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);/*  w w w  .j  ava2s  .c  om*/
    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.imageanalyzer.ImageAnalyzer.java

void createWidgets() {
    // Add the widgets to the shell in a grid layout.
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;/*from ww w. j  av a 2  s  .c om*/
    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);
}

From source file:fr.inria.soctrace.framesoc.ui.piechart.view.StatisticsPieChartView.java

@Override
public void createFramesocPartControl(Composite parent) {

    // parent layout
    GridLayout gl_parent = new GridLayout(1, false);
    gl_parent.verticalSpacing = 2;//from   ww w .j a  v  a  2  s .  c om
    gl_parent.marginWidth = 0;
    gl_parent.horizontalSpacing = 0;
    gl_parent.marginHeight = 0;
    parent.setLayout(gl_parent);

    // -------------------------------
    // Base GUI: pie + table
    // -------------------------------

    SashForm sashForm = new SashForm(parent, SWT.BORDER | SWT.SMOOTH);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    // Composite Left: composite combo + composite pie
    Composite compositeLeft = new Composite(sashForm, SWT.NONE);
    GridLayout gl_compositeLeft = new GridLayout(1, false);
    gl_compositeLeft.marginBottom = 3;
    gl_compositeLeft.verticalSpacing = 0;
    gl_compositeLeft.marginHeight = 0;
    compositeLeft.setLayout(gl_compositeLeft);

    // Composite Combo
    Composite compositeCombo = new Composite(compositeLeft, SWT.NONE);
    compositeCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    GridLayout gl_compositeCombo = new GridLayout(1, false);
    gl_compositeCombo.marginWidth = 0;
    compositeCombo.setLayout(gl_compositeCombo);

    // combo
    combo = new Combo(compositeCombo, SWT.READ_ONLY);
    combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    combo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean firstTime = true;
            for (LoaderDescriptor d : loaderDescriptors) {
                firstTime = firstTime && !d.dataLoaded();
            }
            if (firstTime) {
                return;
            }
            currentDescriptor = loaderDescriptors.get(combo.getSelectionIndex());
            cleanTableFilter();
            refreshTableFilter();
            // use global load interval
            timeBar.setSelection(globalLoadInterval);
            loadPieChart();
        }
    });

    int position = 0;
    for (LoaderDescriptor descriptor : loaderDescriptors) {
        combo.add(descriptor.loader.getStatName(), position++);
    }
    combo.select(0);
    currentDescriptor = loaderDescriptors.get(0);
    combo.setEnabled(false);

    // Composite Pie
    compositePie = new Group(compositeLeft, SWT.NONE);
    // Fill layout with Grid Data (FILL) to allow correct resize
    compositePie.setLayout(new FillLayout());
    compositePie.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    txtDescription = new Text(compositePie, SWT.READ_ONLY | SWT.WRAP | SWT.CENTER | SWT.MULTI);
    txtDescription.setEnabled(false);
    txtDescription.setEditable(false);
    txtDescription.setText("Select one of the above metrics, then press the Load button.");
    txtDescription.setVisible(false);

    // Composite Table
    Composite compositeTable = new Composite(sashForm, SWT.NONE);
    GridLayout gl_compositeTable = new GridLayout(1, false);
    compositeTable.setLayout(gl_compositeTable);

    // filter
    textFilter = new Text(compositeTable, SWT.BORDER);
    textFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textFilter.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent e) {
            String filter = textFilter.getText().trim();
            if (filter.isEmpty()) {
                cleanTableFilter();
            }
        }

        @Override
        public void focusGained(FocusEvent e) {
            String filter = textFilter.getText().trim();
            if (filter.equals(FILTER_HINT)) {
                textFilter.setText("");
                textFilter.setData("");
                textFilter.setForeground(blackColor);
            }
        }
    });
    textFilter.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.CR || textFilter.getText().trim().isEmpty()) {
                textFilter.setData(textFilter.getText());
                refreshTableFilter();
            }
        }
    });

    // table
    tableTreeViewer = new TreeViewer(compositeTable,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL);
    tableTreeViewer.setContentProvider(new TreeContentProvider());
    comparator = new StatisticsColumnComparator();
    tableTreeViewer.setComparator(comparator);
    Tree table = tableTreeViewer.getTree();
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    createColumns();
    createContextMenu();

    // status bar
    Composite statusBar = new Composite(compositeTable, SWT.BORDER);
    GridLayout statusBarLayout = new GridLayout();
    GridData statusBarGridData = new GridData();
    statusBarGridData.horizontalAlignment = SWT.FILL;
    statusBarGridData.grabExcessHorizontalSpace = true;
    statusBar.setLayoutData(statusBarGridData);
    statusBarLayout.numColumns = 1;
    statusBar.setLayout(statusBarLayout);
    // text
    statusText = new Text(statusBar, SWT.NONE);
    statusText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    statusText.setText(getStatus(0, 0));

    // -------------------------------
    // TIME MANAGEMENT BAR
    // -------------------------------

    Composite timeComposite = new Composite(parent, SWT.BORDER);
    timeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gl_timeComposite = new GridLayout(1, false);
    gl_timeComposite.horizontalSpacing = 0;
    timeComposite.setLayout(gl_timeComposite);
    // time manager
    timeBar = new TimeBar(timeComposite, SWT.NONE, true, true);
    timeBar.setEnabled(false);
    combo.setEnabled(false);
    IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager();
    timeBar.setStatusLineManager(statusLineManager);

    // button to synch the timebar with the gantt
    timeBar.getSynchButton().addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (combo != null && timeBar != null && currentDescriptor != null) {
                if (currentDescriptor.dataLoaded()) {
                    timeBar.setSelection(currentDescriptor.interval.startTimestamp,
                            currentDescriptor.interval.endTimestamp);
                } else {
                    timeBar.setSelection(currentShownTrace.getMinTimestamp(),
                            currentShownTrace.getMaxTimestamp());
                }
            }
        }
    });
    timeBar.getSynchButton().setToolTipText("Synch Selection With Pie Chart");

    // load button
    timeBar.getLoadButton().addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (combo.getSelectionIndex() == -1)
                return;
            currentDescriptor = loaderDescriptors.get(combo.getSelectionIndex());
            cleanTableFilter();
            refreshTableFilter();
            loadPieChart();
        }
    });

    // ----------
    // TOOL BAR
    // ----------

    // filters and actions
    createFilterDialogs();
    createActions();

    // create SWT resources
    createResources();
    // clean the filter, after creating the font
    cleanTableFilter();

}

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);//  w  w w  .j  a  v  a  2  s.co  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:org.eclipse.swt.examples.layoutexample.Tab.java

/**
 * Creates the composite that contains the example layout.
 *///from w w w  . j  ava  2  s . com
void createLayoutComposite() {
    layoutComposite = new Composite(layoutGroup, SWT.BORDER);
    layoutComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    createLayout();
}

From source file:org.eclipse.swt.examples.layoutexample.Tab.java

/**
 * Creates the tab folder page.//from  w  ww.j  a  va2 s. co  m
 *
 * @param tabFolder org.eclipse.swt.widgets.TabFolder
 * @return the new page for the tab folder
 */
Composite createTabFolderPage(TabFolder tabFolder) {
    /* Cache the shell and display. */
    shell = tabFolder.getShell();
    display = shell.getDisplay();

    /* Create a two column page with a SashForm*/
    tabFolderPage = new Composite(tabFolder, SWT.NONE);
    tabFolderPage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    tabFolderPage.setLayout(new FillLayout());
    sash = new SashForm(tabFolderPage, SWT.HORIZONTAL);

    /* Create the "layout" and "control" columns */
    createLayoutGroup();
    createControlGroup();

    sash.setWeights(sashWeights());
    return tabFolderPage;
}

From source file:edu.isistan.carcha.plugin.editors.TraceabilityEditor.java

/**
 * Creates the impact list page.//ww w.j  a  v  a2 s  .  c  o  m
 */
void impactListPage() {
    final Composite composite = new Composite(getContainer(), SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    composite.setLayout(new GridLayout());

    Label concernLabel = new Label(composite, SWT.BORDER);
    concernLabel.setText("Crosccuting Concerns(CCC)");
    concernLabel.setToolTipText("This are the concern detected on the requierement document.");
    GridData gridData = new GridData(SWT.LEFT, SWT.TOP, false, false);
    concernLabel.setLayoutData(gridData);

    /////////////////////
    ScrolledComposite sc = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    parent.setLayout(new GridLayout());

    topViewLink = new TableViewer(parent, SWT.BORDER);
    createColumns(parent, topViewLink);

    final Table table = topViewLink.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    topViewLink.setContentProvider(new ArrayContentProvider());

    getSite().setSelectionProvider(topViewLink);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.heightHint = 10 * table.getItemHeight();
    table.setLayoutData(data);

    sc.setContent(parent);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));

    /////////////////////

    Button button = new Button(composite, SWT.PUSH);
    button.setText("Remove");
    button.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent event) {
        }

        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection topSelection = (IStructuredSelection) topViewLink.getSelection();
            IStructuredSelection bottomSelection = (IStructuredSelection) bottomViewLink.getSelection();

            String[] crosscuttingConcern = (String[]) topSelection.getFirstElement();
            String[] designDecision = (String[]) bottomSelection.getFirstElement();
            if (topSelection.size() > 1) {
                MessageDialog.openError(composite.getShell(), "Error",
                        "Please select one crosscutting concern");
            } else {
                if ((crosscuttingConcern != null) && (designDecision != null)) {
                    // create dialog with ok and cancel button and info icon
                    MessageBox dialog = new MessageBox(composite.getShell(),
                            SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
                    dialog.setText("Link confirmation");
                    dialog.setMessage("Do you want to remove the link between the selected items?");

                    // open dialog and await user selection
                    int response = dialog.open();
                    if (response == SWT.OK) {
                        PluginUtil.removeLink(crosscuttingConcern, designDecision, cp);
                        dirty = true;
                        firePropertyChange(IEditorPart.PROP_DIRTY);
                        // update the list after the remove
                        generateLinkViewData();
                        bottomViewLink.getTable().clearAll();
                    }
                } else {
                    MessageDialog.openError(composite.getShell(), "Error",
                            "Please select a crosscutting concern and a design decision to remove a traceability link");
                }
            }
        }
    });
    gridData = new GridData(SWT.CENTER, SWT.TOP, false, false, 2, 1);
    button.setLayoutData(gridData);

    Label ddsLabel = new Label(composite, SWT.BORDER);
    ddsLabel.setText("Architectural design decisions");
    ddsLabel.setToolTipText("This are the design decisions detected on the architectural document");

    gridData = new GridData(SWT.LEFT, SWT.TOP, false, false);
    ddsLabel.setLayoutData(gridData);

    bottomViewLink = new TableViewer(composite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    createColumns(composite, bottomViewLink);
    Table table2 = bottomViewLink.getTable();
    table2.setHeaderVisible(true);
    table2.setLinesVisible(true);
    bottomViewLink.setContentProvider(new ArrayContentProvider());
    topViewLink.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                String[] cccs = (String[]) selection.getFirstElement();
                List<DesignDecision> dds = PluginUtil.getDesignDecisionsForCrossCuttingConcern(cp, cccs[1],
                        cccs[0]);
                logger.info("Impact List for CCC (" + dds.size() + " DDD): " + cccs[0] + " - " + cccs[1]);
                List<String[]> designDecisions = new ArrayList<String[]>();

                for (DesignDecision dd : dds) {
                    String[] designDecision = { dd.getKind(), dd.getName() };
                    designDecisions.add(designDecision);
                }
                bottomViewLink.setInput(designDecisions);
            }
        }
    });
    getSite().setSelectionProvider(bottomViewLink);
    gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    bottomViewLink.getControl().setLayoutData(gridData);

    int index = addPage(composite);
    setPageText(index, "Links");
}

From source file:org.eclipse.swt.examples.fileviewer.FileViewer.java

/**
 * Creates the file tree view./*from   ww w . j a  v  a2s.c o m*/
 *
 * @param parent the parent control
 */
private void createTreeView(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    gridLayout.marginHeight = gridLayout.marginWidth = 2;
    gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
    composite.setLayout(gridLayout);

    treeScopeLabel = new Label(composite, SWT.BORDER);
    treeScopeLabel.setText(FileViewer.getResourceString("details.AllFolders.text"));
    treeScopeLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));

    tree = new Tree(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
    tree.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));

    tree.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            final TreeItem[] selection = tree.getSelection();
            if (selection != null && selection.length != 0) {
                TreeItem item = selection[0];
                File file = (File) item.getData(TREEITEMDATA_FILE);

                notifySelectedDirectory(file);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
            final TreeItem[] selection = tree.getSelection();
            if (selection != null && selection.length != 0) {
                TreeItem item = selection[0];
                item.setExpanded(true);
                treeExpandItem(item);
            }
        }
    });
    tree.addTreeListener(new TreeAdapter() {
        @Override
        public void treeExpanded(TreeEvent event) {
            final TreeItem item = (TreeItem) event.item;
            final Image image = (Image) item.getData(TREEITEMDATA_IMAGEEXPANDED);
            if (image != null)
                item.setImage(image);
            treeExpandItem(item);
        }

        @Override
        public void treeCollapsed(TreeEvent event) {
            final TreeItem item = (TreeItem) event.item;
            final Image image = (Image) item.getData(TREEITEMDATA_IMAGECOLLAPSED);
            if (image != null)
                item.setImage(image);
        }
    });
    createTreeDragSource(tree);
    createTreeDropTarget(tree);
}

From source file:SWTFileViewerDemo.java

/**
 * Creates the file tree view./*from  w  ww . j  a v  a  2  s  .c om*/
 * 
 * @param parent
 *            the parent control
 */
private void createTreeView(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    gridLayout.marginHeight = gridLayout.marginWidth = 2;
    gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
    composite.setLayout(gridLayout);

    treeScopeLabel = new Label(composite, SWT.BORDER);
    treeScopeLabel.setText(SWTFileViewerDemo.getResourceString("details.AllFolders.text"));
    treeScopeLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));

    tree = new Tree(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE);
    tree.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));

    tree.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            final TreeItem[] selection = tree.getSelection();
            if (selection != null && selection.length != 0) {
                TreeItem item = selection[0];
                File file = (File) item.getData(TREEITEMDATA_FILE);

                notifySelectedDirectory(file);
            }
        }

        public void widgetDefaultSelected(SelectionEvent event) {
            final TreeItem[] selection = tree.getSelection();
            if (selection != null && selection.length != 0) {
                TreeItem item = selection[0];
                item.setExpanded(true);
                treeExpandItem(item);
            }
        }
    });
    tree.addTreeListener(new TreeAdapter() {
        public void treeExpanded(TreeEvent event) {
            final TreeItem item = (TreeItem) event.item;
            final Image image = (Image) item.getData(TREEITEMDATA_IMAGEEXPANDED);
            if (image != null)
                item.setImage(image);
            treeExpandItem(item);
        }

        public void treeCollapsed(TreeEvent event) {
            final TreeItem item = (TreeItem) event.item;
            final Image image = (Image) item.getData(TREEITEMDATA_IMAGECOLLAPSED);
            if (image != null)
                item.setImage(image);
        }
    });
    createTreeDragSource(tree);
    createTreeDropTarget(tree);
}

From source file:LayoutExample.java

/**
 * Creates the composite that contains the example layout.
 *//* ww  w .  ja  v a  2  s. c  o  m*/
void createLayoutComposite() {
    layoutComposite = new Composite(layoutGroup, SWT.BORDER);
    layoutComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    createLayout();
}