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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations