Search in sources :

Example 66 with ScrollBar

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);
}
Also used : TableEditor(org.eclipse.swt.custom.TableEditor) MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) TableColumn(org.eclipse.swt.widgets.TableColumn) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FontMetrics(org.eclipse.swt.graphics.FontMetrics) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Random(java.util.Random) ControlListener(org.eclipse.swt.events.ControlListener) TextLayout(org.eclipse.swt.graphics.TextLayout) TextStyle(org.eclipse.swt.graphics.TextStyle) Table(org.eclipse.swt.widgets.Table) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) Locale(java.util.Locale) Composite(org.eclipse.swt.widgets.Composite) Listener(org.eclipse.swt.widgets.Listener) BiConsumer(java.util.function.BiConsumer) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) RowData(org.eclipse.swt.layout.RowData) Collator(java.text.Collator) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) ShellEvent(org.eclipse.swt.events.ShellEvent) Test(org.junit.Test) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Consumer(java.util.function.Consumer) RowLayout(org.eclipse.swt.layout.RowLayout) Color(org.eclipse.swt.graphics.Color) ControlAdapter(org.eclipse.swt.events.ControlAdapter) SWT(org.eclipse.swt.SWT) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrollBar(org.eclipse.swt.widgets.ScrollBar) FixMethodOrder(org.junit.FixMethodOrder) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) Shell(org.eclipse.swt.widgets.Shell) ControlEvent(org.eclipse.swt.events.ControlEvent) Test(org.junit.Test)

Example 67 with ScrollBar

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);
}
Also used : TableEditor(org.eclipse.swt.custom.TableEditor) MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) TableColumn(org.eclipse.swt.widgets.TableColumn) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FontMetrics(org.eclipse.swt.graphics.FontMetrics) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Random(java.util.Random) ControlListener(org.eclipse.swt.events.ControlListener) TextLayout(org.eclipse.swt.graphics.TextLayout) TextStyle(org.eclipse.swt.graphics.TextStyle) Table(org.eclipse.swt.widgets.Table) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) Locale(java.util.Locale) Composite(org.eclipse.swt.widgets.Composite) Listener(org.eclipse.swt.widgets.Listener) BiConsumer(java.util.function.BiConsumer) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) RowData(org.eclipse.swt.layout.RowData) Collator(java.text.Collator) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) ShellEvent(org.eclipse.swt.events.ShellEvent) Test(org.junit.Test) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Consumer(java.util.function.Consumer) RowLayout(org.eclipse.swt.layout.RowLayout) Color(org.eclipse.swt.graphics.Color) ControlAdapter(org.eclipse.swt.events.ControlAdapter) SWT(org.eclipse.swt.SWT) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrollBar(org.eclipse.swt.widgets.ScrollBar) FixMethodOrder(org.junit.FixMethodOrder) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Shell(org.eclipse.swt.widgets.Shell) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Test(org.junit.Test)

Example 68 with ScrollBar

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;
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 69 with ScrollBar

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;
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 70 with ScrollBar

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();
            }
        });
    }
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Aggregations

ScrollBar (org.eclipse.swt.widgets.ScrollBar)84 Point (org.eclipse.swt.graphics.Point)39 Rectangle (org.eclipse.swt.graphics.Rectangle)25 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 GC (org.eclipse.swt.graphics.GC)14 GridData (org.eclipse.swt.layout.GridData)12 Event (org.eclipse.swt.widgets.Event)12 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)11 Composite (org.eclipse.swt.widgets.Composite)8 GridLayout (org.eclipse.swt.layout.GridLayout)7 Listener (org.eclipse.swt.widgets.Listener)7 StyledText (org.eclipse.swt.custom.StyledText)6 Button (org.eclipse.swt.widgets.Button)6 Label (org.eclipse.swt.widgets.Label)6 SWT (org.eclipse.swt.SWT)5 ControlListener (org.eclipse.swt.events.ControlListener)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 Font (org.eclipse.swt.graphics.Font)5 Text (org.eclipse.swt.widgets.Text)5 AffineTransform (java.awt.geom.AffineTransform)4