Search in sources :

Example 46 with Component

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

the class BoxPaneSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    BoxPane boxPane = (BoxPane) getComponent();
    int preferredWidth = 0;
    Orientation orientation = boxPane.getOrientation();
    if (orientation == Orientation.HORIZONTAL) {
        int heightUpdated = height;
        // Include padding in constraint
        if (heightUpdated != -1) {
            heightUpdated = Math.max(heightUpdated - padding.getHeight(), 0);
        }
        // Preferred width is the sum of the preferred widths of all components
        int j = 0;
        for (int i = 0, n = boxPane.getLength(); i < n; i++) {
            Component component = boxPane.get(i);
            if (component.isVisible()) {
                preferredWidth += component.getPreferredWidth(fill ? heightUpdated : -1);
                j++;
            }
        }
        // Include spacing
        if (j > 1) {
            preferredWidth += spacing * (j - 1);
        }
    } else {
        // Preferred width is the maximum preferred width of all components
        for (int i = 0, n = boxPane.getLength(); i < n; i++) {
            Component component = boxPane.get(i);
            if (component.isVisible()) {
                preferredWidth = Math.max(preferredWidth, component.getPreferredWidth());
            }
        }
    }
    // Include left and right padding values
    preferredWidth += padding.getWidth();
    return preferredWidth;
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) Orientation(org.apache.pivot.wtk.Orientation) Component(org.apache.pivot.wtk.Component)

Example 47 with Component

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

the class BoxPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    BoxPane boxPane = (BoxPane) getComponent();
    int preferredWidth = 0;
    int preferredHeight = 0;
    switch(boxPane.getOrientation()) {
        case HORIZONTAL:
            {
                // Preferred width is the sum of the preferred widths of all
                // components
                int j = 0;
                for (int i = 0, n = boxPane.getLength(); i < n; i++) {
                    Component component = boxPane.get(i);
                    if (component.isVisible()) {
                        Dimensions preferredSize = component.getPreferredSize();
                        preferredWidth += preferredSize.width;
                        preferredHeight = Math.max(preferredSize.height, preferredHeight);
                        j++;
                    }
                }
                // Include spacing
                if (j > 1) {
                    preferredWidth += spacing * (j - 1);
                }
                break;
            }
        case VERTICAL:
            {
                // Preferred height is the sum of the preferred heights of all components
                int j = 0;
                for (int i = 0, n = boxPane.getLength(); i < n; i++) {
                    Component component = boxPane.get(i);
                    if (component.isVisible()) {
                        Dimensions preferredSize = component.getPreferredSize();
                        preferredWidth = Math.max(preferredSize.width, preferredWidth);
                        preferredHeight += preferredSize.height;
                        j++;
                    }
                }
                // Include spacing
                if (j > 1) {
                    preferredHeight += spacing * (j - 1);
                }
                break;
            }
        default:
            {
                break;
            }
    }
    // Include padding
    preferredWidth += padding.getWidth();
    preferredHeight += padding.getHeight();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 48 with Component

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

