use of org.apache.pivot.wtk.Label 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);
}
use of org.apache.pivot.wtk.Label 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;
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class TerraCalendarSkin method updateLabels.
private void updateLabels() {
TablePane.Row row = calendarTablePane.getRows().get(1);
Calendar calendar = (Calendar) getComponent();
Locale locale = calendar.getLocale();
GregorianCalendar gregorianCalendar = new GregorianCalendar(locale);
SimpleDateFormat monthFormat = new SimpleDateFormat("E", locale);
int firstDayOfWeek = gregorianCalendar.getFirstDayOfWeek();
for (int i = 0; i < 7; i++) {
Label label = (Label) row.get(i);
gregorianCalendar.set(java.util.Calendar.DAY_OF_WEEK, firstDayOfWeek + i);
String text = monthFormat.format(gregorianCalendar.getTime());
text = Character.toString(text.charAt(weekdayCharacterIndex));
label.setText(text);
}
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class TerraCalendarSkin method setFont.
public void setFont(Font font) {
Utils.checkNull(font, "font");
this.font = font;
monthSpinner.getStyles().put(Style.font, font);
yearSpinner.getStyles().put(Style.font, font);
TablePane.Row row = calendarTablePane.getRows().get(1);
for (int i = 0; i < 7; i++) {
Label label = (Label) row.get(i);
label.getStyles().put(Style.font, font);
}
invalidateComponent();
}
use of org.apache.pivot.wtk.Label in project pivot by apache.
the class ComponentInspectorSkin method addInsetsControl.
private static Component addInsetsControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
Insets insets = (Insets) dictionary.get(key);
BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
section.add(boxPane);
Form.setLabel(boxPane, key);
FlowPane flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
TextInput textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(insets.top));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Insets insetsLocal = (Insets) dictionary.get(key);
try {
int top = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Insets(top, insetsLocal.left, insetsLocal.bottom, insetsLocal.right));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(insetsLocal.top));
}
}
}
});
Label label = new Label("top");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(insets.left));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Insets insetsLocal = (Insets) dictionary.get(key);
try {
int left = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Insets(insetsLocal.top, left, insetsLocal.bottom, insetsLocal.right));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(insetsLocal.left));
}
}
}
});
label = new Label("left");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(insets.bottom));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Insets insetsLocal = (Insets) dictionary.get(key);
try {
int bottom = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Insets(insetsLocal.top, insetsLocal.left, bottom, insetsLocal.right));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(insetsLocal.bottom));
}
}
}
});
label = new Label("bottom");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(4);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(insets.right));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Insets insetsLocal = (Insets) dictionary.get(key);
try {
int right = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Insets(insetsLocal.top, insetsLocal.left, insetsLocal.bottom, right));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(String.valueOf(insetsLocal.right));
}
}
}
});
label = new Label("right");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
return boxPane;
}
Aggregations