Search in sources :

Example 71 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project usbdm-eclipse-plugins by podonoghue.

the class ImageCanvas method initScrollBars.

/**
 *  Initialise the scroll-bar and register listeners.
 */
private void initScrollBars() {
    ScrollBar horizontal = getHorizontalBar();
    horizontal.setEnabled(false);
    horizontal.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            scrollHorizontally((ScrollBar) event.widget);
        }
    });
    ScrollBar vertical = getVerticalBar();
    vertical.setEnabled(false);
    vertical.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            scrollVertically((ScrollBar) event.widget);
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 72 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project usbdm-eclipse-plugins by podonoghue.

the class ImageCanvas method syncScrollBars.

/**
 * Synchronize the scroll-bar with the image. If the transform is out
 * of range, it will correct it. This function considers only following
 * factors :<b> transform, image size, client area</b>.
 */
public void syncScrollBars() {
    if (sourceImage == null) {
        redraw();
        return;
    }
    AffineTransform af = fTransform;
    double sx = af.getScaleX(), sy = af.getScaleY();
    double tx = af.getTranslateX(), ty = af.getTranslateY();
    if (tx > 0)
        tx = 0;
    if (ty > 0)
        ty = 0;
    ScrollBar horizontal = getHorizontalBar();
    horizontal.setIncrement((int) (getClientArea().width / 100));
    horizontal.setPageIncrement(getClientArea().width);
    Rectangle imageBound = sourceImage.getBounds();
    int cw = getClientArea().width, ch = getClientArea().height;
    if (imageBound.width * sx > cw) {
        /* image is wider than client area */
        horizontal.setMaximum((int) (imageBound.width * sx));
        horizontal.setEnabled(true);
        if (((int) -tx) > horizontal.getMaximum() - cw)
            tx = -horizontal.getMaximum() + cw;
    } else {
        /* image is narrower than client area */
        horizontal.setEnabled(false);
        // center if too small.
        tx = (cw - imageBound.width * sx) / 2;
    }
    horizontal.setSelection((int) (-tx));
    horizontal.setThumb((int) (getClientArea().width));
    ScrollBar vertical = getVerticalBar();
    vertical.setIncrement((int) (getClientArea().height / 100));
    vertical.setPageIncrement((int) (getClientArea().height));
    if (imageBound.height * sy > ch) {
        /* image is higher than client area */
        vertical.setMaximum((int) (imageBound.height * sy));
        vertical.setEnabled(true);
        if (((int) -ty) > vertical.getMaximum() - ch)
            ty = -vertical.getMaximum() + ch;
    } else {
        /* image is less higher than client area */
        vertical.setEnabled(false);
        // center if too small.
        ty = (ch - imageBound.height * sy) / 2;
    }
    vertical.setSelection((int) (-ty));
    vertical.setThumb((int) (getClientArea().height));
    /* update transform. */
    af = AffineTransform.getScaleInstance(sx, sy);
    af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty));
    fTransform = af;
    redraw();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) AffineTransform(java.awt.geom.AffineTransform) ScrollBar(org.eclipse.swt.widgets.ScrollBar) Point(org.eclipse.swt.graphics.Point)

Example 73 with ScrollBar

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

the class ConsoleTextPresentation method performHorizontalScroll.

@Override
protected void performHorizontalScroll(int scrollCount) {
    ScrollBar hsb = text.getHorizontalBar();
    if (hsb != null && hsb.isVisible()) {
        int curPosition = text.getHorizontalPixel();
        int pageIncrement = UIUtils.getFontHeight(text.getFont()) * 10;
        if (scrollCount > 0) {
            if (curPosition > 0) {
                curPosition -= pageIncrement;
            }
        } else {
            curPosition += pageIncrement;
        }
        if (curPosition < 0)
            curPosition = 0;
        text.setHorizontalPixel(curPosition);
    // text.setHorizontalIndex();
    }
}
Also used : ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 74 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project dbeaver by serge-rider.

