List of usage examples for org.eclipse.swt.widgets ScrollBar getThumb
public int getThumb()
From source file:org.eclipse.swt.snippets.Snippet167.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 167"); shell.setLayout(new FillLayout()); final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button1 = new Button(sc1, SWT.PUSH); button1.setText("Button 1"); button1.setSize(400, 300);//w w w .j a v a2 s .c om sc1.setContent(button1); final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button2 = new Button(sc2, SWT.PUSH); button2.setText("Button 2"); button2.setSize(300, 400); sc2.setContent(button2); final ScrollBar vBar1 = sc1.getVerticalBar(); final ScrollBar vBar2 = sc2.getVerticalBar(); final ScrollBar hBar1 = sc1.getHorizontalBar(); final ScrollBar hBar2 = sc2.getHorizontalBar(); SelectionListener listener1 = widgetSelectedAdapter(e -> { int x = hBar1.getSelection() * (hBar2.getMaximum() - hBar2.getThumb()) / Math.max(1, hBar1.getMaximum() - hBar1.getThumb()); int y = vBar1.getSelection() * (vBar2.getMaximum() - vBar2.getThumb()) / Math.max(1, vBar1.getMaximum() - vBar1.getThumb()); sc2.setOrigin(x, y); }); SelectionListener listener2 = widgetSelectedAdapter(e -> { int x = hBar2.getSelection() * (hBar1.getMaximum() - hBar1.getThumb()) / Math.max(1, hBar2.getMaximum() - hBar2.getThumb()); int y = vBar2.getSelection() * (vBar1.getMaximum() - vBar1.getThumb()) / Math.max(1, vBar2.getMaximum() - vBar2.getThumb()); sc1.setOrigin(x, y); }); vBar1.addSelectionListener(listener1); hBar1.addSelectionListener(listener1); vBar2.addSelectionListener(listener2); hBar2.addSelectionListener(listener2); shell.setSize(400, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:ScrollBarSelectionListener.java
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final ScrolledComposite sc1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button1 = new Button(sc1, SWT.PUSH); button1.setText("Button 1"); button1.setSize(400, 300);/* ww w .jav a 2s.c o m*/ sc1.setContent(button1); final ScrolledComposite sc2 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); Button button2 = new Button(sc2, SWT.PUSH); button2.setText("Button 2"); button2.setSize(300, 400); sc2.setContent(button2); final ScrollBar vBar1 = sc1.getVerticalBar(); final ScrollBar vBar2 = sc2.getVerticalBar(); final ScrollBar hBar1 = sc1.getHorizontalBar(); final ScrollBar hBar2 = sc2.getHorizontalBar(); SelectionListener listener1 = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int x = hBar1.getSelection() * (hBar2.getMaximum() - hBar2.getThumb()) / Math.max(1, hBar1.getMaximum() - hBar1.getThumb()); int y = vBar1.getSelection() * (vBar2.getMaximum() - vBar2.getThumb()) / Math.max(1, vBar1.getMaximum() - vBar1.getThumb()); sc2.setOrigin(x, y); } }; SelectionListener listener2 = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int x = hBar2.getSelection() * (hBar1.getMaximum() - hBar1.getThumb()) / Math.max(1, hBar2.getMaximum() - hBar2.getThumb()); int y = vBar2.getSelection() * (vBar1.getMaximum() - vBar1.getThumb()) / Math.max(1, vBar2.getMaximum() - vBar2.getThumb()); sc1.setOrigin(x, y); } }; vBar1.addSelectionListener(listener1); hBar1.addSelectionListener(listener1); vBar2.addSelectionListener(listener2); hBar2.addSelectionListener(listener2); shell.setSize(400, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.examples.accessibility.CTable.java
void updateColumnWidth(CTableColumn column, int width) { headerHideToolTip();/* w w w . j a va 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 w ww . j a v a2 s .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 . java2 s. c o 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(); } } }