Search in sources :

Example 11 with Form

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

the class TerraFormSkin method getFieldWidth.

private int getFieldWidth(int width) {
    int maximumLabelWidth = 0;
    int maximumFlagMessageWidth = 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);
        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());
                        }
                    }
                }
            }
        }
    }
    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));
    return fieldWidth;
}
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)

Example 12 with Form

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

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

the class TerraFormSkin method updateFieldLabel.

private void updateFieldLabel(Form.Section section, int fieldIndex) {
    Form form = (Form) getComponent();
    Component field = section.get(fieldIndex);
    int sectionIndex = form.getSections().indexOf(section);
    Label label = labels.get(sectionIndex).get(fieldIndex);
    String labelText = Form.getLabel(field);
    label.setText((labelText == null) ? "" : labelText + delimiter);
}
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)

Example 14 with Form

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

the class TerraFormSkin method install.

@Override
public void install(Component component) {
    super.install(component);
    Form form = (Form) component;
    form.getFormListeners().add(this);
    form.getFormAttributeListeners().add(this);
    Form.SectionSequence sections = form.getSections();
    for (int i = 0, n = sections.getLength(); i < n; i++) {
        insertSection(sections.get(i), i);
    }
    form.getDecorators().add(new InlineFlagMessageDecorator());
}
Also used : Form(org.apache.pivot.wtk.Form) Point(org.apache.pivot.wtk.Point)

Example 15 with Form

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

Form (org.apache.pivot.wtk.Form)15 Point (org.apache.pivot.wtk.Point)14 Label (org.apache.pivot.wtk.Label)10 Component (org.apache.pivot.wtk.Component)8 Separator (org.apache.pivot.wtk.Separator)7 Dimensions (org.apache.pivot.wtk.Dimensions)3 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 ArrayList (org.apache.pivot.collections.ArrayList)1 Bounds (org.apache.pivot.wtk.Bounds)1 MessageType (org.apache.pivot.wtk.MessageType)1 Image (org.apache.pivot.wtk.media.Image)1