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

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

Introduction

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

Prototype

public Composite(Composite parent, int style) 

Source Link

Document

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Usage

From source file:org.qsos.radar.GenerateRadar.java

/**
 * This class creates a composite in which the radar char will be
 * implemented//from  ww  w . j  a  va2 s  . c  om
 * 
 * @param parent
 *             Composite where the chart will be seen
 * @param Categories
 *             String[] that contains the name of the elements [4 min and 7 max] the user has chosen to visualize
 * @param Scores
 *             Double[] that contains the average score of each category
 * @return Control
 * 
 */
public static Control createChart(Composite parent, String[] Categories, double[] Scores) {

    Composite Charcomposite = new Composite(parent, SWT.EMBEDDED);
    Charcomposite.setLayout(new FillLayout());
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //
    for (int i = 0; i < CatNumber; i++) {
        dataset.addValue(Scores[i], getTitle(), Categories[i]);
    }

    String BackGroundMire = null;

    //Configuration of the spiderwebplot
    SpiderWebPlot plot = new SpiderWebPlot();
    plot.setDataset(dataset);
    plot.setMaxValue(JQConst.RADAR_MAX_VALUE);
    plot.setSeriesPaint(JQConst.RADAR_SERIES_PAINT);
    plot.setAxisLabelGap(JQConst.RADAR_AXIS_LABEL_GAP);
    plot.setHeadPercent(JQConst.RADAR_HEAD_PERCENT);
    plot.setInteriorGap(JQConst.RADAR_INTERIOR_GAP);
    plot.setWebFilled(true);

    //The backgroundpicture used as a spiderweb is chosen according to the 
    //number of categories selected
    switch (CatNumber) {
    case 4:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_4;
        break;
    case 5:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_5;
        break;
    case 6:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_6;
        break;
    case 7:
        BackGroundMire = JQConst.RADAR_SPIDERWEB_7;
        break;
    }
    javax.swing.ImageIcon icon = new javax.swing.ImageIcon(BackGroundMire);
    plot.setBackgroundImage(icon.getImage());

    //chart creation
    JFreeChart chart = new JFreeChart(plot);

    //Here the background color from the shell is taken in order to match AWT and SWT backgrounds
    Color backgroundColor = parent.getBackground();

    //JFreechart doesn't support SWT so we create an AWT Frame that will depend on Charcomposite
    java.awt.Frame chartPanel = SWT_AWT.new_Frame(Charcomposite);
    chartPanel.setLayout(new java.awt.GridLayout());
    ChartPanel jfreeChartPanel = new ChartPanel(chart);

    chartPanel.setBackground(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(),
            backgroundColor.getBlue()));

    chartPanel.add(jfreeChartPanel);
    chartPanel.pack();

    return parent;

}

From source file:org.eclipse.swt.examples.graphics.RegionClippingTab.java

/**
 * Creates the widgets used to control the drawing.
 *///from  w  w w  . jav a 2s . c om
@Override
public void createControlPanel(Composite parent) {
    // create drop down combo for choosing clipping
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Clipping")); //$NON-NLS-1$
    clippingCb = new Combo(comp, SWT.DROP_DOWN);
    clippingCb.add(GraphicsExample.getResourceString("Region1")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Region2")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Add")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Sub")); //$NON-NLS-1$
    clippingCb.add(GraphicsExample.getResourceString("Inter")); //$NON-NLS-1$
    clippingCb.select(0);
    clippingCb.addListener(SWT.Selection, event -> example.redraw());

    // color menu
    ColorMenu cm = new ColorMenu();
    menu1 = cm.createMenu(parent.getParent(), gb -> {
        colorGB1 = gb;
        colorButton1.setImage(gb.getThumbNail());
        example.redraw();
    });
    menu2 = cm.createMenu(parent.getParent(), gb -> {
        colorGB2 = gb;
        colorButton2.setImage(gb.getThumbNail());
        example.redraw();
    });

    // initialize the color to blue
    colorGB1 = (GraphicsBackground) menu1.getItem(4).getData();
    // initialize the color to red
    colorGB2 = (GraphicsBackground) menu2.getItem(2).getData();

    // color button 1
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    colorButton1 = new Button(comp, SWT.PUSH);
    colorButton1.setText(GraphicsExample.getResourceString("Color1")); //$NON-NLS-1$
    colorButton1.setImage(colorGB1.getThumbNail());
    colorButton1.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu1.setLocation(point.x, point.y + bounds.height);
        menu1.setVisible(true);
    });

    // color button 2
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    colorButton2 = new Button(comp, SWT.PUSH);
    colorButton2.setText(GraphicsExample.getResourceString("Color2")); //$NON-NLS-1$
    colorButton2.setImage(colorGB2.getThumbNail());
    colorButton2.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu2.setLocation(point.x, point.y + bounds.height);
        menu2.setVisible(true);
    });
}

