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.eclipse.swt.examples.graphics.CustomFontTab.java

@Override
public void createControlPanel(Composite parent) {

    Composite mainComp = new Composite(parent, SWT.NONE);
    mainComp.setLayout(new RowLayout());

    // create combo for font face
    Composite comp = new Composite(mainComp, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.LEFT).setText(GraphicsExample.getResourceString("FontFace")); //$NON-NLS-1$
    fontFaceCb = new Combo(comp, SWT.DROP_DOWN);
    for (String name : fontNames) {
        fontFaceCb.add(name);/*from  w w w  . j a  va 2s. c  o  m*/
    }
    fontFaceCb.select(0);
    fontFaceCb.addListener(SWT.Selection, event -> example.redraw());

    // create combo for font style
    comp = new Composite(mainComp, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.LEFT).setText(GraphicsExample.getResourceString("FontStyle")); //$NON-NLS-1$
    fontStyleCb = new Combo(comp, SWT.DROP_DOWN);
    for (String fontStyle : fontStyles) {
        fontStyleCb.add(fontStyle);
    }
    fontStyleCb.select(0);
    fontStyleCb.addListener(SWT.Selection, event -> example.redraw());

    // create spinner for font size (points)
    comp = new Composite(mainComp, SWT.NONE);
    comp.setLayout(new GridLayout(2, false));

    new Label(comp, SWT.LEFT).setText(GraphicsExample.getResourceString("FontSize")); //$NON-NLS-1$
    fontPointSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP);
    fontPointSpinner.setMinimum(1);
    fontPointSpinner.setMaximum(1000);
    fontPointSpinner.setSelection(200);
    fontPointSpinner.addListener(SWT.Selection, event -> example.redraw());

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

    // initialize the background to the 2nd item in the menu (black)
    fontForeground = (GraphicsBackground) menu.getItem(1).getData();

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

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

/**
 * Creates the window contents/*from  w w  w.  java 2s. com*/
 * 
 * @param shell the parent shell
 */
private void createContents(Shell shell) {
    shell.setLayout(new RowLayout(SWT.VERTICAL));
    createToolbar(shell);

    // Create the labels to display the statuses of
    // the "check" and "radio" buttons
    Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayout(new GridLayout(2, true));

    new Label(composite, SWT.RIGHT).setText("Check One Status:");
    checkOneStatus = new Label(composite, SWT.LEFT);
    checkOneStatus.setText("Off");

    new Label(composite, SWT.RIGHT).setText("Check Two Status:");
    checkTwoStatus = new Label(composite, SWT.LEFT);
    checkTwoStatus.setText("Off");

    new Label(composite, SWT.RIGHT).setText("Radio Status:");
    radioStatus = new Label(composite, SWT.LEFT);
    radioStatus.setText("None");
}

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

