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

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

Introduction

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

Prototype

public Label(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:BrowserExample.java

/**
 * Creates an instance of a ControlExample embedded inside the supplied
 * parent Composite.//from  ww w. j  a  v  a  2s  .c o m
 * 
 * @param parent
 *            the container of the example
 */
public BrowserExample(Composite parent) {

    final Display display = parent.getDisplay();
    FormLayout layout = new FormLayout();
    parent.setLayout(layout);
    ToolBar toolbar = new ToolBar(parent, SWT.NONE);
    final ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
    itemBack.setText(getResourceString("Back"));
    final ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
    itemForward.setText(getResourceString("Forward"));
    final ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
    itemStop.setText(getResourceString("Stop"));
    final ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
    itemRefresh.setText(getResourceString("Refresh"));
    final ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
    itemGo.setText(getResourceString("Go"));

    location = new Text(parent, SWT.BORDER);

    images = new Image[] { new Image(display, "java2s.gif") };

    final Canvas canvas = new Canvas(parent, SWT.NO_BACKGROUND);
    final Rectangle rect = images[0].getBounds();
    canvas.addListener(SWT.Paint, new Listener() {
        public void handleEvent(Event e) {
            Point pt = canvas.getSize();
            e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0, pt.x, pt.y);
        }
    });
    canvas.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event e) {
            browser.setUrl(getResourceString("Startup"));
        }
    });

    display.asyncExec(new Runnable() {
        public void run() {
            if (canvas.isDisposed())
                return;
            if (busy) {
                index++;
                if (index == images.length)
                    index = 0;
                canvas.redraw();
            }
            display.timerExec(150, this);
        }
    });

    final Label status = new Label(parent, SWT.NONE);
    final ProgressBar progressBar = new ProgressBar(parent, SWT.NONE);

    FormData data = new FormData();
    data.top = new FormAttachment(0, 5);
    toolbar.setLayoutData(data);

    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.top = new FormAttachment(canvas, 5, SWT.DEFAULT);
    data.bottom = new FormAttachment(status, -5, SWT.DEFAULT);
    try {
        browser = new Browser(parent, SWT.NONE);
        browser.setLayoutData(data);
    } catch (SWTError e) {
        /* Browser widget could not be instantiated */
        Label label = new Label(parent, SWT.CENTER | SWT.WRAP);
        label.setText(getResourceString("BrowserNotCreated"));
        label.setLayoutData(data);
    }

    data = new FormData();
    data.width = 24;
    data.height = 24;
    data.top = new FormAttachment(0, 5);
    data.right = new FormAttachment(100, -5);
    canvas.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(toolbar, 0, SWT.TOP);
    data.left = new FormAttachment(toolbar, 5, SWT.RIGHT);
    data.right = new FormAttachment(canvas, -5, SWT.DEFAULT);
    location.setLayoutData(data);

    data = new FormData();
    data.left = new FormAttachment(0, 5);
    data.right = new FormAttachment(progressBar, 0, SWT.DEFAULT);
    data.bottom = new FormAttachment(100, -5);
    status.setLayoutData(data);

    data = new FormData();
    data.right = new FormAttachment(100, -5);
    data.bottom = new FormAttachment(100, -5);
    progressBar.setLayoutData(data);

    if (browser != null) {
        itemBack.setEnabled(browser.isBackEnabled());
        itemForward.setEnabled(browser.isForwardEnabled());

        Listener listener = new Listener() {
            public void handleEvent(Event event) {
                ToolItem item = (ToolItem) event.widget;
                if (item == itemBack)
                    browser.back();
                else if (item == itemForward)
                    browser.forward();
                else if (item == itemStop)
                    browser.stop();
                else if (item == itemRefresh)
                    browser.refresh();
                else if (item == itemGo)
                    browser.setUrl(location.getText());
            }
        };
        browser.addLocationListener(new LocationListener() {
            public void changed(LocationEvent event) {
                busy = true;
                if (event.top)
                    location.setText(event.location);
            }

            public void changing(LocationEvent event) {
            }
        });
        browser.addProgressListener(new ProgressListener() {
            public void changed(ProgressEvent event) {
                if (event.total == 0)
                    return;
                int ratio = event.current * 100 / event.total;
                progressBar.setSelection(ratio);
                busy = event.current != event.total;
                if (!busy) {
                    index = 0;
                    canvas.redraw();
                }
            }

            public void completed(ProgressEvent event) {
                itemBack.setEnabled(browser.isBackEnabled());
                itemForward.setEnabled(browser.isForwardEnabled());
                progressBar.setSelection(0);
                busy = false;
                index = 0;
                canvas.redraw();
            }
        });
        browser.addStatusTextListener(new StatusTextListener() {
            public void changed(StatusTextEvent event) {
                status.setText(event.text);
            }
        });
        if (parent instanceof Shell) {
            final Shell shell = (Shell) parent;
            browser.addTitleListener(new TitleListener() {
                public void changed(TitleEvent event) {
                    shell.setText(event.title + " - " + getResourceString("window.title"));
                }
            });
        }
        itemBack.addListener(SWT.Selection, listener);
        itemForward.addListener(SWT.Selection, listener);
        itemStop.addListener(SWT.Selection, listener);
        itemRefresh.addListener(SWT.Selection, listener);
        itemGo.addListener(SWT.Selection, listener);
        location.addListener(SWT.DefaultSelection, new Listener() {
            public void handleEvent(Event e) {
                browser.setUrl(location.getText());
            }
        });

        initialize(display, browser);
        browser.setUrl(getResourceString("Startup"));
    }
}

