Search in sources :

Example 16 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.

the class PaintSurface method handleResize.

/**
 * Handles resize events
 */
private void handleResize() {
    paintCanvas.update();
    Rectangle visibleRect = paintCanvas.getClientArea();
    visibleWidth = visibleRect.width;
    visibleHeight = visibleRect.height;
    ScrollBar horizontal = paintCanvas.getHorizontalBar();
    if (horizontal != null) {
        displayFDC.xOffset = Math.min(horizontal.getSelection(), imageWidth - visibleWidth);
        if (imageWidth <= visibleWidth) {
            horizontal.setEnabled(false);
            horizontal.setSelection(0);
        } else {
            horizontal.setEnabled(true);
            horizontal.setValues(displayFDC.xOffset, 0, imageWidth, visibleWidth, 8, visibleWidth);
        }
    }
    ScrollBar vertical = paintCanvas.getVerticalBar();
    if (vertical != null) {
        displayFDC.yOffset = Math.min(vertical.getSelection(), imageHeight - visibleHeight);
        if (imageHeight <= visibleHeight) {
            vertical.setEnabled(false);
            vertical.setSelection(0);
        } else {
            vertical.setEnabled(true);
            vertical.setValues(displayFDC.yOffset, 0, imageHeight, visibleHeight, 8, visibleHeight);
        }
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 17 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.

the class CTable method destroyItem.

void destroyItem(CTableColumn column) {
    headerHideToolTip();
    int index = column.getIndex();
    int orderedIndex = column.getOrderIndex();
    CTableColumn[] newColumns = new CTableColumn[columns.length - 1];
    System.arraycopy(columns, 0, newColumns, 0, index);
    System.arraycopy(columns, index + 1, newColumns, index, newColumns.length - index);
    columns = newColumns;
    if (orderedColumns != null) {
        if (columns.length < 2) {
            orderedColumns = null;
        } else {
            int removeIndex = column.getOrderIndex();
            CTableColumn[] newOrderedColumns = new CTableColumn[orderedColumns.length - 1];
            System.arraycopy(orderedColumns, 0, newOrderedColumns, 0, removeIndex);
            System.arraycopy(orderedColumns, removeIndex + 1, newOrderedColumns, removeIndex, newOrderedColumns.length - removeIndex);
            orderedColumns = newOrderedColumns;
        }
    }
    /* ensure that column 0 always has left-alignment */
    if (index == 0 && columns.length > 0) {
        int style = columns[0].getStyle();
        style |= SWT.LEFT;
        style &= ~(SWT.CENTER | SWT.RIGHT);
        columns[0].setStyle(style);
    }
    /* allow all items to update their internal structures accordingly */
    for (int i = 0; i < itemsCount; i++) {
        items[i].removeColumn(column, index);
    }
    /* update horizontal scrollbar */
    int lastColumnIndex = columns.length - 1;
    if (lastColumnIndex < 0) {
        /* no more columns */
        updateHorizontalBar();
    } else {
        int newWidth = 0;
        for (CTableColumn column2 : columns) {
            newWidth += column2.width;
        }
        ScrollBar hBar = getHorizontalBar();
        if (hBar != null) {
            hBar.setMaximum(newWidth);
            hBar.setVisible(clientArea.width < newWidth);
        }
        int selection = hBar.getSelection();
        if (selection != horizontalOffset) {
            horizontalOffset = selection;
            redraw();
            if (header.isVisible() && drawCount <= 0)
                header.redraw();
        }
    }
    CTableColumn[] orderedColumns = getOrderedColumns();
    for (int i = orderedIndex; i < orderedColumns.length; i++) {
        if (!orderedColumns[i].isDisposed()) {
            orderedColumns[i].notifyListeners(SWT.Move, new Event());
        }
    }
    int[] eventData = new int[5];
    eventData[0] = ACC.DELETE;
    eventData[1] = 0;
    eventData[2] = 0;
    eventData[3] = index;
    eventData[4] = 1;
    getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);
    if (sortColumn == column) {
        sortColumn = null;
    }
}
Also used : Event(org.eclipse.swt.widgets.Event) AccessibleControlEvent(org.eclipse.swt.accessibility.AccessibleControlEvent) AccessibleTableEvent(org.eclipse.swt.accessibility.AccessibleTableEvent) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 18 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.

the class CTable method showColumn.

/**
 * Shows the column.  If the column is already showing in the receiver,
 * this method simply returns.  Otherwise, the columns are scrolled until
 * the column is visible.
 *
 * @param column the column to be shown
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT - if the column is null</li>
 *    <li>ERROR_INVALID_ARGUMENT - if the column has been disposed</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 *
 * @since 3.0
 */
public void showColumn(CTableColumn column) {
    checkWidget();
    if (column == null)
        SWT.error(SWT.ERROR_NULL_ARGUMENT);
    if (column.isDisposed())
        SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    if (column.parent != this)
        return;
    int x = column.getX();
    int rightX = x + column.width;
    if (0 <= x && rightX <= clientArea.width)
        return;
    /* column is fully visible */
    headerHideToolTip();
    int absX = 0;
    /* the X of the column irrespective of the horizontal scroll */
    CTableColumn[] orderedColumns = getOrderedColumns();
    for (int i = 0; i < column.getOrderIndex(); i++) {
        absX += orderedColumns[i].width;
    }
    if (x < clientArea.x) {
        /* column is to left of viewport */
        horizontalOffset = absX;
    } else {
        horizontalOffset = absX + column.width - clientArea.width;
    }
    ScrollBar hBar = getHorizontalBar();
    if (hBar != null)
        hBar.setSelection(horizontalOffset);
    redraw();
    if (drawCount <= 0 && header.isVisible())
        header.redraw();
}
Also used : Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 19 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.

the class CanvasTab method createExampleWidgets.

/**
 * Creates the "Example" widgets.
 */
@Override
void createExampleWidgets() {
    /* Compute the widget style */
    int style = getDefaultStyle();
    if (horizontalButton.getSelection())
        style |= SWT.H_SCROLL;
    if (verticalButton.getSelection())
        style |= SWT.V_SCROLL;
    if (borderButton.getSelection())
        style |= SWT.BORDER;
    if (noBackgroundButton.getSelection())
        style |= SWT.NO_BACKGROUND;
    if (noFocusButton.getSelection())
        style |= SWT.NO_FOCUS;
    if (noMergePaintsButton.getSelection())
        style |= SWT.NO_MERGE_PAINTS;
    if (noRedrawResizeButton.getSelection())
        style |= SWT.NO_REDRAW_RESIZE;
    if (doubleBufferedButton.getSelection())
        style |= SWT.DOUBLE_BUFFERED;
    /* Create the example widgets */
    paintCount = 0;
    cx = 0;
    cy = 0;
    canvas = new Canvas(canvasGroup, style);
    canvas.addPaintListener(e -> {
        paintCount++;
        GC gc = e.gc;
        if (fillDamageButton.getSelection()) {
            Color color = e.display.getSystemColor(colors[paintCount % colors.length]);
            gc.setBackground(color);
            gc.fillRectangle(e.x, e.y, e.width, e.height);
        }
        Point size = canvas.getSize();
        gc.drawArc(cx + 1, cy + 1, size.x - 2, size.y - 2, 0, 360);
        gc.drawRectangle(cx + (size.x - 10) / 2, cy + (size.y - 10) / 2, 10, 10);
        Point extent = gc.textExtent(canvasString);
        gc.drawString(canvasString, cx + (size.x - extent.x) / 2, cy - extent.y + (size.y - 10) / 2, true);
    });
    canvas.addControlListener(ControlListener.controlResizedAdapter(e -> {
        Point size = canvas.getSize();
        maxX = size.x * 3 / 2;
        maxY = size.y * 3 / 2;
        resizeScrollBars();
    }));
    ScrollBar bar = canvas.getHorizontalBar();
    if (bar != null) {
        hookListeners(bar);
        bar.addSelectionListener(widgetSelectedAdapter(event -> scrollHorizontal((ScrollBar) event.widget)));
    }
    bar = canvas.getVerticalBar();
    if (bar != null) {
        hookListeners(bar);
        bar.addSelectionListener(widgetSelectedAdapter(event -> scrollVertical((ScrollBar) event.widget)));
    }
}
Also used : TabFolder(org.eclipse.swt.widgets.TabFolder) Button(org.eclipse.swt.widgets.Button) Rectangle(org.eclipse.swt.graphics.Rectangle) Caret(org.eclipse.swt.widgets.Caret) ControlListener(org.eclipse.swt.events.ControlListener) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Group(org.eclipse.swt.widgets.Group) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) Color(org.eclipse.swt.graphics.Color) Composite(org.eclipse.swt.widgets.Composite) SWT(org.eclipse.swt.SWT) Canvas(org.eclipse.swt.widgets.Canvas) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) Widget(org.eclipse.swt.widgets.Widget) ScrollBar(org.eclipse.swt.widgets.ScrollBar) GridLayout(org.eclipse.swt.layout.GridLayout) Canvas(org.eclipse.swt.widgets.Canvas) Color(org.eclipse.swt.graphics.Color) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 20 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project eclipse.platform.swt by eclipse.

