Search in sources :

Example 51 with ScrollBar

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

the class CTable method removeAll.

/**
 * Removes all of the items from the receiver.
 *
 * @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>
 */
public void removeAll() {
    checkWidget();
    if (itemsCount == 0)
        return;
    setRedraw(false);
    setFocusItem(null, false);
    for (int i = 0; i < itemsCount; i++) {
        items[i].dispose(false);
    }
    items = new CTableItem[0];
    selectedItems = new CTableItem[0];
    int oldCount = itemsCount;
    itemsCount = topIndex = 0;
    anchorItem = lastClickedItem = null;
    lastSelectionEvent = null;
    int[] eventData = new int[5];
    eventData[0] = ACC.DELETE;
    eventData[1] = 0;
    eventData[2] = oldCount;
    eventData[3] = 0;
    eventData[4] = 0;
    getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);
    ScrollBar vBar = getVerticalBar();
    if (vBar != null) {
        vBar.setMaximum(1);
        vBar.setVisible(false);
    }
    if (columns.length == 0) {
        horizontalOffset = 0;
        ScrollBar hBar = getHorizontalBar();
        if (hBar != null) {
            hBar.setMaximum(1);
            hBar.setVisible(false);
        }
    }
    setRedraw(true);
}
Also used : Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 52 with ScrollBar

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

the class CTable method updateHorizontalBar.

/*
 * Update the horizontal bar, if needed, in response to an item change (eg.- created,
 * disposed, expanded, etc.).  newRightX is the new rightmost X value of the item,
 * and rightXchange is the change that led to the item's rightmost X value becoming
 * newRightX (so oldRightX + rightXchange = newRightX)
 */
void updateHorizontalBar(int newRightX, int rightXchange) {
    if (drawCount > 0)
        return;
    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 */
}
Also used : ScrollBar(org.eclipse.swt.widgets.ScrollBar) Point(org.eclipse.swt.graphics.Point)

Example 53 with ScrollBar

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

the class CTable method updateColumnWidth.

void updateColumnWidth(CTableColumn column, int width) {
    headerHideToolTip();
    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 */
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) 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) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 54 with ScrollBar

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

the class ClipboardExample method createImageTransfer.