From source file:TabComplex.java

/**
 * Gets the control for tab three//from w w  w  .  j av  a2s . c o  m
 * 
 * @param tabFolder the parent tab folder
 * @return Control
 */
private Control getTabThreeControl(TabFolder tabFolder) {
    // Create some labels and text fields
    Composite composite = new Composite(tabFolder, SWT.NONE);
    composite.setLayout(new RowLayout());
    new Label(composite, SWT.LEFT).setText("Label One:");
    new Text(composite, SWT.BORDER);
    new Label(composite, SWT.RIGHT).setText("Label Two:");
    new Text(composite, SWT.BORDER);
    return composite;
}

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

/**
 * Standard constructor: builds a panel for displaying/editing the
 * properties of the specified title./* w w w. j  a v  a2 s. c o  m*/
 * 
 * @param parent
 *            the parent.
 * @param style
 *            the style.
 * @param title
 *            the title, which should be changed.
 * 
 */
SWTTitleEditor(Composite parent, int style, Title title) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);

    TextTitle t = (title != null ? (TextTitle) title : new TextTitle(localizationResources.getString("Title")));
    this.showTitle = (title != null);
    this.titleFont = SWTUtils.toSwtFontData(getDisplay(), t.getFont(), true);
    this.titleColor = SWTUtils.toSwtColor(getDisplay(), t.getPaint());

    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));
    // row 1
    Label label = new Label(general, SWT.NONE);
    label.setText(localizationResources.getString("Show_Title"));
    GridData gridData = new GridData();
    gridData.horizontalSpan = 2;
    label.setLayoutData(gridData);
    this.showTitleCheckBox = new Button(general, SWT.CHECK);
    this.showTitleCheckBox.setSelection(this.showTitle);
    this.showTitleCheckBox.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    this.showTitleCheckBox.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            SWTTitleEditor.this.showTitle = SWTTitleEditor.this.showTitleCheckBox.getSelection();
        }
    });
    // row 2
    new Label(general, SWT.NONE).setText(localizationResources.getString("Text"));
    this.titleField = new Text(general, SWT.BORDER);
    this.titleField.setText(t.getText());
    this.titleField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(general, SWT.NONE).setText("");
    // row 3
    new Label(general, SWT.NONE).setText(localizationResources.getString("Font"));
    this.fontField = new Text(general, SWT.BORDER);
    this.fontField.setText(this.titleFont.toString());
    this.fontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    this.selectFontButton = new Button(general, SWT.PUSH);
    this.selectFontButton.setText(localizationResources.getString("Select..."));
    this.selectFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the font-change dialog
            FontDialog dlg = new FontDialog(getShell());
            dlg.setText(localizationResources.getString("Font_Selection"));
            dlg.setFontList(new FontData[] { SWTTitleEditor.this.titleFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTTitleEditor.this.font != null) {
                    SWTTitleEditor.this.font.dispose();
                }
                // Create the new font and set it into the title
                // label
                SWTTitleEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                // titleField.setFont(font);
                SWTTitleEditor.this.fontField.setText(SWTTitleEditor.this.font.getFontData()[0].toString());
                SWTTitleEditor.this.titleFont = SWTTitleEditor.this.font.getFontData()[0];
            }
        }
    });
    // row 4
    new Label(general, SWT.NONE).setText(localizationResources.getString("Color"));
    // Use a SwtPaintCanvas to show the color, note that we must set the
    // heightHint.
    final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.titleColor);
    GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    canvasGridData.heightHint = 20;
    colorCanvas.setLayoutData(canvasGridData);
    this.selectColorButton = new Button(general, SWT.PUSH);
    this.selectColorButton.setText(localizationResources.getString("Select..."));
    this.selectColorButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Title_Color"));
            dlg.setRGB(SWTTitleEditor.this.titleColor.getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                // create the new color and set it to the
                // SwtPaintCanvas
                SWTTitleEditor.this.titleColor = new Color(getDisplay(), rgb);
                colorCanvas.setColor(SWTTitleEditor.this.titleColor);
            }
        }
    });
}

