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

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

Introduction

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

Prototype

public int getSelection() 

Source Link

Document

Returns the single 'selection' that is the receiver's value.

Usage

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

void destroyItem(CTableColumn column) {
    headerHideToolTip();/*from   w  ww .  ja  v a2  s.  c  o m*/
    int index = column.getIndex();
    int orderedIndex = column.getOrderIndex();

    CTableColumn[] newColumns = new CTableColumn[columns.length - 1];
    System.arraycopy(columns, 0, newColumns, 0, index);
    System.arraycopy(columns, index + 1, newColumns, index, newColumns.length - index);
    columns = newColumns;

    if (orderedColumns != null) {
        if (columns.length < 2) {
            orderedColumns = null;
        } else {
            int removeIndex = column.getOrderIndex();
            CTableColumn[] newOrderedColumns = new CTableColumn[orderedColumns.length - 1];
            System.arraycopy(orderedColumns, 0, newOrderedColumns, 0, removeIndex);
            System.arraycopy(orderedColumns, removeIndex + 1, newOrderedColumns, removeIndex,
                    newOrderedColumns.length - removeIndex);
            orderedColumns = newOrderedColumns;
        }
    }

    /* ensure that column 0 always has left-alignment */
    if (index == 0 && columns.length > 0) {
        int style = columns[0].getStyle();
        style |= SWT.LEFT;
        style &= ~(SWT.CENTER | SWT.RIGHT);
        columns[0].setStyle(style);
    }

    /* allow all items to update their internal structures accordingly */
    for (int i = 0; i < itemsCount; i++) {
        items[i].removeColumn(column, index);
    }

    /* update horizontal scrollbar */
    int lastColumnIndex = columns.length - 1;
    if (lastColumnIndex < 0) { /* no more columns */
        updateHorizontalBar();
    } else {
        int newWidth = 0;
        for (CTableColumn column2 : columns) {
            newWidth += column2.width;
        }
        ScrollBar hBar = getHorizontalBar();
        if (hBar != null) {
            hBar.setMaximum(newWidth);
            hBar.setVisible(clientArea.width < newWidth);
        }
        int selection = hBar.getSelection();
        if (selection != horizontalOffset) {
            horizontalOffset = selection;
            redraw();
            if (header.isVisible() && drawCount <= 0)
                header.redraw();
        }
    }
    CTableColumn[] orderedColumns = getOrderedColumns();
    for (int i = orderedIndex; i < orderedColumns.length; i++) {
        if (!orderedColumns[i].isDisposed()) {
            orderedColumns[i].notifyListeners(SWT.Move, new Event());
        }
    }

    int[] eventData = new int[5];
    eventData[0] = ACC.DELETE;
    eventData[1] = 0;
    eventData[2] = 0;
    eventData[3] = index;
    eventData[4] = 1;
    getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);

    if (sortColumn == column) {
        sortColumn = null;
    }
}

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

