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

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

Introduction

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

Prototype

public void setSelection(int selection) 

Source Link

Document

Sets the single selection that is the receiver's value to the argument which must be greater than or equal to zero.

Usage

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

void onArrowRight(int stateMask) {
    ScrollBar hBar = getHorizontalBar();
    if (hBar == null)
        return;//  w  w  w . j  a va 2 s  . c  om
    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 updateHorizontalBar() {
    if (drawCount > 0)
        return;//www .  j  av  a2 s .  c  om
    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:PrintKTableExample.java

protected void doCalculations() {
    if (m_Model == null) {
        ScrollBar sb = getHorizontalBar();
        if (sb != null) {
            sb.setMinimum(0);//from   w w w.  j av a  2s . c o m
            sb.setMaximum(1);
            sb.setPageIncrement(1);
            sb.setThumb(1);
            sb.setSelection(1);
        }
        sb = getVerticalBar();
        if (sb != null) {
            sb.setMinimum(0);
            sb.setMaximum(1);
            sb.setPageIncrement(1);
            sb.setThumb(1);
            sb.setSelection(1);
        }
        return;
    }

    int m_HeaderHeight = m_Model.getFirstRowHeight();
    int m_RowHeight = m_Model.getRowHeight();

    Rectangle rect = getClientArea();
    if (m_LeftColumn < m_Model.getFixedColumnCount()) {
        m_LeftColumn = m_Model.getFixedColumnCount();
    }

    if (m_TopRow < m_Model.getFixedRowCount()) {
        m_TopRow = m_Model.getFixedRowCount();
    }

    int fixedWidth = getFixedWidth();
    int fixedHeight = m_HeaderHeight + (m_Model.getFixedRowCount() - 1) * m_Model.getRowHeight();
    m_ColumnsVisible = 0;
    m_ColumnsFullyVisible = 0;

    if (m_Model.getColumnCount() > m_Model.getFixedColumnCount()) {
        int runningWidth = getColumnLeft(m_LeftColumn);
        for (int col = m_LeftColumn; col < m_Model.getColumnCount(); col++) {
            if (runningWidth < rect.width + rect.x)
                m_ColumnsVisible++;
            runningWidth += m_Model.getColumnWidth(col);
            if (runningWidth < rect.width + rect.x)
                m_ColumnsFullyVisible++;
            else
                break;
        }
    }

    ScrollBar sb = getHorizontalBar();
    if (sb != null) {
        if (m_Model.getColumnCount() <= m_Model.getFixedColumnCount()) {
            sb.setMinimum(0);
            sb.setMaximum(1);
            sb.setPageIncrement(1);
            sb.setThumb(1);
            sb.setSelection(1);
        } else {
            sb.setMinimum(m_Model.getFixedColumnCount());
            sb.setMaximum(m_Model.getColumnCount());
            sb.setIncrement(1);
            sb.setPageIncrement(2);
            sb.setThumb(m_ColumnsFullyVisible);
            sb.setSelection(m_LeftColumn);
        }
    }

    m_RowsFullyVisible = Math.max(0, (rect.height - fixedHeight) / m_RowHeight);
    m_RowsFullyVisible = Math.min(m_RowsFullyVisible, m_Model.getRowCount() - m_Model.getFixedRowCount());
    m_RowsFullyVisible = Math.max(0, m_RowsFullyVisible);

    m_RowsVisible = m_RowsFullyVisible + 1;

    if (m_TopRow + m_RowsFullyVisible > m_Model.getRowCount()) {
        m_TopRow = Math.max(m_Model.getFixedRowCount(), m_Model.getRowCount() - m_RowsFullyVisible);
    }

    if (m_TopRow + m_RowsFullyVisible >= m_Model.getRowCount()) {
        m_RowsVisible--;
    }

    sb = getVerticalBar();
    if (sb != null) {
        if (m_Model.getRowCount() <= m_Model.getFixedRowCount()) {
            sb.setMinimum(0);
            sb.setMaximum(1);
            sb.setPageIncrement(1);
            sb.setThumb(1);
            sb.setSelection(1);
        } else {
            sb.setMinimum(m_Model.getFixedRowCount());
            sb.setMaximum(m_Model.getRowCount());
            sb.setPageIncrement(m_RowsVisible);
            sb.setIncrement(1);
            sb.setThumb(m_RowsFullyVisible);
            sb.setSelection(m_TopRow);
        }
    }
}