From source file:WordJumbles.java

public WordJumbles(String word) {
    this.word = word;

    shell.setText("Word Jumbles");

    labelsRowOne = new Label[word.length()];
    labelsRowTwo = new Label[word.length()];

    int width = 40;

    // In the production version, you need to implement random permutation
    // generation.
    // Apache Jakarta Commons provides this function, see
    // org.apache.commons.math.random.RandomDataImpl
    int[] randomPermutation = { 5, 2, 6, 3, 1, 4, 0 };

    for (int i = 0; i < word.length(); i++) {
        final Label labelRowOne = new Label(shell, SWT.BORDER);
        labelsRowOne[i] = labelRowOne;//from  w  ww  .j  av a2  s  .  com
        labelRowOne.setBounds(10 + width * i, 10, width - 5, width - 5);
        labelRowOne.setFont(font);
        labelRowOne.setText(word.charAt(randomPermutation[i]) + "");
        labelRowOne.setAlignment(SWT.CENTER);

        setDragSource(labelRowOne);
        //setDropTarget(labelRowOne);

        final Label labelRowTwo = new Label(shell, SWT.BORDER);
        labelsRowTwo[i] = labelRowTwo;
        labelRowTwo.setBounds(10 + width * i, 20 + width, width - 5, width - 5);
        labelRowTwo.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
        labelRowTwo.setFont(font);
        labelRowTwo.setAlignment(SWT.CENTER);

        setDragSource(labelRowTwo);
        //setDropTarget(labelRowTwo);
    }

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:de.dekarlab.moneybuilder.view.AnalyticsView.java

/**
 * Create GUI method./*  www.  j ava2 s .  c o  m*/
 */
protected void initView() throws Exception {
    // init layout
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    setLayout(layout);
    Label lblReport = new Label(this, SWT.NONE);
    lblReport.setText(App.getGuiProp("analytics.reports"));

    cmbReports = new Combo(this, SWT.READ_ONLY);
    cmbReports.add(App.getGuiProp("report.allperiods.capital"));
    cmbReports.add(App.getGuiProp("report.allperiods.pl"));
    cmbReports.add(App.getGuiProp("report.income"));
    cmbReports.add(App.getGuiProp("report.expenses"));
    cmbReports.add(App.getGuiProp("report.assets"));
    cmbReports.add(App.getGuiProp("report.liability"));
    cmbReports.add(App.getGuiProp("report.profit"));
    cmbReports.select(0);
    createChart();
    // select by default
    cmbReports.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event arg0) {
            createChart();
        }
    });
}