void onResize(Event event) {
    clientArea = getClientArea();//from ww  w .  ja v a  2  s .com
    /* 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 updateColumnWidth(CTableColumn column, int width) {
    headerHideToolTip();/* w w  w  . j av a  2 s.c  o m*/
    int oldWidth = column.width;
    int columnX = column.getX();
    int x = columnX + oldWidth - 1; /* -1 ensures that grid line is included */

    update();
    GC gc = new GC(this);
    gc.copyArea(x, 0, clientArea.width - x, clientArea.height, columnX + width - 1,
            0); /* dest x -1 offsets x's -1 above */
    if (width > oldWidth) {
        /* column width grew */
        int change = width - oldWidth + 1; /* +1 offsets x's -1 above */
        /* -1/+1 below ensure that right bound of selection redraws correctly in column */
        redraw(x - 1, 0, change + 1, clientArea.height, false);
    } else {
        int change = oldWidth - width + 1; /* +1 offsets x's -1 above */
        redraw(clientArea.width - change, 0, change, clientArea.height, false);
    }
    /* the focus box must be repainted because its stipple may become shifted as a result of its new width */
    if (focusItem != null)
        redrawItem(focusItem.index, true);

    GC headerGC = new GC(header);
    if (drawCount <= 0 && header.getVisible()) {
        Rectangle headerBounds = header.getClientArea();
        header.update();
        x -= 1; /* -1 ensures that full header column separator is included */
        headerGC.copyArea(x, 0, headerBounds.width - x, headerBounds.height, columnX + width - 2,
                0); /* dest x -2 offsets x's -1s above */
        if (width > oldWidth) {
            /* column width grew */
            int change = width - oldWidth + 2; /* +2 offsets x's -1s above */
            header.redraw(x, 0, change, headerBounds.height, false);
        } else {
            int change = oldWidth - width + 2; /* +2 offsets x's -1s above */
            header.redraw(headerBounds.width - change, 0, change, headerBounds.height, false);
        }
    }

    column.width = width;

    /*
     * Notify column and all items of column width change so that display labels
     * can be recomputed if needed.
     */
    column.updateWidth(headerGC);
    headerGC.dispose();
    for (int i = 0; i < itemsCount; i++) {
        items[i].updateColumnWidth(column, gc);
    }
    gc.dispose();

    int maximum = 0;
    for (CTableColumn column2 : columns) {
        maximum += column2.width;
    }
    ScrollBar hBar = getHorizontalBar();
    if (hBar != null) {
        hBar.setMaximum(Math.max(1, maximum)); /* setting a value of 0 here is ignored */
        if (hBar.getThumb() != clientArea.width) {
            hBar.setThumb(clientArea.width);
            hBar.setPageIncrement(clientArea.width);
        }
        int oldHorizontalOffset = horizontalOffset; /* hBar.setVisible() can modify horizontalOffset */
        hBar.setVisible(clientArea.width < maximum);
        int selection = hBar.getSelection();
        if (selection != oldHorizontalOffset) {
            horizontalOffset = selection;
            redraw();
            if (drawCount <= 0 && header.getVisible())
                header.redraw();
        }
    }

    column.notifyListeners(SWT.Resize, new Event());
    CTableColumn[] orderedColumns = getOrderedColumns();
    for (int i = column.getOrderIndex() + 1; i < orderedColumns.length; i++) {
        if (!orderedColumns[i].isDisposed()) {
            orderedColumns[i].notifyListeners(SWT.Move, new Event());
        }
    }

    if (itemsCount == 0)
        redraw(); /* ensure that static focus rectangle updates properly */
}

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

void updateVerticalBar() {
    if (drawCount > 0)
        return;/*from   ww w . j a va  2s .c  o m*/
    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

void updateHorizontalBar() {
    if (drawCount > 0)
        return;/*  w  w  w  .java  2s . 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();
        }
    }
}

From source file:CustomControlExample.java

/**
 * Scrolls the canvas horizontally.// w  w w  .  j  ava2s.  c o  m
 * 
 * @param scrollBar
 */
void scrollHorizontal(ScrollBar scrollBar) {
    Rectangle bounds = canvas.getClientArea();
    int x = -scrollBar.getSelection();
    if (x + maxX < bounds.width) {
        x = bounds.width - maxX;
    }
    canvas.scroll(x, cy, cx, cy, maxX, maxY, false);
    cx = x;
}

From source file:CustomControlExample.java

/**
 * Scrolls the canvas vertically./*from   w ww. j  a  v a 2 s  . co m*/
 * 
 * @param scrollBar
 */
void scrollVertical(ScrollBar scrollBar) {
    Rectangle bounds = canvas.getClientArea();
    int y = -scrollBar.getSelection();
    if (y + maxY < bounds.height) {
        y = bounds.height - maxY;
    }
    canvas.scroll(cx, y, cx, cy, maxX, maxY, false);
    cy = y;
}