Search in sources :

Example 11 with CoolBar

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

the class CoolBarTab method createExampleWidgets.

/**
 * Creates the "Example" widgets.
 */
@Override
void createExampleWidgets() {
    int style = getDefaultStyle(), itemStyle = 0;
    /* Compute the widget, item, and item toolBar styles */
    int toolBarStyle = SWT.FLAT;
    boolean vertical = false;
    if (horizontalButton.getSelection()) {
        style |= SWT.HORIZONTAL;
        toolBarStyle |= SWT.HORIZONTAL;
    }
    if (verticalButton.getSelection()) {
        style |= SWT.VERTICAL;
        toolBarStyle |= SWT.VERTICAL;
        vertical = true;
    }
    if (borderButton.getSelection())
        style |= SWT.BORDER;
    if (flatButton.getSelection())
        style |= SWT.FLAT;
    if (dropDownButton.getSelection())
        itemStyle |= SWT.DROP_DOWN;
    /*
		* Create the example widgets.
		*/
    coolBar = new CoolBar(coolBarGroup, style);
    /* Create the push button toolbar cool item */
    ToolBar toolBar = new ToolBar(coolBar, toolBarStyle);
    ToolItem item = new ToolItem(toolBar, SWT.PUSH);
    item.setImage(instance.images[ControlExample.ciClosedFolder]);
    item.setToolTipText("SWT.PUSH");
    item = new ToolItem(toolBar, SWT.PUSH);
    item.setImage(instance.images[ControlExample.ciOpenFolder]);
    item.setToolTipText("SWT.PUSH");
    item = new ToolItem(toolBar, SWT.PUSH);
    item.setImage(instance.images[ControlExample.ciTarget]);
    item.setToolTipText("SWT.PUSH");
    item = new ToolItem(toolBar, SWT.SEPARATOR);
    item = new ToolItem(toolBar, SWT.PUSH);
    item.setImage(instance.images[ControlExample.ciClosedFolder]);
    item.setToolTipText("SWT.PUSH");
    item = new ToolItem(toolBar, SWT.PUSH);
    item.setImage(instance.images[ControlExample.ciOpenFolder]);
    item.setToolTipText("SWT.PUSH");
    pushItem = new CoolItem(coolBar, itemStyle);
    pushItem.setControl(toolBar);
    pushItem.addSelectionListener(new CoolItemSelectionListener());
    /* Create the dropdown toolbar cool item */
    toolBar = new ToolBar(coolBar, toolBarStyle);
    item = new ToolItem(toolBar, SWT.DROP_DOWN);
    item.setImage(instance.images[ControlExample.ciOpenFolder]);
    item.setToolTipText("SWT.DROP_DOWN");
    item.addSelectionListener(new DropDownSelectionListener());
    item = new ToolItem(toolBar, SWT.DROP_DOWN);
    item.setImage(instance.images[ControlExample.ciClosedFolder]);
    item.setToolTipText("SWT.DROP_DOWN");
    item.addSelectionListener(new DropDownSelectionListener());
    dropDownItem = new CoolItem(coolBar, itemStyle);
    dropDownItem.setControl(toolBar);
    dropDownItem.addSelectionListener(new CoolItemSelectionListener());
    /* Create the radio button toolbar cool item */
    toolBar = new ToolBar(coolBar, toolBarStyle);
    item = new ToolItem(toolBar, SWT.RADIO);
    item.setImage(instance.images[ControlExample.ciClosedFolder]);
    item.setToolTipText("SWT.RADIO");
    item = new ToolItem(toolBar, SWT.RADIO);
    item.setImage(instance.images[ControlExample.ciClosedFolder]);
    item.setToolTipText("SWT.RADIO");
    item = new ToolItem(toolBar, SWT.RADIO);
    item.setImage(instance.images[ControlExample.ciClosedFolder]);
    item.setToolTipText("SWT.RADIO");
    radioItem = new CoolItem(coolBar, itemStyle);
    radioItem.setControl(toolBar);
    radioItem.addSelectionListener(new CoolItemSelectionListener());
    /* Create the check button toolbar cool item */
    toolBar = new ToolBar(coolBar, toolBarStyle);
    item = new ToolItem(toolBar, SWT.CHECK);
    item.setImage(instance.images[ControlExample.ciClosedFolder]);
    item.setToolTipText("SWT.CHECK");
    item = new ToolItem(toolBar, SWT.CHECK);
    item.setImage(instance.images[ControlExample.ciTarget]);
    item.setToolTipText("SWT.CHECK");
    item = new ToolItem(toolBar, SWT.CHECK);
    item.setImage(instance.images[ControlExample.ciOpenFolder]);
    item.setToolTipText("SWT.CHECK");
    item = new ToolItem(toolBar, SWT.CHECK);
    item.setImage(instance.images[ControlExample.ciTarget]);
    item.setToolTipText("SWT.CHECK");
    checkItem = new CoolItem(coolBar, itemStyle);
    checkItem.setControl(toolBar);
    checkItem.addSelectionListener(new CoolItemSelectionListener());
    /* Create the text cool item */
    if (!vertical) {
        Text text = new Text(coolBar, SWT.BORDER | SWT.SINGLE);
        textItem = new CoolItem(coolBar, itemStyle);
        textItem.setControl(text);
        textItem.addSelectionListener(new CoolItemSelectionListener());
        Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        textSize = textItem.computeSize(textSize.x, textSize.y);
        textItem.setMinimumSize(textSize);
        textItem.setPreferredSize(textSize);
        textItem.setSize(textSize);
    }
    /* Set the sizes after adding all cool items */
    CoolItem[] coolItems = coolBar.getItems();
    for (CoolItem coolItem : coolItems) {
        Control control = coolItem.getControl();
        Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        Point coolSize = coolItem.computeSize(size.x, size.y);
        if (control instanceof ToolBar) {
            ToolBar bar = (ToolBar) control;
            if (bar.getItemCount() > 0) {
                if (vertical) {
                    size.y = bar.getItem(0).getBounds().height;
                } else {
                    size.x = bar.getItem(0).getWidth();
                }
            }
        }
        coolItem.setMinimumSize(size);
        coolItem.setPreferredSize(coolSize);
        coolItem.setSize(coolSize);
    }
    /* If we have saved state, restore it */
    if (order != null && order.length == coolBar.getItemCount()) {
        coolBar.setItemLayout(order, wrapIndices, sizes);
    } else {
        coolBar.setWrapIndices(new int[] { 1, 3 });
    }
    /* Add a listener to resize the group box to match the coolbar */
    coolBar.addListener(SWT.Resize, event -> exampleGroup.layout());
}
Also used : Control(org.eclipse.swt.widgets.Control) CoolBar(org.eclipse.swt.widgets.CoolBar) ToolBar(org.eclipse.swt.widgets.ToolBar) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) CoolItem(org.eclipse.swt.widgets.CoolItem) Point(org.eclipse.swt.graphics.Point) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 12 with CoolBar

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

