Example usage for org.eclipse.swt.widgets Button setSelection

List of usage examples for org.eclipse.swt.widgets Button setSelection

Introduction

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

Prototype

public void setSelection(boolean selected) 

Source Link

Document

Sets the selection state of the receiver, if it is of type CHECK, RADIO, or TOGGLE.

Usage

From source file:org.eclipse.swt.snippets.Snippet336.java

public static void main(String[] args) {
    display = new Display();
    shell = new Shell(display);
    shell.setText("Snippet 336");
    shell.setLayout(new GridLayout());
    TabFolder folder = new TabFolder(shell, SWT.NONE);
    folder.setLayoutData(new GridData(GridData.FILL_BOTH));

    //Progress tab
    TabItem item = new TabItem(folder, SWT.NONE);
    item.setText("Progress");
    Composite composite = new Composite(folder, SWT.NONE);
    composite.setLayout(new GridLayout());
    item.setControl(composite);/*from  ww  w.  j  av  a 2s .  c  o m*/
    Listener listener = event -> {
        Button button = (Button) event.widget;
        if (!button.getSelection())
            return;
        TaskItem item1 = getTaskBarItem();
        if (item1 != null) {
            int state = ((Integer) button.getData()).intValue();
            item1.setProgressState(state);
        }
    };
    Group group = new Group(composite, SWT.NONE);
    group.setText("State");
    group.setLayout(new GridLayout());
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Button button;
    String[] stateLabels = { "SWT.DEFAULT", "SWT.INDETERMINATE", "SWT.NORMAL", "SWT.ERROR", "SWT.PAUSED" };
    int[] states = { SWT.DEFAULT, SWT.INDETERMINATE, SWT.NORMAL, SWT.ERROR, SWT.PAUSED };
    for (int i = 0; i < states.length; i++) {
        button = new Button(group, SWT.RADIO);
        button.setText(stateLabels[i]);
        button.setData(Integer.valueOf(states[i]));
        button.addListener(SWT.Selection, listener);
        if (i == 0)
            button.setSelection(true);
    }
    group = new Group(composite, SWT.NONE);
    group.setText("Value");
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label label = new Label(group, SWT.NONE);
    label.setText("Progress");
    final Scale scale = new Scale(group, SWT.NONE);
    scale.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    scale.addListener(SWT.Selection, event -> {
        TaskItem item1 = getTaskBarItem();
        if (item1 != null)
            item1.setProgress(scale.getSelection());
    });

    //Overlay text tab
    item = new TabItem(folder, SWT.NONE);
    item.setText("Text");
    composite = new Composite(folder, SWT.NONE);
    composite.setLayout(new GridLayout());
    item.setControl(composite);
    group = new Group(composite, SWT.NONE);
    group.setText("Enter a short text:");
    group.setLayout(new GridLayout(2, false));
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    final Text text = new Text(group, SWT.BORDER | SWT.SINGLE);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    text.setLayoutData(data);
    button = new Button(group, SWT.PUSH);
    button.setText("Set");
    button.addListener(SWT.Selection, event -> {
        TaskItem item1 = getTaskBarItem();
        if (item1 != null)
            item1.setOverlayText(text.getText());
    });
    button = new Button(group, SWT.PUSH);
    button.setText("Clear");
    button.addListener(SWT.Selection, event -> {
        text.setText("");
        TaskItem item1 = getTaskBarItem();
        if (item1 != null)
            item1.setOverlayText("");
    });

    //Overlay image tab
    item = new TabItem(folder, SWT.NONE);
    item.setText("Image");
    composite = new Composite(folder, SWT.NONE);
    composite.setLayout(new GridLayout());
    item.setControl(composite);
    Listener listener3 = event -> {
        Button button1 = (Button) event.widget;
        if (!button1.getSelection())
            return;
        TaskItem item1 = getTaskBarItem();
        if (item1 != null) {
            String text1 = button1.getText();
            Image image = null;
            if (!text1.equals("NONE"))
                image = new Image(display, Snippet336.class.getResourceAsStream(text1));
            Image oldImage = item1.getOverlayImage();
            item1.setOverlayImage(image);
            if (oldImage != null)
                oldImage.dispose();
        }
    };
    group = new Group(composite, SWT.NONE);
    group.setText("Images");
    group.setLayout(new GridLayout());
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    button = new Button(group, SWT.RADIO);
    button.setText("NONE");
    button.addListener(SWT.Selection, listener3);
    button.setSelection(true);
    String[] images = { "eclipse.png", "pause.gif", "run.gif", "warning.gif" };
    for (int i = 0; i < images.length; i++) {
        button = new Button(group, SWT.RADIO);
        button.setText(images[i]);
        button.addListener(SWT.Selection, listener3);
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.talend.dataprofiler.chart.util.HideSeriesChartDialog.java

private Composite createUtilityControl(Composite parent) {
    Composite comp = new Composite(parent, SWT.BORDER);
    comp.setLayout(new RowLayout());
    comp.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));

    if (isCountAvgNull) {
        XYDataset dataset = chart.getXYPlot().getDataset();
        int count = dataset.getSeriesCount();

        for (int i = 0; i < count; i++) {

            Button checkBtn = new Button(comp, SWT.CHECK);
            checkBtn.setText(dataset.getSeriesKey(i).toString());
            checkBtn.setSelection(true);
            checkBtn.addSelectionListener(listener);
            checkBtn.setData(SERIES_KEY_ID, i);
        }/*from   ww w. j  a  va 2s . c o m*/
    }

    if (isMinMaxDate) {
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryDataset dataset = plot.getDataset();
        int count = dataset.getRowCount();

        for (int i = 0; i < count; i++) {

            Button checkBtn = new Button(comp, SWT.CHECK);
            checkBtn.setText(dataset.getRowKey(i).toString());
            checkBtn.setSelection(true);
            checkBtn.addSelectionListener(listener);
            checkBtn.setData(SERIES_KEY_ID, i);
        }
    }

    return comp;
}

