Search in sources :

Example 16 with ScrollPane

use of org.apache.pivot.wtk.ScrollPane in project pivot by apache.

the class ScrollPaneSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    ScrollPane scrollPane = (ScrollPane) getComponent();
    Component view = scrollPane.getView();
    if (view != null) {
        int preferredRowHeaderWidth = 0;
        Component rowHeader = scrollPane.getRowHeader();
        if (rowHeader != null) {
            preferredRowHeaderWidth = rowHeader.getPreferredWidth(-1);
        }
        int preferredColumnHeaderHeight = 0;
        Component columnHeader = scrollPane.getColumnHeader();
        if (columnHeader != null) {
            preferredColumnHeaderHeight = columnHeader.getPreferredHeight(-1);
        }
        ScrollBarPolicy verticalPolicy = scrollPane.getVerticalScrollBarPolicy();
        if (verticalPolicy != ScrollBarPolicy.FILL) {
            // Get the unconstrained preferred size of the view
            Dimensions preferredViewSize = view.getPreferredSize();
            if (verticalPolicy == ScrollBarPolicy.FILL_TO_CAPACITY) {
                if (height < 0) {
                    verticalPolicy = ScrollBarPolicy.AUTO;
                } else {
                    int preferredHeight = preferredViewSize.height + preferredColumnHeaderHeight;
                    if (preferredHeight < height) {
                        verticalPolicy = ScrollBarPolicy.FILL;
                    } else {
                        verticalPolicy = ScrollBarPolicy.AUTO;
                    }
                }
            }
            if (verticalPolicy == ScrollBarPolicy.ALWAYS || verticalPolicy == ScrollBarPolicy.NEVER || verticalPolicy == ScrollBarPolicy.AUTO) {
                preferredWidth = preferredViewSize.width + preferredRowHeaderWidth;
                // preferred width calculation
                if (verticalPolicy == ScrollBarPolicy.ALWAYS || (verticalPolicy == ScrollBarPolicy.AUTO && height > 0 && preferredViewSize.height + preferredColumnHeaderHeight > height)) {
                    preferredWidth += verticalScrollBar.getPreferredWidth(-1);
                }
            }
        }
        if (verticalPolicy == ScrollBarPolicy.FILL) {
            // Preferred width is the sum of the constrained preferred
            // width of the view and the unconstrained preferred width of
            // the row header
            int heightUpdated = height;
            if (heightUpdated >= 0) {
                // Subtract the unconstrained preferred height of the
                // column header from the height constraint
                heightUpdated = Math.max(heightUpdated - preferredColumnHeaderHeight, 0);
            }
            preferredWidth = view.getPreferredWidth(heightUpdated) + preferredRowHeaderWidth;
        }
    }
    return preferredWidth;
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) ScrollBarPolicy(org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint)

Example 17 with ScrollPane

use of org.apache.pivot.wtk.ScrollPane in project pivot by apache.

the class ScrollPaneSkin method isOptimizeScrolling.

private boolean isOptimizeScrolling() {
    boolean optimizeScrollingLocal = this.optimizeScrolling;
    if (optimizeScrollingLocal) {
        // Due to Sun bug #6293145, we cannot call copyArea if scaling is
        // applied to the graphics context.
        // Due to Sun bug #4033851, we cannot call copyArea if the display
        // host is obscured. For a full description of why this is the case,
        // see http://people.apache.org/~tvolkert/tests/scrolling/
        ScrollPane scrollPane = (ScrollPane) getComponent();
        ApplicationContext.DisplayHost displayHost = scrollPane.getDisplay().getDisplayHost();
        optimizeScrollingLocal = (displayHost.getScale() == 1 && (DesktopApplicationContext.isActive() && displayHost.isDisplayable()));
    }
    return optimizeScrollingLocal;
}
Also used : ApplicationContext(org.apache.pivot.wtk.ApplicationContext) DesktopApplicationContext(org.apache.pivot.wtk.DesktopApplicationContext) ScrollPane(org.apache.pivot.wtk.ScrollPane)

Example 18 with ScrollPane

use of org.apache.pivot.wtk.ScrollPane in project pivot by apache.

