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

TabbedShellExample() {
    d = new Display();
    s = new Shell(d);

    s.setSize(250, 200);/*from www. j av a 2  s  . c  om*/

    s.setText("A Tabbed Shell Example");
    s.setLayout(new FillLayout());

    TabFolder tf = new TabFolder(s, SWT.BORDER);

    TabItem ti1 = new TabItem(tf, SWT.BORDER);
    ti1.setText("Option Group");
    ti1.setControl(new GroupExample(tf, SWT.SHADOW_ETCHED_IN));

    TabItem ti2 = new TabItem(tf, SWT.BORDER);
    ti2.setText("Grid");
    ti2.setControl(new GridComposite(tf));

    TabItem ti3 = new TabItem(tf, SWT.BORDER);
    ti3.setText("Text");
    Composite c1 = new Composite(tf, SWT.BORDER);
    c1.setLayout(new FillLayout());
    Text t = new Text(c1, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
    ti3.setControl(c1);

    TabItem ti4 = new TabItem(tf, SWT.BORDER);
    ti4.setText("Settings");
    Composite c2 = new Composite(tf, SWT.BORDER);
    c2.setLayout(new RowLayout());
    Text t2 = new Text(c2, SWT.BORDER | SWT.SINGLE | SWT.WRAP | SWT.V_SCROLL);
    Button b = new Button(c2, SWT.PUSH | SWT.BORDER);
    b.setText("Save");
    ti4.setControl(c2);

    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:FileTreeWindowApplication.java

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

    final TreeViewer tv = new TreeViewer(composite);
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput("root");

    return composite;
}

From source file:ShowProgress.java

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

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

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

    final Shell shell = parent.getShell();

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

    parent.pack();
    return composite;
}

From source file:MainClass.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    Button preserveCase = new Button(composite, SWT.CHECK);
    preserveCase.setText("&Preserve case");
    final TreeViewer tv = new TreeViewer(composite);
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput("root");

    preserveCase.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            boolean preserveCase = ((Button) event.widget).getSelection();
            FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv.getLabelProvider();
            ftlp.setPreserveCase(preserveCase);
        }/*from   w  w  w.jav  a 2  s .c  om*/
    });
    return composite;
}

From source file:AdvancedBrowser.java

public AdvancedBrowser(String location) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Advanced Browser");

    shell.setLayout(new FormLayout());

    Composite controls = new Composite(shell, SWT.NONE);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    controls.setLayoutData(data);//from w  w w  .j a v a 2 s.c o m

    Label status = new Label(shell, SWT.NONE);
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(100, 0);
    status.setLayoutData(data);

    final Browser browser = new Browser(shell, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(controls);
    data.bottom = new FormAttachment(status);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    browser.setLayoutData(data);

    controls.setLayout(new GridLayout(7, false));

    Button button = new Button(controls, SWT.PUSH);
    button.setText("Back");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.back();
        }
    });

    button = new Button(controls, SWT.PUSH);
    button.setText("Forward");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.forward();
        }
    });

    button = new Button(controls, SWT.PUSH);
    button.setText("Refresh");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.refresh();
        }
    });

    button = new Button(controls, SWT.PUSH);
    button.setText("Stop");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.stop();
        }
    });

    final Text url = new Text(controls, SWT.BORDER);
    url.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    url.setFocus();

    button = new Button(controls, SWT.PUSH);
    button.setText("Go");
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            browser.setUrl(url.getText());
        }
    });

    Label throbber = new Label(controls, SWT.NONE);
    throbber.setText(AT_REST);

    shell.setDefaultButton(button);

    browser.addCloseWindowListener(new AdvancedCloseWindowListener());
    browser.addLocationListener(new AdvancedLocationListener(url));
    browser.addProgressListener(new AdvancedProgressListener(throbber));
    browser.addStatusTextListener(new AdvancedStatusTextListener(status));

    // Go to the initial URL
    if (location != null) {
        browser.setUrl(location);
    }

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

From source file:MainClass.java

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

    new Label(composite, SWT.LEFT).setText("Please enter your complaints");
    Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    text.setLayoutData(new GridData(GridData.FILL_BOTH));

    setControl(composite);/*from   w w  w .j  a  v  a 2 s .  co  m*/
}