From source file:msi.gama.hpc.gui.perspective.chart.HeadlessChart.java

private void createDataset() {
    lstvarname_flag = new ArrayList<String>();
    lsttimestep = new ArrayList<Integer>();
    lstchkbox = new ArrayList<Button>();
    readDataset();/*from   w w w . j a  v a2  s. com*/
    ArrayList<Result> listres = sim.result;
    int n = 0;
    series = new ArrayList<XYSeries>();
    for (int i = 0; i < listres.size(); i++) {
        String varname = listres.get(i).getName();
        if (lstvarname_flag.contains(varname)) {
            int idx = lstvarname_flag.indexOf(varname);
            lsttimestep.set(idx, lsttimestep.get(idx) + 1);
            series.get(idx).add(lsttimestep.get(idx), listres.get(i).getValue());
        } else {
            lstvarname_flag.add(varname);
            Button b1 = new Button(comp.getParent(), SWT.CHECK);
            b1.setText("Show " + varname);
            b1.setSelection(true);
            b1.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    // TODO Auto-generated method stub
                    showChart();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                    // TODO Auto-generated method stub

                }

            });
            lstchkbox.add(b1);
            lsttimestep.add(new Integer(0));
            XYSeries ss = new XYSeries(varname);
            series.add(ss);
        }
        // System.out.println(" " + listres.get(i).getName()+" " + listres.get(i).getValue());
    }

}

From source file:org.eclipse.swt.examples.addressbook.SearchDialog.java

/**
 * Class constructor that sets the parent shell and the table widget that
 * the dialog will search./*from ww  w .j  a  va 2  s . com*/
 *
 * @param parent   Shell
 *         The shell that is the parent of the dialog.
 */
