Java Code Examples for org.eclipse.swt.widgets.ScrollBar#setSelection()

The following examples show how to use org.eclipse.swt.widgets.ScrollBar#setSelection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodsViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Restores the state of the filter actions
 * @param memento the memento
 */
public void restoreState(IMemento memento) {
	fMemberFilterActionGroup.restoreState(memento);
	getControl().setRedraw(false);
	refresh();
	getControl().setRedraw(true);

	boolean showInherited= Boolean.valueOf(memento.getString(TAG_SHOWINHERITED)).booleanValue();
	showInheritedMethods(showInherited);

	boolean showDefiningTypes= Boolean.valueOf(memento.getString(TAG_SORTBYDEFININGTYPE)).booleanValue();
	sortByDefiningType(showDefiningTypes);

	ScrollBar bar= getTable().getVerticalBar();
	if (bar != null) {
		Integer vScroll= memento.getInteger(TAG_VERTICAL_SCROLL);
		if (vScroll != null) {
			bar.setSelection(vScroll.intValue());
		}
	}
}
 
Example 2
Source File: ContextDialog.java    From hop with Apache License 2.0 5 votes vote down vote up
private void selectItem( Item item ) {

		if ( this.selectedItem == item ) {
			return;
		}

		this.selectedItem = item;

		int nrColumns = calculateNrColumns();
		int index = filteredItems.indexOf( item );

		if ( item == null ) {
			wlTooltip.setText( "" );
		} else {
			wlTooltip.setText( Const.NVL( item.getAction().getTooltip(), "" ) );

			ScrollBar bar = wCanvas.getVerticalBar();

			int row = Math.floorDiv( index, nrColumns );


			//	        if ( row >= bar.getSelection()+bar.getPageIncrement() ) {
			//	          // We scrolled down and need to scroll the scrollbar
			//	          //
			//	          bar.setSelection( Math.min(row, bar.getMaximum() ) );
			//	        }
			if ( row < bar.getSelection() ) {
				// We scrolled up and need to scroll the scrollbar up
				//
				bar.setSelection( Math.max( row, bar.getMinimum() ) );
			}
		}

		wCanvas.redraw();
	}
 
Example 3
Source File: Gallery.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Move the scrollbar to reflect the current visible items position.
 * 
 * @param bar
 *            - the scroll bar to move
 * @param clientSize
 *            - Client (visible) area size
 * @param totalSize
 *            - Total Size
 */
private void updateScrollBarProperties(ScrollBar bar, int clientSize,
		int totalSize) {
	if (bar == null)
		return;

	bar.setMinimum(0);
	bar.setPageIncrement(clientSize);
	bar.setMaximum(totalSize);
	bar.setThumb(clientSize);

	// Let the group renderer use a custom increment value.
	if (groupRenderer != null)
		bar.setIncrement(groupRenderer.getScrollBarIncrement());

	if (totalSize > clientSize) {
		if (DEBUG)
			System.out.println("Enabling scrollbar"); //$NON-NLS-1$

		bar.setEnabled(true);
		bar.setVisible(true);
		bar.setSelection(translate);

		// Ensure that translate has a valid value.
		validateTranslation();
	} else {
		if (DEBUG)
			System.out.println("Disabling scrollbar"); //$NON-NLS-1$

		bar.setEnabled(false);
		bar.setVisible(false);
		bar.setSelection(0);
		translate = 0;
	}

}
 
Example 4
Source File: CustomPreviewTable.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void scrollTable( ScrollBar widget, KeyEvent event )
{
	int newSelectionValue = widget.getSelection( );
	if ( event.keyCode == SWT.ARROW_LEFT )
	{
		newSelectionValue -= TableCanvas.SCROLL_HORIZONTAL_STEP;
	}
	else if ( event.keyCode == SWT.ARROW_RIGHT )
	{
		newSelectionValue += TableCanvas.SCROLL_HORIZONTAL_STEP;
	}
	else if ( event.keyCode == SWT.PAGE_UP 
			|| event.keyCode == SWT.ARROW_UP )
	{
		newSelectionValue -= 1;
	}
	else if ( event.keyCode == SWT.PAGE_DOWN
			|| event.keyCode == SWT.ARROW_DOWN )
	{
		newSelectionValue += 1;
	}

	if ( newSelectionValue < widget.getMinimum( ) )
	{
		newSelectionValue = widget.getMinimum( );
	}
	else if ( newSelectionValue > widget.getMaximum( ) )
	{
		newSelectionValue = widget.getMaximum( );
	}

	widget.setSelection( newSelectionValue );
	Event newEvent = new Event( );
	newEvent.widget = widget;
	newEvent.type = SWT.Selection;
	newEvent.data = event.data;
	widget.notifyListeners( SWT.Selection, newEvent );
}
 
