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

/**
 * Creates the main window's contents//from ww w . ja v  a  2s  . co  m
 * 
 * @param shell the main window
 */
private void createContents(final Shell shell) {
    color = new Color(shell.getDisplay(), 255, 0, 0);

    // Create a composite that will be the parent of the editor
    final Composite composite = new Composite(shell, SWT.NONE);
    composite.setBackground(color);
    composite.setBounds(0, 0, 300, 100);

    // Create the editor
    ControlEditor editor = new ControlEditor(composite);

    // Create the control associated with the editor
    final Text text = new Text(composite, SWT.BORDER);
    text.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            RGB rgb = (RGB) COLORS.get(text.getText());
            if (rgb != null) {
                if (color != null)
                    color.dispose();
                color = new Color(shell.getDisplay(), rgb);
                composite.setBackground(color);
            }
        }
    });

    // Place the editor in the top middle of the parent composite
    editor.horizontalAlignment = SWT.CENTER;
    editor.verticalAlignment = SWT.TOP;
    Point size = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    editor.minimumWidth = size.x;
    editor.minimumHeight = size.y;
    editor.setEditor(text);
}

From source file:ControlSizeLocation.java

private void init() {
    GridLayout gridLayout = new GridLayout(2, true);
    shell.setLayout(gridLayout);//w w  w  . j  ava 2s. c o m

    Composite left = new Composite(shell, SWT.NULL);
    left.setLayout(new GridLayout());
    //left.setLayout(new FillLayout());
    left.setLayoutData(new GridData(GridData.FILL_BOTH));
    left.setBackground(display.getSystemColor(SWT.COLOR_GREEN));

    button = new Button(left, SWT.PUSH);
    button.setText("Button");
    button.setLayoutData(new GridData());

    Composite right = new Composite(shell, SWT.NULL);
    right.setLayout(new GridLayout(4, true));
    right.setLayoutData(new GridData(GridData.FILL_BOTH));

    Label label = new Label(right, SWT.NULL);
    label.setText("X");

    label = new Label(right, SWT.NULL);
    label.setText("Y");

    label = new Label(right, SWT.NULL);
    label.setText("Width");

    label = new Label(right, SWT.NULL);
    label.setText("Height");

    x = new Text(right, SWT.BORDER);
    y = new Text(right, SWT.BORDER);
    w = new Text(right, SWT.BORDER);
    h = new Text(right, SWT.BORDER);

    SelectionListener selectionListener = new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            Button b = (Button) e.widget;
            if (b == get) {
                System.out.println("------------------------------");
                System.out.println("getBounds: " + button.getBounds());
                System.out.println("getLocation: " + button.getLocation());
                System.out.println("getSize: " + button.getSize());

            } else if (b == set) {
                int vx = getNumber(x);
                int vy = getNumber(y);
                int vw = getNumber(w);
                int vh = getNumber(h);

                if (vx != -1 && vy != -1) {
                    if (vw != -1 && vh != -1) {
                        Rectangle rectangle = new Rectangle(vx, vy, vw, vh);
                        button.setBounds(rectangle);
                        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                        System.out.println("# setBounds: " + rectangle);
                    } else {
                        Point point = new Point(vx, vy);
                        button.setLocation(point);
                        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                        System.out.println("# setLocation: " + point);
                    }
                } else if (vw != -1 && vh != -1) {
                    Point point = new Point(vw, vh);
                    button.setSize(point);
                    System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    System.out.println("# setSize: " + point);
                }
            }

        }

        public void widgetDefaultSelected(SelectionEvent e) {
            // TODO Auto-generated method stub

        }
    };

    get = new Button(right, SWT.PUSH);
    get.setText("Get");
    get.addSelectionListener(selectionListener);

    set = new Button(right, SWT.PUSH);
    set.setText("Set");
    set.addSelectionListener(selectionListener);

}

From source file:MailDialog.java

/**
 * @see org.eclipse.jface.dialogs.Dialog#
 *      createDialogArea(org.eclipse.swt.widgets.Composite) Here we fill the
 *      center area of the dialog//from w  ww.j  a  v a 2s.c om
 */
protected Control createDialogArea(Composite parent) {
    // Create new composite as container
    final Composite area = new Composite(parent, SWT.NULL);
    // We use a grid layout and set the size of the margins
    final GridLayout gridLayout = new GridLayout();
    gridLayout.marginWidth = 15;
    gridLayout.marginHeight = 10;
    area.setLayout(gridLayout);
    // Now we create the list widget
    list = new List(area, SWT.BORDER | SWT.MULTI);
    // We define a minimum width for the list
    final GridData gridData = new GridData();
    gridData.widthHint = 200;
    list.setLayoutData(gridData);
    // We add a SelectionListener
    list.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            // When the selection changes, we re-validate the list
            validate();
        }
    });
    // We add the initial mail messages to the list
    for (int i = 0; i < items.length; i++) {
        list.add(items[i]);
    }
    return area;
}

From source file:Look.java

/**
 * Creates the main window's contents//from  ww w  . j a v  a2s  .  co m
 * 
 * @param parent the main window
 */
