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

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

Introduction

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

Prototype

public void setLayout(Layout layout) 

Source Link

Document

Sets the layout which is associated with the receiver to be the argument which may be null.

Usage

From source file:ClassFigure.java

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

    canvas = new Canvas(composite, SWT.NULL);
    canvas.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));

    LightweightSystem lws = new LightweightSystem(canvas);
    contents = new Figure();
    xyLayout = new XYLayout();
    contents.setLayoutManager(xyLayout);

    lws.setContents(contents);/* w w  w . j  a  va  2s .  com*/

    showClass(this.getClass());

    // Creates tool bar items.
    getToolBarManager().add(new Action("Set class ...") {
        public void run() {
            InputDialog dialog = new InputDialog(getShell(), "", "Please enter the class name", "", null);
            if (dialog.open() != Dialog.OK)
                return;

            contents.removeAll();
            Class cls = null;
            try {
                cls = Class.forName(dialog.getValue());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            if (cls != null) {
                showClass(cls);
            }
        }
    });
    getToolBarManager().update(true);

    return composite;
}

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

/**
 * Creates the widgets used to control the drawing.
 *//*  ww  w .  j  a v a 2 s  .  c o  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:MainClass.java

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

    new Label(composite, SWT.LEFT).setText("E-mail Address:");
    final Text ea = new Text(composite, SWT.BORDER);
    ea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    ea.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            email = ea.getText();//from   w w  w.  j  ava2s.co  m
            setPageComplete(email.length() > 0);
        }
    });

    setControl(composite);
}

From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java

public SWTInstanceToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver,
        NetworkNode networkNode, int x, int y) {
    super(parent, x, y);

    this.networkNode = networkNode;

    final Color backgroundColor = getShell().getBackground();
    final Color foregroundColor = getShell().getForeground();

    boolean isProfilingEnabled = false;
    final InstanceVisualizationData instanceVisualizationData = (InstanceVisualizationData) networkNode
            .getAttachment();//from ww w .j  av  a 2s. co m
    if (instanceVisualizationData != null) {
        isProfilingEnabled = instanceVisualizationData.isProfilingEnabledForJob();
    }

    int height;

    // Set the title
    setTitle(networkNode.getName());

    // Only create chart if profiling is enabled
    if (isProfilingEnabled) {
        this.cpuChart = createCPUChart(instanceVisualizationData, backgroundColor);
        this.cpuChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        this.memoryChart = createMemoryChart(instanceVisualizationData, backgroundColor);
        this.memoryChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        this.networkChart = createNetworkChart(instanceVisualizationData, backgroundColor);
        this.networkChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        height = 460;
    } else {
        this.cpuChart = null;
        this.memoryChart = null;
        this.networkChart = null;
        height = 75;
    }

    // Available instance actions
    final Composite instanceActionComposite = new Composite(getShell(), SWT.NONE);
    instanceActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
    instanceActionComposite.setBackground(backgroundColor);
    instanceActionComposite.setForeground(foregroundColor);

    final Button killInstanceButton = new Button(instanceActionComposite, SWT.PUSH);
    final String instanceName = this.networkNode.getName();
    killInstanceButton.setText("Kill instance...");
    killInstanceButton.setEnabled(this.networkNode.isLeafNode());
    killInstanceButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            commandReceiver.killInstance(instanceName);
        }

    });

    getShell().setSize(WIDTH, height);

    finishInstantiation(x, y, WIDTH, false);
}

From source file:net.bioclipse.seneca.views.BestStructureView.java

public void createPartControl(Composite parent) {
    SashForm sash = new SashForm(parent, SWT.VERTICAL);
    jcpwidget = new JChemPaintEditorWidget(sash, SWT.PUSH);
    Composite contChartcomposite = new Composite(sash, SWT.EMBEDDED);
    FillLayout layout = new FillLayout(SWT.VERTICAL);
    contChartcomposite.setLayout(layout);
    fileTableFrame = SWT_AWT.new_Frame(contChartcomposite);

    String xAxisLabel = "Steps";
    String yAxisLabel = "Temperature/Score";
    String title = "Annealing progress";
    XYSeries series = new XYSeries("Signal");
    for (int i = 0; i < (maxSteps != 0 ? maxSteps : temps.size()); i++) {
        if (i < temps.size())
            series.add(i, temps.get(i));
        else//from   w  ww  .  j a v  a 2s  .  co m
            series.add(i, 0);
    }

    XYDataset xyDataset = new XYSeriesCollection(series);
    continuousChart = ChartFactory.createXYAreaChart(title, xAxisLabel, yAxisLabel, xyDataset,
            PlotOrientation.VERTICAL, false, true, false);
    continuousChart.setAntiAlias(false);

    XYPlot continuousPlot = continuousChart.getXYPlot();

    continuousPlot.setRenderer(new StandardXYItemRenderer());
    ChartPanel chart = new ChartPanel(continuousChart);
    fileTableFrame.add(chart);
    //fileTableFrame.validate();
    //fileTableFrame.repaint();

}

From source file:com.rcp.wbw.demo.editor.SWTNumberAxisEditor.java

/**
 * Creates a new editor.//from  w w  w .  j  av a 2  s .co m
 * 
 * @param parent
 *            the parent.
 * @param style
 *            the style.
 * @param axis
 *            the axis.
 */
