Search in sources :

Example 31 with Label

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

the class TerraFormSkin method insertSection.

private void insertSection(Form.Section section, int index) {
    Form form = (Form) getComponent();
    // Insert separator
    Separator separator = new Separator(section.getHeading());
    separator.getStyles().put(Style.color, separatorColor);
    separator.getStyles().put(Style.headingColor, separatorHeadingColor);
    separators.insert(separator, index);
    form.add(separator);
    // Insert label list
    ArrayList<Label> sectionLabels = new ArrayList<>();
    labels.insert(sectionLabels, index);
    // Insert fields
    for (int i = 0, n = section.getLength(); i < n; i++) {
        insertField(section, section.get(i), i);
    }
    invalidateComponent();
}
Also used : Form(org.apache.pivot.wtk.Form) Label(org.apache.pivot.wtk.Label) ArrayList(org.apache.pivot.collections.ArrayList) Separator(org.apache.pivot.wtk.Separator) Point(org.apache.pivot.wtk.Point)

Example 32 with Label

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

the class TerraFormSkin method insertField.

private void insertField(Form.Section section, Component field, int index) {
    Form form = (Form) getComponent();
    int sectionIndex = form.getSections().indexOf(section);
    // Create the label
    Label label = new Label();
    labels.get(sectionIndex).insert(label, index);
    form.add(label);
    // Add mouse listener
    field.getComponentMouseListeners().add(fieldMouseListener);
    // Update the field label
    updateFieldLabel(section, index);
    invalidateComponent();
}
Also used : Form(org.apache.pivot.wtk.Form) Label(org.apache.pivot.wtk.Label) Point(org.apache.pivot.wtk.Point)

Example 33 with Label

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

the class TerraFormSkin method removeFields.

private void removeFields(int sectionIndex, int index, Sequence<Component> removed) {
    Form form = (Form) getComponent();
    int count = removed.getLength();
    // Remove the labels
    Sequence<Label> removedLabels = labels.get(sectionIndex).remove(index, count);
    for (int i = 0; i < count; i++) {
        form.remove(removedLabels.get(i));
        // Remove mouse listener
        Component field = removed.get(i);
        field.getComponentMouseListeners().remove(fieldMouseListener);
    }
    invalidateComponent();
}
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 34 with Label

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

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

Aggregations

Label (org.apache.pivot.wtk.Label)44 Component (org.apache.pivot.wtk.Component)20 BoxPane (org.apache.pivot.wtk.BoxPane)15 Point (org.apache.pivot.wtk.Point)13 Form (org.apache.pivot.wtk.Form)10 TextInput (org.apache.pivot.wtk.TextInput)8 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)7 FlowPane (org.apache.pivot.wtk.FlowPane)7 IntValidator (org.apache.pivot.wtk.validation.IntValidator)7 TablePane (org.apache.pivot.wtk.TablePane)6 FontRenderContext (java.awt.font.FontRenderContext)5 Rectangle2D (java.awt.geom.Rectangle2D)5 Dimensions (org.apache.pivot.wtk.Dimensions)5 Frame (org.apache.pivot.wtk.Frame)5 Separator (org.apache.pivot.wtk.Separator)5 Color (java.awt.Color)3 Font (java.awt.Font)3 LineMetrics (java.awt.font.LineMetrics)3 IOException (java.io.IOException)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3