From source file:org.eclipse.swt.examples.graphics.CustomAlphaTab.java

/**
 * Creates the widgets used to control the drawing.
 *//*ww w .jav  a2s .  co  m*/
@Override
public void createControlPanel(Composite parent) {
    super.createControlPanel(parent);

    // create drop down combo for choosing clipping
    Composite comp;

    // create spinner for line width
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));
    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Alpha")); //$NON-NLS-1$
    alphaSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    alphaSpinner.setMinimum(0);
    alphaSpinner.setMaximum(255);
    alphaSpinner.setSelection(127);
    alphaSpinner.addListener(SWT.Selection, event -> example.redraw());

    // color menu
    ColorMenu cm = new ColorMenu();
    cm.setPatternItems(example.checkAdvancedGraphics());
    menu = cm.createMenu(parent.getParent(), gb -> {
        background = gb;
        colorButton.setImage(gb.getThumbNail());
        example.redraw();
    });

    // initialize the background to the 5th item in the menu (blue)
    background = (GraphicsBackground) menu.getItem(4).getData();

    // color button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("Color")); //$NON-NLS-1$
    colorButton.setImage(background.getThumbNail());
    colorButton.addListener(SWT.Selection, event -> {
        final Button button = (Button) event.widget;
        final Composite parent1 = button.getParent();
        Rectangle bounds = button.getBounds();
        Point point = parent1.toDisplay(new Point(bounds.x, bounds.y));
        menu.setLocation(point.x, point.y + bounds.height);
        menu.setVisible(true);
    });
}

From source file:BackupFiles.java

/**
 * Creates the main window's contents//w w w.j  av  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 source directory panel and its controls
    final Text sourceDir = createFilePanelHelper(composite, "Source Dir:");

    // Create the CheckboxTableViewer to display the files in the source dir
    final CheckboxTableViewer ctv = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
    ctv.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    ctv.setContentProvider(new BackupFilesContentProvider());
    ctv.setLabelProvider(new BackupFilesLabelProvider());

    // Create the destination directory panel and its controls
    final Text destDir = createFilePanelHelper(composite, "Dest Dir:");

    // Create the Copy button
    Button copy = new Button(composite, SWT.PUSH);
    copy.setText("Copy");

    // Create the status field
    status = new Label(composite, SWT.NONE);
    status.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // When the source directory changes, change the input for the viewer
    sourceDir.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            ctv.setInput(((Text) event.widget).getText());
        }
    });

    // When copy is pressed, copy the files
    copy.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Get the checked elements
            Object[] files = ctv.getCheckedElements();
            if (files.length > 0) {
                // Some files are checked; make sure we have a valid
                // destination
                File dest = new File(destDir.getText());
                if (dest.isDirectory()) {
                    // Go through each file
                    for (int i = 0, n = files.length; i < n; i++) {
                        copyFile((File) files[i], dest);
                    }
                } else
                    showMessage("You must select a valid destination directory");
            } else
                showMessage("You must select some files to copy");
        }
    });

    return composite;
}

From source file:org.vast.stt.renderer.JFreeChart.JFreeChartRenderer.java

@Override
public void init() {
    swt_awt = new Composite(composite, SWT.EMBEDDED | SWT.DOUBLE_BUFFERED);
    Frame rootFrame = SWT_AWT.new_Frame(swt_awt);
    swt_awt.setBounds(0, 0, composite.getClientArea().width, composite.getClientArea().height);
    chartPanel = new ChartPanel(null);
    chartPanel.setDoubleBuffered(true);/*from ww w .ja v a2s . c  o  m*/
    //chartPanel.setPopupMenu(null);
    rootFrame.add(chartPanel);
    //composite.addPaintListener(this);
}

From source file:org.eclipse.swt.examples.graphics.ImageTransformTab.java

/**
 * This method creates the controls specific to the tab. The call to the
 * createControlPanel method in the super class create the controls that are
 * defined in the super class./*from  w  w w. j a v a 2 s.  c  o m*/
 *
 * @param parent The parent composite
 */
