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