public SWTJobTabItem(SWTVisualizationGUI visualizationGUI, GraphVisualizationData visualizationData,
        Composite parent, int style, boolean detectBottlenecks) {
    super(parent, style);

    this.setLayout(new FillLayout());

    this.visualizationGUI = visualizationGUI;
    this.visualizationData = visualizationData;

    // Layout of GUI depends on availability of profiling data
    if (visualizationData.isProfilingAvailableForJob()) {

        final SashForm verticalSash = new SashForm(this, SWT.VERTICAL);

        // Create the tabs
        this.tabFolder = new TabFolder(verticalSash, SWT.BOTTOM);
        this.tabFolder.addListener(SWT.Selection, this);

        final TabItem graphItem = new TabItem(this.tabFolder, SWT.NONE);
        this.graphCanvas = new SWTGraphCanvas(visualizationData, this, tabFolder, SWT.NONE, detectBottlenecks);
        graphItem.setControl(this.graphCanvas);
        graphItem.setText("Execution Graph");

        final TabItem topologyItem = new TabItem(tabFolder, SWT.NONE);
        this.topologyCanvas = new SWTTopologyCanvas(visualizationData, this, tabFolder, SWT.NONE);
        topologyItem.setControl(this.topologyCanvas);
        topologyItem.setText("Allocated Instances");

        final Composite statisticsComposite = new Composite(verticalSash, SWT.NONE);
        statisticsComposite.setLayout(new FillLayout(SWT.HORIZONTAL));

        final NetworkTopology networkTopology = visualizationData.getNetworkTopology();
        final InstanceVisualizationData summaryDataset = (InstanceVisualizationData) networkTopology
                .getAttachment();/*from  ww w . jav a  2  s  . c o m*/

        this.cpuChart = initializeCPUChart(statisticsComposite, summaryDataset.getCpuDataSet());
        this.memoryChart = initializeMemoryChart(statisticsComposite, summaryDataset.getMemoryDataSet());
        this.networkChart = initializeNetworkChart(statisticsComposite, summaryDataset.getNetworkDataSet());

        verticalSash.setWeights(new int[] { 7, 3 });

    } else {

        // Create the tabs
        this.tabFolder = new TabFolder(this, SWT.BOTTOM);
        final TabItem graphItem = new TabItem(this.tabFolder, SWT.NONE);
        this.graphCanvas = new SWTGraphCanvas(visualizationData, this, tabFolder, SWT.NONE, detectBottlenecks);
        graphItem.setControl(graphCanvas);
        graphItem.setText("Execution Graph");

        final TabItem topologyItem = new TabItem(tabFolder, SWT.NONE);
        this.topologyCanvas = new SWTTopologyCanvas(visualizationData, this, tabFolder, SWT.NONE);
        topologyItem.setControl(this.topologyCanvas);
        topologyItem.setText("Allocated Instances");

        this.cpuChart = null;
        this.memoryChart = null;
        this.networkChart = null;
    }

}

From source file:org.jfree.experimental.chart.swt.editor.SWTNumberAxisEditor.java

/**
 * Creates a new editor.//from   w  ww .j a  v  a 2 s .c  o 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:grafici.PrenotazioneTimeSeriesChart.java

/**
 * A demonstration application showing how to create a simple time series
 * chart. This example uses monthly data.
 * // w w  w . j  av a  2  s .  c  o m
 * @param title
 *            the frame title.
 */
public PrenotazioneTimeSeriesChart(String title, Composite parent, int style, int tipo) {
    super(parent, style);

    Label titolo = new Label(this, SWT.NONE);
    titolo.setFont(new Font(titolo.getDisplay(), "arial", 15, SWT.BOLD));
    titolo.setText(title);
    GridData gdLbl = new GridData(SWT.FILL);
    titolo.setLayoutData(gdLbl);
    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));
}

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();/*from ww  w.j a v a 2  s.  com*/

    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:com.rcp.wbw.demo.editor.SWTNumberAxisEditor.java

