Search in sources :

Example 81 with Component

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

the class TerraFormSkin method layout.

@Override
public void layout() {
    Form form = (Form) getComponent();
    Form.SectionSequence sections = form.getSections();
    // Determine the maximum label and flag message width
    int maximumLabelWidth = 0;
    int maximumFlagMessageWidth = 0;
    for (int sectionIndex = 0, sectionCount = sections.getLength(); sectionIndex < sectionCount; sectionIndex++) {
        Form.Section section = sections.get(sectionIndex);
        for (int fieldIndex = 0, fieldCount = section.getLength(); fieldIndex < fieldCount; fieldIndex++) {
            Component field = section.get(fieldIndex);
            if (field.isVisible()) {
                Label label = labels.get(sectionIndex).get(fieldIndex);
                maximumLabelWidth = Math.max(maximumLabelWidth, label.getPreferredWidth());
                if (showFlagMessagesInline) {
                    // Calculate maximum flag message width
                    Form.Flag flag = Form.getFlag(field);
                    if (flag != null) {
                        String message = flag.getMessage();
                        if (message != null) {
                            flagMessageLabel.setText(message);
                            maximumFlagMessageWidth = Math.max(maximumFlagMessageWidth, flagMessageLabel.getPreferredWidth());
                        }
                    }
                }
            }
        }
    }
    // Determine the field width
    int width = getWidth();
    int fieldWidth = Math.max(0, width - (maximumLabelWidth + horizontalSpacing));
    if (showFlagIcons) {
        fieldWidth = Math.max(0, fieldWidth - (maximumFlagImageWidth + flagIconOffset));
    }
    if (showFlagMessagesInline) {
        fieldWidth = Math.max(0, fieldWidth - (maximumFlagMessageWidth + (INLINE_FIELD_INDICATOR_WIDTH - 2)));
    }
    fieldWidth = Math.max(0, fieldWidth - (padding.left + padding.right));
    // Lay out the components
    int rowY = padding.top;
    for (int sectionIndex = 0, sectionCount = sections.getLength(); sectionIndex < sectionCount; sectionIndex++) {
        Form.Section section = sections.get(sectionIndex);
        Separator separator = separators.get(sectionIndex);
        if (sectionIndex > 0 || section.getHeading() != null) {
            int separatorWidth = Math.max(width - (padding.left + padding.right), 0);
            separator.setVisible(true);
            separator.setSize(separatorWidth, separator.getPreferredHeight(separatorWidth));
            separator.setLocation(padding.left, rowY);
            rowY += separator.getHeight();
        } else {
            separator.setVisible(false);
        }
        for (int fieldIndex = 0, fieldCount = section.getLength(); fieldIndex < fieldCount; fieldIndex++) {
            Label label = labels.get(sectionIndex).get(fieldIndex);
            Component field = section.get(fieldIndex);
            if (field.isVisible()) {
                // Show the label
                label.setVisible(true);
                // Determine the label size and baseline
                Dimensions labelSize = label.getPreferredSize();
                label.setSize(labelSize);
                int labelAscent = label.getBaseline(labelSize.width, labelSize.height);
                int labelDescent = labelSize.height - labelAscent;
                // Determine the field size and baseline
                Dimensions fieldSize;
                if (fill) {
                    fieldSize = new Dimensions(fieldWidth, field.getPreferredHeight(fieldWidth));
                } else {
                    fieldSize = field.getPreferredSize();
                }
                field.setSize(fieldSize);
                int fieldAscent = field.getBaseline(fieldSize.width, fieldSize.height);
                if (fieldAscent == -1) {
                    fieldAscent = labelAscent;
                }
                int fieldDescent = fieldSize.height - fieldAscent;
                // Determine the baseline and row height
                int maximumAscent = Math.max(labelAscent, fieldAscent);
                int maximumDescent = Math.max(labelDescent, fieldDescent);
                int baseline = maximumAscent;
                int rowHeight = maximumAscent + maximumDescent;
                // Position the label
                int labelX = padding.left;
                if (!leftAlignLabels) {
                    labelX += maximumLabelWidth - label.getWidth();
                }
                if (showFlagIcons) {
                    labelX += (maximumFlagImageWidth + flagIconOffset);
                }
                int labelY = rowY + (baseline - labelAscent);
                label.setLocation(labelX, labelY);
                // Position the field
                int fieldX = padding.left + maximumLabelWidth + horizontalSpacing;
                if (showFlagIcons) {
                    fieldX += (maximumFlagImageWidth + flagIconOffset);
                }
                int fieldY = rowY + (baseline - fieldAscent);
                field.setLocation(fieldX, fieldY);
                // Update the row y-coordinate
                rowY += rowHeight + verticalSpacing;
            } else {
                // Hide the label
                label.setVisible(false);
            }
        }
    }
}
Also used : Form(org.apache.pivot.wtk.Form) Label(org.apache.pivot.wtk.Label) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) Separator(org.apache.pivot.wtk.Separator)

