Search in sources :

Example 1 with FillPane

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

the class FillPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    FillPane fillPane = (FillPane) getComponent();
    int preferredWidth = 0;
    int preferredHeight = 0;
    switch(fillPane.getOrientation()) {
        case HORIZONTAL:
            {
                // Preferred width is the sum of the preferred widths of all
                // components
                int j = 0;
                for (int i = 0, n = fillPane.getLength(); i < n; i++) {
                    Component component = fillPane.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 = fillPane.getLength(); i < n; i++) {
                    Component component = fillPane.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 : FillPane(org.apache.pivot.wtk.FillPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 2 with FillPane

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

the class FillPaneSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    FillPane fillPane = (FillPane) getComponent();
    int preferredWidth = 0;
    Orientation orientation = fillPane.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 = fillPane.getLength(); i < n; i++) {
            Component component = fillPane.get(i);
            if (component.isVisible()) {
                preferredWidth += component.getPreferredWidth(heightUpdated);
                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 = fillPane.getLength(); i < n; i++) {
            Component component = fillPane.get(i);
            if (component.isVisible()) {
                preferredWidth = Math.max(preferredWidth, component.getPreferredWidth());
            }
        }
    }
    // Include left and right padding values
    preferredWidth += padding.getWidth();
    return preferredWidth;
}
Also used : FillPane(org.apache.pivot.wtk.FillPane) Orientation(org.apache.pivot.wtk.Orientation) Component(org.apache.pivot.wtk.Component)

Example 3 with FillPane

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

the class FillPaneSkin method layout.

@Override
public void layout() {
    FillPane fillPane = (FillPane) getComponent();
    // n is the number of 'visible' components
    // len is the total number of components
    int n = 0;
    int len = fillPane.getLength();
    for (int i = 0; i < len; i++) {
        Component component = fillPane.get(i);
        if (component.isVisible()) {
            n++;
        }
    }
    int width = getWidth();
    int height = getHeight();
    if (width <= 0) {
        width = getPreferredWidth(-1);
    }
    if (height <= 0) {
        height = getPreferredHeight(-1);
    }
    Orientation orientation = fillPane.getOrientation();
    if (orientation == Orientation.HORIZONTAL) {
        // Determine the starting x-coordinate
        int x = padding.left;
        int totalWidth = width - padding.getWidth();
        if (n > 1) {
            totalWidth -= spacing * (n - 1);
        }
        int dividedWidth = n == 0 ? 0 : totalWidth / n;
        int leftoverWidth = totalWidth - (dividedWidth * n);
        // Lay out the components
        for (int i = 0, j = 0; i < len; i++) {
            Component component = fillPane.get(i);
            if (component.isVisible()) {
                int componentWidth = dividedWidth;
                if (j == n - 1) {
                    componentWidth += leftoverWidth;
                }
                int componentHeight = Math.max(height - padding.getHeight(), 0);
                int y = padding.top;
                // Set the component's size and position
                component.setSize(componentWidth, componentHeight);
                component.setLocation(x, y);
                // Increment the x-coordinate
                x += componentWidth + spacing;
                j++;
            }
        }
    } else {
        // Determine the starting y-coordinate
        int y = padding.top;
        int totalHeight = height - padding.getHeight();
        if (n > 1) {
            totalHeight -= spacing * (n - 1);
        }
        int dividedHeight = n == 0 ? 0 : totalHeight / n;
        int leftoverHeight = totalHeight - (dividedHeight * n);
        // Lay out the components
        for (int i = 0, j = 0; i < len; i++) {
            Component component = fillPane.get(i);
            if (component.isVisible()) {
                int componentHeight = dividedHeight;
                if (j == n - 1) {
                    componentHeight += leftoverHeight;
                }
                int componentWidth = Math.max(width - padding.getWidth(), 0);
                int x = padding.left;
                // Set the component's size and position
                component.setSize(componentWidth, componentHeight);
                component.setLocation(x, y);
                // Increment the y-coordinate
                y += componentHeight + spacing;
                j++;
            }
        }
    }
}
Also used : FillPane(org.apache.pivot.wtk.FillPane) Component(org.apache.pivot.wtk.Component) Orientation(org.apache.pivot.wtk.Orientation)

Example 4 with FillPane

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

the class FillPaneSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    FillPane fillPane = (FillPane) getComponent();
    int preferredHeight = 0;
    Orientation orientation = fillPane.getOrientation();
    if (orientation == Orientation.HORIZONTAL) {
        // components
        for (int i = 0, n = fillPane.getLength(); i < n; i++) {
            Component component = fillPane.get(i);
            if (component.isVisible()) {
                preferredHeight = Math.max(preferredHeight, component.getPreferredHeight());
            }
        }
    } else {
        int widthUpdated = width;
        // Include padding in constraint
        if (widthUpdated != -1) {
            widthUpdated = Math.max(widthUpdated - padding.getWidth(), 0);
        }
        // Preferred height is the sum of the preferred heights of all
        // components
        int j = 0;
        for (int i = 0, n = fillPane.getLength(); i < n; i++) {
            Component component = fillPane.get(i);
            if (component.isVisible()) {
                preferredHeight += component.getPreferredHeight(widthUpdated);
                j++;
            }
        }
        // Include spacing
        if (j > 1) {
            preferredHeight += spacing * (j - 1);
        }
    }
    // Include top and bottom padding values
    preferredHeight += padding.getHeight();
    return preferredHeight;
}
Also used : FillPane(org.apache.pivot.wtk.FillPane) Orientation(org.apache.pivot.wtk.Orientation) Component(org.apache.pivot.wtk.Component)

Example 5 with FillPane

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

the class FillPaneSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    FillPane fillPane = (FillPane) component;
    fillPane.getFillPaneListeners().add(this);
}
Also used : FillPane(org.apache.pivot.wtk.FillPane)

Aggregations

FillPane (org.apache.pivot.wtk.FillPane)6 Component (org.apache.pivot.wtk.Component)5 Orientation (org.apache.pivot.wtk.Orientation)3 Dimensions (org.apache.pivot.wtk.Dimensions)2