From source file:DialogExamples.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);

    composite.setLayout(new GridLayout());

    /* ------ MessageDialog ------------- */
    // openQuestion
    final Button buttonOpenMessage = new Button(composite, SWT.PUSH);
    buttonOpenMessage.setText("Demo: MessageDialog.openQuestion");
    buttonOpenMessage.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {

            boolean answer = MessageDialog.openQuestion(getShell(), "A Simple Question",
                    "Is SWT/JFace your favorite Java UI framework?");
            System.out.println("Your answer is " + (answer ? "YES" : "NO"));
        }/*from  w  ww.  j ava2 s . com*/
    });

    final Button buttonMessageDialog = new Button(composite, SWT.PUSH);
    buttonMessageDialog.setText("Demo: new MessageDialog");
    buttonMessageDialog.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            MessageDialog dialog = new MessageDialog(getShell(), "Select your favorite Java UI framework", null,
                    "Which one of the following is your favorite Java UI framework?", MessageDialog.QUESTION,
                    new String[] { "AWT", "Swing", "SWT/JFace" }, 2);
            int answer = dialog.open();

            switch (answer) {
            case -1: // if the user closes the dialog without clicking any button.
                System.out.println("No selection");
                break;

            case 0:
                System.out.println("Your selection is: AWT");
                break;
            case 1:
                System.out.println("Your selection is: Swing");
                break;
            case 2:
                System.out.println("Your selection is: SWT/JFace");
                break;

            }
        }
    });

    /* ------ InputDialog ------------- */
    final Button buttonInputDialog = new Button(composite, SWT.PUSH);
    buttonInputDialog.setText("Demo: InputDialog");
    buttonInputDialog.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            IInputValidator validator = new IInputValidator() {
                public String isValid(String newText) {
                    if (newText.equalsIgnoreCase("SWT/JFace") || newText.equalsIgnoreCase("AWT")
                            || newText.equalsIgnoreCase("Swing"))
                        return null;
                    else
                        return "The allowed values are: SWT/JFace, AWT, Swing";
                }
            };
            InputDialog dialog = new InputDialog(getShell(), "Question",
                    "What's your favorite Java UI framework?", "SWT/JFace", validator);
            if (dialog.open() == Window.OK) {
                System.out.println("Your favorite Java UI framework is: " + dialog.getValue());
            } else {
                System.out.println("Action cancelled");
            }
        }
    });

    /* ------ ProgressMonitorDialog ------------- */
    final Button buttonProgressDialog = new Button(composite, SWT.PUSH);
    buttonProgressDialog.setText("Demo: ProgressMonitorDialog");
    buttonProgressDialog.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask("Number counting", 10);
                    for (int i = 0; i < 10; i++) {
                        if (monitor.isCanceled()) {
                            monitor.done();
                            return;
                        }

                        System.out.println("Count number: " + i);
                        monitor.worked(1);
                        Thread.sleep(500); // 0.5s.
                    }
                    monitor.done();
                }
            };

            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            try {
                dialog.run(true, true, runnableWithProgress);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    });
    return super.createContents(parent);
}

From source file:CheckFileTreeViewer.java

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

    // 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 a checkbox in the tree, check all its children
    tv.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked()) {
                tv.setSubtreeChecked(event.getElement(), true);
            }
        }
    });
    return composite;
}

From source file:WordOLE.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new FillLayout());

    oleFrame = new OleFrame(composite, SWT.NULL);

    if (getMenuBarManager() != null) {
        MenuItem windowMenu = new MenuItem(getMenuBarManager().getMenu(), SWT.CASCADE);
        windowMenu.setText("[Window]");

        MenuItem containerMenu = new MenuItem(getMenuBarManager().getMenu(), SWT.CASCADE);
        containerMenu.setText("[Container]");

        MenuItem fileMenu = new MenuItem(getMenuBarManager().getMenu(), SWT.CASCADE);
        fileMenu.setText("[File]");

        oleFrame.setWindowMenus(new MenuItem[] { windowMenu });
        oleFrame.setContainerMenus(new MenuItem[] { containerMenu });
        oleFrame.setFileMenus(new MenuItem[] { fileMenu });

        System.out.println("menu set");
    }/*  ww  w  .  j a  v a2  s  . com*/

    clientSite = new OleClientSite(oleFrame, SWT.NULL, new File("test.doc"));
    // clientSite = new OleClientSite(oleFrame, SWT.NONE,
    // "Word.Document.8");

    //    clientSite = new OleControlSite(oleFrame, SWT.NONE,
    //    "Word.Document.8");

    System.out.println(clientSite.getProgramID() + ", " + clientSite);
    clientSite.doVerb(OLE.OLEIVERB_SHOW);

    return composite;
}

From source file:FocusTraversal.java

private void init() {
    shell.setLayout(new RowLayout());

    Composite composite1 = new Composite(shell, SWT.BORDER);
    composite1.setLayout(new RowLayout());
    composite1.setBackground(display.getSystemColor(SWT.COLOR_WHITE));

    Button button1 = new Button(composite1, SWT.PUSH);
    button1.setText("Button1");

    List list = new List(composite1, SWT.MULTI | SWT.BORDER);
    list.setItems(new String[] { "Item-1", "Item-2", "Item-3" });

    Button radioButton1 = new Button(composite1, SWT.RADIO);
    radioButton1.setText("radio-1");
    Button radioButton2 = new Button(composite1, SWT.RADIO);
    radioButton2.setText("radio-2");

    Composite composite2 = new Composite(shell, SWT.BORDER);
    composite2.setLayout(new RowLayout());
    composite2.setBackground(display.getSystemColor(SWT.COLOR_GREEN));

    Button button2 = new Button(composite2, SWT.PUSH);
    button2.setText("Button2");

    final Canvas canvas = new Canvas(composite2, SWT.NULL);
    canvas.setSize(50, 50);/* w ww.  j  av a  2  s .c  om*/
    canvas.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));

    Combo combo = new Combo(composite2, SWT.DROP_DOWN);
    combo.add("combo");
    combo.select(0);

    canvas.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            GC gc = new GC(canvas);
            // Erase background first. 
            Rectangle rect = canvas.getClientArea();
            gc.fillRectangle(rect.x, rect.y, rect.width, rect.height);

            Font font = new Font(display, "Arial", 32, SWT.BOLD);
            gc.setFont(font);

            gc.drawString("" + e.character, 15, 10);

            gc.dispose();
            font.dispose();
        }

        public void keyReleased(KeyEvent e) {
        }
    });

    canvas.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS)
                e.doit = true;
        }
    });

    composite1.setTabList(new Control[] { button1, list });
    composite2.setTabList(new Control[] { button2, canvas, combo });

    shell.setTabList(new Control[] { composite2, composite1 });
}