From source file:edu.isistan.carcha.plugin.editors.DXMIEditor.java

/**
 * Creates the DDD list page.//w ww  . ja  v a  2s  . com
 */
void createListPage() {
    final Composite composite = new Composite(getContainer(), SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 4));
    composite.setLayout(new GridLayout());
    Label concernLabel = new Label(composite, SWT.BORDER);
    concernLabel.setText("Design Decisions");
    concernLabel.setToolTipText("This are the Design Decisions detected in the architectural document");
    GridData gridData = new GridData(SWT.LEFT, SWT.LEFT, false, false);
    concernLabel.setLayoutData(gridData);

    ddsViewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    createColumns(composite, ddsViewer);

    final Table table = ddsViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    ddsViewer.setContentProvider(new ArrayContentProvider());

    getSite().setSelectionProvider(ddsViewer);
    // define layout for the viewer
    gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    ddsViewer.getControl().setLayoutData(gridData);

    int index = addPage(composite);
    setPageText(index, "List");
}

From source file:net.bioclipse.chembl.moss.ui.wizard.ChemblMossWizardPage2.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;//  ww  w  .j a va2  s  . co m
    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(true);

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

    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);
                                    cboxAct.setText(index);
                                    info.setText("Distinct compunds: " + matrix2.getRowCount());
                                    addToTable(matrix);
                                } 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());

                //Adds activity to histogram series
                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.");
    Font font1 = new Font(container.getDisplay(), "Helvetica", 13, SWT.NONE);
    label.setFont(font1);
    gridData = new GridData();
    gridData.horizontalSpan = 4;
    gridData.verticalSpan = 5;
    label.setLayoutData(gridData);

    check = new Button(container, SWT.CHECK);
    check.setText("Modify activities");
    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: ");
    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(0);
    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 matrix = chembl.mossSetActivityBound(matrixAct, spinnLow.getSelection(),
                        spinnHigh.getSelection());
                addToTable(matrix);
                spinn.setSelection(matrix.getRowCount());
                info.setText("Total compound hit: " + matrix.getRowCount());
            } 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("Compounds (SMILES)");
}

From source file:Ch11WizardComposite.java

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

    Label l = new Label(topLevel, SWT.CENTER);
    l.setText("Enter the directory to use:");

    text = new Text(topLevel, SWT.SINGLE);
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    setControl(topLevel);//  w  ww .j  av a  2s  .c  o m
    setPageComplete(true);
}

From source file:ClipboardExample.java

void createTextTransfer(Composite copyParent, Composite pasteParent) {

    // TextTransfer
    Label l = new Label(copyParent, SWT.NONE);
    l.setText("TextTransfer:"); //$NON-NLS-1$
    copyText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    copyText.setText("some\nplain\ntext");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    copyText.setLayoutData(data);// w w  w  .j  a v  a2s  .co  m
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String data = copyText.getText();
            if (data.length() > 0) {
                status.setText("");
                clipboard.setContents(new Object[] { data }, new Transfer[] { TextTransfer.getInstance() });
            } else {
                status.setText("nothing to copy");
            }
        }
    });

    l = new Label(pasteParent, SWT.NONE);
    l.setText("TextTransfer:"); //$NON-NLS-1$
    pasteText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = data.widthHint = SIZE;
    pasteText.setLayoutData(data);
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            String data = (String) clipboard.getContents(TextTransfer.getInstance());
            if (data != null && data.length() > 0) {
                status.setText("");
                pasteText.setText("begin paste>" + data + "<end paste");
            } else {
                status.setText("nothing to paste");
            }
        }
    });
}

