Search in sources :

Example 21 with Dimensions

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

the class DimensionsTest method test.

@Test
public void test() {
    Dimensions zero = Dimensions.ZERO;
    Dimensions zeroA = new Dimensions(0, 0);
    Dimensions zeroB = new Dimensions(0);
    Dimensions one = new Dimensions(1, 1);
    Dimensions oneA = zero.expand(1);
    Dimensions zeroC = oneA.expand(-1, -1);
    Dimensions seven = new Dimensions(7);
    Dimensions sevenA = new Dimensions(7, 7);
    Dimensions sevenB = zero.expand(7);
    Dimensions sevenC = zeroA.expand(7, 7);
    Dimensions a = Dimensions.decode("2 x 3");
    Dimensions a1 = new Dimensions(2, 3);
    Dimensions b = Dimensions.decode("{width:4, height:5}");
    Dimensions b1 = new Dimensions(4, 5);
    Dimensions c = Dimensions.decode("1  ,  2");
    Dimensions c1 = new Dimensions(1, 2);
    Dimensions d = Dimensions.decode("[  17,   23]");
    Dimensions d1 = new Dimensions(17, 23);
    Dimensions e = Dimensions.decode("23 ; 45");
    Dimensions e1 = new Dimensions(23, 45);
    Insets i1 = new Insets(1, 2, 1, 2);
    Dimensions f = e1.expand(i1);
    Dimensions f1 = new Dimensions(27, 47);
    assertEquals(zero, zeroA);
    assertEquals(one, oneA);
    assertEquals(zeroA, zeroB);
    assertEquals(zero, zeroC);
    assertEquals(seven, sevenA);
    assertEquals(seven, sevenB);
    assertEquals(sevenB, sevenC);
    assertEquals(a, a1);
    assertEquals(b, b1);
    assertEquals(c, c1);
    assertEquals(d, d1);
    assertEquals(e, e1);
    assertEquals(f, f1);
}
Also used : Insets(org.apache.pivot.wtk.Insets) Dimensions(org.apache.pivot.wtk.Dimensions) Test(org.junit.Test)

Example 22 with Dimensions

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

the class TerraDialogSkin method windowOpened.

@Override
public void windowOpened(Window window) {
    super.windowOpened(window);
    Display display = window.getDisplay();
    display.getContainerMouseListeners().add(displayMouseListener);
    display.reenterMouse();
    if (!window.requestFocus()) {
        Component.clearFocus();
    }
    // Center the dialog over its owner
    Container ancestor = window.getOwner();
    if (ancestor == null) {
        ancestor = window.getDisplay();
    }
    Dimensions size = window.getPreferredSize();
    int deltaWidth = ancestor.getWidth() - size.width;
    int deltaHeight = ancestor.getHeight() - size.height;
    int x = Math.max(0, Math.round(ancestor.getX() + 0.5f * deltaWidth));
    int y = Math.max(0, Math.round(ancestor.getY() + GOLDEN_SECTION * deltaHeight));
    window.setLocation(x, y);
}
Also used : Container(org.apache.pivot.wtk.Container) Dimensions(org.apache.pivot.wtk.Dimensions) Display(org.apache.pivot.wtk.Display)

Example 23 with Dimensions

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

the class TerraExpanderSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    Expander expander = (Expander) getComponent();
    Component content = expander.getContent();
    Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
    int preferredWidth = titleBarSize.width;
    int preferredHeight = titleBarSize.height;
    if (content != null) {
        Dimensions contentSize = content.getPreferredSize();
        preferredWidth = Math.max(contentSize.width + padding.getWidth(), preferredWidth);
        if (expander.isExpanded() || expandTransition != null) {
            // Title bar border is only drawn when expander is expanded
            // or expanding
            preferredHeight += 1;
            int fullHeight = padding.getHeight() + contentSize.height;
            if (expandTransition == null) {
                preferredHeight += fullHeight;
            } else {
                float scale = expandTransition.getScale();
                preferredHeight += (int) (scale * fullHeight);
            }
        }
    }
    preferredWidth += 2;
    preferredHeight += 2;
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Expander(org.apache.pivot.wtk.Expander) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) GradientPaint(java.awt.GradientPaint)

Example 24 with Dimensions

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

the class TerraFormSkin method layout.

@Override
public void layout() {
    Form form = (Form) getComponent();
    Form.SectionSequence sections = form.getSections();
    // Determine the maximum label and flag message width
    int maximumLabelWidth = 0;
    int maximumFlagMessageWidth = 0;
    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());
                        }
                    }
                }
            }
        }
    }
    // Determine the field width
    int width = getWidth();
    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));
    // Lay out the components
    int rowY = padding.top;
    for (int sectionIndex = 0, sectionCount = sections.getLength(); sectionIndex < sectionCount; sectionIndex++) {
        Form.Section section = sections.get(sectionIndex);
        Separator separator = separators.get(sectionIndex);
        if (sectionIndex > 0 || section.getHeading() != null) {
            int separatorWidth = Math.max(width - (padding.left + padding.right), 0);
            separator.setVisible(true);
            separator.setSize(separatorWidth, separator.getPreferredHeight(separatorWidth));
            separator.setLocation(padding.left, rowY);
            rowY += separator.getHeight();
        } else {
            separator.setVisible(false);
        }
        for (int fieldIndex = 0, fieldCount = section.getLength(); fieldIndex < fieldCount; fieldIndex++) {
            Label label = labels.get(sectionIndex).get(fieldIndex);
            Component field = section.get(fieldIndex);
            if (field.isVisible()) {
                // Show the label
                label.setVisible(true);
                // Determine the label size and baseline
                Dimensions labelSize = label.getPreferredSize();
                label.setSize(labelSize);
                int labelAscent = label.getBaseline(labelSize.width, labelSize.height);
                int labelDescent = labelSize.height - labelAscent;
                // Determine the field size and baseline
                Dimensions fieldSize;
                if (fill) {
                    fieldSize = new Dimensions(fieldWidth, field.getPreferredHeight(fieldWidth));
                } else {
                    fieldSize = field.getPreferredSize();
                }
                field.setSize(fieldSize);
                int fieldAscent = field.getBaseline(fieldSize.width, fieldSize.height);
                if (fieldAscent == -1) {
                    fieldAscent = labelAscent;
                }
                int fieldDescent = fieldSize.height - fieldAscent;
                // Determine the baseline and row height
                int maximumAscent = Math.max(labelAscent, fieldAscent);
                int maximumDescent = Math.max(labelDescent, fieldDescent);
                int baseline = maximumAscent;
                int rowHeight = maximumAscent + maximumDescent;
                // Position the label
                int labelX = padding.left;
                if (!leftAlignLabels) {
                    labelX += maximumLabelWidth - label.getWidth();
                }
                if (showFlagIcons) {
                    labelX += (maximumFlagImageWidth + flagIconOffset);
                }
                int labelY = rowY + (baseline - labelAscent);
                label.setLocation(labelX, labelY);
                // Position the field
                int fieldX = padding.left + maximumLabelWidth + horizontalSpacing;
                if (showFlagIcons) {
                    fieldX += (maximumFlagImageWidth + flagIconOffset);
                }
                int fieldY = rowY + (baseline - fieldAscent);
                field.setLocation(fieldX, fieldY);
                // Update the row y-coordinate
                rowY += rowHeight + verticalSpacing;
            } else {
                // Hide the label
                label.setVisible(false);
            }
        }
    }
}
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 25 with Dimensions

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

the class TerraFormSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    int baseline = -1;
    Form form = (Form) getComponent();
    Form.SectionSequence sections = form.getSections();
    // Determine the field width constraint
    int fieldWidth = (fill) ? getFieldWidth(width) : -1;
    int sectionCount = sections.getLength();
    int sectionIndex = 0;
    int rowY = 0;
    while (sectionIndex < sectionCount && baseline == -1) {
        Form.Section section = sections.get(sectionIndex);
        if (sectionIndex > 0 || section.getHeading() != null) {
            Separator separator = separators.get(sectionIndex);
            rowY += separator.getPreferredHeight(width);
            rowY += verticalSpacing;
        }
        int fieldCount = section.getLength();
        int fieldIndex = 0;
        while (fieldIndex < fieldCount && baseline == -1) {
            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);
                // 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 = labelAscent;
                }
                // Determine the baseline
                int maximumAscent = Math.max(labelAscent, fieldAscent);
                baseline = rowY + maximumAscent;
            }
            fieldIndex++;
        }
        sectionIndex++;
    }
    baseline += padding.top;
    return baseline;
}
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)

Aggregations

Dimensions (org.apache.pivot.wtk.Dimensions)76 Component (org.apache.pivot.wtk.Component)40 GradientPaint (java.awt.GradientPaint)21 Point (org.apache.pivot.wtk.Point)16 FontRenderContext (java.awt.font.FontRenderContext)9 Button (org.apache.pivot.wtk.Button)9 Paint (java.awt.Paint)7 Rectangle2D (java.awt.geom.Rectangle2D)6 LineMetrics (java.awt.font.LineMetrics)5 BoxPane (org.apache.pivot.wtk.BoxPane)5 FlowPane (org.apache.pivot.wtk.FlowPane)5 Label (org.apache.pivot.wtk.Label)5 ScrollPane (org.apache.pivot.wtk.ScrollPane)4 Separator (org.apache.pivot.wtk.Separator)4 Form (org.apache.pivot.wtk.Form)3 ImageView (org.apache.pivot.wtk.ImageView)3 Image (org.apache.pivot.wtk.media.Image)3 Color (java.awt.Color)2 Font (java.awt.Font)2 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)2