Search in sources :

Example 51 with ToolBar

use of org.eclipse.swt.widgets.ToolBar in project eclipse.platform.swt by eclipse.

the class PaintExample method createToolBar.

/**
 * Creates the toolbar.
 * Note: Only called by standalone.
 */
private void createToolBar(Composite parent) {
    ToolBar toolbar = new ToolBar(parent, SWT.NONE);
    String group = null;
    for (int i = 0; i < tools.length; i++) {
        Tool tool = tools[i];
        if (group != null && !tool.group.equals(group)) {
            new ToolItem(toolbar, SWT.SEPARATOR);
        }
        group = tool.group;
        ToolItem item = addToolItem(toolbar, tool);
        if (i == Default_tool || i == Default_fill || i == Default_linestyle)
            item.setSelection(true);
    }
}
Also used : ToolBar(org.eclipse.swt.widgets.ToolBar) Point(org.eclipse.swt.graphics.Point) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 52 with ToolBar

use of org.eclipse.swt.widgets.ToolBar in project eclipse.platform.swt by eclipse.

the class ControlsWithLabelsExample method main.

public static void main(String[] args) {
    display = new Display();
    shell = new Shell(display);
    shell.setLayout(new GridLayout(4, true));
    shell.setText("All Controls Test");
    new Label(shell, SWT.NONE).setText("Label for Label");
    label = new Label(shell, SWT.NONE);
    label.setText("Label");
    new Label(shell, SWT.NONE).setText("Label for CLabel");
    cLabel = new CLabel(shell, SWT.NONE);
    cLabel.setText("CLabel");
    new Label(shell, SWT.NONE).setText("Label for Push Button");
    buttonPush = new Button(shell, SWT.PUSH);
    buttonPush.setText("Push Button");
    new Label(shell, SWT.NONE).setText("Label for Radio Button");
    buttonRadio = new Button(shell, SWT.RADIO);
    buttonRadio.setText("Radio Button");
    new Label(shell, SWT.NONE).setText("Label for Check Button");
    buttonCheck = new Button(shell, SWT.CHECK);
    buttonCheck.setText("Check Button");
    new Label(shell, SWT.NONE).setText("Label for Toggle Button");
    buttonToggle = new Button(shell, SWT.TOGGLE);
    buttonToggle.setText("Toggle Button");
    new Label(shell, SWT.NONE).setText("Label for Editable Combo");
    combo = new Combo(shell, SWT.BORDER);
    for (int i = 0; i < 4; i++) {
        combo.add("item" + i);
    }
    combo.select(0);
    new Label(shell, SWT.NONE).setText("Label for Read-Only Combo");
    combo = new Combo(shell, SWT.READ_ONLY | SWT.BORDER);
    for (int i = 0; i < 4; i++) {
        combo.add("item" + i);
    }
    combo.select(0);
    new Label(shell, SWT.NONE).setText("Label for CCombo");
    cCombo = new CCombo(shell, SWT.BORDER);
    for (int i = 0; i < 5; i++) {
        cCombo.add("item" + i);
    }
    cCombo.select(0);
    new Label(shell, SWT.NONE).setText("Label for List");
    list = new List(shell, SWT.SINGLE | SWT.BORDER);
    list.setItems("Item0", "Item1", "Item2");
    new Label(shell, SWT.NONE).setText("Label for Spinner");
    spinner = new Spinner(shell, SWT.BORDER);
    new Label(shell, SWT.NONE).setText("Label for Single-line Text");
    textSingle = new Text(shell, SWT.SINGLE | SWT.BORDER);
    textSingle.setText("Contents of Single-line Text");
    new Label(shell, SWT.NONE).setText("Label for Multi-line Text");
    textMulti = new Text(shell, SWT.MULTI | SWT.BORDER);
    textMulti.setText("\nContents of Multi-line Text\n");
    new Label(shell, SWT.NONE).setText("Label for StyledText");
    styledText = new StyledText(shell, SWT.MULTI | SWT.BORDER);
    styledText.setText("\nContents of Multi-line StyledText\n");
    new Label(shell, SWT.NONE).setText("Label for Table");
    table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    for (int col = 0; col < 3; col++) {
        TableColumn column = new TableColumn(table, SWT.NONE);
        column.setText("Col " + col);
        column.setWidth(50);
    }
    for (int row = 0; row < 3; row++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(new String[] { "C0R" + row, "C1R" + row, "C2R" + row });
    }
    new Label(shell, SWT.NONE).setText("Label for Tree");
    tree = new Tree(shell, SWT.BORDER | SWT.MULTI);
    for (int i = 0; i < 3; i++) {
        TreeItem item = new TreeItem(tree, SWT.NONE);
        item.setText("Item" + i);
        for (int j = 0; j < 4; j++) {
            new TreeItem(item, SWT.NONE).setText("Item" + i + j);
        }
    }
    new Label(shell, SWT.NONE).setText("Label for Tree with columns");
    treeTable = new Tree(shell, SWT.BORDER | SWT.MULTI);
    treeTable.setHeaderVisible(true);
    treeTable.setLinesVisible(true);
    for (int col = 0; col < 3; col++) {
        TreeColumn column = new TreeColumn(treeTable, SWT.NONE);
        column.setText("Col " + col);
        column.setWidth(50);
    }
    for (int i = 0; i < 3; i++) {
        TreeItem item = new TreeItem(treeTable, SWT.NONE);
        item.setText(new String[] { "I" + i + "C0", "I" + i + "C1", "I" + i + "C2" });
        for (int j = 0; j < 4; j++) {
            new TreeItem(item, SWT.NONE).setText(new String[] { "I" + i + j + "C0", "I" + i + j + "C1", "I" + i + j + "C2" });
        }
    }
    new Label(shell, SWT.NONE).setText("Label for ToolBar");
    toolBar = new ToolBar(shell, SWT.FLAT);
    for (int i = 0; i < 3; i++) {
        ToolItem item = new ToolItem(toolBar, SWT.PUSH);
        item.setText("Item" + i);
        item.setToolTipText("ToolItem ToolTip" + i);
    }
    new Label(shell, SWT.NONE).setText("Label for CoolBar");
    coolBar = new CoolBar(shell, SWT.FLAT);
    for (int i = 0; i < 2; i++) {
        CoolItem coolItem = new CoolItem(coolBar, SWT.PUSH);
        ToolBar coolItemToolBar = new ToolBar(coolBar, SWT.FLAT);
        int toolItemWidth = 0;
        for (int j = 0; j < 2; j++) {
            ToolItem item = new ToolItem(coolItemToolBar, SWT.PUSH);
            item.setText("Item" + i + j);
            item.setToolTipText("ToolItem ToolTip" + i + j);
            if (item.getWidth() > toolItemWidth)
                toolItemWidth = item.getWidth();
        }
        coolItem.setControl(coolItemToolBar);
        Point size = coolItemToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        Point coolSize = coolItem.computeSize(size.x, size.y);
        coolItem.setMinimumSize(toolItemWidth, coolSize.y);
        coolItem.setPreferredSize(coolSize);
        coolItem.setSize(coolSize);
    }
    new Label(shell, SWT.NONE).setText("Label for Canvas");
    canvas = new Canvas(shell, SWT.BORDER);
    canvas.setLayoutData(new GridData(64, 64));
    canvas.addPaintListener(e -> e.gc.drawString("Canvas", 15, 25));
    canvas.setCaret(new Caret(canvas, SWT.NONE));
    /* Hook key listener so canvas will take focus during traversal in. */
    canvas.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    });
    /* Hook traverse listener to make canvas give up focus during traversal out. */
    canvas.addTraverseListener(e -> e.doit = true);
    new Label(shell, SWT.NONE).setText("Label for Group");
    group = new Group(shell, SWT.NONE);
    group.setText("Group");
    group.setLayout(new FillLayout());
    new Text(group, SWT.SINGLE | SWT.BORDER).setText("Text in Group");
    new Label(shell, SWT.NONE).setText("Label for TabFolder");
    tabFolder = new TabFolder(shell, SWT.NONE);
    for (int i = 0; i < 3; i++) {
        TabItem item = new TabItem(tabFolder, SWT.NONE);
        item.setText("TabItem &" + i);
        item.setToolTipText("TabItem ToolTip" + i);
        Text itemText = new Text(tabFolder, SWT.SINGLE | SWT.BORDER);
        itemText.setText("Text for TabItem " + i);
        item.setControl(itemText);
    }
    new Label(shell, SWT.NONE).setText("Label for CTabFolder");
    cTabFolder = new CTabFolder(shell, SWT.BORDER);
    for (int i = 0; i < 3; i++) {
        CTabItem item = new CTabItem(cTabFolder, SWT.NONE);
        item.setText("CTabItem &" + i);
        item.setToolTipText("CTabItem ToolTip" + i);
        Text itemText = new Text(cTabFolder, SWT.SINGLE | SWT.BORDER);
        itemText.setText("Text for CTabItem " + i);
        item.setControl(itemText);
    }
    cTabFolder.setSelection(cTabFolder.getItem(0));
    new Label(shell, SWT.NONE).setText("Label for Scale");
    scale = new Scale(shell, SWT.NONE);
    new Label(shell, SWT.NONE).setText("Label for Slider");
    slider = new Slider(shell, SWT.NONE);
    new Label(shell, SWT.NONE).setText("Label for ProgressBar");
    progressBar = new ProgressBar(shell, SWT.NONE);
    progressBar.setSelection(50);
    new Label(shell, SWT.NONE).setText("Label for Sash");
    sash = new Sash(shell, SWT.NONE);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) Group(org.eclipse.swt.widgets.Group) CTabFolder(org.eclipse.swt.custom.CTabFolder) Slider(org.eclipse.swt.widgets.Slider) TreeItem(org.eclipse.swt.widgets.TreeItem) Spinner(org.eclipse.swt.widgets.Spinner) TableItem(org.eclipse.swt.widgets.TableItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) CCombo(org.eclipse.swt.custom.CCombo) Combo(org.eclipse.swt.widgets.Combo) CTabItem(org.eclipse.swt.custom.CTabItem) KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) CoolBar(org.eclipse.swt.widgets.CoolBar) Button(org.eclipse.swt.widgets.Button) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) List(org.eclipse.swt.widgets.List) CoolItem(org.eclipse.swt.widgets.CoolItem) ProgressBar(org.eclipse.swt.widgets.ProgressBar) ToolItem(org.eclipse.swt.widgets.ToolItem) StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) Sash(org.eclipse.swt.widgets.Sash) Canvas(org.eclipse.swt.widgets.Canvas) TabFolder(org.eclipse.swt.widgets.TabFolder) CTabFolder(org.eclipse.swt.custom.CTabFolder) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) Scale(org.eclipse.swt.widgets.Scale) Point(org.eclipse.swt.graphics.Point) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) TabItem(org.eclipse.swt.widgets.TabItem) CTabItem(org.eclipse.swt.custom.CTabItem) CCombo(org.eclipse.swt.custom.CCombo) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) Caret(org.eclipse.swt.widgets.Caret) Display(org.eclipse.swt.widgets.Display)