void createImageTransfer(Composite copyParent, Composite pasteParent) {
    final Image[] copyImage = new Image[] { null };
    Label l = new Label(copyParent, SWT.NONE);
    // $NON-NLS-1$
    l.setText("ImageTransfer:");
    GridData data = new GridData();
    data.verticalSpan = 2;
    l.setLayoutData(data);
    final Canvas copyImageCanvas = new Canvas(copyParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    data.verticalSpan = 2;
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    copyImageCanvas.setLayoutData(data);
    final Point copyOrigin = new Point(0, 0);
    final ScrollBar copyHBar = copyImageCanvas.getHorizontalBar();
    copyHBar.setEnabled(false);
    copyHBar.addListener(SWT.Selection, e -> {
        if (copyImage[0] != null) {
            int hSelection = copyHBar.getSelection();
            int destX = -hSelection - copyOrigin.x;
            Rectangle rect = copyImage[0].getBounds();
            copyImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false);
            copyOrigin.x = -hSelection;
        }
    });
    final ScrollBar copyVBar = copyImageCanvas.getVerticalBar();
    copyVBar.setEnabled(false);
    copyVBar.addListener(SWT.Selection, e -> {
        if (copyImage[0] != null) {
            int vSelection = copyVBar.getSelection();
            int destY = -vSelection - copyOrigin.y;
            Rectangle rect = copyImage[0].getBounds();
            copyImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false);
            copyOrigin.y = -vSelection;
        }
    });
    copyImageCanvas.addListener(SWT.Paint, e -> {
        if (copyImage[0] != null) {
            GC gc = e.gc;
            gc.drawImage(copyImage[0], copyOrigin.x, copyOrigin.y);
            Rectangle rect = copyImage[0].getBounds();
            Rectangle client = copyImageCanvas.getClientArea();
            int marginWidth = client.width - rect.width;
            if (marginWidth > 0) {
                gc.fillRectangle(rect.width, 0, marginWidth, client.height);
            }
            int marginHeight = client.height - rect.height;
            if (marginHeight > 0) {
                gc.fillRectangle(0, rect.height, client.width, marginHeight);
            }
            gc.dispose();
        }
    });
    Button openButton = new Button(copyParent, SWT.PUSH);
    openButton.setText("Open Image");
    openButton.addSelectionListener(widgetSelectedAdapter(e -> {
        FileDialog dialog = new FileDialog(shell, SWT.OPEN);
        dialog.setText("Open an image file or cancel");
        String string = dialog.open();
        if (string != null) {
            if (copyImage[0] != null) {
                System.out.println("CopyImage");
                copyImage[0].dispose();
            }
            copyImage[0] = new Image(e.display, string);
            copyVBar.setEnabled(true);
            copyHBar.setEnabled(true);
            copyOrigin.x = 0;
            copyOrigin.y = 0;
            Rectangle rect = copyImage[0].getBounds();
            Rectangle client = copyImageCanvas.getClientArea();
            copyHBar.setMaximum(rect.width);
            copyVBar.setMaximum(rect.height);
            copyHBar.setThumb(Math.min(rect.width, client.width));
            copyVBar.setThumb(Math.min(rect.height, client.height));
            copyImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
            copyVBar.setSelection(0);
            copyHBar.setSelection(0);
            copyImageCanvas.redraw();
        }
    }));
    Button b = new Button(copyParent, SWT.PUSH);
    b.setText("Copy");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        if (copyImage[0] != null) {
            status.setText("");
            // Fetch ImageData at current zoom and save in the clip-board.
            clipboard.setContents(new Object[] { copyImage[0].getImageDataAtCurrentZoom() }, new Transfer[] { ImageTransfer.getInstance() });
        } else {
            status.setText("No image to copy");
        }
    }));
    final Image[] pasteImage = new Image[] { null };
    l = new Label(pasteParent, SWT.NONE);
    l.setText("ImageTransfer:");
    final Canvas pasteImageCanvas = new Canvas(pasteParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    data = new GridData(GridData.FILL_BOTH);
    data.widthHint = HSIZE;
    data.heightHint = VSIZE;
    pasteImageCanvas.setLayoutData(data);
    final Point pasteOrigin = new Point(0, 0);
    final ScrollBar pasteHBar = pasteImageCanvas.getHorizontalBar();
    pasteHBar.setEnabled(false);
    pasteHBar.addListener(SWT.Selection, e -> {
        if (pasteImage[0] != null) {
            int hSelection = pasteHBar.getSelection();
            int destX = -hSelection - pasteOrigin.x;
            Rectangle rect = pasteImage[0].getBounds();
            pasteImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false);
            pasteOrigin.x = -hSelection;
        }
    });
    final ScrollBar pasteVBar = pasteImageCanvas.getVerticalBar();
    pasteVBar.setEnabled(false);
    pasteVBar.addListener(SWT.Selection, e -> {
        if (pasteImage[0] != null) {
            int vSelection = pasteVBar.getSelection();
            int destY = -vSelection - pasteOrigin.y;
            Rectangle rect = pasteImage[0].getBounds();
            pasteImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false);
            pasteOrigin.y = -vSelection;
        }
    });
    pasteImageCanvas.addListener(SWT.Paint, e -> {
        if (pasteImage[0] != null) {
            GC gc = e.gc;
            gc.drawImage(pasteImage[0], pasteOrigin.x, pasteOrigin.y);
            Rectangle rect = pasteImage[0].getBounds();
            Rectangle client = pasteImageCanvas.getClientArea();
            int marginWidth = client.width - rect.width;
            if (marginWidth > 0) {
                gc.fillRectangle(rect.width, 0, marginWidth, client.height);
            }
            int marginHeight = client.height - rect.height;
            if (marginHeight > 0) {
                gc.fillRectangle(0, rect.height, client.width, marginHeight);
            }
        }
    });
    b = new Button(pasteParent, SWT.PUSH);
    b.setText("Paste");
    b.addSelectionListener(widgetSelectedAdapter(e -> {
        ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance());
        if (imageData != null) {
            if (pasteImage[0] != null) {
                System.out.println("PasteImage");
                pasteImage[0].dispose();
            }
            status.setText("");
            // Consume the ImageData at current zoom as-is.
            pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData));
            pasteVBar.setEnabled(true);
            pasteHBar.setEnabled(true);
            pasteOrigin.x = 0;
            pasteOrigin.y = 0;
            Rectangle rect = pasteImage[0].getBounds();
            Rectangle client = pasteImageCanvas.getClientArea();
            pasteHBar.setMaximum(rect.width);
            pasteVBar.setMaximum(rect.height);
            pasteHBar.setThumb(Math.min(rect.width, client.width));
            pasteVBar.setThumb(Math.min(rect.height, client.height));
            pasteImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
            pasteVBar.setSelection(0);
            pasteHBar.setSelection(0);
            pasteImageCanvas.redraw();
        } else {
            status.setText("No image to paste");
        }
    }));
}
Also used : RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) StyledText(org.eclipse.swt.custom.StyledText) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) ImageData(org.eclipse.swt.graphics.ImageData) Table(org.eclipse.swt.widgets.Table) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) ImageDataProvider(org.eclipse.swt.graphics.ImageDataProvider) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) Composite(org.eclipse.swt.widgets.Composite) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) FileTransfer(org.eclipse.swt.dnd.FileTransfer) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display) Group(org.eclipse.swt.widgets.Group) File(java.io.File) Transfer(org.eclipse.swt.dnd.Transfer) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) List(org.eclipse.swt.widgets.List) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Canvas(org.eclipse.swt.widgets.Canvas) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Button(org.eclipse.swt.widgets.Button) ImageData(org.eclipse.swt.graphics.ImageData) GridData(org.eclipse.swt.layout.GridData) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) ImageTransfer(org.eclipse.swt.dnd.ImageTransfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) FileTransfer(org.eclipse.swt.dnd.FileTransfer) Transfer(org.eclipse.swt.dnd.Transfer) HTMLTransfer(org.eclipse.swt.dnd.HTMLTransfer) GC(org.eclipse.swt.graphics.GC) FileDialog(org.eclipse.swt.widgets.FileDialog) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 55 with ScrollBar

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