public SearchDialog(Shell parent) {
    shell = new Shell(parent, SWT.CLOSE | SWT.BORDER | SWT.TITLE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    shell.setLayout(layout);
    shell.setText(resAddressBook.getString("Search_dialog_title"));
    shell.addShellListener(ShellListener.shellClosedAdapter(e -> {
        // don't dispose of the shell, just hide it for later use
        e.doit = false;
        shell.setVisible(false);
    }));

    Label label = new Label(shell, SWT.LEFT);
    label.setText(resAddressBook.getString("Dialog_find_what"));
    searchText = new Text(shell, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchText.setLayoutData(gridData);
    searchText.addModifyListener(e -> {
        boolean enableFind = (searchText.getCharCount() != 0);
        findButton.setEnabled(enableFind);
    });

    searchAreaLabel = new Label(shell, SWT.LEFT);
    searchArea = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchArea.setLayoutData(gridData);

    matchCase = new Button(shell, SWT.CHECK);
    matchCase.setText(resAddressBook.getString("Dialog_match_case"));
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchCase.setLayoutData(gridData);

    matchWord = new Button(shell, SWT.CHECK);
    matchWord.setText(resAddressBook.getString("Dialog_match_word"));
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchWord.setLayoutData(gridData);

    Group direction = new Group(shell, SWT.NONE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    direction.setLayoutData(gridData);
    direction.setLayout(new FillLayout());
    direction.setText(resAddressBook.getString("Dialog_direction"));

    Button up = new Button(direction, SWT.RADIO);
    up.setText(resAddressBook.getString("Dialog_dir_up"));
    up.setSelection(false);

    down = new Button(direction, SWT.RADIO);
    down.setText(resAddressBook.getString("Dialog_dir_down"));
    down.setSelection(true);

    Composite composite = new Composite(shell, SWT.NONE);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    composite.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    composite.setLayout(layout);

    findButton = new Button(composite, SWT.PUSH);
    findButton.setText(resAddressBook.getString("Dialog_find"));
    findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    findButton.setEnabled(false);
    findButton.addSelectionListener(widgetSelectedAdapter(e -> {
        if (!findHandler.find()) {
            MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL);
            box.setText(shell.getText());
            box.setMessage(resAddressBook.getString("Cannot_find") + "\"" + searchText.getText() + "\"");
            box.open();
        }
    }));

    Button cancelButton = new Button(composite, SWT.PUSH);
    cancelButton.setText(resAddressBook.getString("Cancel"));
    cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    cancelButton.addSelectionListener(widgetSelectedAdapter(e -> shell.setVisible(false)));
    shell.pack();
}

From source file:org.amanzi.awe.charts.ui.ChartsView.java

/**
 * Creates radio button with the text specified and assigns the layout data
 * /*from   w ww  . j av  a 2  s . c  o  m*/
 * @param parent parent composite
 * @param chartType TODO
 */
private Button createRadioButton(final Composite parent, final String text, final boolean selected,
        final ChartType chartType) {
    Button radioButton = new Button(parent, SWT.RADIO);
    radioButton.setText(text);
    radioButton.setSelection(selected);

    GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    radioButton.setLayoutData(layoutData);
    radioButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            type = chartType;
            onItemSelected();
        }
    });
    return radioButton;
}

From source file:BugTracker.java

