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

The following examples show how to use org.eclipse.swt.widgets.ScrollBar#getSelection() . 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: ContextDialog.java    From hop with Apache License 2.0 6 votes vote down vote up
private Item findItem( int x, int y ) {
	ScrollBar verticalBar = wCanvas.getVerticalBar();

	int startRow = verticalBar.getSelection();
	int nrColumns = calculateNrColumns();
	int nrRows = calculateNrRows();

	int canvasRow = Math.min( Math.floorDiv( y, cellHeight ), nrRows );
	int canvasColumn = Math.min( Math.floorDiv( x, cellWidth ), nrColumns );

	int index = startRow * calculateNrColumns() + canvasRow * nrColumns + canvasColumn;
	if ( index < 0 || index >= filteredItems.size() ) {
		return null;
	}

	return filteredItems.get( index );
}
 
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
protected void scrollVertical() {
	int areaHeight = getClientArea().height;

	if (gHeight > areaHeight) {
		// image is higher than client area
		ScrollBar bar = getVerticalBar();
		scroll(0, translate - bar.getSelection(), 0, 0,
				getClientArea().width, areaHeight, false);
		translate = bar.getSelection();
	} else {
		translate = 0;
	}
}
 
Example 4
Source File: Gallery.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected void scrollHorizontal() {

		int areaWidth = getClientArea().width;
		if (gWidth > areaWidth) {
			// image is higher than client area
			ScrollBar bar = getHorizontalBar();
			scroll(translate - bar.getSelection(), 0, 0, 0, areaWidth,
					getClientArea().height, false);
			translate = bar.getSelection();
		} else {
			translate = 0;
		}

	}
 
Example 5
Source File: ScrollingSmoother.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void handleEvent(Event event) {
	// Remove standard behavior
	event.doit = false;

	// Get scrollbar on which the event occurred.
	ScrollBar currentScrollBar = getScrollbar(event);

	int start = currentScrollBar.getSelection();
	int end = start;

	// If an effect is currently running, get the current and target
	// values.
	if (me != null) {
		start = me.getCurrent();
		end = me.getEnd();
	}

	end -= event.count * currentScrollBar.getIncrement();

	if (end > currentScrollBar.getMaximum()
			- currentScrollBar.getThumb()) {
		end = currentScrollBar.getMaximum()
				- currentScrollBar.getThumb();
	}

	if (end < currentScrollBar.getMinimum()) {
		end = currentScrollBar.getMinimum();
	}

	startEffect(new MoveScrollBar(currentScrollBar, start, end,
			2000, movement, null, null));

}
 
Example 6
Source File: TagCloud.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private void updateScrollbars() {
	if (zoomLayerImage == null) {
		return;
	}
	Rectangle rect = zoomLayerImage.getBounds();
	Rectangle client = getClientArea();
	ScrollBar hBar = getHorizontalBar();
	ScrollBar vBar = getVerticalBar();
	if (hBar != null) {
		hBar.setMaximum(rect.width);
		hBar.setThumb(Math.min(rect.width, client.width));
		int hPage = rect.width - client.width;
		int hSelection = hBar.getSelection();
		if (hSelection >= hPage) {
			if (hPage <= 0)
				hSelection = 0;
			origin.x = -hSelection;
		}
	}
	if (vBar != null) {
		vBar.setMaximum(rect.height);
		vBar.setThumb(Math.min(rect.height, client.height));
		int vPage = rect.height - client.height;
		int vSelection = vBar.getSelection();
		if (vSelection >= vPage) {
			if (vPage <= 0)
				vSelection = 0;
			origin.y = -vSelection;
		}
	}
}
 
Example 7
Source File: ParameterExpandBar.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public void onScroll(final Event event) {
	final ScrollBar verticalBar = getVerticalBar();
	if (verticalBar != null) {
		yCurrentScroll = verticalBar.getSelection();
		layoutItems(0, false);
	}
}
 
Example 8
Source File: TypeHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void saveState(IMemento memento) {
	if (fPagebook == null) {
		// part has not been created
		if (fMemento != null) { //Keep the old state;
			memento.putMemento(fMemento);
		}
		return;
	}
	if (fInputElements != null) {
		memento.putString(TAG_INPUT, fInputElements[0].getHandleIdentifier());
		for (int i= 1; i < fInputElements.length; i++) {
			IJavaElement element= fInputElements[i];
			memento.putString(TAG_INPUT + i, element.getHandleIdentifier());
		}
	}
	memento.putInteger(TAG_VIEW, getHierarchyMode());
	memento.putInteger(TAG_LAYOUT, getViewLayout());
	memento.putInteger(TAG_QUALIFIED_NAMES, isQualifiedTypeNamesEnabled() ? 1 : 0);
	memento.putInteger(TAG_EDITOR_LINKING, isLinkingEnabled() ? 1 : 0);

	int weigths[]= fTypeMethodsSplitter.getWeights();
	int ratio= (weigths[0] * 1000) / (weigths[0] + weigths[1]);
	memento.putInteger(TAG_RATIO, ratio);

	ScrollBar bar= getCurrentViewer().getTree().getVerticalBar();
	int position= bar != null ? bar.getSelection() : 0;
	memento.putInteger(TAG_VERTICAL_SCROLL, position);

	IJavaElement selection= (IJavaElement)((IStructuredSelection) getCurrentViewer().getSelection()).getFirstElement();
	if (selection != null) {
		memento.putString(TAG_SELECTION, selection.getHandleIdentifier());
	}

	fWorkingSetActionGroup.saveState(memento);

	fMethodsViewer.saveState(memento);
}
 