the class CTable method onScrollHorizontal.

void onScrollHorizontal(Event event) {
    ScrollBar hBar = getHorizontalBar();
    if (hBar == null)
        return;
    int newSelection = hBar.getSelection();
    update();
    if (itemsCount > 0) {
        GC gc = new GC(this);
        gc.copyArea(0, 0, clientArea.width, clientArea.height, horizontalOffset - newSelection, 0);
        gc.dispose();
    } else {
        redraw();
    /* ensure that static focus rectangle updates properly */
    }
    if (drawCount <= 0 && header.isVisible()) {
        header.update();
        Rectangle headerClientArea = header.getClientArea();
        GC gc = new GC(header);
        gc.copyArea(0, 0, headerClientArea.width, headerClientArea.height, horizontalOffset - newSelection, 0);
        gc.dispose();
    }
    horizontalOffset = newSelection;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) GC(org.eclipse.swt.graphics.GC) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Point(org.eclipse.swt.graphics.Point)

Aggregations

ScrollBar (org.eclipse.swt.widgets.ScrollBar)84 Point (org.eclipse.swt.graphics.Point)39 Rectangle (org.eclipse.swt.graphics.Rectangle)25 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 GC (org.eclipse.swt.graphics.GC)14 GridData (org.eclipse.swt.layout.GridData)12 Event (org.eclipse.swt.widgets.Event)12 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)11 Composite (org.eclipse.swt.widgets.Composite)8 GridLayout (org.eclipse.swt.layout.GridLayout)7 Listener (org.eclipse.swt.widgets.Listener)7 StyledText (org.eclipse.swt.custom.StyledText)6 Button (org.eclipse.swt.widgets.Button)6 Label (org.eclipse.swt.widgets.Label)6 SWT (org.eclipse.swt.SWT)5 ControlListener (org.eclipse.swt.events.ControlListener)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 Font (org.eclipse.swt.graphics.Font)5 Text (org.eclipse.swt.widgets.Text)5 AffineTransform (java.awt.geom.AffineTransform)4