Search in sources :

Example 36 with Label

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);
}
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 37 with Label

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

Example 38 with Label

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);
    }
}
Also used : Locale(java.util.Locale) GregorianCalendar(java.util.GregorianCalendar) Calendar(org.apache.pivot.wtk.Calendar) GregorianCalendar(java.util.GregorianCalendar) Label(org.apache.pivot.wtk.Label) SimpleDateFormat(java.text.SimpleDateFormat) GradientPaint(java.awt.GradientPaint) TablePane(org.apache.pivot.wtk.TablePane)

Example 39 with Label

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();
}
Also used : Label(org.apache.pivot.wtk.Label) GradientPaint(java.awt.GradientPaint) TablePane(org.apache.pivot.wtk.TablePane)

Example 40 with Label

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;
}
Also used : Insets(org.apache.pivot.wtk.Insets) IntValidator(org.apache.pivot.wtk.validation.IntValidator) BoxPane(org.apache.pivot.wtk.BoxPane) Label(org.apache.pivot.wtk.Label) FlowPane(org.apache.pivot.wtk.FlowPane) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

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