the class CanvasTab method resizeScrollBars.

/**
 * Resizes the maximum and thumb of both scrollbars.
 */
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);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Aggregations

ScrollBar (org.eclipse.swt.widgets.ScrollBar)50 Point (org.eclipse.swt.graphics.Point)32 Rectangle (org.eclipse.swt.graphics.Rectangle)20 GC (org.eclipse.swt.graphics.GC)14 Event (org.eclipse.swt.widgets.Event)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 GridData (org.eclipse.swt.layout.GridData)7 Listener (org.eclipse.swt.widgets.Listener)7 Composite (org.eclipse.swt.widgets.Composite)6 SWT (org.eclipse.swt.SWT)5 Font (org.eclipse.swt.graphics.Font)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 Button (org.eclipse.swt.widgets.Button)5 AccessibleControlEvent (org.eclipse.swt.accessibility.AccessibleControlEvent)4 AccessibleEvent (org.eclipse.swt.accessibility.AccessibleEvent)4 AccessibleTableEvent (org.eclipse.swt.accessibility.AccessibleTableEvent)4 ControlListener (org.eclipse.swt.events.ControlListener)4 Color (org.eclipse.swt.graphics.Color)4 ClientAreaResizeCommand (net.sourceforge.nattable.grid.command.ClientAreaResizeCommand)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3