the class Test_org_eclipse_swt_widgets_CoolBar method setUp.

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

Example 13 with CoolBar

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

the class Test_org_eclipse_swt_widgets_CoolBar method createCoolBar.

private void createCoolBar(List<String> events) {
    tearDown();
    super.setUp();
    String test = getTestName();
    coolBar = new CoolBar(shell, SWT.FLAT);
    ToolBar[] coolItemToolBar = new ToolBar[2];
    for (int i = 0; i < 2; i++) {
        CoolItem coolItem = new CoolItem(coolBar, SWT.DROP_DOWN);
        coolItemToolBar[i] = new ToolBar(coolBar, SWT.FLAT);
        hookExpectedEvents(coolItem, test, events);
        hookExpectedEvents(coolItemToolBar[i], test, events);
        int toolItemWidth = 0;
        for (int j = 0; j < 2; j++) {
            ToolItem item = new ToolItem(coolItemToolBar[i], SWT.CHECK);
            item.setText("CB" + ((i * 2) + j));
            item.setToolTipText("ToolItem ToolTip" + i + j);
            if (item.getWidth() > toolItemWidth)
                toolItemWidth = item.getWidth();
            hookExpectedEvents(item, test, events);
        }
        coolItem.setControl(coolItemToolBar[i]);
        Point size;
        if (i == 1)
            size = coolItemToolBar[i].computeSize(20, SWT.DEFAULT);
        else
            size = coolItemToolBar[i].computeSize(SWT.DEFAULT, SWT.DEFAULT);
        Point coolSize = coolItem.computeSize(size.x, size.y);
        coolItem.setMinimumSize(toolItemWidth / 3, coolSize.y);
        coolItem.setPreferredSize(coolSize);
        coolItem.setSize(coolSize.x / 3, coolSize.y);
        coolItem.addSelectionListener(new CoolItemSelectionListener());
    }
    setWidget(coolBar);
}
Also used : CoolBar(org.eclipse.swt.widgets.CoolBar) ToolBar(org.eclipse.swt.widgets.ToolBar) Point(org.eclipse.swt.graphics.Point) CoolItem(org.eclipse.swt.widgets.CoolItem) Point(org.eclipse.swt.graphics.Point) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 14 with CoolBar

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