Example 53 with ToolBar

use of org.eclipse.swt.widgets.ToolBar in project eclipse.platform.swt by eclipse.

the class BrowserExample method show.

void show(boolean owned, Point location, Point size, boolean addressBar, boolean menuBar, boolean statusBar, boolean toolBar) {
    final Shell shell = browser.getShell();
    if (owned) {
        if (location != null)
            shell.setLocation(location);
        if (size != null)
            shell.setSize(shell.computeSize(size.x, size.y));
    }
    FormData data = null;
    if (toolBar) {
        toolbar = new ToolBar(parent, SWT.NONE);
        data = new FormData();
        data.top = new FormAttachment(0, 5);
        toolbar.setLayoutData(data);
        itemBack = new ToolItem(toolbar, SWT.PUSH);
        itemBack.setText(getResourceString("Back"));
        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"));
        itemBack.setEnabled(browser.isBackEnabled());
        itemForward.setEnabled(browser.isForwardEnabled());
        Listener listener = 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(locationBar.getText());
        };
        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);
        canvas = new Canvas(parent, SWT.NO_BACKGROUND);
        data = new FormData();
        data.width = 24;
        data.height = 24;
        data.top = new FormAttachment(0, 5);
        data.right = new FormAttachment(100, -5);
        canvas.setLayoutData(data);
        final Rectangle rect = images[0].getBounds();
        canvas.addListener(SWT.Paint, e -> {
            Point pt = ((Canvas) e.widget).getSize();
            e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0, pt.x, pt.y);
        });
        canvas.addListener(SWT.MouseDown, e -> browser.setUrl(getResourceString("Startup")));
        final Display display = parent.getDisplay();
        display.asyncExec(new Runnable() {

            @Override
            public void run() {
                if (canvas.isDisposed())
                    return;
                if (busy) {
                    index++;
                    if (index == images.length)
                        index = 0;
                    canvas.redraw();
                }
                display.timerExec(150, this);
            }
        });
    }
    if (addressBar) {
        locationBar = new Text(parent, SWT.BORDER);
        data = new FormData();
        if (toolbar != null) {
            data.top = new FormAttachment(toolbar, 0, SWT.TOP);
            data.left = new FormAttachment(toolbar, 5, SWT.RIGHT);
            data.right = new FormAttachment(canvas, -5, SWT.DEFAULT);
        } else {
            data.top = new FormAttachment(0, 0);
            data.left = new FormAttachment(0, 0);
            data.right = new FormAttachment(100, 0);
        }
        locationBar.setLayoutData(data);
        locationBar.addListener(SWT.DefaultSelection, e -> browser.setUrl(locationBar.getText()));
    }
    if (statusBar) {
        status = new Label(parent, SWT.NONE);
        progressBar = new ProgressBar(parent, SWT.NONE);
        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);
        browser.addStatusTextListener(event -> status.setText(event.text));
    }
    parent.setLayout(new FormLayout());
    Control aboveBrowser = toolBar ? (Control) canvas : (addressBar ? (Control) locationBar : null);
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.top = aboveBrowser != null ? new FormAttachment(aboveBrowser, 5, SWT.DEFAULT) : new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = status != null ? new FormAttachment(status, -5, SWT.DEFAULT) : new FormAttachment(100, 0);
    browser.setLayoutData(data);
    if (statusBar || toolBar) {
        browser.addProgressListener(new ProgressListener() {

            @Override
            public void changed(ProgressEvent event) {
                if (event.total == 0)
                    return;
                int ratio = event.current * 100 / event.total;
                if (progressBar != null)
                    progressBar.setSelection(ratio);
                busy = event.current != event.total;
                if (!busy) {
                    index = 0;
                    if (canvas != null)
                        canvas.redraw();
                }
            }

            @Override
            public void completed(ProgressEvent event) {
                if (progressBar != null)
                    progressBar.setSelection(0);
                busy = false;
                index = 0;
                if (canvas != null) {
                    itemBack.setEnabled(browser.isBackEnabled());
                    itemForward.setEnabled(browser.isForwardEnabled());
                    canvas.redraw();
                }
            }
        });
    }
    if (addressBar || statusBar || toolBar) {
        browser.addLocationListener(LocationListener.changedAdapter(event -> {
            busy = true;
            if (event.top && locationBar != null)
                locationBar.setText(event.location);
        }));
    }
    if (title) {
        browser.addTitleListener(event -> shell.setText(event.title + " - " + getResourceString("window.title")));
    }
    parent.layout(true);
    if (owned)
        shell.open();
}
Also used : FormData(org.eclipse.swt.layout.FormData) ProgressBar(org.eclipse.swt.widgets.ProgressBar) ToolBar(org.eclipse.swt.widgets.ToolBar) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) ProgressListener(org.eclipse.swt.browser.ProgressListener) ImageData(org.eclipse.swt.graphics.ImageData) Point(org.eclipse.swt.graphics.Point) SWTError(org.eclipse.swt.SWTError) ResourceBundle(java.util.ResourceBundle) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Composite(org.eclipse.swt.widgets.Composite) Listener(org.eclipse.swt.widgets.Listener) LocationListener(org.eclipse.swt.browser.LocationListener) Canvas(org.eclipse.swt.widgets.Canvas) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) FillLayout(org.eclipse.swt.layout.FillLayout) Browser(org.eclipse.swt.browser.Browser) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) FormAttachment(org.eclipse.swt.layout.FormAttachment) Display(org.eclipse.swt.widgets.Display) ToolItem(org.eclipse.swt.widgets.ToolItem) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) InputStream(java.io.InputStream) FormLayout(org.eclipse.swt.layout.FormLayout) ProgressListener(org.eclipse.swt.browser.ProgressListener) Listener(org.eclipse.swt.widgets.Listener) LocationListener(org.eclipse.swt.browser.LocationListener) VisibilityWindowListener(org.eclipse.swt.browser.VisibilityWindowListener) Canvas(org.eclipse.swt.widgets.Canvas) Rectangle(org.eclipse.swt.graphics.Rectangle) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) Shell(org.eclipse.swt.widgets.Shell) Control(org.eclipse.swt.widgets.Control) ProgressListener(org.eclipse.swt.browser.ProgressListener) ToolBar(org.eclipse.swt.widgets.ToolBar) ProgressBar(org.eclipse.swt.widgets.ProgressBar) FormAttachment(org.eclipse.swt.layout.FormAttachment) ToolItem(org.eclipse.swt.widgets.ToolItem) Display(org.eclipse.swt.widgets.Display)

