Search in sources :

Example 6 with ScrollBar

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

the class TerraScrollBarSkin method mouseDown.

/**
 * Initiates automatic block scrolling. This only happens if the handle is
 * visible since whether the user clicked before or after the handle
 * determines the direction of the scrolling.
 *
 * @param component The scroll bar.
 * @param button The button that was pressed.
 * @param x The x-coordinate of the event in the scroll bar's coordinate
 * space.
 * @param y The y-coordinate of the event in the scroll bar's coordinate
 * space.
 */
@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
    boolean consumed = super.mouseDown(component, button, x, y);
    if (button == Mouse.Button.LEFT && handle.isVisible()) {
        ScrollBar scrollBar = (ScrollBar) getComponent();
        // Begin automatic block scrolling. Calculate the direction of
        // the scroll by checking to see if the user pressed the mouse
        // in the area "before" the handle or "after" it.
        int direction;
        int realStopValue;
        if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
            direction = x < handle.getX() ? -1 : 1;
            int pixelStopValue = x - scrollUpButton.getWidth() + 1;
            if (direction == 1) {
                // If we're scrolling down, account for the width of the
                // handle in our pixel stop value so that we stop as soon
                // as the *bottom* of the handle reaches our click point
                pixelStopValue -= handle.getWidth();
            }
            realStopValue = (int) (pixelStopValue / getValueScale());
        } else {
            direction = y < handle.getY() ? -1 : 1;
            int pixelStopValue = y - scrollUpButton.getHeight() + 1;
            if (direction == 1) {
                // If we're scrolling down, account for the height of the
                // handle in our pixel stop value so that we stop as soon
                // as the *bottom* of the handle reaches our click point
                pixelStopValue -= handle.getHeight();
            }
            realStopValue = (int) (pixelStopValue / getValueScale());
        }
        // Start the automatic scroller
        automaticScroller.start(direction, Mouse.ScrollType.BLOCK, realStopValue);
        consumed = true;
    }
    return consumed;
}
Also used : ScrollBar(org.apache.pivot.wtk.ScrollBar) GradientPaint(java.awt.GradientPaint)

Example 7 with ScrollBar

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

the class TerraScrollBarSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    ScrollBar scrollBar = (ScrollBar) component;
    scrollBar.getScrollBarListeners().add(this);
    scrollBar.getScrollBarValueListeners().add(this);
    scrollBar.add(scrollUpButton);
    scrollBar.add(scrollDownButton);
    scrollBar.add(handle);
    Theme theme = currentTheme();
    Color backgroundColor = theme.getColor(9);
    Color brightBackgroundColor = TerraTheme.brighten(backgroundColor);
    GradientPaint backgroundPaint;
    if (!themeIsFlat()) {
        if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
            backgroundPaint = new GradientPaint(0, 1, backgroundColor, 0, DEFAULT_THICKNESS - 2, brightBackgroundColor);
        } else {
            backgroundPaint = new GradientPaint(1, 0, backgroundColor, DEFAULT_THICKNESS - 2, 0, brightBackgroundColor);
        }
    } else {
        backgroundPaint = new GradientPaint(0, 0, backgroundColor, 0, DEFAULT_THICKNESS - 2, // gradient but with the same colors
        backgroundColor);
    }
    setBackgroundPaint(backgroundPaint);
    enabledChanged(scrollBar);
}
Also used : Color(java.awt.Color) Theme(org.apache.pivot.wtk.Theme) GradientPaint(java.awt.GradientPaint) ScrollBar(org.apache.pivot.wtk.ScrollBar)

Example 8 with ScrollBar

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

the class TerraScrollBarSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    super.paint(graphics);
    if (!themeIsFlat()) {
        ScrollBar scrollBar = (ScrollBar) getComponent();
        int width = getWidth();
        int height = getHeight();
        graphics.setPaint(borderColor);
        // Paint the scroll bar border lines
        if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
            int scrollUpButtonWidth = scrollUpButton.getWidth();
            int scrollDownButtonWidth = scrollDownButton.getWidth();
            GraphicsUtilities.drawLine(graphics, scrollUpButtonWidth, 0, width - scrollDownButtonWidth - scrollUpButtonWidth, Orientation.HORIZONTAL);
            GraphicsUtilities.drawLine(graphics, scrollUpButtonWidth, height - 1, width - scrollDownButtonWidth - scrollUpButtonWidth, Orientation.HORIZONTAL);
        } else {
            int scrollUpButtonHeight = scrollUpButton.getHeight();
            int scrollDownButtonHeight = scrollDownButton.getHeight();
            GraphicsUtilities.drawLine(graphics, 0, scrollUpButtonHeight, height - scrollDownButtonHeight - scrollUpButtonHeight, Orientation.VERTICAL);
            GraphicsUtilities.drawLine(graphics, width - 1, scrollUpButtonHeight, height - scrollDownButtonHeight - scrollUpButtonHeight, Orientation.VERTICAL);
        }
    }
}
Also used : ScrollBar(org.apache.pivot.wtk.ScrollBar) GradientPaint(java.awt.GradientPaint)

Example 9 with ScrollBar

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

the class TerraScrollBarSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    ScrollBar scrollBar = (ScrollBar) getComponent();
    int preferredHeight = 0;
    if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
        preferredHeight = DEFAULT_THICKNESS;
    } else {
        preferredHeight = DEFAULT_LENGTH;
    }
    return preferredHeight;
}
Also used : ScrollBar(org.apache.pivot.wtk.ScrollBar) GradientPaint(java.awt.GradientPaint)

Aggregations

GradientPaint (java.awt.GradientPaint)9 ScrollBar (org.apache.pivot.wtk.ScrollBar)9 Color (java.awt.Color)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 Theme (org.apache.pivot.wtk.Theme)1