Example 5
Source File: ScrollView.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Setup scroll bar using contents, visible and scroll bar mode properties.
 */
protected void updateScrollBarsValues() {
    /* update vertical scrollbar */
    ScrollBar b = getVerticalBar();
    if (b != null) {
        b.setMinimum(0);
        b.setMaximum(getContentsHeight());
        b.setThumb(getVisibleHeight());
        b.setPageIncrement(getVisibleHeight());
        b.setIncrement(fVertScrollbarIncrement);
        b.setSelection(getContentsY());
    }

    // update "hidden" vertical bar too
    b = fViewControl.getVerticalBar();
    if (b != null) {
        b.setMinimum(0);
        b.setMaximum(getContentsHeight());
        b.setThumb(getVisibleHeight());
        b.setPageIncrement(getVisibleHeight());
        b.setIncrement(fVertScrollbarIncrement);
        b.setSelection(getContentsY());
    }

    /* update horizontal scrollbar */
    b = getHorizontalBar();
    if (b != null) {
        b.setMinimum(0);
        b.setMaximum(getContentsWidth());
        b.setThumb(getVisibleWidth());
        b.setSelection(getContentsX());
        b.setPageIncrement(getVisibleWidth());
        b.setIncrement(fHorScrollbarIncrement);
    }
    // update "hidden" horizontal bar too
    b = fViewControl.getHorizontalBar();
    if (b != null) {
        b.setMinimum(0);
        b.setMaximum(getContentsWidth());
        b.setThumb(getVisibleWidth());
        b.setSelection(getContentsX());
        b.setPageIncrement(getVisibleWidth());
        b.setIncrement(fHorScrollbarIncrement);
    }
}
 
Example 6
Source File: TypeHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Restores the state of the type hierarchy view from the memento.
 * 
 * @param memento the memento
 * @param input the input java elements
 * @since 3.7
 */
final void doRestoreState(IMemento memento, IJavaElement[] input) {
	synchronized (this) {
		if (fRestoreStateJob == null) {
			return;
		}
		fRestoreStateJob= null;
	}

	fWorkingSetActionGroup.restoreState(memento);
	setKeepShowingEmptyViewers(false);
	setInputElements(input);

	Integer viewerIndex= memento.getInteger(TAG_VIEW);
	if (viewerIndex != null) {
		setHierarchyMode(viewerIndex.intValue());
	}
	Integer layout= memento.getInteger(TAG_LAYOUT);
	if (layout != null) {
		setViewLayout(layout.intValue());
	}

	Integer val= memento.getInteger(TAG_EDITOR_LINKING);
	if (val != null) {
		setLinkingEnabled(val.intValue() != 0);
	}

	Integer showQualified= memento.getInteger(TAG_QUALIFIED_NAMES);
	if (showQualified != null) {
		showQualifiedTypeNames(showQualified.intValue() != 0);
	}

	updateCheckedState();

	Integer ratio= memento.getInteger(TAG_RATIO);
	if (ratio != null) {
		fTypeMethodsSplitter.setWeights(new int[] { ratio.intValue(), 1000 - ratio.intValue() });
	}
	ScrollBar bar= getCurrentViewer().getTree().getVerticalBar();
	if (bar != null) {
		Integer vScroll= memento.getInteger(TAG_VERTICAL_SCROLL);
		if (vScroll != null) {
			bar.setSelection(vScroll.intValue());
		}
	}
	fMethodsViewer.restoreState(memento);
}
 
Example 7
Source File: IconCanvas.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * SYNC the scroll-bars with the image.
 */
public void syncScrollBars( )
{
	if ( sourceImage == null )
	{
		redraw( );
		return;
	}

	AffineTransform af = transform;
	double sx = af.getScaleX( ), sy = af.getScaleY( );
	double tx = af.getTranslateX( ), ty = af.getTranslateY( );
	if ( tx > 0 )
		tx = 0;
	if ( ty > 0 )
		ty = 0;

	Rectangle imageBound = sourceImage.getBounds( );
	int cw = getClientArea( ).width, ch = getClientArea( ).height;

	ScrollBar horizontal = getHorizontalBar( );

	if ( horizontal != null )
	{
		horizontal.setIncrement( ( getClientArea( ).width / 100 ) );
		horizontal.setPageIncrement( getClientArea( ).width );

		if ( imageBound.width * sx > cw )
		{
			horizontal.setMaximum( (int) ( imageBound.width * sx ) );
			horizontal.setEnabled( true );
			if ( ( (int) -tx ) > horizontal.getMaximum( ) - cw )
				tx = -horizontal.getMaximum( ) + cw;
		}
		else
		{
			horizontal.setEnabled( false );
			tx = ( cw - imageBound.width * sx ) / 2;
		}
		horizontal.setSelection( (int) ( -tx ) );
		horizontal.setThumb( ( getClientArea( ).width ) );
	}
	ScrollBar vertical = getVerticalBar( );
	if ( vertical != null )
	{
		vertical.setIncrement( ( getClientArea( ).height / 100 ) );
		vertical.setPageIncrement( ( getClientArea( ).height ) );
		if ( imageBound.height * sy > ch )
		{
			vertical.setMaximum( (int) ( imageBound.height * sy ) );
			vertical.setEnabled( true );
			if ( ( (int) -ty ) > vertical.getMaximum( ) - ch )
				ty = -vertical.getMaximum( ) + ch;
		}
		else
		{
			vertical.setEnabled( false );
			ty = ( ch - imageBound.height * sy ) / 2;
		}
		vertical.setSelection( (int) ( -ty ) );
		vertical.setThumb( ( getClientArea( ).height ) );
	}

	af = AffineTransform.getScaleInstance( sx, sy );
	af.preConcatenate( AffineTransform.getTranslateInstance( tx, ty ) );
	transform = af;

	redraw( );
}
 