public void createContents(Composite parent) {
    parent.setLayout(new GridLayout(1, false));

    // Pressing the "New Document" button will create a new ViewForm
    Button button = new Button(parent, SWT.PUSH);
    button.setText("New Document");

    // Create the composite that holds the ViewForms
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    composite.setLayout(new FillLayout());

    // Add the event handler to create the ViewForms
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            createViewFormHelper(composite, "Document " + (++count));
            composite.layout();
        }
    });
}

From source file:MainClass.java

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

    Combo combo = new Combo(composite, SWT.READ_ONLY);
    combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    tv = new TableViewer(composite);

    tv.setContentProvider(new PlayerContentProvider());
    tv.setLabelProvider(new PlayerLabelProvider());
    tv.setSorter(new StudentViewerSorter());

    Table table = tv.getTable();//from  w ww . j  a v a  2s . c om
    table.setLayoutData(new GridData(GridData.FILL_BOTH));

    TableColumn tc = new TableColumn(table, SWT.LEFT);
    tc.setText("First Name");
    tc.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ((StudentViewerSorter) tv.getSorter()).doSort(Const.COLUMN_FIRST_NAME);
            tv.refresh();
        }
    });

    tc = new TableColumn(table, SWT.LEFT);
    tc.setText("Last Name");
    tc.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ((StudentViewerSorter) tv.getSorter()).doSort(Const.COLUMN_LAST_NAME);
            tv.refresh();
        }
    });

    tc = new TableColumn(table, SWT.RIGHT);
    tc.setText("Math");
    tc.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ((StudentViewerSorter) tv.getSorter()).doSort(Const.COLUMN_MATH);
            tv.refresh();
        }
    });

    tc = new TableColumn(table, SWT.RIGHT);
    tc.setText("CHEM");
    tc.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ((StudentViewerSorter) tv.getSorter()).doSort(Const.COLUMN_CHEM);
            tv.refresh();
        }
    });

    tc = new TableColumn(table, SWT.RIGHT);
    tc.setText("AVE");
    tc.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ((StudentViewerSorter) tv.getSorter()).doSort(Const.COLUMN_AVE);
            tv.refresh();
        }
    });

    for (int i = 0, n = model.teams.length; i < n; i++) {
        combo.add(model.teams[i].getName());
    }

    combo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            update(model.teams[((Combo) event.widget).getSelectionIndex()]);
        }
    });

    combo.select(0);
    update(model.teams[0]);

    for (int i = 0, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    return composite;
}

From source file:MainClass.java

protected Control createDialogArea(Composite parent) {
    createMessageArea(parent);/*from www  .  ja va  2 s.  c om*/
    Composite composite = new Composite(parent, SWT.NONE);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    composite.setLayoutData(data);
    composite.setLayout(new FillLayout());

    label = new Label(composite, SWT.LEFT);
    return composite;
}

From source file:CheckFileTree.java

/**
 * Creates the main window's contents//from   w  ww.  j  a v a2  s  . co  m
 * 
 * @param parent
 *            the main window
 * @return Control
 */
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));

    // Add a checkbox to toggle whether the labels preserve case
    Button preserveCase = new Button(composite, SWT.CHECK);
    preserveCase.setText("&Preserve case");

    // Create the tree viewer to display the file tree
    final CheckboxTreeViewer tv = new CheckboxTreeViewer(composite);
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput("root"); // pass a non-null that will be ignored

    // When user checks the checkbox, toggle the preserve case attribute
    // of the label provider
    preserveCase.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            boolean preserveCase = ((Button) event.widget).getSelection();
            FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv.getLabelProvider();
            ftlp.setPreserveCase(preserveCase);
        }
    });

    // When user checks a checkbox in the tree, check all its children
    tv.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            // If the item is checked . . .
            if (event.getChecked()) {
                // . . . check all its children
                tv.setSubtreeChecked(event.getElement(), true);
            }
        }
    });
    return composite;
}

From source file:SWT2D.java

