use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.
the class MJ_Table method bug51079_setWidth_getWidth.
/**
* Last column should be big enough so that text inside it can be read.
* Notion that getWidth() when called after setWidth() returns a different size.
*/
@Test
public void bug51079_setWidth_getWidth() {
Shell shell = mkShell("column SetGet Width : Make shell smaller and bigger. If you don't see COL_SIZE_ERROR in console, all is well.");
shell.setSize(SWIDTH, SHEIGHT);
shell.setLayout(new FillLayout());
StringBuffer sbBuffer = new StringBuffer();
final Composite comp = new Composite(shell, SWT.NONE);
final Table table = new Table(comp, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);
final TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText("Column 1");
column1.setResizable(false);
final TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText("Column 2");
column2.setResizable(false);
for (int i = 0; i < 60; i++) {
TableItem item = new TableItem(table, SWT.NONE);
sbBuffer.append("M");
item.setText(new String[] { "item 0 " + sbBuffer.toString() + " " + i, "item 1 " + i });
}
Consumer<Integer> setColumnWidths = (width) -> {
int c1w = (int) (width * 0.9);
column1.setWidth(c1w);
int c1wPost = column1.getWidth();
if (c1w != c1wPost)
System.err.println("COL_SIZE_ERROR 1 Expected:" + c1w + " actual:" + c1wPost);
int c2w = width - column1.getWidth();
column2.setWidth(c2w);
int c2wPost = column2.getWidth();
if (c2w != c2wPost)
System.err.println("COL_SIZE_ERROR 2 Expected:" + c2w + " actual:" + column2.getWidth());
};
comp.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Rectangle area = table.getParent().getClientArea();
Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
int width = area.width - 2 * table.getBorderWidth();
if (preferredSize.y > area.height) {
// Subtract the scrollbar width from the total column width
// if a vertical scrollbar will be required
Point vBarSize = table.getVerticalBar().getSize();
width -= vBarSize.x;
}
Point oldSize = table.getSize();
if (oldSize.x > area.width) {
// table is getting smaller so make the columns
// smaller first and then resize the table to
// match the client area width
setColumnWidths.accept(width);
table.setSize(area.width, area.height);
} else {
// table is getting bigger so make the table
// bigger first and then make the columns wider
// to match the client area width
table.setSize(area.width, area.height);
setColumnWidths.accept(width);
}
}
});
shell.open();
mainLoop(shell);
}
use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.
the class MJ_Table method column_dynamic_resize.
@Test
public void column_dynamic_resize() {
Shell shell = mkShell("Try resizing shell. Columns should resize as you resize shell");
shell.setLayout(new FillLayout());
final Composite comp = new Composite(shell, SWT.NONE);
final Table table = new Table(comp, SWT.BORDER | SWT.V_SCROLL);
table.setHeaderVisible(true);
table.setLinesVisible(true);
final TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText("Column 1");
final TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText("Column 2");
for (int i = 0; i < 10; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] { "item 0" + i, "item 1" + i });
}
comp.addControlListener(ControlListener.controlResizedAdapter(e -> {
Rectangle area = comp.getClientArea();
Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
ScrollBar vBar = table.getVerticalBar();
int width = area.width - table.computeTrim(0, 0, 0, 0).width - vBar.getSize().x;
if (size.y > area.height + table.getHeaderHeight()) {
// Subtract the scrollbar width from the total column width
// if a vertical scrollbar will be required
Point vBarSize = vBar.getSize();
width -= vBarSize.x;
}
Point oldSize = table.getSize();
if (oldSize.x > area.width) {
// table is getting smaller so make the columns
// smaller first and then resize the table to
// match the client area width
column1.setWidth(width / 3);
column2.setWidth(width - column1.getWidth());
table.setSize(area.width, area.height);
} else {
// table is getting bigger so make the table
// bigger first and then make the columns wider
// to match the client area width
table.setSize(area.width, area.height);
column1.setWidth(width / 3);
column2.setWidth(width - column1.getWidth());
}
}));
shell.open();
mainLoop(shell);
}
use of org.eclipse.swt.widgets.ScrollBar in project netxms by netxms.
the class Gallery method scrollVertical.
protected void scrollVertical() {
int areaHeight = getClientArea().height;
if (gHeight > areaHeight) {
// image is higher than client area
ScrollBar bar = getVerticalBar();
// scroll(0, translate - bar.getSelection(), 0, 0, getClientArea().width, areaHeight, false);
translate = bar.getSelection();
} else {
translate = 0;
}
}
use of org.eclipse.swt.widgets.ScrollBar in project netxms by netxms.
the class Gallery method scrollHorizontal.
protected void scrollHorizontal() {
int areaWidth = getClientArea().width;
if (gWidth > areaWidth) {
// image is higher than client area
ScrollBar bar = getHorizontalBar();
// scroll(translate - bar.getSelection(), 0, 0, 0, areaWidth,getClientArea().height, false);
translate = bar.getSelection();
} else {
translate = 0;
}
}
use of org.eclipse.swt.widgets.ScrollBar in project netxms by netxms.
the class Gallery method _addScrollBarsListeners.
/**
* Add internal scrollbars listeners to this gallery.
*/
private void _addScrollBarsListeners() {
// Vertical bar
ScrollBar verticalBar = getVerticalBar();
if (verticalBar != null) {
verticalBar.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (vertical)
scrollVertical();
}
});
}
// Horizontal bar
ScrollBar horizontalBar = getHorizontalBar();
if (horizontalBar != null) {
horizontalBar.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (!vertical)
scrollHorizontal();
}
});
}
}
Aggregations