Search in sources :

Example 11 with BoxPane

use of org.apache.pivot.wtk.BoxPane 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 12 with BoxPane

use of org.apache.pivot.wtk.BoxPane 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 13 with BoxPane

use of org.apache.pivot.wtk.BoxPane 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 14 with BoxPane

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

the class ColorSchemeBuilderWindow method createColorPaletteCell.

private static Component createColorPaletteCell(int index) {
    Border border = new Border();
    border.getStyles().put(Style.backgroundColor, index);
    Theme theme = Theme.getTheme();
    Label label = new Label();
    label.setText(Integer.toString(index));
    label.getStyles().put(Style.font, "{size:'80%'}");
    label.getStyles().put(Style.backgroundColor, 4);
    label.getStyles().put(Style.padding, 1);
    BoxPane boxPane = new BoxPane();
    boxPane.getStyles().put(Style.padding, 2);
    boxPane.getStyles().put(Style.horizontalAlignment, HorizontalAlignment.CENTER);
    boxPane.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
    boxPane.add(new Border(label));
    border.setContent(boxPane);
    return border;
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) Label(org.apache.pivot.wtk.Label) Theme(org.apache.pivot.wtk.Theme) Border(org.apache.pivot.wtk.Border)

Example 15 with BoxPane

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

the class ColorListButtonTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    BoxPane boxPane = (BoxPane) bxmlSerializer.readObject(ColorListButtonTest.class, "color_list_button_test.bxml");
    listButton = (ListButton) bxmlSerializer.getNamespace().get("listButton");
    // test the getListPopup() method
    listButton.getListPopup().getDecorators().add(new ReflectionDecorator());
    frame = new Frame(boxPane);
    frame.setTitle("Color List Button Test");
    frame.setPreferredSize(480, 360);
    frame.open(display);
}
Also used : Frame(org.apache.pivot.wtk.Frame) BoxPane(org.apache.pivot.wtk.BoxPane) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) ReflectionDecorator(org.apache.pivot.wtk.effects.ReflectionDecorator)

Aggregations

BoxPane (org.apache.pivot.wtk.BoxPane)38 Component (org.apache.pivot.wtk.Component)18 Label (org.apache.pivot.wtk.Label)15 TextInput (org.apache.pivot.wtk.TextInput)15 Button (org.apache.pivot.wtk.Button)9 Frame (org.apache.pivot.wtk.Frame)9 PushButton (org.apache.pivot.wtk.PushButton)9 Window (org.apache.pivot.wtk.Window)8 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)7 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)7 FlowPane (org.apache.pivot.wtk.FlowPane)7 IntValidator (org.apache.pivot.wtk.validation.IntValidator)7 Dimensions (org.apache.pivot.wtk.Dimensions)5 Border (org.apache.pivot.wtk.Border)4 TablePane (org.apache.pivot.wtk.TablePane)4 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 ListView (org.apache.pivot.wtk.ListView)3 Sheet (org.apache.pivot.wtk.Sheet)3 Spinner (org.apache.pivot.wtk.Spinner)3 Color (java.awt.Color)2