Search in sources :

Example 96 with Component

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

the class TerraPanoramaSkin method mouseWheel.

@Override
public boolean mouseWheel(Component component, Mouse.ScrollType scrollType, int scrollAmount, int wheelRotation, int x, int y) {
    boolean consumed = false;
    Panorama panorama = (Panorama) getComponent();
    Component view = panorama.getView();
    if (view != null) {
        // presssed while the mouse wheel was scrolled
        if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
            // Treat the mouse wheel as a horizontal scroll event
            int previousScrollLeft = panorama.getScrollLeft();
            int newScrollLeft = previousScrollLeft + (scrollAmount * wheelRotation * (int) INITIAL_SCROLL_DISTANCE);
            if (wheelRotation > 0) {
                int maxScrollLeft = getMaxScrollLeft();
                newScrollLeft = Math.min(newScrollLeft, maxScrollLeft);
                if (previousScrollLeft < maxScrollLeft) {
                    consumed = true;
                }
            } else {
                newScrollLeft = Math.max(newScrollLeft, 0);
                if (previousScrollLeft > 0) {
                    consumed = true;
                }
            }
            panorama.setScrollLeft(newScrollLeft);
        } else {
            // Treat the mouse wheel as a vertical scroll event
            int previousScrollTop = panorama.getScrollTop();
            int newScrollTop = previousScrollTop + (scrollAmount * wheelRotation * (int) INITIAL_SCROLL_DISTANCE);
            if (wheelRotation > 0) {
                int maxScrollTop = getMaxScrollTop();
                newScrollTop = Math.min(newScrollTop, maxScrollTop);
                if (previousScrollTop < maxScrollTop) {
                    consumed = true;
                }
            } else {
                newScrollTop = Math.max(newScrollTop, 0);
                if (previousScrollTop > 0) {
                    consumed = true;
                }
            }
            panorama.setScrollTop(newScrollTop);
        }
    }
    return consumed;
}
Also used : Panorama(org.apache.pivot.wtk.Panorama) Component(org.apache.pivot.wtk.Component)

Example 97 with Component

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

the class TerraPanoramaSkin method getMaxScrollTop.

protected int getMaxScrollTop() {
    int maxScrollTop = 0;
    Panorama panorama = (Panorama) getComponent();
    int height = getHeight();
    Component view = panorama.getView();
    if (view != null) {
        maxScrollTop = Math.max(view.getHeight() - height, 0);
    }
    return maxScrollTop;
}
Also used : Panorama(org.apache.pivot.wtk.Panorama) Component(org.apache.pivot.wtk.Component)

Example 98 with Component

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

the class TerraPanoramaSkin method scrollTopChanged.

// Viewport events
@Override
public void scrollTopChanged(Viewport panorama, int previousScrollTop) {
    Component view = panorama.getView();
    if (view != null) {
        int maxScrollTop = getMaxScrollTop();
        int scrollTop = Math.min(panorama.getScrollTop(), maxScrollTop);
        view.setLocation(view.getX(), -scrollTop);
        updateScrollButtonVisibility();
    }
}
Also used : Component(org.apache.pivot.wtk.Component)

Example 99 with Component

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

the class TerraPromptSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Prompt prompt = (Prompt) component;
    prompt.setPreferredWidth(320);
    prompt.setMinimumWidth(160);
    prompt.getPromptListeners().add(this);
    // Load the prompt content
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    Component content;
    try {
        content = (Component) bxmlSerializer.readObject(TerraPromptSkin.class, "terra_prompt_skin.bxml");
    } catch (Exception exception) {
        throw new RuntimeException(exception);
    }
    prompt.setContent(content);
    typeImageView = (ImageView) bxmlSerializer.getNamespace().get("typeImageView");
    messageLabel = (Label) bxmlSerializer.getNamespace().get("messageLabel");
    messageBoxPane = (BoxPane) bxmlSerializer.getNamespace().get("messageBoxPane");
    optionButtonBoxPane = (BoxPane) bxmlSerializer.getNamespace().get("optionButtonBoxPane");
    for (Object option : prompt.getOptions()) {
        PushButton optionButton = new PushButton(option);
        optionButton.setStyleName(BUTTON_STYLE_NAME);
        optionButton.getButtonPressListeners().add(optionButtonPressListener);
        optionButtonBoxPane.add(optionButton);
    }
    messageTypeChanged(prompt, null);
    messageChanged(prompt, null);
    bodyChanged(prompt, null);
}
Also used : Prompt(org.apache.pivot.wtk.Prompt) Component(org.apache.pivot.wtk.Component) PushButton(org.apache.pivot.wtk.PushButton) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 100 with Component

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

the class TerraRollupSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    Rollup rollup = (Rollup) getComponent();
    Component heading = rollup.getHeading();
    int baseline = -1;
    if (heading != null) {
        int headingWidth, headingHeight;
        if (fill) {
            headingWidth = Math.max(width - rollupButton.getPreferredWidth(-1) - buffer, 0);
            headingHeight = heading.getPreferredHeight(headingWidth);
        } else {
            Dimensions headingPreferredSize = heading.getPreferredSize();
            headingWidth = headingPreferredSize.width;
            headingHeight = headingPreferredSize.height;
        }
        baseline = heading.getBaseline(headingWidth, headingHeight);
    }
    return baseline;
}
Also used : Rollup(org.apache.pivot.wtk.Rollup) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Aggregations

Component (org.apache.pivot.wtk.Component)209 Dimensions (org.apache.pivot.wtk.Dimensions)40 Point (org.apache.pivot.wtk.Point)38 GradientPaint (java.awt.GradientPaint)33 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)24 TextInput (org.apache.pivot.wtk.TextInput)21 Label (org.apache.pivot.wtk.Label)20 BoxPane (org.apache.pivot.wtk.BoxPane)18 Paint (java.awt.Paint)17 Button (org.apache.pivot.wtk.Button)15 PushButton (org.apache.pivot.wtk.PushButton)14 ScrollPane (org.apache.pivot.wtk.ScrollPane)14 TablePane (org.apache.pivot.wtk.TablePane)14 Window (org.apache.pivot.wtk.Window)14 IOException (java.io.IOException)13 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)13 Frame (org.apache.pivot.wtk.Frame)13 FlowPane (org.apache.pivot.wtk.FlowPane)12 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)11 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)10