public BugTracker() {
    GridLayout gridLayout = new GridLayout();
    shell.setLayout(gridLayout);//from w  w w . j av a  2  s.c  om
    shell.setText("Bug Tracking System");

    // Action.
    Action actionAddNew = new Action("New bug") {
        public void run() {
            // Append.
            TableItem item = new TableItem(table, SWT.NULL);
            item.setImage(bugIcon);
            table.select(table.getItemCount() - 1);
        }
    };

    Action actionDelete = new Action("Delete selected") {
        public void run() {
            int index = table.getSelectionIndex();
            if (index < 0) {
                System.out.println("Please select an item first. ");
                return;
            }
            MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO);
            messageBox.setText("Confirmation");
            messageBox.setMessage("Are you sure to remove the bug with id #" + table.getItem(index).getText(0));
            if (messageBox.open() == SWT.YES) {
                table.remove(index);
            }
        }
    };

    Action actionSave = new Action("Save") {
        public void run() {
            saveBugs();
        }
    };

    ToolBar toolBar = new ToolBar(shell, SWT.RIGHT | SWT.FLAT);

    ToolBarManager manager = new ToolBarManager(toolBar);
    manager.add(actionAddNew);
    manager.add(actionDelete);
    manager.add(new Separator());
    manager.add(actionSave);
    manager.update(true);

    table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
    table.setLayoutData(new GridData(GridData.FILL_BOTH));

    table.setLinesVisible(true);
    table.setHeaderVisible(true);

    TableColumn tcID = new TableColumn(table, SWT.LEFT);
    tcID.setText("ID");

    TableColumn tcSummary = new TableColumn(table, SWT.NULL);
    tcSummary.setText("Summary");

    TableColumn tcAssignedTo = new TableColumn(table, SWT.NULL);
    tcAssignedTo.setText("Assigned to");

    TableColumn tcSolved = new TableColumn(table, SWT.NULL);
    tcSolved.setText("Solved");

    tcID.setWidth(60);
    tcSummary.setWidth(200);
    tcAssignedTo.setWidth(80);
    tcSolved.setWidth(50);

    table.pack();

    // Table editor.
    final TableEditor editor = new TableEditor(table);

    table.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event event) {
            // Locate the cell position.
            Point point = new Point(event.x, event.y);
            final TableItem item = table.getItem(point);
            if (item == null)
                return;
            int column = -1;
            for (int i = 0; i < table.getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(point))
                    column = i;
            }
            if (column != 3)
                return;

            // Cell position located, now open the table editor.

            final Button button = new Button(table, SWT.CHECK);
            button.setSelection(item.getText(column).equalsIgnoreCase("YES"));

            editor.horizontalAlignment = SWT.LEFT;
            editor.grabHorizontal = true;

            editor.setEditor(button, item, column);

            final int selectedColumn = column;
            Listener buttonListener = new Listener() {
                public void handleEvent(final Event e) {
                    switch (e.type) {
                    case SWT.FocusOut:
                        item.setText(selectedColumn, button.getSelection() ? "YES" : "NO");
                        button.dispose();
                        break;
                    case SWT.Traverse:
                        switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                            item.setText(selectedColumn, button.getSelection() ? "YES" : "NO");
                            //FALL THROUGH
                        case SWT.TRAVERSE_ESCAPE:
                            button.dispose();
                            e.doit = false;
                        }
                        break;
                    }
                }
            };

            button.addListener(SWT.FocusOut, buttonListener);
            button.addListener(SWT.Traverse, buttonListener);

            button.setFocus();

        }
    });

    table.addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event event) {
            // Locate the cell position.
            Point point = new Point(event.x, event.y);
            final TableItem item = table.getItem(point);
            if (item == null)
                return;
            int column = -1;
            for (int i = 0; i < table.getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(point))
                    column = i;
            }
            if (column < 0 || column >= 3)
                return;

            // Cell position located, now open the table editor.

            final Text text = new Text(table, SWT.NONE);
            text.setText(item.getText(column));

            editor.horizontalAlignment = SWT.LEFT;
            editor.grabHorizontal = true;

            editor.setEditor(text, item, column);

            final int selectedColumn = column;
            Listener textListener = new Listener() {
                public void handleEvent(final Event e) {
                    switch (e.type) {
                    case SWT.FocusOut:
                        item.setText(selectedColumn, text.getText());
                        text.dispose();
                        break;
                    case SWT.Traverse:
                        switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                            item.setText(selectedColumn, text.getText());
                            //FALL THROUGH
                        case SWT.TRAVERSE_ESCAPE:
                            text.dispose();
                            e.doit = false;
                        }
                        break;
                    }
                }
            };

            text.addListener(SWT.FocusOut, textListener);
            text.addListener(SWT.Traverse, textListener);

            text.setFocus();
        }

    });

    loadBugs();

    table.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            System.out.println("Selected: " + table.getSelection()[0]);
        }
    });

    Listener sortListener = new Listener() {
        public void handleEvent(Event event) {
            if (!(event.widget instanceof TableColumn))
                return;
            TableColumn tc = (TableColumn) event.widget;
            sortTable(table, table.indexOf(tc));
            System.out.println("The table is sorted by column #" + table.indexOf(tc));
        }
    };

    for (int i = 0; i < table.getColumnCount(); i++)
        ((TableColumn) table.getColumn(i)).addListener(SWT.Selection, sortListener);

    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:eu.hydrologis.jgrass.charting.datamodels.MultiXYTimeChartCreator.java

/**
 * Make a composite with the plot of the supplied chartdata. There are several HINT* variables
 * that can be set to tweak and configure the plot.
 * /* w w  w  . j  a  v a2  s . c om*/
 * @param parentComposite
 * @param chartData
 */