Example 8
Source File: ImageCanvas.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * SYNC the scroll-bars with the image.
 */
public void syncScrollBars( )
{
	if ( sourceImage == null )
	{
		redraw( );
		return;
	}

	AffineTransform af = transform;
	double sx = af.getScaleX( ), sy = af.getScaleY( );
	double tx = af.getTranslateX( ), ty = af.getTranslateY( );
	if ( tx > 0 )
		tx = 0;
	if ( ty > 0 )
		ty = 0;

	Rectangle imageBound = sourceImage.getBounds( );
	int cw = getClientArea( ).width, ch = getClientArea( ).height;

	ScrollBar horizontal = getHorizontalBar( );

	if ( horizontal != null )
	{
		horizontal.setIncrement( (int) ( getClientArea( ).width / 100 ) );
		horizontal.setPageIncrement( getClientArea( ).width );

		if ( imageBound.width * sx > cw )
		{
			horizontal.setMaximum( (int) ( imageBound.width * sx ) );
			horizontal.setEnabled( true );
			if ( ( (int) -tx ) > horizontal.getMaximum( ) - cw )
				tx = -horizontal.getMaximum( ) + cw;
		}
		else
		{
			horizontal.setEnabled( false );
			tx = ( cw - imageBound.width * sx ) / 2;
		}
		horizontal.setSelection( (int) ( -tx ) );
		horizontal.setThumb( (int) ( getClientArea( ).width ) );
	}
	ScrollBar vertical = getVerticalBar( );
	if ( vertical != null )
	{
		vertical.setIncrement( (int) ( getClientArea( ).height / 100 ) );
		vertical.setPageIncrement( (int) ( getClientArea( ).height ) );
		if ( imageBound.height * sy > ch )
		{
			vertical.setMaximum( (int) ( imageBound.height * sy ) );
			vertical.setEnabled( true );
			if ( ( (int) -ty ) > vertical.getMaximum( ) - ch )
				ty = -vertical.getMaximum( ) + ch;
		}
		else
		{
			vertical.setEnabled( false );
			ty = ( ch - imageBound.height * sy ) / 2;
		}
		vertical.setSelection( (int) ( -ty ) );
		vertical.setThumb( (int) ( getClientArea( ).height ) );
	}

	af = AffineTransform.getScaleInstance( sx, sy );
	af.preConcatenate( AffineTransform.getTranslateInstance( tx, ty ) );
	transform = af;

	redraw( );
}
 
Example 9
Source File: BaseOutlinePage.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * called when model has structural changes, refreshes all items underneath
 * @param items: items to refresh, or null for the whole tree
 * tries to preserve the scrolling
 */
public void refreshItems(Object[] items) {
    try {
        unlinkAll();
        TreeViewer viewer = getTreeViewer();
        if (viewer != null) {
            Tree treeWidget = viewer.getTree();
            if (isDisconnectedFromTree()) {
                return;
            }

            ScrollBar bar = treeWidget.getVerticalBar();
            int barPosition = 0;
            if (bar != null) {
                barPosition = bar.getSelection();
            }
            if (items == null) {
                if (isDisconnectedFromTree()) {
                    return;
                }
                viewer.refresh();

            } else {
                if (isDisconnectedFromTree()) {
                    return;
                }
                for (int i = 0; i < items.length; i++) {
                    viewer.refresh(items[i]);
                }
            }

            if (barPosition != 0) {
                bar.setSelection(Math.min(bar.getMaximum(), barPosition));
            }
        }
    } catch (Throwable e) {
        //things may be disposed...
        Log.log(e);
    } finally {
        relinkAll();
    }
}