the class Test_org_eclipse_swt_widgets_CoolItem method test_getControl.

@Test
public void test_getControl() {
    CoolBar coolBar = new CoolBar(shell, 0);
    CoolItem coolItem = new CoolItem(coolBar, 0);
    assertNull(coolItem.getControl());
    Button button = new Button(coolBar, SWT.PUSH);
    coolItem.setControl(button);
    Control control = coolItem.getControl();
    assertEquals(button, control);
    button = new Button(coolBar, SWT.PUSH);
    coolItem.setControl(button);
    control = coolItem.getControl();
    assertEquals(button, control);
}
Also used : Control(org.eclipse.swt.widgets.Control) CoolBar(org.eclipse.swt.widgets.CoolBar) Button(org.eclipse.swt.widgets.Button) CoolItem(org.eclipse.swt.widgets.CoolItem) Test(org.junit.Test)

Example 15 with CoolBar

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

the class Test_org_eclipse_swt_widgets_CoolItem method test_computeSizeII.

@Test
public void test_computeSizeII() {
    CoolBar coolBar = new CoolBar(shell, 0);
    CoolItem coolItem = new CoolItem(coolBar, 0);
    Button button = new Button(coolBar, SWT.PUSH);
    button.setText("foo");
    Point size = coolItem.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    coolItem.setControl(button);
    Point size2 = coolItem.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    assertTrue(size2.x == size.x);
    size = coolItem.computeSize(50, 25);
    size2 = coolItem.computeSize(100, 25);
    assertEquals(size.x + 50, size2.x);
    assertEquals(size.y, size2.y);
    size = coolItem.computeSize(1, 1);
    size2 = coolItem.computeSize(26, 26);
    assertEquals(25, size2.x - size.x);
}
Also used : CoolBar(org.eclipse.swt.widgets.CoolBar) Button(org.eclipse.swt.widgets.Button) Point(org.eclipse.swt.graphics.Point) CoolItem(org.eclipse.swt.widgets.CoolItem) Test(org.junit.Test)

Aggregations

CoolBar (org.eclipse.swt.widgets.CoolBar)22 CoolItem (org.eclipse.swt.widgets.CoolItem)20 Point (org.eclipse.swt.graphics.Point)15 Button (org.eclipse.swt.widgets.Button)14 Test (org.junit.Test)13 ToolBar (org.eclipse.swt.widgets.ToolBar)6 ToolItem (org.eclipse.swt.widgets.ToolItem)6 Control (org.eclipse.swt.widgets.Control)5 Text (org.eclipse.swt.widgets.Text)5 StyledText (org.eclipse.swt.custom.StyledText)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 GridData (org.eclipse.swt.layout.GridData)4 Combo (org.eclipse.swt.widgets.Combo)4 Label (org.eclipse.swt.widgets.Label)4 CCombo (org.eclipse.swt.custom.CCombo)3 FillLayout (org.eclipse.swt.layout.FillLayout)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Canvas (org.eclipse.swt.widgets.Canvas)3 Composite (org.eclipse.swt.widgets.Composite)3 Display (org.eclipse.swt.widgets.Display)3