public void makePlot(Composite parentComposite, NumericChartData chartData) {
    final int tabNums = chartData.getTabItemNumbers();

    if (tabNums == 0) {
        return;
    }

    Shell dummyShell = null;
    // try {
    // dummyShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
    // } catch (Exception e) {
    dummyShell = new Shell(Display.getCurrent(), SWT.None);
    // }
    /*
     * wrapping panel needed in the case of hide checks
     */
    TabFolder tabFolder = null;
    if (tabNums > 1) {
        tabFolder = new TabFolder(parentComposite, SWT.BORDER);
        tabFolder.setLayout(new GridLayout());
        tabFolder.setLayoutData(
                new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
    }

    for (int i = 0; i < tabNums; i++) {
        NumericChartDataItem chartItem = chartData.getChartDataItem(i);
        int chartNums = chartItem.chartSeriesData.size();
        /*
         * are there data to create the lower chart panel
         */
        List<LinkedHashMap<String, Integer>> series = new ArrayList<LinkedHashMap<String, Integer>>();
        List<XYPlot> plots = new ArrayList<XYPlot>();
        List<JFreeChart> charts = new ArrayList<JFreeChart>();

        for (int j = 0; j < chartNums; j++) {
            final LinkedHashMap<String, Integer> chartSeries = new LinkedHashMap<String, Integer>();
            XYPlot chartPlot = null;
            JGrassChart chart = null;
            double[][][] cLD = chartItem.chartSeriesData.get(j);

            if (M_HINT_CREATE_CHART[i][j]) {

                final String[] cT = chartItem.seriesNames.get(j);
                final String title = chartItem.chartTitles.get(j);
                final String xT = chartItem.chartXLabels.get(j);
                final String yT = chartItem.chartYLabels.get(j);

                if (M_HINT_CHART_TYPE[i][j] == XYLINECHART) {
                    chart = new JGrassXYLineChart(cT, cLD);
                } else if (M_HINT_CHART_TYPE[i][j] == XYBARCHART) {
                    chart = new JGrassXYBarChart(cT, cLD, HINT_barwidth);
                } else if (M_HINT_CHART_TYPE[i][j] == TIMEYLINECHART) {
                    chart = new JGrassXYTimeLineChart(cT, cLD, Minute.class);
                    ((JGrassXYTimeLineChart) chart).setTimeAxisFormat(TIMEFORMAT);
                } else if (M_HINT_CHART_TYPE[i][j] == TIMEYBARCHART) {
                    chart = new JGrassXYTimeBarChart(cT, cLD, Minute.class, HINT_barwidth);
                    ((JGrassXYTimeBarChart) chart).setTimeAxisFormat(TIMEFORMAT);
                } else if (M_HINT_CHART_TYPE[i][j] == XYPOINTCHART) {
                    chart = new JGrassXYLineChart(cT, cLD);
                    ((JGrassXYLineChart) chart).toggleLineShapesDisplay(false, true);
                } else if (M_HINT_CHART_TYPE[i][j] == TIMEXYPOINTCHART) {
                    chart = new JGrassXYTimeLineChart(cT, cLD, Minute.class);
                    ((JGrassXYTimeLineChart) chart).setTimeAxisFormat(TIMEFORMAT);
                    ((JGrassXYTimeLineChart) chart).toggleLineShapesDisplay(false, true);
                } else {
                    chart = new JGrassXYLineChart(cT, cLD);
                }

                final Composite p1Composite = new Composite(dummyShell, SWT.None);
                p1Composite.setLayout(new FillLayout());
                p1Composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                chart.makeChartPanel(p1Composite, title, xT, yT, null, true, true, true, true);
                chartPlot = (XYPlot) chart.getPlot();
                XYItemRenderer renderer = chartPlot.getRenderer();

                chartPlot.setDomainGridlinesVisible(HINT_doDomainGridVisible);
                chartPlot.setRangeGridlinesVisible(HINT_doRangeGridVisible);

                if (HINT_doDisplayToolTips) {
                    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
                }

                if (!M_HINT_CHARTORIENTATION_UP[i][j]) {
                    chartPlot.getRangeAxis().setInverted(true);
                }
                if (M_HINT_CHARTSERIESCOLOR != null) {
                    final XYItemRenderer rend = renderer;

                    for (int k = 0; k < cLD.length; k++) {
                        rend.setSeriesPaint(k, M_HINT_CHARTSERIESCOLOR[i][j][k]);
                    }
                }
                chart.toggleFilledShapeDisplay(HINT_doDisplayBaseShapes, HINT_doFillBaseShapes, true);

                for (int k = 0; k < cT.length; k++) {
                    chartSeries.put(cT[k], k);
                }
                series.add(chartSeries);
                chartPlot.setNoDataMessage("No data available");
                chartPlot.setNoDataMessagePaint(Color.red);
                plots.add(chartPlot);

                charts.add(chart.getChart(title, xT, yT, null, true, HINT_doDisplayToolTips, true));
                chartsList.add(chart);

                /*
                 * add annotations?
                 */
                if (chartItem.annotationsOnChart.size() > 0) {
                    LinkedHashMap<String, double[]> annotations = chartItem.annotationsOnChart.get(j);
                    if (annotations.size() > 0) {
                        Set<String> keys = annotations.keySet();
                        for (String key : keys) {
                            double[] c = annotations.get(key);
                            XYPointerAnnotation ann = new XYPointerAnnotation(key, c[0], c[1],
                                    HINT_AnnotationArrowAngle);
                            ann.setTextAnchor(HINT_AnnotationTextAncor);
                            ann.setPaint(HINT_AnnotationTextColor);
                            ann.setArrowPaint(HINT_AnnotationArrowColor);
                            // ann.setArrowLength(15);
                            renderer.addAnnotation(ann);

                            // Marker currentEnd = new ValueMarker(c[0]);
                            // currentEnd.setPaint(Color.red);
                            // currentEnd.setLabel("");
                            // currentEnd.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
                            // currentEnd.setLabelTextAnchor(TextAnchor.TOP_LEFT);
                            // chartPlot.addDomainMarker(currentEnd);

                            // Drawable cd = new LineDrawer(Color.red, new BasicStroke(1.0f));
                            // XYAnnotation bestBid = new XYDrawableAnnotation(c[0], c[1]/2.0,
                            // 0, c[1],
                            // cd);
                            // chartPlot.addAnnotation(bestBid);
                            // pointer.setFont(new Font("SansSerif", Font.PLAIN, 9));
                        }
                    }
                }
            }

        }

        JFreeChart theChart = null;

        if (plots.size() > 1) {

            ValueAxis domainAxis = null;
            if (M_HINT_CHART_TYPE[i][0] == ChartCreator.TIMEYBARCHART
                    || M_HINT_CHART_TYPE[i][0] == ChartCreator.TIMEYLINECHART) {

                domainAxis = (plots.get(0)).getDomainAxis();
            } else {
                domainAxis = new NumberAxis(chartItem.chartXLabels.get(0));
            }

            final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domainAxis);
            plot.setGap(10.0);
            // add the subplots...
            for (int k = 0; k < plots.size(); k++) {
                XYPlot tmpPlot = plots.get(k);

                if (HINT_labelInsets != null) {
                    tmpPlot.getRangeAxis().setLabelInsets(HINT_labelInsets);
                }

                plot.add(tmpPlot, k + 1);
            }
            plot.setOrientation(PlotOrientation.VERTICAL);

            theChart = new JFreeChart(chartItem.bigTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        } else if (plots.size() == 1) {
            theChart = new JFreeChart(chartItem.chartTitles.get(0), JFreeChart.DEFAULT_TITLE_FONT, plots.get(0),
                    true);
        } else {
            return;
        }

        /*
         * create the chart composite
         */
        Composite tmp;
        if (tabNums > 1 && tabFolder != null) {
            tmp = new Composite(tabFolder, SWT.None);
        } else {
            tmp = new Composite(parentComposite, SWT.None);
        }
        tmp.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        tmp.setLayout(new GridLayout());
        final ChartComposite frame = new ChartComposite(tmp, SWT.None, theChart, 680, 420, 300, 200, 700, 500,
                false, true, // properties
                true, // save
                true, // print
                true, // zoom
                true // tooltips
        );

        // public static final boolean DEFAULT_BUFFER_USED = false;
        // public static final int DEFAULT_WIDTH = 680;
        // public static final int DEFAULT_HEIGHT = 420;
        // public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300;
        // public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200;
        // public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800;
        // public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600;
        // public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10;

        frame.setLayoutData(
                new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        frame.setLayout(new FillLayout());
        frame.setDisplayToolTips(HINT_doDisplayToolTips);
        frame.setHorizontalAxisTrace(HINT_doHorizontalAxisTrace);
        frame.setVerticalAxisTrace(HINT_doVerticalAxisTrace);
        frame.setDomainZoomable(HINT_doDomainZoomable);
        frame.setRangeZoomable(HINT_doRangeZoomable);

        if (tabNums > 1 && tabFolder != null) {
            final TabItem item = new TabItem(tabFolder, SWT.NONE);
            item.setText(chartData.getChartDataItem(i).chartStringExtra);
            item.setControl(tmp);
        }

        /*
         * create the hide toggling part
         */
        for (int j = 0; j < plots.size(); j++) {

            if (M_HINT_CREATE_TOGGLEHIDESERIES[i][j]) {
                final LinkedHashMap<Button, Integer> allButtons = new LinkedHashMap<Button, Integer>();
                Group checksComposite = new Group(tmp, SWT.None);
                checksComposite.setText("");
                RowLayout rowLayout = new RowLayout();
                rowLayout.wrap = true;
                rowLayout.type = SWT.HORIZONTAL;
                checksComposite.setLayout(rowLayout);
                checksComposite
                        .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));

                final XYItemRenderer renderer = plots.get(j).getRenderer();
                Set<String> lTitles = series.get(j).keySet();
                for (final String title : lTitles) {
                    final Button b = new Button(checksComposite, SWT.CHECK);
                    b.setText(title);
                    b.setSelection(true);
                    final int index = series.get(j).get(title);
                    b.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
                            boolean visible = renderer.getItemVisible(index, 0);
                            renderer.setSeriesVisible(index, new Boolean(!visible));
                        }
                    });
                    allButtons.put(b, index);
                }

                /*
                 * toggle all and none
                 */
                if (HINT_doToggleTuttiButton) {
                    Composite allchecksComposite = new Composite(tmp, SWT.None);
                    RowLayout allrowLayout = new RowLayout();
                    allrowLayout.wrap = true;
                    allrowLayout.type = SWT.HORIZONTAL;
                    allchecksComposite.setLayout(allrowLayout);
                    allchecksComposite
                            .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));

                    final Button tuttiButton = new Button(allchecksComposite, SWT.BORDER | SWT.PUSH);
                    tuttiButton.setText("Tutti");
                    tuttiButton.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
                            Set<Button> set = allButtons.keySet();
                            for (Button button : set) {
                                button.setSelection(true);
                                int i = allButtons.get(button);
                                if (renderer != null) {
                                    renderer.setSeriesVisible(i, new Boolean(true));
                                }
                            }
                        }
                    });
                    final Button noneButton = new Button(allchecksComposite, SWT.BORDER | SWT.PUSH);
                    noneButton.setText("Nessuno");
                    noneButton.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
                            Set<Button> set = allButtons.keySet();
                            for (Button button : set) {
                                button.setSelection(false);
                                int i = allButtons.get(button);
                                if (renderer != null) {
                                    renderer.setSeriesVisible(i, new Boolean(false));
                                }
                            }
                        }
                    });
                }

            }

        }

    }
}