public SWTNumberAxisEditor(Composite parent, int style, NumberAxis axis) {
    super(parent, style, axis);
    this.autoRange = axis.isAutoRange();
    this.minimumValue = axis.getLowerBound();
    this.maximumValue = axis.getUpperBound();

    TabItem item2 = new TabItem(getOtherTabs(), SWT.NONE);
    item2.setText(" " + localizationResources.getString("Range") + " ");
    Composite range = new Composite(getOtherTabs(), SWT.NONE);
    range.setLayout(new GridLayout(2, true));
    item2.setControl(range);

    this.autoRangeCheckBox = new Button(range, SWT.CHECK);
    this.autoRangeCheckBox.setText(localizationResources.getString("Auto-adjust_range"));
    this.autoRangeCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    this.autoRangeCheckBox.setSelection(this.autoRange);
    this.autoRangeCheckBox.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            toggleAutoRange();
        }
    });
    new Label(range, SWT.NONE).setText(localizationResources.getString("Minimum_range_value"));
    this.minimumRangeValue = new Text(range, SWT.BORDER);
    this.minimumRangeValue.setText(String.valueOf(this.minimumValue));
    this.minimumRangeValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    this.minimumRangeValue.setEnabled(!this.autoRange);
    // this.minimumRangeValue.addModifyListener(this);
    // this.minimumRangeValue.addVerifyListener(this);
    this.minimumRangeValue.addFocusListener(this);
    new Label(range, SWT.NONE).setText(localizationResources.getString("Maximum_range_value"));
    this.maximumRangeValue = new Text(range, SWT.BORDER);
    this.maximumRangeValue.setText(String.valueOf(this.maximumValue));
    this.maximumRangeValue.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    this.maximumRangeValue.setEnabled(!this.autoRange);
    // this.maximumRangeValue.addModifyListener(this);
    // this.maximumRangeValue.addVerifyListener(this);
    this.maximumRangeValue.addFocusListener(this);
}

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

@Override
public void createControlPanel(Composite parent) {

    Composite comp;

    // create draw button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    drawButton = new Button(comp, SWT.TOGGLE);
    drawButton.setText(GraphicsExample.getResourceString("DrawPath")); //$NON-NLS-1$
    drawButton.addListener(SWT.Selection, event -> example.redraw());
    drawButton.setSelection(true);/*from  w w  w. ja  v  a  2s .  c o m*/

    // create fill button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    fillButton = new Button(comp, SWT.TOGGLE);
    fillButton.setText(GraphicsExample.getResourceString("FillPath")); //$NON-NLS-1$
    fillButton.addListener(SWT.Selection, event -> example.redraw());

    // create close button
    comp = new Composite(parent, SWT.NONE);
    comp.setLayout(new GridLayout());

    closeButton = new Button(comp, SWT.TOGGLE);
    closeButton.setText(GraphicsExample.getResourceString("ClosePath")); //$NON-NLS-1$
    closeButton.addListener(SWT.Selection, event -> example.redraw());

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

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

    // initialize the foreground to the 5th item in the menu (green)
    fillColor = (GraphicsBackground) menu.getItem(3).getData();

    // color button
    colorButton = new Button(comp, SWT.PUSH);
    colorButton.setText(GraphicsExample.getResourceString("FillColor")); //$NON-NLS-1$
    colorButton.setImage(fillColor.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:MainClass.java

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

    new Label(composite, SWT.LEFT).setText("First Name:");
    final Text first = new Text(composite, SWT.BORDER);
    first.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(composite, SWT.LEFT).setText("Last Name:");
    final Text last = new Text(composite, SWT.BORDER);
    last.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    first.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            firstName = first.getText();
            setPageComplete(firstName.length() > 0 && lastName.length() > 0);
        }//w  ww . j a  v  a 2s.  c om
    });

    last.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            lastName = last.getText();
            setPageComplete(firstName.length() > 0 && lastName.length() > 0);
        }
    });

    setControl(composite);
}

From source file:ch.unibe.iam.scg.archie.controller.ProviderChartFactory.java

/**
 * Creates a chart from the currently set chart model and attaches it to the
 * given parent.//from  w ww  . ja va 2  s  .  co m
 * 
 * @param parent
 *            Chart composite cotainer.
 * @return Composite containing the chart just created.
 */
public Composite createChart(Composite parent) {
    // set layout of parent container
    parent.setLayout(new GridLayout());
    parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // create an error message if no model present
    if (this.model == null) {
        return new GraphicalMessage(parent, ArchieActivator.getImage(ArchieActivator.IMG_ERROR),
                Messages.NO_CHART_MODEL);
    }

    // else return a chart composite based on the chart type
    if (this.model.getChartType() == ChartModel.CHART_PIE) {
        return this.createPieChart(parent);
    }
    return this.createBarChart(parent);
}

From source file:FoodList.java

/**
 * Creates the main window's contents//from w  w w.  j  av  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 filter
    Button filterHealthy = new Button(composite, SWT.CHECK);
    filterHealthy.setText("&Show only healthy");

    final ListViewer lv = new ListViewer(composite);
    lv.setContentProvider(new FoodContentProvider());
    lv.setLabelProvider(new FoodLabelProvider());
    lv.setInput(new GroceryList());

    // When user checks the checkbox, toggle the filter
    filterHealthy.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            if (((Button) event.widget).getSelection())
                lv.addFilter(filter);
            else
                lv.removeFilter(filter);
        }
    });

    parent.pack();
    return composite;
}