Search in sources :

Example 46 with ScrollBar

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

Example 47 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 48 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 49 with ScrollBar

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

Example 50 with ScrollBar

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));
}
Also used : STDisposeListener(org.eclipse.linuxtools.dataviewers.listeners.STDisposeListener) IContentProvider(org.eclipse.jface.viewers.IContentProvider) GridData(org.eclipse.swt.layout.GridData) Scrollable(org.eclipse.swt.widgets.Scrollable) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Aggregations

ScrollBar (org.eclipse.swt.widgets.ScrollBar)50 Point (org.eclipse.swt.graphics.Point)32 Rectangle (org.eclipse.swt.graphics.Rectangle)20 GC (org.eclipse.swt.graphics.GC)14 Event (org.eclipse.swt.widgets.Event)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 GridData (org.eclipse.swt.layout.GridData)7 Listener (org.eclipse.swt.widgets.Listener)7 Composite (org.eclipse.swt.widgets.Composite)6 SWT (org.eclipse.swt.SWT)5 Font (org.eclipse.swt.graphics.Font)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 Button (org.eclipse.swt.widgets.Button)5 AccessibleControlEvent (org.eclipse.swt.accessibility.AccessibleControlEvent)4 AccessibleEvent (org.eclipse.swt.accessibility.AccessibleEvent)4 AccessibleTableEvent (org.eclipse.swt.accessibility.AccessibleTableEvent)4 ControlListener (org.eclipse.swt.events.ControlListener)4 Color (org.eclipse.swt.graphics.Color)4 ClientAreaResizeCommand (net.sourceforge.nattable.grid.command.ClientAreaResizeCommand)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3