/**
 * Creates a new editor.//from   ww  w.  j a  v  a2 s  .c o 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:at.ac.tuwien.inso.subcat.ui.widgets.TimeChartControlPanel.java

public TimeChartControlPanel(Composite parent, int style) {
    super(parent, SWT.NONE);
    setLayout(new GridLayout(3, false));

    Composite composite = new Composite(this, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    GridLayout gl_composite = new GridLayout(3, false);
    gl_composite.verticalSpacing = 0;/*ww w  . jav  a  2 s.  co  m*/
    gl_composite.marginWidth = 0;
    gl_composite.marginHeight = 0;
    gl_composite.horizontalSpacing = 0;
    composite.setLayout(gl_composite);

    // Chart, Top Panel:
    new Label(composite, SWT.NONE);
    ;

    Composite chartTopComposite = new Composite(composite, SWT.NONE);
    GridLayout chartBottomLayout = new GridLayout(3, true);
    chartTopComposite.setLayout(chartBottomLayout);
    chartBottomLayout.verticalSpacing = 0;
    chartBottomLayout.marginWidth = 0;
    chartBottomLayout.marginHeight = 0;
    chartBottomLayout.horizontalSpacing = 0;

    chartTopComposite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
    yearSelector = new Combo(chartTopComposite, SWT.READ_ONLY);

    chartTopComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    chartSelector = new Combo(chartTopComposite, SWT.READ_ONLY);
    chartSelector.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));

    chartTopComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    Button saveButton = new Button(chartTopComposite, SWT.NONE);
    saveButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
    saveButton.setText("Save");

    new Label(composite, SWT.NONE);

    // Chart Row:
    btnPrev = new Button(composite, SWT.NONE);
    btnPrev.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    btnPrev.setText("<");

    // TODO: drop scrolledComposite 
    scrolledComposite = new ScrolledComposite(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setLayout(new FillLayout());

    chartComposite = new ChartComposite(scrolledComposite, SWT.NONE, null);
    chartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    chartComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
    scrolledComposite.setContent(chartComposite);

    btnNext = new Button(composite, SWT.NONE);
    btnNext.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    btnNext.setText(">");

    // ** Event handling:

    chartSelector.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            for (TimeChartControlPanelListener listener : listeners) {
                listener.chartSelectionChanged();
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    // *** Year Setting:
    yearSelector.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            btnPrev.setEnabled(hasPrevChart());
            btnNext.setEnabled(hasNextChart());

            triggerChartSelected();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    btnPrev.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            yearSelector.select(yearSelector.getSelectionIndex() - 1);
            btnPrev.setEnabled(hasPrevChart());
            btnNext.setEnabled(hasNextChart());

            triggerChartSelected();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    btnNext.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            yearSelector.select(yearSelector.getSelectionIndex() + 1);
            btnPrev.setEnabled(hasPrevChart());
            btnNext.setEnabled(hasNextChart());

            triggerChartSelected();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    saveButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(TimeChartControlPanel.this.getShell(), SWT.SAVE);
            fd.setText("Save Chart");
            String[] filterExt = { "*.png", "*.jpg" };
            fd.setFilterExtensions(filterExt);
            String selectedPath = fd.open();
            if (selectedPath == null) {
                return;
            }

            for (TimeChartControlPanelListener listener : listeners) {
                listener.chartSaveRequest(selectedPath);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}

From source file:Ch11WizardComposite.java

public void createControl(Composite parent) {
    Composite topLevel = new Composite(parent, SWT.NONE);
    topLevel.setLayout(new FillLayout());

    textLabel = new Label(topLevel, SWT.CENTER);
    textLabel.setText("");

    setControl(topLevel);//ww w  .j  a  v a2 s  .  co  m
    setPageComplete(true);
}

From source file:net.bioclipse.chembl.moss.ui.wizard.ChemblMossWizardPage1.java

@Override
public void createControl(Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    final GridLayout layout = new GridLayout(4, false);
    layout.marginRight = 2;//from ww  w  .  j  a  v  a2 s.c om
    layout.marginLeft = 2;
    layout.marginBottom = -2;
    layout.marginTop = 10;
    layout.marginWidth = 2;
    layout.marginHeight = 2;
    layout.verticalSpacing = 5;
    layout.horizontalSpacing = 5;
    container.setLayout(layout);

    PlatformUI.getWorkbench().getHelpSystem().setHelp(container, "net.bioclipse.moss.business.helpmessage");
    setControl(container);
    setMessage("Select the first protein family to compare with substructure mining.");
    setPageComplete(false);

    label = new Label(container, SWT.NONE);
    gridData = new GridData(GridData.FILL);
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalSpan = 2;
    label.setLayoutData(gridData);
    label.setText("Choose a Kinase Protein Family");

    cbox = new Combo(container, SWT.READ_ONLY);
    cbox.setToolTipText("Kinase family");
    gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalSpan = 2;
    gridData.widthHint = 100;
    cbox.setLayoutData(gridData);
    String[] items = { "TK", "TKL", "STE", "CK1", "CMGC", "AGC", "CAMK" };
    cbox.setItems(items);
    cbox.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            final String selected = cbox.getItem(cbox.getSelectionIndex());

            try {
                table.clearAll();
                table.removeAll();
                setErrorMessage(null);
                List<String> list = chembl.mossAvailableActivities(selected);
                if (list.size() > 0) {
                    String[] item = new String[list.size()];
                    for (int i = 0; i < list.size(); i++) {
                        item[i] = list.get(i);
                    }
                    if (cboxAct.isEnabled()) {
                        if (cboxAct.getSelection().x == cboxAct.getSelection().y) {
                            cboxAct.setItems(item);
                        } else {
                            //Solves the problem involving changing the protein family...
                            //Brings the current activities to an array
                            String oldItems[] = cboxAct.getItems();
                            // Takes that array and makes it a list
                            for (int i = 0; i < list.size(); i++) {
                                cboxAct.add(item[i]);
                            }

                            //Remove the old items in the combobox
                            int oldlistsize = cboxAct.getItemCount() - list.size();
                            index = cboxAct.getText();//cboxAct.getItem(cboxAct.getSelectionIndex());
                            cboxAct.remove(0, oldlistsize - 1);
                            //Adds new items to the comboboxlist
                            List<String> oldItemsList = new ArrayList<String>();
                            for (int i = 0; i < oldItems.length; i++) {
                                oldItemsList.add(oldItems[i]);
                            }

                            //New query with the given settings
                            //if(oldItemsList.contains((index))==true){
                            if (list.contains((index)) == true) {

                                spinn.setSelection(50);
                                IStringMatrix matrix, matrix2;
                                try {
                                    matrix = chembl.mossGetCompoundsFromProteinFamilyWithActivity(selected,
                                            index, spinn.getSelection());
                                    matrix2 = chembl.mossGetCompoundsFromProteinFamily(selected, index);

                                    helpToHistogram(chembl
                                            .mossGetCompoundsFromProteinFamilyWithActivity(selected, index));
                                    cboxAct.setText(index);
                                    info.setText("Distinct compunds: " + matrix2.getRowCount());
                                    addToTable(matrix);

                                    //adds info about target, activities and compounds to a file
                                    ((ChemblMossWizard) getWizard()).data.matrix3 = chembl
                                            .mossGetCompoundsFromProteinFamilyWithActivityTarget(
                                                    cbox.getItem(cbox.getSelectionIndex()),
                                                    cboxAct.getItem(cboxAct.getSelectionIndex()),
                                                    spinn.getSelection());
                                    //adds the query to a file
                                    ((ChemblMossWizard) getWizard()).data.query = chembl
                                            .mossGetCompoundsFromProteinFamilyWithActivitySPARQL(selected,
                                                    index);

                                } catch (BioclipseException e1) {
                                    // TODO Auto-generated catch block
                                    e1.printStackTrace();
                                }

                            } else {
                                setErrorMessage("The activity " + index
                                        + " does not exist for the protein family " + selected + ".");
                                info.setText("Total compund hit:");
                                setPageComplete(false);

                            }
                        }
                    } else {
                        cboxAct.setItems(item);
                        cboxAct.setEnabled(true);
                    }
                }
            } catch (BioclipseException e1) {
                e1.printStackTrace();
            }
        }
    });

    /*Returns the available compunds for the family*/
    label = new Label(container, SWT.NONE);
    gridData = new GridData(GridData.FILL);
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalSpan = 2;
    label.setLayoutData(gridData);
    label.setText("Choose one available activity");

    cboxAct = new Combo(container, SWT.READ_ONLY);
    gridData = new GridData(GridData.FILL);
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalSpan = 2;
    gridData.widthHint = 100;
    String[] item = { "No available activity" };
    cboxAct.setItems(item);
    cboxAct.setLayoutData(gridData);
    cboxAct.setEnabled(false);
    cboxAct.setToolTipText("These activities are only accurate for chosen protein");
    //Listener for available activities(IC50, Ki etc)
    cboxAct.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String selected = cboxAct.getItem(cboxAct.getSelectionIndex());
            try {
                setErrorMessage(null);
                table.clearAll();
                table.removeAll();
                spinn.setSelection(50);
                check.setSelection(false);
                spinnLow.setEnabled(false);
                spinnHigh.setEnabled(false);
                spinnLow.setSelection(0);
                spinnHigh.setSelection(1000);

                //SPARQL queries for fetching compounds and activities
                IStringMatrix matrix = chembl.mossGetCompoundsFromProteinFamilyWithActivity(
                        cbox.getItem(cbox.getSelectionIndex()), selected, spinn.getSelection());
                addToTable(matrix);
                //Count the amount of compounds there is for one hit, i.e. same query without limit.
                IStringMatrix matrix2 = chembl.mossGetCompoundsFromProteinFamily(
                        cbox.getItem(cbox.getSelectionIndex()), cboxAct.getItem(cboxAct.getSelectionIndex()));
                info.setText("Distinct compounds: " + matrix2.getRowCount());
                //Query for activities. Adds them to the plot series.
                matrixAct = chembl.mossGetCompoundsFromProteinFamilyWithActivity(
                        cbox.getItem(cbox.getSelectionIndex()), selected);
                //IStringMatrix matrix = chembl.MossProtFamilyCompounds(cbox.getItem(cbox.getSelectionIndex()), selected,50);
                //IStringMatrix matrix = chembl.MossProtFamilyCompounds(cbox.getItem(cbox.getSelectionIndex()), selected, spinn.getSelection());

                ((ChemblMossWizard) getWizard()).data.matrix3 = chembl
                        .mossGetCompoundsFromProteinFamilyWithActivityTarget(
                                cbox.getItem(cbox.getSelectionIndex()), selected, spinn.getSelection());

                ((ChemblMossWizard) getWizard()).data.query = chembl
                        .mossGetCompoundsFromProteinFamilyWithActivitySPARQL(
                                cbox.getItem(cbox.getSelectionIndex()), selected);

                //Adds activity to histogram series
                helpToHistogram(matrixAct);

                //               series = new XYSeries("Activity for compounds");
                //               histogramSeries = new HistogramDataset();
                //               histogramSeries.setType(HistogramType.FREQUENCY);
                //               ArrayList<Double> activites = new ArrayList<Double>();
                //               double value;
                //               int cnt =1;
                //               double[] histact = new double[matrixAct.getRowCount()+1];
                //               for(int i = 1; i< matrixAct.getRowCount()+1;i++){
                //                  if(matrixAct.get(i,"actval").equals("")){ value =0;}
                //                  else{value = Double.parseDouble(matrixAct.get(i,"actval"));}
                //                  activites.add(value);
                //               }
                //               //Sort list to increasing order of activities and adds them to histogram
                //               Collections.sort(activites);
                //               for(int i=0; i< activites.size(); i++){
                //                  double d=activites.get(i);
                //                  histact[i]=d;
                //                  int t= activites.size()-1;
                //                  if(i == t){
                //                     series.add(d,cnt);
                //                  }else{
                //                     double dd= activites.get(i+1);
                //
                //                     if(d==dd){
                //                        cnt++;
                //                     }
                //                     else{
                //                        histact[i]=d;
                //                        series.add(d,cnt);
                //                        cnt =1;
                //                     }
                //                  }
                //               }
                //               histogramSeries.addSeries("Histogram",histact,matrixAct.getRowCount());
                button.setEnabled(true);
                spinn.setEnabled(true);
                check.setEnabled(true);
                //cboxAct.setEnabled(true);
                //buttonH.setEnabled(true);

            } catch (BioclipseException e1) {
                e1.printStackTrace();
            }
            setPageComplete(true);
        }
    });

    label = new Label(container, SWT.NONE);
    gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalSpan = 2;
    label.setLayoutData(gridData);
    label.setText("Limit");

    spinn = new Spinner(container, SWT.BORDER);
    gridData = new GridData();
    spinn.setLayoutData(gridData);
    spinn.setSelection(50);
    spinn.setMaximum(10000000);
    spinn.setIncrement(50);
    spinn.setEnabled(false);
    gridData.widthHint = 100;
    gridData.horizontalSpan = 1;
    spinn.setToolTipText("Limits the search, increases by 50");
    spinn.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selected = spinn.getSelection();
            try {
                table.clearAll();
                table.removeAll();
                IStringMatrix matrix = chembl.mossGetCompounds(cbox.getItem(cbox.getSelectionIndex()),
                        cboxAct.getItem(cboxAct.getSelectionIndex()), selected);
                table.setVisible(true);
                addToTable(matrix);
            } catch (BioclipseException e1) {
                e1.printStackTrace();
            }
        }
    });

    //Button that adds all hits to the limit
    button = new Button(container, SWT.PUSH);
    button.setToolTipText("Add all compounds to the table");
    button.setText("Display all");
    button.setEnabled(false);
    button.setLayoutData(gridData);
    gridData = new GridData();
    gridData.horizontalSpan = 1;
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            //try {
            table.removeAll();
            //            ProgressMonitorDialog dialog = new ProgressMonitorDialog(container.getShell());
            //            
            //            try {
            //               dialog.run(true, true, new IRunnableWithProgress(){
            //                  public void run(IProgressMonitor monitor) {
            //                     monitor.beginTask("Searching for compounds", IProgressMonitor.UNKNOWN);
            try {
                IStringMatrix matrix = chembl.mossGetCompoundsFromProteinFamilyWithActivity(
                        cbox.getItem(cbox.getSelectionIndex()), cboxAct.getItem(cboxAct.getSelectionIndex()));

                //                        final IStringMatrix matrix = chembl.MossProtFamilyCompoundsAct("TK", "Ki");
                addToTable(matrix);
                info.setText("Total hit(not always distinct compounds): " + matrix.getRowCount());
                spinn.setSelection(matrix.getRowCount());

            } catch (BioclipseException eb) {
                // TODO Auto-generated catch block
                eb.printStackTrace();
            }

            //                     
            //                     monitor.done();
            //                  }
            //               });
            //            } catch (InvocationTargetException e1) {
            //               // TODO Auto-generated catch block
            //               e1.printStackTrace();
            //            } catch (InterruptedException e1) {
            //               // TODO Auto-generated catch block
            //               e1.printStackTrace();
            //            }

            //            } catch (BioclipseException e1) {
            //               // TODO Auto-generated catch block
            //               e1.printStackTrace();
            //            }
        }
    });

    //      label = new Label(container, SWT.NONE);
    //      label.setText("Optional: Modify activity values.");
    //      gridData = new GridData();
    //      gridData.horizontalSpan=4;
    //      gridData.verticalSpan=5;
    //      label.setLayoutData(gridData);

    check = new Button(container, SWT.CHECK);
    check.setText("Modify activities (optional)");
    check.setToolTipText("Modify data by specifying upper and lower activity limit");
    check.setEnabled(false);
    gridData = new GridData(GridData.BEGINNING);
    gridData.horizontalSpan = 2;
    check.setLayoutData(gridData);
    check.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            boolean selected = check.getSelection();
            if (selected == true) {
                spinnLow.setEnabled(true);
                spinnHigh.setEnabled(true);
                buttonUpdate.setEnabled(true);
                labelHigh.setEnabled(true);
                labelLow.setEnabled(true);
                buttonH.setEnabled(true);
            } else if (selected == false) {
                spinnLow.setEnabled(false);
                spinnHigh.setEnabled(false);
                buttonUpdate.setEnabled(false);
                labelHigh.setEnabled(false);
                labelLow.setEnabled(false);
                buttonH.setEnabled(false);
            }
        }
    });
    label = new Label(container, SWT.NONE);
    label.setText("Look at activity span: ");
    label.setToolTipText("The graph don't consider limited search, will display for all available compounds");
    gridData = new GridData();
    gridData.horizontalSpan = 1;
    label.setLayoutData(gridData);
    buttonH = new Button(container, SWT.PUSH);
    buttonH.setText("Graph");
    buttonH.setToolTipText("Shows activity in a graph(for all compounds)");
    buttonH.setEnabled(false);
    gridData = new GridData();
    gridData.horizontalSpan = 1;
    buttonH.setLayoutData(gridData);
    buttonH.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {

            JFreeChart jfreechart = ChartFactory.createXYLineChart("Histogram Demo", "Activity values",
                    "Number of compounds", histogramSeries, PlotOrientation.VERTICAL, true, false, false);

            //            final XYSeriesCollection dataset = new XYSeriesCollection(series);
            //            JFreeChart chart = ChartFactory.createXYBarChart(
            //                  "Activity chart",
            //                  "Activity value",
            //                  false,
            //                  "Number of Compounds", 
            //                  dataset,
            //                  PlotOrientation.VERTICAL,
            //                  true,
            //                  true,
            //                  false
            //            );
            ChartFrame frame = new ChartFrame("Activities", jfreechart);
            frame.pack();
            frame.setVisible(true);
        }
    });
    // Lower activity bound for updating table
    labelLow = new Label(container, SWT.NONE);
    labelLow.setText("Lower activity limit");
    labelLow.setEnabled(false);
    gridData = new GridData();
    gridData.horizontalSpan = 1;
    labelLow.setLayoutData(gridData);
    spinnLow = new Spinner(container, SWT.NONE);
    spinnLow.setSelection(1);
    spinnLow.setMaximum(10000000);
    spinnLow.setIncrement(50);
    spinnLow.setEnabled(false);
    spinnLow.setToolTipText("Specify lower activity limit");
    gridData = new GridData();
    gridData.widthHint = 100;
    gridData.horizontalSpan = 1;
    spinnLow.setLayoutData(gridData);

    buttonUpdate = new Button(container, SWT.PUSH);
    buttonUpdate.setText("Update table");
    buttonUpdate.setToolTipText("Update the table with the specified activity limits");
    buttonUpdate.setEnabled(false);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    buttonUpdate.setLayoutData(gridData);
    buttonUpdate.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            table.clearAll();
            table.removeAll();
            try {
                IStringMatrix mmatrixAct = chembl.mossGetCompoundsFromProteinFamilyWithActivity(
                        cbox.getItem(cbox.getSelectionIndex()), cboxAct.getText());

                IStringMatrix matrix = chembl.mossSetActivityBound(mmatrixAct, spinnLow.getSelection(),
                        spinnHigh.getSelection());
                //               IStringMatrix m = chembl.mossSetActivityOutsideBound(matrixAct, spinnLow.getSelection(), spinnHigh.getSelection());

                addToTable(matrix);

                int yes = 0, no = 0;

                for (int index = 1; index < matrix.getRowCount() + 1; index++) {
                    if (matrix.get(index, "active").equals("yes")) {
                        yes++;
                    } else
                        no++;
                }
                spinn.setSelection(matrix.getRowCount());
                info.setText("Total compound hit: " + matrix.getRowCount() + ": active: " + yes + ", inactive: "
                        + no);
            } catch (BioclipseException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    });

    //Upper activity bound for updating table
    labelHigh = new Label(container, SWT.NONE);
    labelHigh.setText("Upper activity limit");
    labelHigh.setEnabled(false);
    gridData = new GridData();
    gridData.horizontalSpan = 1;
    labelHigh.setLayoutData(gridData);
    spinnHigh = new Spinner(container, SWT.BORDER);
    spinnHigh.setSelection(1000);
    spinnHigh.setMaximum(1000000000);
    spinnHigh.setIncrement(50);
    spinnHigh.setEnabled(false);
    spinnHigh.setToolTipText("Specify upper activity limit");
    gridData = new GridData();
    gridData.widthHint = 100;
    gridData.horizontalSpan = 3;
    spinnHigh.setLayoutData(gridData);

    //Label for displaying compound hits
    info = new Label(container, SWT.NONE);
    gridData = new GridData();
    info.setLayoutData(gridData);
    gridData.horizontalSpan = 4;
    gridData.verticalSpan = 6;
    gridData.widthHint = 350;
    info.setText("Total compound hit:");

    //Table displaying contents
    table = new Table(container, SWT.BORDER);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.widthHint = 300;
    gridData.heightHint = 300;
    gridData.horizontalSpan = 4;
    table.setLayoutData(gridData);
    column1 = new TableColumn(table, SWT.NONE);
    column1.setText("Index");
    column2 = new TableColumn(table, SWT.NONE);
    column2.setText("Activity value");
    column3 = new TableColumn(table, SWT.NONE);
    column3.setText("Active?");
    column4 = new TableColumn(table, SWT.NONE);
    column4.setText("Compounds (SMILES)");

}