private void run() {
    // Create top level shell
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Java 2D Example");
    // GridLayout for canvas and button
    shell.setLayout(new GridLayout());
    // Create container for AWT canvas
    final Composite canvasComp = new Composite(shell, SWT.EMBEDDED);
    // Set preferred size
    GridData data = new GridData();
    data.widthHint = 600;//from  w  w w .ja v a 2 s  .c om
    data.heightHint = 500;
    canvasComp.setLayoutData(data);
    // Create AWT Frame for Canvas
    java.awt.Frame canvasFrame = SWT_AWT.new_Frame(canvasComp);
    // Create Canvas and add it to the Frame
    final java.awt.Canvas canvas = new java.awt.Canvas();
    canvasFrame.add(canvas);
    // Get graphical context and cast to Java2D
    final java.awt.Graphics2D g2d = (java.awt.Graphics2D) canvas.getGraphics();
    // Enable antialiasing
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Remember initial transform
    final java.awt.geom.AffineTransform origTransform = g2d.getTransform();
    // Create Clear button and position it
    Button clearButton = new Button(shell, SWT.PUSH);
    clearButton.setText("Clear");
    data = new GridData();
    data.horizontalAlignment = GridData.CENTER;
    clearButton.setLayoutData(data);
    // Event processing for Clear button
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            // Delete word list and redraw canvas
            wordList.clear();
            canvasComp.redraw();
        }
    });
    // Process canvas mouse clicks
    canvas.addMouseListener(new java.awt.event.MouseListener() {
        public void mouseClicked(java.awt.event.MouseEvent e) {
        }

        public void mouseEntered(java.awt.event.MouseEvent e) {
        }

        public void mouseExited(java.awt.event.MouseEvent e) {
        }

        public void mousePressed(java.awt.event.MouseEvent e) {
            // Manage pop-up editor
            display.syncExec(new Runnable() {
                public void run() {
                    if (eShell == null) {
                        // Create new Shell: non-modal!
                        eShell = new Shell(shell, SWT.NO_TRIM | SWT.MODELESS);
                        eShell.setLayout(new FillLayout());
                        // Text input field
                        eText = new Text(eShell, SWT.BORDER);
                        eText.setText("Text rotation in the SWT?");
                        eShell.pack();
                        // Set position (Display coordinates)
                        java.awt.Rectangle bounds = canvas.getBounds();
                        org.eclipse.swt.graphics.Point pos = canvasComp.toDisplay(bounds.width / 2,
                                bounds.height / 2);
                        Point size = eShell.getSize();
                        eShell.setBounds(pos.x, pos.y, size.x, size.y);
                        // Open Shell
                        eShell.open();
                    } else if (!eShell.isVisible()) {
                        // Editor versteckt, sichtbar machen
                        eShell.setVisible(true);
                    } else {
                        // Editor is visible - get text
                        String t = eText.getText();
                        // set editor invisible
                        eShell.setVisible(false);
                        // Add text to list and redraw canvas
                        wordList.add(t);
                        canvasComp.redraw();
                    }
                }
            });
        }

        public void mouseReleased(java.awt.event.MouseEvent e) {
        }
    });
    // Redraw the canvas
    canvasComp.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            // Pass the redraw task to AWT event queue
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    // Compute canvas center
                    java.awt.Rectangle bounds = canvas.getBounds();
                    int originX = bounds.width / 2;
                    int originY = bounds.height / 2;
                    // Reset canvas
                    g2d.setTransform(origTransform);
                    g2d.setColor(java.awt.Color.WHITE);
                    g2d.fillRect(0, 0, bounds.width, bounds.height);
                    // Set font
                    g2d.setFont(new java.awt.Font("Myriad", java.awt.Font.PLAIN, 32));
                    double angle = 0d;
                    // Prepare star shape
                    double increment = Math.toRadians(30);
                    Iterator iter = wordList.iterator();
                    while (iter.hasNext()) {
                        // Determine text colors in RGB color cycle
                        float red = (float) (0.5 + 0.5 * Math.sin(angle));
                        float green = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(120)));
                        float blue = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(240)));
                        g2d.setColor(new java.awt.Color(red, green, blue));
                        // Redraw text
                        String text = (String) iter.next();
                        g2d.drawString(text, originX + 50, originY);
                        // Rotate for next text output
                        g2d.rotate(increment, originX, originY);
                        angle += increment;
                    }
                }
            });
        }
    });
    // Finish shell and open it
    shell.pack();
    shell.open();
    // SWT event processing
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.talend.dataprofiler.chart.util.HideSeriesChartDialog.java

private Composite createUtilityControl(Composite parent) {
    Composite comp = new Composite(parent, SWT.BORDER);
    comp.setLayout(new RowLayout());
    comp.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));

    if (isCountAvgNull) {
        XYDataset dataset = chart.getXYPlot().getDataset();
        int count = dataset.getSeriesCount();

        for (int i = 0; i < count; i++) {

            Button checkBtn = new Button(comp, SWT.CHECK);
            checkBtn.setText(dataset.getSeriesKey(i).toString());
            checkBtn.setSelection(true);
            checkBtn.addSelectionListener(listener);
            checkBtn.setData(SERIES_KEY_ID, i);
        }/*  ww  w .  j ava2  s .  c  om*/
    }

    if (isMinMaxDate) {
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryDataset dataset = plot.getDataset();
        int count = dataset.getRowCount();

        for (int i = 0; i < count; i++) {

            Button checkBtn = new Button(comp, SWT.CHECK);
            checkBtn.setText(dataset.getRowKey(i).toString());
            checkBtn.setSelection(true);
            checkBtn.addSelectionListener(listener);
            checkBtn.setData(SERIES_KEY_ID, i);
        }
    }

    return comp;
}

From source file:WidgetTest2.java

public static Composite createComposite(Composite parent) {
    /** * Composite ** */
    //       Create new Composite instance
    final Composite composite = new Composite(parent, 0);
    //       Get properties from the containing composite
    composite.setBackground(parent.getBackground());
    composite.setForeground(parent.getForeground());
    composite.setFont(parent.getFont());
    //       Set position and size
    composite.setBounds(X, Y, WIDTH, HEIGHT);
    return composite;
}