From source file:org.eclipse.swt.examples.layoutexample.Tab.java

/**
 * Creates the "control" group. This is the group on the
 * right half of each example tab. It contains controls
 * for adding new children to the layoutComposite, and
 * for modifying the children's layout data.
 *//*from w ww.  j  a va 2  s . c  om*/
void createControlGroup() {
    controlGroup = new Group(sash, SWT.NONE);
    controlGroup.setText(LayoutExample.getResourceString("Parameters"));
    GridLayout layout = new GridLayout(2, true);
    layout.horizontalSpacing = 10;
    controlGroup.setLayout(layout);
    final Button preferredButton = new Button(controlGroup, SWT.CHECK);
    preferredButton.setText(LayoutExample.getResourceString("Preferred_Size"));
    preferredButton.setSelection(false);
    preferredButton.addSelectionListener(widgetSelectedAdapter(e -> {
        resetEditors();
        GridData data = (GridData) layoutComposite.getLayoutData();
        if (preferredButton.getSelection()) {
            data.heightHint = data.widthHint = SWT.DEFAULT;
            data.verticalAlignment = data.horizontalAlignment = 0;
            data.grabExcessVerticalSpace = data.grabExcessHorizontalSpace = false;
        } else {
            data.verticalAlignment = data.horizontalAlignment = SWT.FILL;
            data.grabExcessVerticalSpace = data.grabExcessHorizontalSpace = true;
        }
        layoutComposite.setLayoutData(data);
        layoutGroup.layout(true);
    }));
    preferredButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    createControlWidgets();
}

