Search in sources :

Example 81 with ScrollBar

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

the class StatisticsNavigatorNodeRenderer method renderDataSourceHostName.

// /////////////////////////////////////////////////////////////////
// Host name
private void renderDataSourceHostName(DBNDataSource element, Tree tree, GC gc, Event event, int widthOccupied) {
    DBPDataSourceContainer dataSourceContainer = element.getDataSourceContainer();
    String hostText = DataSourceUtils.getDataSourceAddressText(dataSourceContainer);
    if (!CommonUtils.isEmpty(hostText)) {
        Font oldFont = gc.getFont();
        DBPDataSourceContainer ds = element.getDataSourceContainer();
        Color bgColor = UIUtils.getConnectionColor(ds.getConnectionConfiguration());
        Color hostNameColor = UIUtils.getSharedColor((bgColor == null ? UIStyles.isDarkTheme() : UIUtils.isDark(bgColor.getRGB())) ? HOST_NAME_FG_DARK : HOST_NAME_FG_LIGHT);
        gc.setForeground(hostNameColor);
        Font hostNameFont = getFontItalic(tree);
        gc.setFont(hostNameFont);
        Point hostTextSize = gc.stringExtent(hostText);
        int xOffset = isLinux ? 16 : 2;
        ScrollBar hSB = tree.getHorizontalBar();
        boolean scrollEnabled = (hSB != null && hSB.isVisible());
        if (!scrollEnabled) {
            // In case of visible scrollbar it must respect full scrollable area size
            int treeWidth = tree.getClientArea().width;
            gc.setClipping(event.x + event.width + xOffset, event.y + ((event.height - hostTextSize.y) / 2), treeWidth - (event.x + event.width + xOffset + widthOccupied), event.height);
        }
        gc.drawText(" - " + hostText, event.x + event.width + xOffset, event.y + ((event.height - hostTextSize.y) / 2), true);
        if (!scrollEnabled) {
            gc.setClipping((Rectangle) null);
        }
        gc.setFont(oldFont);
    }
}
Also used : ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 82 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project titan.EclipsePlug-ins by eclipse.

the class ScrollView method updateScrollBarsValues.

/**
 * Setup scroll bar using contents, visible and scroll bar mode properties.
 */
private void updateScrollBarsValues() {
    /* update vertical scrollbar */
    ScrollBar b = getVerticalBar();
    if (b != null) {
        b.setMinimum(0);
        b.setMaximum(getContentsHeight());
        b.setThumb(getVisibleHeight());
        b.setPageIncrement(getVisibleHeight());
        b.setIncrement(this.vScrollbarIncrement);
        b.setSelection(getContentsY());
    }
    // update "hidden" vertical bar too
    b = this.viewcontrol.getVerticalBar();
    if (b != null) {
        b.setMinimum(0);
        b.setMaximum(getContentsHeight());
        b.setThumb(getVisibleHeight());
        b.setPageIncrement(getVisibleHeight());
        b.setIncrement(this.vScrollbarIncrement);
        b.setSelection(getContentsY());
    }
    /* update horizontal scrollbar */
    b = getHorizontalBar();
    if (b != null) {
        b.setMinimum(0);
        b.setMaximum(getContentsWidth());
        b.setThumb(getVisibleWidth());
        b.setSelection(getContentsX());
        b.setPageIncrement(getVisibleWidth());
        b.setIncrement(this.hScrollbarIncrement);
    }
    // update "hidden" horizontal bar too
    b = this.viewcontrol.getHorizontalBar();
    if (b != null) {
        b.setMinimum(0);
        b.setMaximum(getContentsWidth());
        b.setThumb(getVisibleWidth());
        b.setSelection(getContentsX());
        b.setPageIncrement(getVisibleWidth());
        b.setIncrement(this.hScrollbarIncrement);
    }
}
Also used : ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 83 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project pmd-eclipse-plugin by pmd.

the class DataflowGraphTable method syncScrollBars.

/**
 * Synchronizes the ScrollBars when the Source-View is resized
 *
 * @param source
 */
private void syncScrollBars(Composite source) {
    // get the Width and Height
    int sourceWidth = source.getSize().x - source.getVerticalBar().getSize().x;
    int sourceHeight = source.getSize().y - source.getHorizontalBar().getSize().y;
    // get the Bars
    ScrollBar horizontalBar = bodyFrame.getHorizontalBar();
    ScrollBar verticalBar = bodyFrame.getVerticalBar();
    // first set all Bars enabled
    horizontalBar.setEnabled(true);
    verticalBar.setEnabled(true);
    if (sourceWidth >= tableSize.x) {
        // if the viewed Area is larger than the Table
        // we don't need to scroll
        horizontalBar.setEnabled(false);
    } else {
        // ... else we adjust the Bar
        horizontalBar.setMaximum(tableSize.x);
        horizontalBar.setIncrement(tableSize.x / 100);
        horizontalBar.setPageIncrement(tableSize.x);
        horizontalBar.setThumb(sourceWidth);
    }
    if (sourceHeight >= tableSize.y) {
        // if the viewed Area is larger than the Table
        // we don't need to scroll
        verticalBar.setEnabled(false);
    } else {
        // ... else we adjust the Bar
        verticalBar.setMaximum(tableSize.y);
        verticalBar.setIncrement(tableSize.y / 100);
        verticalBar.setPageIncrement(tableSize.y);
        verticalBar.setThumb(sourceHeight);
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Example 84 with ScrollBar

use of org.eclipse.swt.widgets.ScrollBar in project erlide_eclipse by erlang.

the class SWTImageCanvas method syncScrollBars.

/**
 * Synchronize the scrollbar 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 = transform;
    final double sx = af.getScaleX();
    final double sy = af.getScaleY();
    double tx = af.getTranslateX();
    double ty = af.getTranslateY();
    if (tx > 0) {
        tx = 0;
    }
    if (ty > 0) {
        ty = 0;
    }
    final ScrollBar horizontal = getHorizontalBar();
    horizontal.setIncrement(getClientArea().width / 100);
    horizontal.setPageIncrement(getClientArea().width);
    final Rectangle imageBound = sourceImage.getBounds();
    final int cw = getClientArea().width;
    final int 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(getClientArea().width);
    final ScrollBar vertical = getVerticalBar();
    vertical.setIncrement(getClientArea().height / 100);
    vertical.setPageIncrement(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(getClientArea().height);
    /* update transform. */
    af = AffineTransform.getScaleInstance(sx, sy);
    af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty));
    transform = af;
    redraw();
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) AffineTransform(java.awt.geom.AffineTransform) 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