use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.
the class ImageAnalyzer method resizeScrollBars.
void resizeScrollBars() {
// Set the max and thumb for the image canvas scroll bars.
ScrollBar horizontal = imageCanvas.getHorizontalBar();
ScrollBar vertical = imageCanvas.getVerticalBar();
Rectangle canvasBounds = imageCanvas.getClientArea();
int width = Math.round(imageData.width * xscale);
if (width > canvasBounds.width) {
// The image is wider than the canvas.
horizontal.setEnabled(true);
horizontal.setMaximum(width);
horizontal.setThumb(canvasBounds.width);
horizontal.setPageIncrement(canvasBounds.width);
} else {
// The canvas is wider than the image.
horizontal.setEnabled(false);
if (ix != 0) {
// Make sure the image is completely visible.
ix = 0;
imageCanvas.redraw();
}
}
int height = Math.round(imageData.height * yscale);
if (height > canvasBounds.height) {
// The image is taller than the canvas.
vertical.setEnabled(true);
vertical.setMaximum(height);
vertical.setThumb(canvasBounds.height);
vertical.setPageIncrement(canvasBounds.height);
} else {
// The canvas is taller than the image.
vertical.setEnabled(false);
if (iy != 0) {
// Make sure the image is completely visible.
iy = 0;
imageCanvas.redraw();
}
}
// Set the max and thumb for the palette canvas scroll bar.
vertical = paletteCanvas.getVerticalBar();
if (imageData.palette.isDirect) {
vertical.setEnabled(false);
} else {
// indexed palette
canvasBounds = paletteCanvas.getClientArea();
// 10 pixels each index + 20 for margins.
int paletteHeight = imageData.palette.getRGBs().length * 10 + 20;
vertical.setEnabled(true);
vertical.setMaximum(paletteHeight);
vertical.setThumb(canvasBounds.height);
vertical.setPageIncrement(canvasBounds.height);
}
}
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 eclipse.platform.text by eclipse.
the class ColumnLayout method computeTrim.
private int computeTrim(Rectangle area, Table table, int tableWidth) {
Point preferredSize = computeTableSize(table, area.width, area.height);
int trim;
if (tableWidth > 1) {
trim = tableWidth - table.getClientArea().width;
} else {
// initially, the table has no extend and no client area - use the border with
// plus some padding as educated guess
trim = 2 * table.getBorderWidth() + 1;
}
if (preferredSize.y > area.height) {
// Subtract the scrollbar width from the total column width
// if a vertical scrollbar will be required, but is not currently showing
// (in which case it is already subtracted above)
ScrollBar vBar = table.getVerticalBar();
if (!vBar.isVisible()) {
Point vBarSize = vBar.getSize();
trim += vBarSize.x;
}
}
return trim;
}
use of org.eclipse.swt.widgets.ScrollBar in project linuxtools by eclipse.
the class AbstractSTViewer method init.
/*
* Initializes this view with the given view site. A memento is passed to the view which contains a snapshot of the
* views state from a previous session. Where possible, the view should try to recreate that state within the part
* controls. <p> This implementation will ignore the memento and initialize the view in a fresh state. Subclasses
* may override the implementation to perform any state restoration as needed.
*/
/**
* Initializes the viewers. It sets: the columns of the viewers, a viewer setting (similar to memento) a column
* manager a viewer comparator ColumnViewerToolTipSupport an OpenListener a KeyListener a PaintListener a
* DisposeListener the input the content provider
* @param parent The parent composite.
* @param style SWT style to be used.
*/
private void init(Composite parent, int style) {
viewer = createViewer(parent, style);
viewerSettings = createSTAbstractDataViewersSettings();
fields = getAllFields();
createColumns();
restoreColumnOrder();
// building columns manager
// (needs the columns to be created first)
STDataViewersHideShowManager manager = new STDataViewersHideShowManager(this);
manager.restoreState(viewerSettings);
setHideShowManager(manager);
// building the column comparator
// (needs the columns to be created first)
STDataViewersComparator comparator = new STDataViewersComparator(getColumns());
comparator.restoreState(viewerSettings);
setComparator(comparator);
setSortIndicators();
IContentProvider cp = createContentProvider();
viewer.setContentProvider(cp);
viewer.setUseHashlookup(true);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
viewer.getControl().setLayoutData(data);
viewer.setInput(null);
ColumnViewerToolTipSupport.enableFor(viewer);
Scrollable scrollable = (Scrollable) viewer.getControl();
ScrollBar bar = scrollable.getVerticalBar();
if (bar != null) {
bar.setSelection(restoreVerticalScrollBarPosition());
}
bar = scrollable.getHorizontalBar();
if (bar != null) {
bar.setSelection(restoreHorizontalScrollBarPosition());
}
viewer.addOpenListener(event -> handleOpenEvent(event));
viewer.getControl().addDisposeListener(new STDisposeListener(this));
}
Aggregations