Search in sources :

Example 11 with Separator

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

the class TerraFormSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    int maximumLabelWidth = 0;
    int maximumFieldWidth = 0;
    int maximumSeparatorWidth = 0;
    Form form = (Form) getComponent();
    Form.SectionSequence sections = form.getSections();
    for (int sectionIndex = 0, sectionCount = sections.getLength(); sectionIndex < sectionCount; sectionIndex++) {
        Form.Section section = sections.get(sectionIndex);
        if (sectionIndex > 0 || section.getHeading() != null) {
            Separator separator = separators.get(sectionIndex);
            maximumSeparatorWidth = Math.max(maximumSeparatorWidth, separator.getPreferredWidth());
        }
        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());
                int fieldWidth = field.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);
                            fieldWidth += (INLINE_FIELD_INDICATOR_WIDTH - 2) + flagMessageLabel.getPreferredWidth();
                        }
                    }
                }
                maximumFieldWidth = Math.max(maximumFieldWidth, fieldWidth);
            }
        }
    }
    preferredWidth = maximumLabelWidth + horizontalSpacing + maximumFieldWidth;
    if (showFlagIcons) {
        preferredWidth += maximumFlagImageWidth + flagIconOffset;
    }
    preferredWidth = Math.max(preferredWidth + padding.left + padding.right, maximumSeparatorWidth);
    return preferredWidth;
}
Also used : Form(org.apache.pivot.wtk.Form) Label(org.apache.pivot.wtk.Label) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) Separator(org.apache.pivot.wtk.Separator)

Example 12 with Separator

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

the class TerraFormSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = 0;
    Form form = (Form) getComponent();
    Form.SectionSequence sections = form.getSections();
    // Determine the field width constraint
    int fieldWidth = (fill && width != -1) ? getFieldWidth(width) : -1;
    for (int sectionIndex = 0, sectionCount = sections.getLength(); sectionIndex < sectionCount; sectionIndex++) {
        Form.Section section = sections.get(sectionIndex);
        if (sectionIndex > 0 || section.getHeading() != null) {
            Separator separator = separators.get(sectionIndex);
            preferredHeight += separator.getPreferredHeight(width);
            preferredHeight += verticalSpacing;
        }
        for (int fieldIndex = 0, fieldCount = section.getLength(); fieldIndex < fieldCount; fieldIndex++) {
            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);
                int labelDescent = labelSize.height - labelAscent;
                // 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 = fieldSize.height;
                }
                int fieldDescent = fieldSize.height - fieldAscent;
                // Determine the row height
                int maximumAscent = Math.max(labelAscent, fieldAscent);
                int maximumDescent = Math.max(labelDescent, fieldDescent);
                int rowHeight = maximumAscent + maximumDescent;
                preferredHeight += rowHeight;
                if (fieldIndex > 0) {
                    preferredHeight += verticalSpacing;
                }
            }
        }
    }
    preferredHeight += (padding.top + padding.bottom);
    return preferredHeight;
}
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)

Aggregations

Separator (org.apache.pivot.wtk.Separator)12 Form (org.apache.pivot.wtk.Form)7 Point (org.apache.pivot.wtk.Point)7 Label (org.apache.pivot.wtk.Label)5 FontRenderContext (java.awt.font.FontRenderContext)4 Component (org.apache.pivot.wtk.Component)4 Dimensions (org.apache.pivot.wtk.Dimensions)4 LineMetrics (java.awt.font.LineMetrics)3 Rectangle2D (java.awt.geom.Rectangle2D)3 BasicStroke (java.awt.BasicStroke)1 Area (java.awt.geom.Area)1 ArrayList (org.apache.pivot.collections.ArrayList)1 Theme (org.apache.pivot.wtk.Theme)1