Search in sources :

Example 1 with ScrollBar

use of org.eclipse.draw2d.ScrollBar in project archi by archimatetool.

the class OverlayScrollPaneLayout method layout.

/**
 * {@inheritDoc}
 */
@Override
public void layout(IFigure parent) {
    ScrollPane scrollpane = (ScrollPane) parent;
    Rectangle clientArea = parent.getClientArea();
    ScrollBar hBar = scrollpane.getHorizontalScrollBar(), vBar = scrollpane.getVerticalScrollBar();
    Viewport viewport = scrollpane.getViewport();
    Insets insets = new Insets();
    insets.bottom = hBar.getPreferredSize(clientArea.width, clientArea.height).height;
    insets.right = vBar.getPreferredSize(clientArea.width, clientArea.height).width;
    int hVis = scrollpane.getHorizontalScrollBarVisibility(), vVis = scrollpane.getVerticalScrollBarVisibility();
    Dimension available = clientArea.getSize(), preferred = viewport.getPreferredSize(available.width, available.height).getCopy();
    boolean none = available.contains(preferred), both = !none && vVis != NEVER && hVis != NEVER && preferred.contains(available), showV = both || preferred.height > available.height, showH = both || preferred.width > available.width;
    // Adjust for visibility override flags
    showV = !(vVis == NEVER) && (showV || vVis == ALWAYS);
    showH = !(hVis == NEVER) && (showH || hVis == ALWAYS);
    if (!showV)
        insets.right = 0;
    if (!showH)
        insets.bottom = 0;
    Rectangle bounds, viewportArea = clientArea;
    if (showV) {
        bounds = new Rectangle(viewportArea.right() - insets.right, viewportArea.y, insets.right, viewportArea.height);
        vBar.setBounds(bounds);
    // vBar.setMaximum(preferred.height);
    }
    if (showH) {
        bounds = new Rectangle(viewportArea.x, viewportArea.bottom() - insets.bottom, viewportArea.width, insets.bottom);
        hBar.setBounds(bounds);
    // hBar.setMaximum(preferred.width);
    }
    vBar.setVisible(showV);
    hBar.setVisible(showH);
    viewport.setBounds(viewportArea);
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) ScrollPane(org.eclipse.draw2d.ScrollPane) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Viewport(org.eclipse.draw2d.Viewport) Dimension(org.eclipse.draw2d.geometry.Dimension) ScrollBar(org.eclipse.draw2d.ScrollBar)

Example 2 with ScrollBar

use of org.eclipse.draw2d.ScrollBar in project archi by archimatetool.

the class PaletteScrollBar method initialize.

@Override
protected void initialize() {
    super.initialize();
    setLayoutManager(new ScrollBarLayout(transposer) {

        @SuppressWarnings("deprecation")
        @Override
        protected Rectangle layoutButtons(ScrollBar scrollBar) {
            Rectangle bounds = transposer.t(scrollBar.getClientArea());
            Dimension buttonSize = new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT);
            getButtonUp().setBounds(transposer.t(new Rectangle(bounds.getTop().getTranslated(-(buttonSize.width / 2), 0), buttonSize)));
            Rectangle r = new Rectangle(bounds.getBottom().getTranslated(-(buttonSize.width / 2), -buttonSize.height), buttonSize);
            getButtonDown().setBounds(transposer.t(r));
            Rectangle trackBounds = bounds.getCropped(new Insets(buttonSize.height, 0, buttonSize.height, 0));
            RangeModel model = scrollBar.getRangeModel();
            getButtonUp().setVisible(model.getValue() != model.getMinimum());
            getButtonDown().setVisible(model.getValue() != model.getMaximum() - model.getExtent());
            return trackBounds;
        }
    });
    setPageUp(null);
    setPageDown(null);
    setThumb(null);
    setOpaque(false);
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) ScrollBarLayout(org.eclipse.draw2d.ScrollBarLayout) RangeModel(org.eclipse.draw2d.RangeModel) ScrollBar(org.eclipse.draw2d.ScrollBar)

Aggregations

ScrollBar (org.eclipse.draw2d.ScrollBar)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Insets (org.eclipse.draw2d.geometry.Insets)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 RangeModel (org.eclipse.draw2d.RangeModel)1 ScrollBarLayout (org.eclipse.draw2d.ScrollBarLayout)1 ScrollPane (org.eclipse.draw2d.ScrollPane)1 Viewport (org.eclipse.draw2d.Viewport)1