From source file:Bookmark.java

public BookmarkOrganizer() {
    shell.setText("Bookmark organizer");
    shell.setLayout(new GridLayout(1, true));

    ToolBar toolBar = new ToolBar(shell, SWT.FLAT);
    ToolItem itemOpen = new ToolItem(toolBar, SWT.PUSH);
    itemOpen.setText("Load");
    itemOpen.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            FileDialog dialog = new FileDialog(shell, SWT.OPEN);
            String file = dialog.open();
            if (file != null) {
                // removes existing items.
                TreeItem[] items = rootItem.getItems();
                for (int i = 0; i < items.length; i++)
                    items[i].dispose();//from  w w  w .  j  a  v a 2  s.com

                loadBookmark(new File(file), rootItem);
                setStatus("Bookmarks loaded successfully");
            }
        }
    });

    ToolItem itemSave = new ToolItem(toolBar, SWT.PUSH);
    itemSave.setText("Save as");
    itemSave.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            FileDialog dialog = new FileDialog(shell, SWT.SAVE);
            String file = dialog.open();
            if (file != null) {
                try {
                    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
                    saveBookmark(writer, rootItem);
                    writer.close();
                    setStatus("Bookmarks saved successfully to file: " + file);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });

    tree = new Tree(shell, SWT.BORDER);
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    rootItem = new TreeItem(tree, SWT.NULL);
    rootItem.setText("BOOKMARKS");
    rootItem.setImage(iconRoot);

    label = new Label(shell, SWT.BORDER);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    final DragSource dragSource = new DragSource(tree, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
    dragSource.setTransfer(new Transfer[] { BookmarkTransfer.getInstance() });

    dragSource.addDragListener(new DragSourceAdapter() {
        public void dragStart(DragSourceEvent event) {
            TreeItem[] selection = tree.getSelection();
            // Only a URL bookmark can be dragged.
            if (selection.length > 0 && selection[0].getData() != null) {
                event.doit = true;
                dragSourceItem = selection[0];
            } else {
                event.doit = false;
            }
        };

        public void dragSetData(DragSourceEvent event) {
            if (BookmarkTransfer.getInstance().isSupportedType(event.dataType))
                event.data = dragSourceItem.getData();
        }

        public void dragFinished(DragSourceEvent event) {
            if (event.detail == DND.DROP_MOVE)
                dragSourceItem.dispose();
            dragSourceItem = null;
        }

    });

    final DropTarget dropTarget = new DropTarget(tree, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
    dropTarget.setTransfer(new Transfer[] { BookmarkTransfer.getInstance() });
    dropTarget.addDropListener(new DropTargetAdapter() {
        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_EXPAND | DND.FEEDBACK_SCROLL | DND.FEEDBACK_SELECT;
        }

        public void dropAccept(DropTargetEvent event) {
            // can only drops into to a folder
            if (event.item == null || ((TreeItem) event.item).getData() != null)
                event.detail = DND.DROP_NONE;
        }

        public void drop(DropTargetEvent event) {
            try {
                if (event.data == null) {
                    event.detail = DND.DROP_NONE;
                    return;
                }

                TreeItem item = new TreeItem((TreeItem) event.item, SWT.NULL);
                Bookmark bookmark = (Bookmark) event.data;
                item.setText(bookmark.name);
                item.setImage(iconURL);
                item.setData(bookmark);
            } catch (RuntimeException e) {
                e.printStackTrace();
            }
        }
    });

    tree.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TreeItem item = (TreeItem) e.item;
            Bookmark bookmark = (Bookmark) item.getData();
            if (bookmark != null) {
                setStatus(bookmark.href);
            } else if (item.getData(KEY_ADD_DATE) != null) { // folder.
                setStatus("Folder: " + item.getText());
            }
        }
    });

    shell.setSize(400, 300);
    shell.open();
    //textUser.forceFocus();

    loadBookmark(new File("icons/mybookmark.htm"), rootItem);

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}