Example usage for org.eclipse.swt.widgets ScrollBar getMaximum

List of usage examples for org.eclipse.swt.widgets ScrollBar getMaximum

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets ScrollBar getMaximum.

Prototype

public int getMaximum() 

Source Link

Document

Returns the maximum value which the receiver will allow.

Usage

From source file:org.eclipse.swt.snippets.Snippet167.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 167");
    shell.setLayout(new FillLayout());

    final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    Button button1 = new Button(sc1, SWT.PUSH);
    button1.setText("Button 1");
    button1.setSize(400, 300);//w w  w  . ja v  a2 s.  c o  m
    sc1.setContent(button1);

    final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    Button button2 = new Button(sc2, SWT.PUSH);
    button2.setText("Button 2");
    button2.setSize(300, 400);
    sc2.setContent(button2);

    final ScrollBar vBar1 = sc1.getVerticalBar();
    final ScrollBar vBar2 = sc2.getVerticalBar();
    final ScrollBar hBar1 = sc1.getHorizontalBar();
    final ScrollBar hBar2 = sc2.getHorizontalBar();
    SelectionListener listener1 = widgetSelectedAdapter(e -> {
        int x = hBar1.getSelection() * (hBar2.getMaximum() - hBar2.getThumb())
                / Math.max(1, hBar1.getMaximum() - hBar1.getThumb());
        int y = vBar1.getSelection() * (vBar2.getMaximum() - vBar2.getThumb())
                / Math.max(1, vBar1.getMaximum() - vBar1.getThumb());
        sc2.setOrigin(x, y);
    });
    SelectionListener listener2 = widgetSelectedAdapter(e -> {
        int x = hBar2.getSelection() * (hBar1.getMaximum() - hBar1.getThumb())
                / Math.max(1, hBar2.getMaximum() - hBar2.getThumb());
        int y = vBar2.getSelection() * (vBar1.getMaximum() - vBar1.getThumb())
                / Math.max(1, vBar2.getMaximum() - vBar2.getThumb());
        sc1.setOrigin(x, y);
    });
    vBar1.addSelectionListener(listener1);
    hBar1.addSelectionListener(listener1);
    vBar2.addSelectionListener(listener2);
    hBar2.addSelectionListener(listener2);

    shell.setSize(400, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:ScrollBarSelectionListener.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    Button button1 = new Button(sc1, SWT.PUSH);
    button1.setText("Button 1");
    button1.setSize(400, 300);/*from   w w w. j  av a2  s  .com*/
    sc1.setContent(button1);

    final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    Button button2 = new Button(sc2, SWT.PUSH);
    button2.setText("Button 2");
    button2.setSize(300, 400);
    sc2.setContent(button2);

    final ScrollBar vBar1 = sc1.getVerticalBar();
    final ScrollBar vBar2 = sc2.getVerticalBar();
    final ScrollBar hBar1 = sc1.getHorizontalBar();
    final ScrollBar hBar2 = sc2.getHorizontalBar();
    SelectionListener listener1 = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int x = hBar1.getSelection() * (hBar2.getMaximum() - hBar2.getThumb())
                    / Math.max(1, hBar1.getMaximum() - hBar1.getThumb());
            int y = vBar1.getSelection() * (vBar2.getMaximum() - vBar2.getThumb())
                    / Math.max(1, vBar1.getMaximum() - vBar1.getThumb());
            sc2.setOrigin(x, y);
        }
    };
    SelectionListener listener2 = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int x = hBar2.getSelection() * (hBar1.getMaximum() - hBar1.getThumb())
                    / Math.max(1, hBar2.getMaximum() - hBar2.getThumb());
            int y = vBar2.getSelection() * (vBar1.getMaximum() - vBar1.getThumb())
                    / Math.max(1, vBar2.getMaximum() - vBar2.getThumb());
            sc1.setOrigin(x, y);
        }
    };
    vBar1.addSelectionListener(listener1);
    hBar1.addSelectionListener(listener1);
    vBar2.addSelectionListener(listener2);
    hBar2.addSelectionListener(listener2);

    shell.setSize(400, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

void onArrowRight(int stateMask) {
    ScrollBar hBar = getHorizontalBar();
    if (hBar == null)
        return;/*from   w w w  .  ja va2  s.c  o m*/
    int maximum = hBar.getMaximum();
    int clientWidth = clientArea.width;
    if ((horizontalOffset + clientArea.width) == maximum)
        return;
    if (maximum <= clientWidth)
        return;
    int newSelection = Math.min(horizontalOffset + SIZE_HORIZONTALSCROLL, maximum - clientWidth);
    update();
    GC gc = new GC(this);
    gc.copyArea(0, 0, clientArea.width, clientArea.height, horizontalOffset - newSelection, 0);
    gc.dispose();
    if (header.getVisible()) {
        Rectangle headerClientArea = header.getClientArea();
        header.update();
        gc = new GC(header);
        gc.copyArea(0, 0, headerClientArea.width, headerClientArea.height, horizontalOffset - newSelection, 0);
        gc.dispose();
    }
    horizontalOffset = newSelection;
    hBar.setSelection(horizontalOffset);
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

void onResize(Event event) {
    clientArea = getClientArea();/*from  www . j  av a  2 s. c  o  m*/
    /* vertical scrollbar */
    ScrollBar vBar = getVerticalBar();
    if (vBar != null) {
        int clientHeight = (clientArea.height - getHeaderHeight()) / itemHeight;
        int thumb = Math.min(clientHeight, itemsCount);
        vBar.setThumb(thumb);
        vBar.setPageIncrement(thumb);
        int index = vBar.getSelection();
        if (index != topIndex) {
            topIndex = index;
            redraw();
        }
        boolean visible = clientHeight < itemsCount;
        if (visible != vBar.getVisible()) {
            vBar.setVisible(visible);
            clientArea = getClientArea();
        }
    }

    /* horizontal scrollbar */
    ScrollBar hBar = getHorizontalBar();
    if (hBar != null) {
        int hBarMaximum = hBar.getMaximum();
        int thumb = Math.min(clientArea.width, hBarMaximum);
        hBar.setThumb(thumb);
        hBar.setPageIncrement(thumb);
        horizontalOffset = hBar.getSelection();
        boolean visible = clientArea.width < hBarMaximum;
        if (visible != hBar.getVisible()) {
            hBar.setVisible(visible);
            clientArea = getClientArea();
        }
    }

    /* header */
    int headerHeight = Math.max(fontHeight, headerImageHeight) + 2 * getHeaderPadding();
    header.setSize(clientArea.width, headerHeight);

    /* if this is the focus control but there are no items then the boundary focus ring must be repainted */
    if (itemsCount == 0 && isFocusControl())
        redraw();
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

void updateHorizontalBar(int newRightX, int rightXchange) {
    if (drawCount > 0)
        return;/*from   ww w . j av  a2  s. com*/
    ScrollBar hBar = getHorizontalBar();
    if (hBar == null)
        return;

    newRightX += horizontalOffset;
    int barMaximum = hBar.getMaximum();
    if (newRightX > barMaximum) { /* item has extended beyond previous maximum */
        hBar.setMaximum(newRightX);
        int clientAreaWidth = clientArea.width;
        int thumb = Math.min(newRightX, clientAreaWidth);
        hBar.setThumb(thumb);
        hBar.setPageIncrement(thumb);
        hBar.setVisible(clientAreaWidth <= newRightX);
        return;
    }

    int previousRightX = newRightX - rightXchange;
    if (previousRightX != barMaximum) {
        /* this was not the rightmost item, so just check for client width change */
        int clientAreaWidth = clientArea.width;
        int thumb = Math.min(barMaximum, clientAreaWidth);
        hBar.setThumb(thumb);
        hBar.setPageIncrement(thumb);
        hBar.setVisible(clientAreaWidth <= barMaximum);
        return;
    }
    updateHorizontalBar(); /* must search for the new rightmost item */
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

void updateVerticalBar() {
    if (drawCount > 0)
        return;//from ww  w  . j a va 2s.  c om
    ScrollBar vBar = getVerticalBar();
    if (vBar == null)
        return;

    int pageSize = (clientArea.height - getHeaderHeight()) / itemHeight;
    int maximum = Math.max(1, itemsCount); /* setting a value of 0 here is ignored */
    if (maximum != vBar.getMaximum()) {
        vBar.setMaximum(maximum);
    }
    int thumb = Math.min(pageSize, maximum);
    if (thumb != vBar.getThumb()) {
        vBar.setThumb(thumb);
        vBar.setPageIncrement(thumb);
    }
    vBar.setVisible(pageSize < maximum);

    /* reclaim any space now left on the bottom */
    if (maximum < topIndex + thumb) {
        topIndex = maximum - thumb;
        vBar.setSelection(topIndex);
        redraw();
    } else {
        int selection = vBar.getSelection();
        if (selection != topIndex) {
            topIndex = selection;
            redraw();
        }
    }
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

@Override
public void setFont(Font value) {
    checkWidget();//from w w  w .j a v a 2s .  c  om
    Font oldFont = getFont();
    super.setFont(value);
    Font font = getFont();
    if (font.equals(oldFont))
        return;

    GC gc = new GC(this);

    /* recompute the receiver's cached font height and item height values */
    fontHeight = gc.getFontMetrics().getHeight();
    setItemHeight(Math.max(fontHeight, imageHeight) + 2 * getCellPadding());
    Point headerSize = header.getSize();
    int newHeaderHeight = Math.max(fontHeight, headerImageHeight) + 2 * getHeaderPadding();
    if (headerSize.y != newHeaderHeight) {
        header.setSize(headerSize.x, newHeaderHeight);
    }
    header.setFont(font);

    /*
     * Notify all columns and items of the font change so that elements that
     * use the receiver's font can recompute their cached string widths.
     */
    for (CTableColumn column : columns) {
        column.updateFont(gc);
    }
    for (int i = 0; i < itemsCount; i++) {
        items[i].updateFont(gc);
    }

    gc.dispose();

    if (drawCount <= 0 && header.isVisible())
        header.redraw();

    /* update scrollbars */
    if (columns.length == 0)
        updateHorizontalBar();
    ScrollBar vBar = getVerticalBar();
    if (vBar != null) {
        int thumb = (clientArea.height - getHeaderHeight()) / itemHeight;
        vBar.setThumb(thumb);
        vBar.setPageIncrement(thumb);
        topIndex = vBar.getSelection();
        vBar.setVisible(thumb < vBar.getMaximum());
    }
    redraw();
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

void updateHorizontalBar() {
    if (drawCount > 0)
        return;/*from   ww  w .ja  va  2  s.  co m*/
    ScrollBar hBar = getHorizontalBar();
    if (hBar == null)
        return;

    int maxX = 0;
    if (columns.length > 0) {
        for (CTableColumn column : columns) {
            maxX += column.width;
        }
    } else {
        for (int i = 0; i < itemsCount; i++) {
            Rectangle itemBounds = items[i].getCellBounds(0);
            maxX = Math.max(maxX, itemBounds.x + itemBounds.width + horizontalOffset);
        }
    }

    int clientWidth = clientArea.width;
    if (maxX != hBar.getMaximum()) {
        hBar.setMaximum(Math.max(1, maxX)); /* setting a value of 0 here is ignored */
    }
    int thumb = Math.min(clientWidth, maxX);
    if (thumb != hBar.getThumb()) {
        hBar.setThumb(thumb);
        hBar.setPageIncrement(thumb);
    }
    hBar.setVisible(clientWidth < maxX);

    /* reclaim any space now left on the right */
    if (maxX < horizontalOffset + thumb) {
        horizontalOffset = maxX - thumb;
        hBar.setSelection(horizontalOffset);
        redraw();
    } else {
        int selection = hBar.getSelection();
        if (selection != horizontalOffset) {
            horizontalOffset = selection;
            redraw();
        }
    }
}