Example 54 with ToolBar

use of org.eclipse.swt.widgets.ToolBar in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_ToolBar method setUp.

@Override
@Before
public void setUp() {
    super.setUp();
    toolBar = new ToolBar(shell, 0);
    setWidget(toolBar);
}
Also used : ToolBar(org.eclipse.swt.widgets.ToolBar) Before(org.junit.Before)

Example 55 with ToolBar

use of org.eclipse.swt.widgets.ToolBar in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_ToolBar method test_getRowCount.

@Test
public void test_getRowCount() {
    if (SwtTestUtil.isGTK) {
        // TODO Fix GTK failure.
        if (SwtTestUtil.verbose) {
            System.out.println("Excluded test_getRowCount(org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_ToolBar)");
        }
        return;
    }
    toolBar = new ToolBar(shell, SWT.WRAP);
    int number = 5;
    ToolItem[] items = new ToolItem[number];
    for (int i = 0; i < number; i++) {
        items[i] = new ToolItem(toolBar, 0);
    }
    // ????  because of Size(0, 0)
    assertTrue(":a:" + toolBar.getRowCount(), toolBar.getRowCount() == number);
    toolBar = new ToolBar(shell, 0);
    number = 5;
    items = new ToolItem[number];
    for (int i = 0; i < number; i++) {
        items[i] = new ToolItem(toolBar, 0);
    }
    assertTrue(":a:", toolBar.getRowCount() == 1);
}
Also used : ToolBar(org.eclipse.swt.widgets.ToolBar) ToolItem(org.eclipse.swt.widgets.ToolItem) Test(org.junit.Test)

Aggregations

ToolBar (org.eclipse.swt.widgets.ToolBar)127 ToolItem (org.eclipse.swt.widgets.ToolItem)110 SelectionEvent (org.eclipse.swt.events.SelectionEvent)82 GridData (org.eclipse.swt.layout.GridData)81 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)74 GridLayout (org.eclipse.swt.layout.GridLayout)68 Composite (org.eclipse.swt.widgets.Composite)67 Image (org.eclipse.swt.graphics.Image)35 Label (org.eclipse.swt.widgets.Label)34 DisposeEvent (org.eclipse.swt.events.DisposeEvent)27 DisposeListener (org.eclipse.swt.events.DisposeListener)26 Point (org.eclipse.swt.graphics.Point)24 Cursor (org.eclipse.swt.graphics.Cursor)22 TableViewer (org.eclipse.jface.viewers.TableViewer)18 FillLayout (org.eclipse.swt.layout.FillLayout)18 Button (org.eclipse.swt.widgets.Button)17 Text (org.eclipse.swt.widgets.Text)17 ArrayList (java.util.ArrayList)14 SashForm (org.eclipse.swt.custom.SashForm)14 Combo (org.eclipse.swt.widgets.Combo)14