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();
}
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();
}
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();
}
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;
}
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;
}
Aggregations