use of org.eclipse.swt.widgets.TreeItem in project eclipse.platform.swt by eclipse.
the class GraphicsExample method setTab.
/**
* Sets the current tab.
*/
public void setTab(GraphicsTab tab) {
Control[] children = tabControlPanel.getChildren();
for (Control control : children) {
control.dispose();
}
if (this.tab != null)
this.tab.dispose();
this.tab = tab;
if (tab != null) {
setDoubleBuffered(tab.getDoubleBuffered());
tab.createControlPanel(tabControlPanel);
tabDesc.setText(tab.getDescription());
} else {
tabDesc.setText("");
}
FormData data = (FormData) tabControlPanel.getLayoutData();
children = tabControlPanel.getChildren();
if (children.length != 0) {
data.top = null;
} else {
data.top = new FormAttachment(100, -MARGIN);
}
parent.layout(true, true);
if (tab != null) {
TreeItem[] selection = tabList.getSelection();
if (selection.length == 0 || selection[0].getData() != tab) {
TreeItem item = findItemByData(tabList.getItems(), tab);
if (item != null)
tabList.setSelection(new TreeItem[] { item });
}
}
canvas.redraw();
}
use of org.eclipse.swt.widgets.TreeItem in project eclipse.platform.swt by eclipse.
the class Bug529126_TreeMouseDown method main.
// Static =================================================================
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Custom gradient selection for Tree");
shell.setLayout(new FillLayout());
final Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
final int columnCount = 4;
for (int i = 0; i < columnCount; i++) {
final TreeColumn column = new TreeColumn(tree, SWT.NONE);
column.setText("Column " + i);
}
final int itemCount = 5;
for (int i = 0; i < itemCount; i++) {
final TreeItem item1 = new TreeItem(tree, SWT.NONE);
for (int j = 0; j < i; j++) {
final TreeItem item2 = new TreeItem(item1, SWT.NONE);
for (int k = 0; k < j; k++) {
new TreeItem(item2, SWT.NONE);
}
}
}
tree.addListener(SWT.SetData, event -> {
final TreeItem item = (TreeItem) event.item;
final TreeItem parentItem = item.getParentItem();
final String text;
if (parentItem != null) {
final String parentText = (String) parentItem.getData();
text = parentText + event.index + "/";
} else {
text = "/";
}
item.setData(text);
});
tree.addListener(SWT.PaintItem, event -> {
final TreeItem item = (TreeItem) event.item;
final String text = (String) item.getData();
event.gc.drawText(text + " [" + event.index + "]", event.x, event.y, true);
});
/*
* NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly.
* Therefore, it is critical for performance that these methods be
* as efficient as possible.
*/
tree.addListener(SWT.EraseItem, event -> {
event.detail &= ~SWT.HOT;
if ((event.detail & SWT.SELECTED) != 0) {
final GC gc = event.gc;
final Rectangle area = tree.getClientArea();
/*
* If you wish to paint the selection beyond the end of
* last column, you must change the clipping region.
*/
final int columnCount1 = tree.getColumnCount();
if (event.index == columnCount1 - 1 || columnCount1 == 0) {
final int width = area.x + area.width - event.x;
if (width > 0) {
final Region region = new Region();
gc.getClipping(region);
region.add(event.x, event.y, width, event.height);
gc.setClipping(region);
region.dispose();
}
}
gc.setAdvanced(true);
if (gc.getAdvanced()) {
gc.setAlpha(127);
}
final Rectangle rect = event.getBounds();
final Color foreground = gc.getForeground();
final Color background = gc.getBackground();
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
gc.fillGradientRectangle(0, rect.y, 500, rect.height, false);
// restore colors for subsequent drawing
gc.setForeground(foreground);
gc.setBackground(background);
event.detail &= ~SWT.SELECTED;
}
});
tree.getColumn(0).setWidth(200);
for (int i = 1; i < columnCount; i++) {
tree.getColumn(i).pack();
}
tree.setSelection(tree.getItem(0));
tree.addListener(SWT.MouseDown, event -> System.out.println("event = " + event));
shell.setSize(500, 500);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
use of org.eclipse.swt.widgets.TreeItem in project eclipse.platform.swt by eclipse.
the class Bug530969_ControlPrint method main.
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display, SWT.NO_TRIM);
Color gray = new Color(display, 222, 223, 224);
Composite composite = new Composite(shell, SWT.NONE);
RowLayout layout = new RowLayout();
layout.marginTop = 0;
layout.marginLeft = 0;
layout.marginBottom = 0;
layout.marginRight = 0;
layout.spacing = 0;
composite.setLayout(layout);
createButton(composite, gray, true, true);
createButton(composite, gray, false, true);
createButton(composite, gray, true, false);
createButton(composite, gray, false, false);
Point cSize = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
composite.setSize(cSize);
shell.setBackground(gray);
shell.setLocation(0, 0);
shell.setSize(cSize);
shell.open();
Image canvas = new Image(display, cSize.x, cSize.y);
GC gc = new GC(canvas);
composite.print(gc);
int buttonX = cSize.x / 4;
Image[] images = new Image[4];
for (int i = 0; i < 4; i++) {
Image image = new Image(display, buttonX, cSize.y);
gc.copyArea(image, buttonX * i, 0);
images[i] = image;
}
shell.close();
Shell properShell = new Shell(display);
properShell.setLayout(new FillLayout());
Image firstImage = images[0];
final Tree tree = new Tree(properShell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
TreeItem lastItem = new TreeItem(tree, SWT.NONE);
lastItem.setImage(firstImage);
lastItem.setText("root item with first image");
for (int i = 0; i < 3; i++) {
TreeItem newItem = new TreeItem(lastItem, SWT.NONE);
newItem.setText("descendant item with image " + i);
newItem.setImage(images[i + 1]);
}
lastItem.setExpanded(true);
properShell.setSize(400, 400);
properShell.open();
while (!properShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
canvas.dispose();
gc.dispose();
firstImage.dispose();
}
use of org.eclipse.swt.widgets.TreeItem in project eclipse.platform.swt by eclipse.
the class MJ_Tree method bug73812_treeColumn_getWidth_0.
@Test
public void bug73812_treeColumn_getWidth_0() {
Shell shell = mkShell("Verify that all columns are of same width. (100).");
shell.setSize(SWIDTH, SHEIGHT);
shell.setLayout(new FillLayout());
final Tree tt = new Tree(shell, SWT.FULL_SELECTION | SWT.MULTI | SWT.VIRTUAL);
tt.setLinesVisible(true);
tt.setHeaderVisible(true);
for (int i = 0; i < 10; i++) {
TreeColumn tc = new TreeColumn(tt, SWT.NONE);
tc.setWidth(100);
System.out.println(tc.getWidth());
tc.setWidth(tc.getWidth());
tc.setText("Column " + i);
}
for (int i = 0; i < 100; i++) {
new TreeItem(tt, SWT.NONE);
}
shell.open();
mainLoop(shell);
}
use of org.eclipse.swt.widgets.TreeItem in project eclipse.platform.swt by eclipse.
the class MJ_Tree method basicTree_Snippet35.
@Test
public void basicTree_Snippet35() {
// original was table, modified for tree.
Shell shell = mkShell("TREE: Basic Tree with a few items, no column, no headers");
shell.setLayout(new FillLayout());
Tree tree = new Tree(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
for (int i = 0; i < 12; i++) {
TreeItem item = new TreeItem(tree, 0);
item.setText("Item " + i);
}
shell.setSize(SWIDTH, SHEIGHT);
shell.open();
mainLoop(shell);
}
Aggregations