Example 9
Source File: MethodsViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Saves the state of the filter actions
 * @param memento the memento
 */
public void saveState(IMemento memento) {
	fMemberFilterActionGroup.saveState(memento);

	memento.putString(TAG_SHOWINHERITED, String.valueOf(isShowInheritedMethods()));
	memento.putString(TAG_SORTBYDEFININGTYPE, String.valueOf(isShowDefiningTypes()));

	ScrollBar bar= getTable().getVerticalBar();
	int position= bar != null ? bar.getSelection() : 0;
	memento.putString(TAG_VERTICAL_SCROLL, String.valueOf(position));
}
 
Example 10
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 11
Source File: ImageCanvas.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void scrollHorizontally( ScrollBar scrollBar )
{
	if ( sourceImage == null )
		return;

	AffineTransform af = transform;
	double tx = af.getTranslateX( );
	double select = -scrollBar.getSelection( );
	af.preConcatenate( AffineTransform.getTranslateInstance( select - tx, 0 ) );
	transform = af;
	syncScrollBars( );
}
 
Example 12
Source File: ImageCanvas.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void scrollVertically( ScrollBar scrollBar )
{
	if ( sourceImage == null )
		return;

	AffineTransform af = transform;
	double ty = af.getTranslateY( );
	double select = -scrollBar.getSelection( );
	af.preConcatenate( AffineTransform.getTranslateInstance( 0, select - ty ) );
	transform = af;
	syncScrollBars( );
}
 
Example 13
Source File: CustomPreviewTable.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void widgetSelected( SelectionEvent e )
{
	if ( e.getSource( ) instanceof ScrollBar )
	{
		ScrollBar sb = (ScrollBar) e.getSource( );
		if ( ( sb.getStyle( ) | SWT.H_SCROLL ) == SWT.H_SCROLL )
		{
			if ( iLastProcessedHorizontalScrollPosition == 0 )
			{
				// Initialize the value
				iLastProcessedHorizontalScrollPosition = cnvCells.getVisibleTableWidth( );
			}
			if ( sb.getSelection( ) == iLastProcessedHorizontalScrollPosition )
			{
				return;
			}

			if ( ( sb.getStyle( ) | SWT.H_SCROLL ) == SWT.H_SCROLL )
			{
				// CALCULATE PIXEL SHIFT IN BUTTON POSITION
				int iShift = 0;
				if ( e.detail == SWT.ARROW_UP
						|| e.detail == SWT.PAGE_UP )
				{
					// SHIFT HEADERS ONE COLUMN TO THE RIGHT
					iShift = -SCROLL_HORIZONTAL_STEP;
				}
				else if ( e.detail == SWT.ARROW_DOWN
						|| e.detail == SWT.PAGE_DOWN )
				{
					// SHIFT HEADERS ONE COLUMN TO THE LEFT
					iShift = SCROLL_HORIZONTAL_STEP;
				}
				else
				{
					iShift = sb.getSelection( )
							- iLastProcessedHorizontalScrollPosition;
				}
				iHiddenWidth += iShift;
				// Correction for negative value or overflow
				if ( iHiddenWidth < 0 )
				{
					iShift -= iHiddenWidth;
					iHiddenWidth = 0;
				}
				else if ( iHiddenWidth + getVisibleTableWidth( ) > getMaxTableWidth( ) )
				{
					int diff = getMaxTableWidth( )
							- getVisibleTableWidth( )
							- iHiddenWidth;
					iShift += diff;
					iHiddenWidth += diff;
				}
				// APPLY PIXEL SHIFT TO RELOCATE BUTTONS
				if ( btnHeaders.size( ) > 0 )
				{
					// MOVE ALL BUTTONS TO THE LEFT...AS MUCH AS THE
					// SCROLLING VALUE
					Button btn = btnHeaders.get( 0 );
					( (FormData) btn.getLayoutData( ) ).left = new FormAttachment( 0,
							btn.getLocation( ).x - iShift );
				}
				cmpHeaders.layout( );
				// UPDATE LAST HORIZONTAL SCROLL POSITION
				iLastProcessedHorizontalScrollPosition = sb.getSelection( );
			}
		}
		else
		{
			if ( getVerticalBar( ).getSelection( ) == iLastProcessedVerticalScrollPosition )
			{
				return;
			}

			if ( e.detail == SWT.ARROW_UP || e.detail == SWT.PAGE_UP )
			{
				if ( iVScroll > 0 )
				{
					iVScroll--;
				}
			}
			else if ( e.detail == SWT.ARROW_DOWN
					|| e.detail == SWT.PAGE_DOWN )
			{
				iVScroll++;
			}
			else
			{
				iVScroll += ( sb.getSelection( ) - iLastProcessedVerticalScrollPosition );
			}
			iLastProcessedVerticalScrollPosition = sb.getSelection( );
		}
		redraw( );
	}
}
 
Example 14
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();
    }
}