@Override
public void createControlPanel(Composite parent) {

    Composite comp;
    GridLayout gridLayout = new GridLayout(2, false);

    // create spinner for the rotation angle
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(gridLayout);

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Rotate")); //$NON-NLS-1$
    rotateSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    GC gc = new GC(rotateSpinner);
    int width = (int) (gc.getFontMetrics().getAverageCharacterWidth() * 5);
    gc.dispose();
    rotateSpinner.setLayoutData(new GridData(width, SWT.DEFAULT));
    rotateSpinner.setSelection(0);
    rotateSpinner.setMinimum(-720);
    rotateSpinner.setMaximum(720);
    rotateSpinner.setIncrement(30);
    rotateSpinner.addListener(SWT.Selection, event -> example.redraw());

    // create a spinner for translating along the x axis
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(gridLayout);

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("xtranslate")); //$NON-NLS-1$
    translateSpinnerX = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    translateSpinnerX.setLayoutData(new GridData(width, SWT.DEFAULT));
    translateSpinnerX.setMinimum(-100);
    translateSpinnerX.setMaximum(500);
    translateSpinnerX.setSelection(0);
    translateSpinnerX.setIncrement(10);
    translateSpinnerX.addListener(SWT.Selection, event -> example.redraw());

    // create a spinner for translating along the y axis
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(gridLayout);

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("ytranslate")); //$NON-NLS-1$
    translateSpinnerY = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    translateSpinnerY.setLayoutData(new GridData(width, SWT.DEFAULT));
    translateSpinnerY.setMinimum(-100);
    translateSpinnerY.setMaximum(500);
    translateSpinnerY.setSelection(0);
    translateSpinnerY.setIncrement(10);
    translateSpinnerY.addListener(SWT.Selection, event -> example.redraw());

    // create a spinner for scaling along the x axis
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(gridLayout);

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("xscale")); //$NON-NLS-1$
    scaleSpinnerX = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    scaleSpinnerX.setLayoutData(new GridData(width, SWT.DEFAULT));
    scaleSpinnerX.setDigits(2);
    scaleSpinnerX.setMinimum(1);
    scaleSpinnerX.setMaximum(400);
    scaleSpinnerX.setSelection(100);
    scaleSpinnerX.setIncrement(10);
    scaleSpinnerX.addListener(SWT.Selection, event -> example.redraw());

    // create a spinner for scaling along the y axis
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(gridLayout);

    new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("yscale")); //$NON-NLS-1$
    scaleSpinnerY = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    scaleSpinnerY.setLayoutData(new GridData(width, SWT.DEFAULT));
    scaleSpinnerY.setDigits(2);
    scaleSpinnerY.setMinimum(1);
    scaleSpinnerY.setMaximum(400);
    scaleSpinnerY.setSelection(100);
    scaleSpinnerY.setIncrement(10);
    scaleSpinnerY.addListener(SWT.Selection, event -> example.redraw());

    // create a button for inverting the transform matrix
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());
    invertButton = new Button(comp, SWT.TOGGLE);
    invertButton.setText(GraphicsExample.getResourceString("Invert")); //$NON-NLS-1$
    invertButton.addListener(SWT.Selection, event -> example.redraw());
}

From source file:org.eclipse.swt.examples.browser.demos.views.EditorTab.java