From source file:SWTAddressBook.java

/**
 * Class constructor that sets the parent shell and the table widget that
 * the dialog will search./* w w  w.  ja va 2 s . co m*/
 * 
 * @param parent
 *            Shell The shell that is the parent of the dialog.
 */
public SearchDialog(Shell parent) {
    shell = new Shell(parent, SWT.CLOSE | SWT.BORDER | SWT.TITLE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    shell.setLayout(layout);
    shell.setText("Search");
    shell.addShellListener(new ShellAdapter() {
        public void shellClosed(ShellEvent e) {
            // don't dispose of the shell, just hide it for later use
            e.doit = false;
            shell.setVisible(false);
        }
    });

    Label label = new Label(shell, SWT.LEFT);
    label.setText("Dialog_find_what");
    searchText = new Text(shell, SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchText.setLayoutData(gridData);
    searchText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            boolean enableFind = (searchText.getCharCount() != 0);
            findButton.setEnabled(enableFind);
        }
    });

    searchAreaLabel = new Label(shell, SWT.LEFT);
    searchArea = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.widthHint = 200;
    searchArea.setLayoutData(gridData);

    matchCase = new Button(shell, SWT.CHECK);
    matchCase.setText("Dialog_match_case");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchCase.setLayoutData(gridData);

    matchWord = new Button(shell, SWT.CHECK);
    matchWord.setText("Dialog_match_word");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    matchWord.setLayoutData(gridData);

    Group direction = new Group(shell, SWT.NONE);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    direction.setLayoutData(gridData);
    direction.setLayout(new FillLayout());
    direction.setText("Dialog_direction");

    Button up = new Button(direction, SWT.RADIO);
    up.setText("Dialog_dir_up");
    up.setSelection(false);

    down = new Button(direction, SWT.RADIO);
    down.setText("Dialog_dir_down");
    down.setSelection(true);

    Composite composite = new Composite(shell, SWT.NONE);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.horizontalSpan = 2;
    composite.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.makeColumnsEqualWidth = true;
    composite.setLayout(layout);

    findButton = new Button(composite, SWT.PUSH);
    findButton.setText("Dialog_find");
    findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    findButton.setEnabled(false);
    findButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (!findHandler.find()) {
                MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL);
                box.setText(shell.getText());
                box.setMessage("Cannot_find" + "\"" + searchText.getText() + "\"");
                box.open();
            }
        }
    });

    Button cancelButton = new Button(composite, SWT.PUSH);
    cancelButton.setText("Cancel");
    cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    cancelButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            shell.setVisible(false);
        }
    });

    shell.pack();
}

