Search in sources :

Example 36 with Component

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

the class GridPaneSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    GridPane gridPane = (GridPane) getComponent();
    GridPane.RowSequence rows = gridPane.getRows();
    int columnCount = gridPane.getColumnCount();
    int rowCount = rows.getLength();
    Metadata metadata = new Metadata();
    int cellWidthLocal = getCellWidth(width, metadata);
    int cellHeightLocal = getCellHeight(height, metadata);
    // Return the first available baseline by traversing cells top left to
    // bottom right
    int baseline = -1;
    int rowY = padding.top;
    for (int i = 0; i < rowCount && baseline == -1; i++) {
        if (metadata.isRowVisible(i)) {
            GridPane.Row row = rows.get(i);
            for (int j = 0, n = row.getLength(); j < n && j < columnCount && baseline == -1; j++) {
                Component component = row.get(j);
                if (component != null && component.isVisible()) {
                    baseline = component.getBaseline(cellWidthLocal, cellHeightLocal);
                    if (baseline != -1) {
                        baseline += rowY;
                    }
                }
            }
            rowY += (cellHeightLocal + verticalSpacing);
        }
    }
    return baseline;
}
Also used : GridPane(org.apache.pivot.wtk.GridPane) Component(org.apache.pivot.wtk.Component)

Example 37 with Component

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

the class GridPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    GridPane gridPane = (GridPane) getComponent();
    GridPane.RowSequence rows = gridPane.getRows();
    int columnCount = gridPane.getColumnCount();
    int rowCount = rows.getLength();
    Metadata metadata = new Metadata();
    // calculate the maximum preferred cellWidth and cellHeight
    int preferredCellHeight = 0;
    int preferredCellWidth = 0;
    for (int i = 0; i < rowCount; i++) {
        GridPane.Row row = rows.get(i);
        for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) {
            Component component = row.get(j);
            if (component != null && component.isVisible()) {
                Dimensions d = component.getPreferredSize();
                preferredCellHeight = Math.max(preferredCellHeight, d.height);
                preferredCellWidth = Math.max(preferredCellWidth, d.width);
            }
        }
    }
    // The preferred width of the grid pane is the sum of the column
    // widths, plus padding and spacing
    int preferredWidth = (metadata.visibleColumnCount * preferredCellWidth) + padding.getWidth();
    if (metadata.visibleColumnCount > 1) {
        preferredWidth += (metadata.visibleColumnCount - 1) * horizontalSpacing;
    }
    // The preferred height of the grid pane is the sum of the row
    // heights, plus padding and spacing
    int preferredHeight = (metadata.visibleRowCount * preferredCellHeight) + padding.getHeight();
    if (metadata.visibleRowCount > 1) {
        preferredHeight += (metadata.visibleRowCount - 1) * verticalSpacing;
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : GridPane(org.apache.pivot.wtk.GridPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 38 with Component

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

the class GridPaneSkin method layout.

@Override
public void layout() {
    GridPane gridPane = (GridPane) getComponent();
    GridPane.RowSequence rows = gridPane.getRows();
    int columnCount = gridPane.getColumnCount();
    int rowCount = rows.getLength();
    int width = getWidth();
    int height = getHeight();
    Metadata metadata = new Metadata();
    cellWidth = getCellWidth(width, metadata);
    cellHeight = getCellHeight(height, metadata);
    int componentY = padding.top;
    for (int i = 0; i < rowCount; i++) {
        if (metadata.isRowVisible(i)) {
            GridPane.Row row = rows.get(i);
            int componentX = padding.left;
            for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) {
                Component component = row.get(j);
                if (component != null && component.isVisible()) {
                    component.setLocation(componentX, componentY);
                    component.setSize(cellWidth, cellHeight);
                }
                if (metadata.isColumnVisible(j)) {
                    componentX += (cellWidth + horizontalSpacing);
                }
            }
            componentY += (cellHeight + verticalSpacing);
        }
    }
}
Also used : GridPane(org.apache.pivot.wtk.GridPane) Component(org.apache.pivot.wtk.Component)

Example 39 with Component

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

use of org.apache.pivot.wtk.Component 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)

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