the class BoxPaneSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    BoxPane boxPane = (BoxPane) getComponent();
    int baseline = -1;
    int contentHeight = 0;
    switch(boxPane.getOrientation()) {
        case HORIZONTAL:
            {
                if (fill) {
                    int clientHeight = Math.max(height - padding.getHeight(), 0);
                    for (Component component : boxPane) {
                        if (component.isVisible()) {
                            int componentWidth = component.getPreferredWidth(clientHeight);
                            baseline = Math.max(baseline, component.getBaseline(componentWidth, clientHeight));
                        }
                    }
                } else {
                    contentHeight = 0;
                    for (Component component : boxPane) {
                        if (component.isVisible()) {
                            contentHeight = Math.max(contentHeight, component.getPreferredHeight());
                        }
                    }
                    for (Component component : boxPane) {
                        if (component.isVisible()) {
                            Dimensions size = component.getPreferredSize();
                            int componentBaseline = component.getBaseline(size.width, size.height);
                            if (componentBaseline != -1) {
                                switch(verticalAlignment) {
                                    case CENTER:
                                        {
                                            componentBaseline += (contentHeight - size.height) / 2;
                                            break;
                                        }
                                    case BOTTOM:
                                        {
                                            componentBaseline += contentHeight - size.height;
                                            break;
                                        }
                                    case TOP:
                                        {
                                            break;
                                        }
                                    default:
                                        {
                                            break;
                                        }
                                }
                            }
                            baseline = Math.max(baseline, componentBaseline);
                        }
                    }
                }
                break;
            }
        case VERTICAL:
            {
                int clientWidth = Math.max(width - padding.getWidth(), 0);
                for (Component component : boxPane) {
                    if (component.isVisible()) {
                        Dimensions size;
                        if (fill) {
                            size = new Dimensions(clientWidth, component.getPreferredHeight(clientWidth));
                        } else {
                            size = component.getPreferredSize();
                        }
                        if (baseline == -1) {
                            baseline = component.getBaseline(size.width, size.height);
                            if (baseline != -1) {
                                baseline += contentHeight;
                            }
                        }
                        contentHeight += size.height + spacing;
                    }
                }
                contentHeight -= spacing;
                break;
            }
        default:
            {
                break;
            }
    }
    if (baseline != -1) {
        if (fill) {
            baseline += padding.top;
        } else {
            switch(verticalAlignment) {
                case TOP:
                    {
                        baseline += padding.top;
                        break;
                    }
                case CENTER:
                    {
                        baseline += (height - contentHeight) / 2;
                        break;
                    }
                case BOTTOM:
                    {
                        baseline += height - (contentHeight + padding.bottom);
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
        }
    }
    return baseline;
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 49 with Component

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

the class CardPaneSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = 0;
    CardPane cardPane = (CardPane) getComponent();
    if (sizeToSelection) {
        if (selectionChangeTransition == null) {
            Component selectedCard = cardPane.getSelectedCard();
            if (selectedCard != null) {
                preferredHeight = selectedCard.getPreferredHeight(width);
            }
        } else {
            float percentComplete = selectionChangeTransition.getPercentComplete();
            int previousHeight;
            if (selectionChangeTransition.fromCard == null) {
                previousHeight = 0;
            } else {
                previousHeight = selectionChangeTransition.fromCard.getPreferredHeight(width);
            }
            int height;
            if (selectionChangeTransition.toCard == null) {
                height = 0;
            } else {
                height = selectionChangeTransition.toCard.getPreferredHeight(width);
            }
            preferredHeight = previousHeight + (int) ((height - previousHeight) * percentComplete);
        }
    } else {
        for (Component card : cardPane) {
            preferredHeight = Math.max(preferredHeight, card.getPreferredHeight(width));
        }
        preferredHeight += padding.getHeight();
    }
    return preferredHeight;
}
Also used : CardPane(org.apache.pivot.wtk.CardPane) Component(org.apache.pivot.wtk.Component)

Example 50 with Component

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

the class CardPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = 0;
    int preferredHeight = 0;
    CardPane cardPane = (CardPane) getComponent();
    if (sizeToSelection) {
        if (selectionChangeTransition == null) {
            Component selectedCard = cardPane.getSelectedCard();
            if (selectedCard != null) {
                Dimensions cardSize = selectedCard.getPreferredSize();
                preferredWidth = cardSize.width;
                preferredHeight = cardSize.height;
            }
        } else {
            float percentComplete = selectionChangeTransition.getPercentComplete();
            int previousWidth;
            int previousHeight;
            if (selectionChangeTransition.fromCard == null) {
                previousWidth = 0;
                previousHeight = 0;
            } else {
                Dimensions fromSize = selectionChangeTransition.fromCard.getPreferredSize();
                previousWidth = fromSize.width;
                previousHeight = fromSize.height;
            }
            int width;
            int height;
            if (selectionChangeTransition.toCard == null) {
                width = 0;
                height = 0;
            } else {
                Dimensions toSize = selectionChangeTransition.toCard.getPreferredSize();
                width = toSize.width;
                height = toSize.height;
            }
            preferredWidth = previousWidth + (int) ((width - previousWidth) * percentComplete);
            preferredHeight = previousHeight + (int) ((height - previousHeight) * percentComplete);
        }
    } else {
        for (Component card : cardPane) {
            Dimensions cardSize = card.getPreferredSize();
            preferredWidth = Math.max(cardSize.width, preferredWidth);
            preferredHeight = Math.max(cardSize.height, preferredHeight);
        }
    }
    preferredWidth += padding.getWidth();
    preferredHeight += padding.getHeight();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : CardPane(org.apache.pivot.wtk.CardPane) 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