From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java

private void createInputTab(final CTabFolder parentTabFolder) {
    inputTab = new CTabItem(parentTabFolder, SWT.NONE);
    inputTab.setText(Messages.ProcessExecutionDialog_tabparameters);

    ScrolledComposite scroller = new ScrolledComposite(parentTabFolder, SWT.NONE | SWT.V_SCROLL | SWT.H_SCROLL);
    scroller.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite container = new Composite(scroller, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // local moran's i
    Image image = ToolboxPlugin.getImageDescriptor("icons/public_co.gif").createImage(); //$NON-NLS-1$
    uiBuilder.createLabel(container, Messages.HistogramDialog_InputLayer, EMPTY, image, 2);
    cboLayer = uiBuilder.createCombo(container, 2, true);
    fillLayers(map, cboLayer, VectorLayerType.ALL);

    uiBuilder.createLabel(container, Messages.HistogramDialog_InputField, EMPTY, image, 2);
    cboField = uiBuilder.createCombo(container, 2, true);

    uiBuilder.createLabel(container, Messages.HistogramDialog_BinCount, EMPTY, image, 2);
    spinner = uiBuilder.createSpinner(container, 10, 1, 50, 0, 1, 5, 2);

    // yXais Type
    uiBuilder.createLabel(container, Messages.HistogramDialog_YAxisType, EMPTY, image, 1);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;//from   w w  w .  j  av a 2s . co  m

    Composite subCon = new Composite(container, SWT.NONE);
    subCon.setLayout(layout);
    subCon.setLayoutData(new GridData(SWT.LEFT_TO_RIGHT, SWT.CENTER, false, false, 1, 1));
    final Button chkRatio = uiBuilder.createRadioButton(subCon, Messages.HistogramDialog_Ratio, null, 1);
    final Button chkFrequency = uiBuilder.createRadioButton(subCon, Messages.HistogramDialog_Frequency, null,
            1);
    chkFrequency.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            if (chkFrequency.getSelection()) {
                histogramType = HistogramType.FREQUENCY;
            }
        }
    });
    chkRatio.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            if (chkRatio.getSelection()) {
                histogramType = HistogramType.RELATIVE_FREQUENCY;
            }
        }
    });
    chkRatio.setSelection(true);

    uiBuilder.createLabel(container, null, null, 2);
    chkStatistics = uiBuilder.createCheckbox(container, Messages.ScatterPlotDialog_BasicStatistics, null, 2);

    // register events
    cboLayer.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            inputLayer = MapUtils.getLayer(map, cboLayer.getText());
            if (inputLayer != null) {
                fillFields(cboField, inputLayer.getSchema(), FieldType.Number);
            }
        }
    });

    // finally
    scroller.setContent(container);
    inputTab.setControl(scroller);

    scroller.setMinSize(450, container.getSize().y - 2);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);

    scroller.pack();
    container.pack();
}