use of org.eclipse.swt.widgets.ToolItem 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();
}
use of org.eclipse.swt.widgets.ToolItem 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();
}
use of org.eclipse.swt.widgets.ToolItem 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);
}
use of org.eclipse.swt.widgets.ToolItem in project yamcs-studio by yamcs.
the class PartZoomComboContributionItem method fill.
/**
* The control item implementation of this <code>IContributionItem</code>
* method calls the <code>createControl</code> framework method to create a
* control under the given parent, and then creates a new tool item to hold
* it. Subclasses must implement <code>createControl</code> rather than
* overriding this method.
*
* @param parent
* The ToolBar to add the new control to
* @param index
* Index
*/
@Override
public void fill(ToolBar parent, int index) {
toolitem = new ToolItem(parent, SWT.SEPARATOR, index);
Control control = createControl(parent);
toolitem.setControl(control);
}
use of org.eclipse.swt.widgets.ToolItem in project cubrid-manager by CUBRID.
the class DropDownAction method runWithEvent.
public void runWithEvent(Event event) {
// FIXME remove commented code if don't need it anymore.
//if (event.detail == SWT.ARROW) {
Widget widget = event.widget;
if (widget instanceof ToolItem) {
ToolItem toolItem = (ToolItem) widget;
Composite parent = toolItem.getParent();
Rectangle rect = toolItem.getBounds();
Point pt = new Point(rect.x, rect.y + rect.height);
pt = parent.toDisplay(pt);
Menu contextMenu = menuManager.createContextMenu(parent);
contextMenu.setLocation(pt.x, pt.y);
contextMenu.setVisible(true);
}
// } else {
// run();
// }
}
Aggregations