the class ScrollPaneSkin method scrollLeftChanged.

@Override
public void scrollLeftChanged(Viewport viewport, int previousScrollLeft) {
    // NOTE we don't invalidate the component here because we need only
    // reposition the view and column header. Invalidating would yield
    // the correct positioning, but it would do much more work than needed.
    ScrollPane scrollPane = (ScrollPane) viewport;
    Component view = scrollPane.getView();
    Component rowHeader = scrollPane.getRowHeader();
    Component columnHeader = scrollPane.getColumnHeader();
    int rowHeaderWidth = 0;
    if (rowHeader != null) {
        rowHeaderWidth = rowHeader.getWidth();
    }
    int scrollLeft = scrollPane.getScrollLeft();
    if (view != null && view.isShowing() && isOptimizeScrolling()) {
        Bounds blitArea = view.getVisibleArea();
        int blitX = blitArea.x + view.getX();
        int blitY = blitArea.y + view.getY();
        int blitWidth = blitArea.width;
        int blitHeight = blitArea.height;
        if (columnHeader != null) {
            // Blit the column header as well
            int columnHeaderHeight = columnHeader.getHeight();
            blitY -= columnHeaderHeight;
            blitHeight += columnHeaderHeight;
        }
        int deltaScrollLeft = scrollLeft - previousScrollLeft;
        blitX += Math.max(deltaScrollLeft, 0);
        blitWidth -= Math.abs(deltaScrollLeft);
        Graphics2D graphics = scrollPane.getGraphics();
        graphics.copyArea(blitX, blitY, blitWidth, blitHeight, -deltaScrollLeft, 0);
        scrollPane.setConsumeRepaint(true);
        try {
            view.setLocation(rowHeaderWidth - scrollLeft, view.getY());
            if (columnHeader != null) {
                columnHeader.setLocation(rowHeaderWidth - scrollLeft, 0);
            }
        } finally {
            scrollPane.setConsumeRepaint(false);
        }
        boolean repaintAllViewport = scrollPane.isRepaintAllViewport();
        if (!repaintAllViewport) {
            scrollPane.repaint(rowHeaderWidth + (deltaScrollLeft > 0 ? blitWidth : 0), blitY, Math.abs(deltaScrollLeft), blitHeight, true);
        } else {
            Bounds viewportBounds = getViewportBounds();
            scrollPane.repaint(viewportBounds.x, viewportBounds.y, viewportBounds.width, viewportBounds.height, true);
        }
    } else {
        if (view != null) {
            view.setLocation(rowHeaderWidth - scrollLeft, view.getY());
        }
        if (columnHeader != null) {
            columnHeader.setLocation(rowHeaderWidth - scrollLeft, 0);
        }
    }
    if (scrollLeft >= 0 && scrollLeft <= getMaxScrollLeft()) {
        horizontalScrollBar.setValue(scrollLeft);
    }
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) Bounds(org.apache.pivot.wtk.Bounds) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D)

Aggregations

ScrollPane (org.apache.pivot.wtk.ScrollPane)18 Paint (java.awt.Paint)14 Component (org.apache.pivot.wtk.Component)14 Bounds (org.apache.pivot.wtk.Bounds)4 Dimensions (org.apache.pivot.wtk.Dimensions)4 ScrollBarPolicy (org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy)3 Graphics2D (java.awt.Graphics2D)2 TextInput (org.apache.pivot.wtk.TextInput)2 Color (java.awt.Color)1 ArrayList (org.apache.pivot.collections.ArrayList)1 ApplicationContext (org.apache.pivot.wtk.ApplicationContext)1 BoxPane (org.apache.pivot.wtk.BoxPane)1 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)1 Container (org.apache.pivot.wtk.Container)1 DesktopApplicationContext (org.apache.pivot.wtk.DesktopApplicationContext)1 Frame (org.apache.pivot.wtk.Frame)1 Label (org.apache.pivot.wtk.Label)1 ListView (org.apache.pivot.wtk.ListView)1 ListViewSelectionListener (org.apache.pivot.wtk.ListViewSelectionListener)1 Mouse (org.apache.pivot.wtk.Mouse)1