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

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

Introduction

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

Prototype

public void setBackground(Color color) 

Source Link

Document

Sets the receiver's background color to the color specified by the argument, or to the default system color for the control if the argument is null.

Usage

From source file:eu.stratosphere.nephele.visualization.swt.SWTVertexToolTip.java

public SWTVertexToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver,
        ManagementVertex managementVertex, int x, int y) {
    super(parent, x, y);

    this.managementVertex = managementVertex;

    final VertexVisualizationData vertexVisualizationData = (VertexVisualizationData) managementVertex
            .getAttachment();// w  ww .j  a  v a2s  .  c o  m

    int height;

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

    // Set the title
    final String taskName = managementVertex.getName() + " (" + (managementVertex.getIndexInGroup() + 1)
            + " of " + managementVertex.getNumberOfVerticesInGroup() + ")";
    setTitle(taskName);

    // Only create chart if profiling is enabled
    if (vertexVisualizationData.isProfilingEnabledForJob()) {
        this.threadChart = createThreadChart(vertexVisualizationData, backgroundColor);
        this.threadChart.setLayoutData(new GridData(GridData.FILL_BOTH));
        height = 240; // should be 265 when cancel button is enabled
    } else {
        this.threadChart = null;
        height = 125;
    }

    final Composite tableComposite = new Composite(getShell(), SWT.NONE);
    tableComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tableComposite.setBackground(backgroundColor);
    tableComposite.setForeground(foregroundColor);
    final GridLayout tableGridLayout = new GridLayout(3, false);
    tableGridLayout.marginHeight = 0;
    tableGridLayout.marginLeft = 0;
    tableComposite.setLayout(tableGridLayout);

    final GridData gridData1 = new GridData();
    gridData1.horizontalSpan = 2;
    gridData1.grabExcessHorizontalSpace = true;
    gridData1.widthHint = 200;

    final GridData gridData2 = new GridData();
    gridData2.grabExcessHorizontalSpace = true;

    // Instance type
    final Label instanceTypeTextLabel = new Label(tableComposite, SWT.NONE);
    instanceTypeTextLabel.setBackground(backgroundColor);
    instanceTypeTextLabel.setForeground(foregroundColor);
    instanceTypeTextLabel.setText("Instance type:");

    this.instanceTypeLabel = new Label(tableComposite, SWT.NONE);
    this.instanceTypeLabel.setBackground(backgroundColor);
    this.instanceTypeLabel.setForeground(foregroundColor);
    this.instanceTypeLabel.setText(this.managementVertex.getInstanceType());
    this.instanceTypeLabel.setLayoutData(gridData1);

    // Instance ID
    final Label instanceIDTextLabel = new Label(tableComposite, SWT.NONE);
    instanceIDTextLabel.setBackground(backgroundColor);
    instanceIDTextLabel.setForeground(foregroundColor);
    instanceIDTextLabel.setText("Instance ID:");

    this.instanceIDLabel = new Label(tableComposite, SWT.NONE);
    this.instanceIDLabel.setBackground(backgroundColor);
    this.instanceIDLabel.setForeground(foregroundColor);
    this.instanceIDLabel.setText(this.managementVertex.getInstanceName());
    this.instanceIDLabel.setLayoutData(gridData2);

    final Button switchToInstanceButton = new Button(tableComposite, SWT.PUSH);
    switchToInstanceButton.setText("Switch to instance...");
    switchToInstanceButton.setEnabled(vertexVisualizationData.isProfilingEnabledForJob());
    switchToInstanceButton.setVisible(false);

    /*
     * final String instanceName = this.managementVertex.getInstanceName();
     * switchToInstanceButton.addListener(SWT.Selection, new Listener() {
     * @Override
     * public void handleEvent(Event arg0) {
     * commandReceiver.switchToInstance(instanceName);
     * }
     * });
     */

    // Execution state
    final Label executionStateTextLabel = new Label(tableComposite, SWT.NONE);
    executionStateTextLabel.setBackground(backgroundColor);
    executionStateTextLabel.setForeground(foregroundColor);
    executionStateTextLabel.setText("Execution state:");

    this.executionStateLabel = new Label(tableComposite, SWT.NONE);
    this.executionStateLabel.setBackground(backgroundColor);
    this.executionStateLabel.setForeground(foregroundColor);
    this.executionStateLabel.setText(this.managementVertex.getExecutionState().toString());
    this.executionStateLabel.setLayoutData(gridData1);

    // Checkpoint state
    final Label checkpointStateTextLabel = new Label(tableComposite, SWT.NONE);
    checkpointStateTextLabel.setBackground(backgroundColor);
    checkpointStateTextLabel.setForeground(foregroundColor);
    checkpointStateTextLabel.setText("Checkpoint state:");

    this.checkpointStateLabel = new Label(tableComposite, SWT.NONE);
    this.checkpointStateLabel.setBackground(backgroundColor);
    this.checkpointStateLabel.setForeground(foregroundColor);
    this.checkpointStateLabel.setText(this.managementVertex.getCheckpointState().toString());
    this.checkpointStateLabel.setLayoutData(gridData1);

    final ManagementGroupVertex groupVertex = this.managementVertex.getGroupVertex();
    final GroupVertexVisualizationData groupVertexVisualizationData = (GroupVertexVisualizationData) groupVertex
            .getAttachment();
    if (groupVertexVisualizationData.isCPUBottleneck()) {
        this.warningComposite = createWarningComposite(WARNINGTEXT, SWT.ICON_WARNING);
        height += ICONSIZE;
    } else {
        this.warningComposite = null;
    }

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

    /*
     * final Button cancelTaskButton = new Button(taskActionComposite, SWT.PUSH);
     * final ManagementVertexID vertexID = this.managementVertex.getID();
     * cancelTaskButton.setText("Cancel task");
     * cancelTaskButton.setEnabled(this.managementVertex.getExecutionState() == ExecutionState.RUNNING);
     * cancelTaskButton.addListener(SWT.Selection, new Listener() {
     * @Override
     * public void handleEvent(Event arg0) {
     * commandReceiver.cancelTask(vertexID, taskName);
     * }
     * });
     */

    getShell().setSize(WIDTH, height);

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

From source file:gov.redhawk.statistics.ui.views.StatisticsView.java

/**
 * This is a callback that will allow us to create the viewer and initialize it.
 *//*from www.  j ava 2  s .c  o m*/
@Override
public void createPartControl(Composite comp) {

    parent = comp;
    parent.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(1).create());

    // Custom Action for the View's Menu
    CustomAction customAction = new CustomAction() {

        @Override
        public void run() {
            SettingsDialog dialog = new SettingsDialog(parent.getShell(), datalist.length, curIndex, numBars);
            dialog.create();
            if (dialog.open() == Window.OK) {
                numBars = dialog.getNumBars();
                curIndex = dialog.getSelectedIndex();
                refreshJob.schedule();
            }
        }
    };
    customAction.setText("Settings");
    getViewSite().getActionBars().getMenuManager().add(customAction);

    // creation of chart composite and selection of associated options
    Composite chartComposite = new Composite(parent, SWT.EMBEDDED);
    chartComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    chart = ChartFactory.createXYBarChart(null, null, false, null, dataSet, PlotOrientation.VERTICAL, false,
            true, false);

    org.eclipse.swt.graphics.Color backgroundColor = chartComposite.getBackground();
    chart.setBackgroundPaint(
            new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()));
    chart.getXYPlot().setBackgroundPaint(ChartColor.WHITE);

    Frame chartFrame = SWT_AWT.new_Frame(chartComposite);
    chartFrame.setBackground(
            new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()));
    chartFrame.setLayout(new GridLayout());

    ChartPanel jFreeChartPanel = new ChartPanel(chart);
    chartFrame.add(jFreeChartPanel);

    ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setMargin(0.05);
    renderer.setShadowVisible(false);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        @Override
        public String generateLabel(XYDataset dataset, int series, int item) {
            return String.valueOf((int) (dataset.getYValue(series, item)));
        }
    });
    renderer.setBasePaint(new Color(139, 0, 0));
    renderer.setLegendItemLabelGenerator(new XYSeriesLabelGenerator() {

        @Override
        public String generateLabel(XYDataset ds, int i) {
            if (ds.getSeriesCount() == 2) {
                if (i == 0) {
                    return "Real";
                } else if (i == 1) {
                    return "Imaginary";
                } else {
                    return "Complex";
                }
            } else if (ds.getSeriesCount() > 1) {
                return "Dimension " + i;
            }

            return null;
        }
    });
    chart.getXYPlot().setRenderer(renderer);

    dataSet.addChangeListener(new DatasetChangeListener() {

        @Override
        public void datasetChanged(DatasetChangeEvent event) {
            chart.getPlot().datasetChanged(event);

        }
    });

    // creation of the statistics composite
    FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    section = toolkit.createSection(parent, Section.DESCRIPTION | Section.NO_TITLE | Section.CLIENT_INDENT);
    section.setBackground(parent.getBackground());
    section.setDescription("");
    section.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); // layout within parent

    // Composite for storing the data
    Composite composite = toolkit.createComposite(section, SWT.WRAP);
    composite.setBackground(parent.getBackground());
    composite.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(4).create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); // layout within parent
    toolkit.paintBordersFor(composite);
    section.setClient(composite);

    for (int j = 0; j < STAT_PROPS.length; j++) {
        Label label = new Label(composite, SWT.None);
        label.setText(STAT_PROPS[j] + ":");
        labels[j] = new Label(composite, SWT.None);
        labels[j].setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    }

}