Example 82 with Component

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

the class TerraFormSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    int baseline = -1;
    Form form = (Form) getComponent();
    Form.SectionSequence sections = form.getSections();
    // Determine the field width constraint
    int fieldWidth = (fill) ? getFieldWidth(width) : -1;
    int sectionCount = sections.getLength();
    int sectionIndex = 0;
    int rowY = 0;
    while (sectionIndex < sectionCount && baseline == -1) {
        Form.Section section = sections.get(sectionIndex);
        if (sectionIndex > 0 || section.getHeading() != null) {
            Separator separator = separators.get(sectionIndex);
            rowY += separator.getPreferredHeight(width);
            rowY += verticalSpacing;
        }
        int fieldCount = section.getLength();
        int fieldIndex = 0;
        while (fieldIndex < fieldCount && baseline == -1) {
            Component field = section.get(fieldIndex);
            if (field.isVisible()) {
                // Determine the label size and baseline
                Label label = labels.get(sectionIndex).get(fieldIndex);
                Dimensions labelSize = label.getPreferredSize();
                int labelAscent = label.getBaseline(labelSize.width, labelSize.height);
                // Determine the field size and baseline
                Dimensions fieldSize;
                if (fill && fieldWidth != -1) {
                    fieldSize = new Dimensions(fieldWidth, field.getPreferredHeight(fieldWidth));
                } else {
                    fieldSize = field.getPreferredSize();
                }
                int fieldAscent = field.getBaseline(fieldSize.width, fieldSize.height);
                if (fieldAscent == -1) {
                    fieldAscent = labelAscent;
                }
                // Determine the baseline
                int maximumAscent = Math.max(labelAscent, fieldAscent);
                baseline = rowY + maximumAscent;
            }
            fieldIndex++;
        }
        sectionIndex++;
    }
    baseline += padding.top;
    return baseline;
}
Also used : Form(org.apache.pivot.wtk.Form) Label(org.apache.pivot.wtk.Label) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) Separator(org.apache.pivot.wtk.Separator)

Example 83 with Component

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

the class TerraFrameSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    Frame frame = (Frame) getComponent();
    // Include title bar width plus left/right title bar borders
    Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
    preferredWidth = Math.max(titleBarSize.width + 2, preferredWidth);
    if (height != -1) {
        // Subtract title bar height and top/bottom title bar borders
        // from height constraint
        height -= titleBarSize.height + 2;
    }
    // Include menu bar width
    MenuBar menuBar = frame.getMenuBar();
    if (menuBar != null) {
        Dimensions menuBarSize = menuBar.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, menuBarSize.width);
        if (height != -1) {
            // Subtract menu bar height from height constraint
            height -= menuBarSize.height;
        }
    }
    Component content = frame.getContent();
    if (content != null) {
        if (height != -1) {
            // Subtract padding, top/bottom content borders, and content bevel
            // from height constraint
            height -= (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
            height = Math.max(height, 0);
        }
        preferredWidth = Math.max(preferredWidth, content.getPreferredWidth(height));
    }
    // Add padding and left/right content borders
    preferredWidth += (padding.left + padding.right) + 2;
    return preferredWidth;
}
Also used : Frame(org.apache.pivot.wtk.Frame) Dimensions(org.apache.pivot.wtk.Dimensions) MenuBar(org.apache.pivot.wtk.MenuBar) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 84 with Component

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

the class TerraFrameSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = 0;
    Frame frame = (Frame) getComponent();
    // Include title bar height plus top/bottom title bar borders
    preferredHeight += titleBarTablePane.getPreferredHeight() + 2;
    // Include menu bar height
    MenuBar menuBar = frame.getMenuBar();
    if (menuBar != null) {
        preferredHeight += menuBar.getPreferredHeight();
    }
    Component content = frame.getContent();
    if (content != null) {
        if (width != -1) {
            // Subtract padding and left/right content borders from constraint
            width -= (padding.left + padding.right) + 2;
            width = Math.max(width, 0);
        }
        preferredHeight += content.getPreferredHeight(width);
    }
    // Add padding, top/bottom content borders, and content bevel
    preferredHeight += (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
    return preferredHeight;
}
Also used : Frame(org.apache.pivot.wtk.Frame) MenuBar(org.apache.pivot.wtk.MenuBar) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 85 with Component

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

the class TerraSplitPaneSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = splitterThickness;
    SplitPane splitPane = (SplitPane) getComponent();
    Component topLeft = splitPane.getTopLeft();
    if (topLeft != null) {
        preferredWidth += topLeft.getPreferredWidth(height);
    }
    Component bottomRight = splitPane.getBottomRight();
    if (bottomRight != null) {
        preferredWidth += bottomRight.getPreferredWidth(height);
    }
    return preferredWidth;
}
Also used : SplitPane(org.apache.pivot.wtk.SplitPane) 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