public EditorTab(TabItem item) {
    final Composite parent = new Composite(item.getParent(), SWT.NONE);
    item.setText("Editor");
    item.setControl(parent);/*  w  w  w.  j  a va 2s.c  om*/

    try {
        browser = new Browser(parent, SWT.NONE);
    } catch (SWTError e) {
        e.printStackTrace();
        return;
    }
    final Sash sash = new Sash(parent, SWT.VERTICAL);
    Composite panel = new Composite(parent, SWT.NONE);
    final FormLayout form = new FormLayout();
    parent.setLayout(form);

    FormData data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(sash, 0);
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    browser.setLayoutData(data);

    final FormData sashData = new FormData();
    sashData.left = new FormAttachment(50, 0);
    sashData.top = new FormAttachment(0, 0);
    sashData.bottom = new FormAttachment(100, 0);
    sash.setLayoutData(sashData);
    sash.addListener(SWT.Selection, e -> {
        Rectangle rect = sash.getBounds();
        Rectangle parentRect = sash.getParent().getClientArea();
        int right = parentRect.width - rect.width - 20;
        e.x = Math.max(Math.min(e.x, right), 20);
        if (e.x != rect.x) {
            sashData.left = new FormAttachment(0, e.x);
            parent.layout();
        }
    });
    data = new FormData();
    data.left = new FormAttachment(sash, 0);
    data.right = new FormAttachment(100, 0);
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    panel.setLayoutData(data);

    /* Initialize Panel */
    panel.setLayout(new FillLayout(SWT.VERTICAL));
    Group htmlGroup = new Group(panel, SWT.NONE);
    htmlGroup.setText("setText");
    htmlText = new Text(htmlGroup, SWT.MULTI);
    htmlButton = new Button(htmlGroup, SWT.PUSH);
    htmlButton.setText("setText");
    GridLayout gridLayout = new GridLayout();
    htmlGroup.setLayout(gridLayout);
    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    htmlText.setLayoutData(gridData);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    htmlButton.setLayoutData(gridData);
    htmlGroup.layout();

    Group scriptGroup = new Group(panel, SWT.NONE);
    scriptGroup.setText("execute");
    scriptText = new Text(scriptGroup, SWT.MULTI);
    scriptButton = new Button(scriptGroup, SWT.PUSH);
    scriptButton.setText("execute");
    gridLayout = new GridLayout();
    scriptGroup.setLayout(gridLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    scriptText.setLayoutData(gridData);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    scriptButton.setLayoutData(gridData);
    scriptGroup.layout();

    browser.setText(html);
    htmlText.setText(html);
    scriptText.setText(script);
    parent.layout();

    Listener listener = e -> {
        Widget w = e.widget;
        if (w == htmlButton)
            browser.setText(htmlText.getText());
        if (w == scriptButton)
            browser.execute(scriptText.getText());
    };

    htmlButton.addListener(SWT.Selection, listener);
    scriptButton.addListener(SWT.Selection, listener);
}

From source file:ClipboardExample.java

public void open(Display display) {
    clipboard = new Clipboard(display);
    shell = new Shell(display);
    shell.setText("SWT Clipboard");
    shell.setLayout(new FillLayout());

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);//from  w  ww  .  j av a 2 s .c  o m
    parent.setLayout(new GridLayout(2, true));

    Group copyGroup = new Group(parent, SWT.NONE);
    copyGroup.setText("Copy From:");
    GridData data = new GridData(GridData.FILL_BOTH);
    copyGroup.setLayoutData(data);
    copyGroup.setLayout(new GridLayout(3, false));

    Group pasteGroup = new Group(parent, SWT.NONE);
    pasteGroup.setText("Paste To:");
    data = new GridData(GridData.FILL_BOTH);
    pasteGroup.setLayoutData(data);
    pasteGroup.setLayout(new GridLayout(3, false));

    Group controlGroup = new Group(parent, SWT.NONE);
    controlGroup.setText("Control API:");
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    controlGroup.setLayoutData(data);
    controlGroup.setLayout(new GridLayout(5, false));

    Group typesGroup = new Group(parent, SWT.NONE);
    typesGroup.setText("Available Types");
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    typesGroup.setLayoutData(data);
    typesGroup.setLayout(new GridLayout(2, false));

    status = new Label(parent, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.heightHint = 60;
    status.setLayoutData(data);

    createTextTransfer(copyGroup, pasteGroup);
    createRTFTransfer(copyGroup, pasteGroup);
    createHTMLTransfer(copyGroup, pasteGroup);
    createFileTransfer(copyGroup, pasteGroup);
    createMyTransfer(copyGroup, pasteGroup);
    createControlTransfer(controlGroup);
    createAvailableTypes(typesGroup);

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

    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    clipboard.dispose();
}

From source file:widgetTest3.java

private static Composite createTabPage(TabFolder folder, String label) {
    // Create and label a new tab
    TabItem tab = new TabItem(folder, SWT.NONE);
    tab.setText(label);/*from   www . j av  a 2  s .  c  o  m*/
    // Create a new page as a Composite instance
    Composite page = new Composite(folder, SWT.NONE);
    //... and assign to tab
    tab.setControl(page);
    return page;
}

From source file:grafici.PazientiPieChart.java

/**
 * Default constructor.//from  w ww.  j a  v  a2s  .c  o m
 * 
 * @param title
 *            the frame title.
 */
public PazientiPieChart(String title, Composite parent, int style, int tipo) {
    super(parent, style);
    titolo = title;
    Composite cmp = new Composite(this, SWT.FILL | SWT.EMBEDDED);
    GridData gdCmp = new GridData(SWT.FILL);
    gdCmp.horizontalAlignment = SWT.FILL;
    gdCmp.verticalAlignment = SWT.FILL;
    gdCmp.grabExcessHorizontalSpace = true;
    gdCmp.grabExcessVerticalSpace = true;
    cmp.setLayoutData(gdCmp);
    cmp.setLayout(new GridLayout(1, false));

    JPanel chartPanel = createDemoPanel(tipo);
    Frame graphFrame = SWT_AWT.new_Frame(cmp);
    graphFrame.add(chartPanel);
    graphFrame.pack();

    GridData gdThis = new GridData(SWT.FILL);
    gdThis.horizontalAlignment = SWT.FILL;
    gdThis.verticalAlignment = SWT.FILL;
    gdThis.grabExcessHorizontalSpace = true;
    gdThis.grabExcessVerticalSpace = true;

    this.setLayoutData(gdThis);
    this.setLayout(new GridLayout(1, false));
}