the class ConsoleTextPresentation method createPresentation.

@Override
public void createPresentation(@NotNull final IResultSetController controller, @NotNull Composite parent) {
    super.createPresentation(controller, parent);
    UIUtils.createHorizontalLine(parent);
    text = new StyledText(parent, SWT.READ_ONLY | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    text.setBlockSelection(true);
    text.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_IBEAM));
    text.setMargins(4, 4, 4, 4);
    text.setForeground(UIStyles.getDefaultTextForeground());
    text.setBackground(UIStyles.getDefaultTextBackground());
    text.setTabs(controller.getPreferenceStore().getInt(ResultSetPreferences.RESULT_TEXT_TAB_SIZE));
    text.setTabStops(null);
    text.setFont(UIUtils.getMonospaceFont());
    text.setLayoutData(new GridData(GridData.FILL_BOTH));
    text.addCaretListener(event -> onCursorChange(event.caretOffset));
    text.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            curSelection = text.getSelectionText();
            fireSelectionChanged(new PlainTextSelectionImpl());
        }
    });
    final ScrollBar verticalBar = text.getVerticalBar();
    verticalBar.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (verticalBar.getSelection() + verticalBar.getPageIncrement() >= verticalBar.getMaximum()) {
                if (controller.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_AUTO_FETCH_NEXT_SEGMENT) && !controller.isRecordMode() && controller.isHasMoreData()) {
                    controller.readNextSegment();
                }
            }
        }
    });
    findReplaceTarget = new StyledTextFindReplaceTarget(text);
    TextEditorUtils.enableHostEditorKeyBindingsSupport(controller.getSite(), text);
    applyCurrentThemeSettings();
    registerContextMenu();
    activateTextKeyBindings(controller, text);
    trackPresentationControl();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) StyledTextFindReplaceTarget(org.jkiss.dbeaver.ui.controls.StyledTextFindReplaceTarget) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 75 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project dbeaver by serge-rider.

the class PlainTextPresentation method createPresentation.

@Override
public void createPresentation(@NotNull final IResultSetController controller, @NotNull Composite parent) {
    super.createPresentation(controller, parent);
    UIUtils.createHorizontalLine(parent);
    text = new StyledText(parent, SWT.READ_ONLY | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    text.setBlockSelection(true);
    text.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_IBEAM));
    text.setMargins(4, 4, 4, 4);
    text.setForeground(UIStyles.getDefaultTextForeground());
    text.setBackground(UIStyles.getDefaultTextBackground());
    text.setTabs(controller.getPreferenceStore().getInt(ResultSetPreferences.RESULT_TEXT_TAB_SIZE));
    text.setTabStops(null);
    text.setFont(UIUtils.getMonospaceFont());
    text.setLayoutData(new GridData(GridData.FILL_BOTH));
    text.addCaretListener(event -> onCursorChange(event.caretOffset));
    text.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            curSelection = text.getSelectionText();
            fireSelectionChanged(new PlainTextSelectionImpl());
        }
    });
    final ScrollBar verticalBar = text.getVerticalBar();
    verticalBar.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (verticalBar.getSelection() + verticalBar.getPageIncrement() >= verticalBar.getMaximum()) {
                if (controller.getPreferenceStore().getBoolean(ResultSetPreferences.RESULT_SET_AUTO_FETCH_NEXT_SEGMENT) && !controller.isRecordMode() && controller.isHasMoreData()) {
                    controller.readNextSegment();
                }
            }
        }
    });
    findReplaceTarget = new StyledTextFindReplaceTarget(text);
    TextEditorUtils.enableHostEditorKeyBindingsSupport(controller.getSite(), text);
    applyCurrentThemeSettings();
    registerContextMenu();
    activateTextKeyBindings(controller, text);
    trackPresentationControl();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) StyledTextFindReplaceTarget(org.jkiss.dbeaver.ui.controls.StyledTextFindReplaceTarget) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

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