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

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

Introduction

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

Prototype

public void setMaximum(int maximum) 

Source Link

Document

Sets the maximum.

Usage

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

void updateColumnWidth(CTableColumn column, int width) {
    headerHideToolTip();/*ww w .  jav  a2 s . co 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 updateHorizontalBar(int newRightX, int rightXchange) {
    if (drawCount > 0)
        return;/*from w  w  w .j a v a 2 s  . co m*/
    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;/*w  ww.  ja v  a  2s .com*/
    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;//from   ww w.  j a  va 2s.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 2 s  .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);
        }
    }
}

From source file:CustomControlExample.java

/**
 * Resizes the maximum and thumb of both scrollbars.
 */// w w  w .  jav a2s.  co  m
void resizeScrollBars() {
    Rectangle clientArea = canvas.getClientArea();
    ScrollBar bar = canvas.getHorizontalBar();
    if (bar != null) {
        bar.setMaximum(maxX);
        bar.setThumb(clientArea.width);
        bar.setPageIncrement(clientArea.width);
    }
    bar = canvas.getVerticalBar();
    if (bar != null) {
        bar.setMaximum(maxY);
        bar.setThumb(clientArea.height);
        bar.setPageIncrement(clientArea.height);
    }
}