Search in sources :

Example 16 with Dimensions

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

the class StackPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = 0;
    int preferredHeight = 0;
    StackPane stackPane = (StackPane) getComponent();
    for (Component component : stackPane) {
        Dimensions preferredCardSize = component.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, preferredCardSize.width);
        preferredHeight = Math.max(preferredHeight, preferredCardSize.height);
    }
    preferredWidth += padding.getWidth();
    preferredHeight += padding.getHeight();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) StackPane(org.apache.pivot.wtk.StackPane)

Example 17 with Dimensions

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

the class BorderSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = 0;
    int preferredHeight = 0;
    Border border = (Border) getComponent();
    String title = border.getTitle();
    if (title != null && title.length() > 0) {
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        Rectangle2D headingBounds = font.getStringBounds(title, fontRenderContext);
        preferredWidth = (int) Math.ceil(headingBounds.getWidth());
    }
    Component content = border.getContent();
    if (content != null) {
        Dimensions preferredSize = content.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, preferredSize.width);
        preferredHeight += preferredSize.height;
    }
    preferredWidth += paddingThicknessWidth();
    preferredHeight += paddingThicknessHeight();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Dimensions(org.apache.pivot.wtk.Dimensions) FontRenderContext(java.awt.font.FontRenderContext) Component(org.apache.pivot.wtk.Component) Border(org.apache.pivot.wtk.Border) Paint(java.awt.Paint)

Example 18 with Dimensions

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

the class FlowPaneSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    FlowPane flowPane = (FlowPane) getComponent();
    int baseline = -1;
    if (alignToBaseline) {
        int contentWidth = Math.max(width - padding.getWidth(), 0);
        // Break the components into multiple rows, and calculate the
        // baseline of the first row
        int rowWidth = 0;
        for (int i = 0, n = flowPane.getLength(); i < n; i++) {
            Component component = flowPane.get(i);
            if (component.isVisible()) {
                Dimensions size = component.getPreferredSize();
                if (rowWidth + size.width > contentWidth && rowWidth > 0) {
                    // and it is not the only component in this row; wrap
                    break;
                }
                baseline = Math.max(baseline, component.getBaseline(size.width, size.height));
                rowWidth += size.width + horizontalSpacing;
            }
        }
        // Include top padding value
        baseline += padding.top;
    }
    return baseline;
}
Also used : FlowPane(org.apache.pivot.wtk.FlowPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 19 with Dimensions

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

the class TerraTooltipSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    Dimensions size = Dimensions.ZERO;
    Tooltip tooltip = (Tooltip) getComponent();
    Component content = tooltip.getContent();
    if (content != null) {
        size = content.getPreferredSize();
    }
    return size.expand(padding);
}
Also used : Tooltip(org.apache.pivot.wtk.Tooltip) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 20 with Dimensions

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

the class BoundsTest method test.

@Test
public void test() {
    Bounds bndMinus1 = new Bounds(-1, -1, 0, 0);
    Bounds bnd0 = new Bounds(0, 0, 0, 0);
    Bounds bnd1 = new Bounds(1, 1, 1, 1);
    Dimensions dim0 = new Dimensions(0, 0);
    Dimensions dim1 = new Dimensions(1, 1);
    Point p10 = new Point(10, 10);
    Bounds bnd10 = new Bounds(p10, dim1);
    Bounds bnd10a = new Bounds(dim1);
    Bounds bnd10b = new Bounds(0, 0, 1, 1);
    Bounds bnd2 = Bounds.decode("[2, 3, 4, 5]");
    Bounds bnd3 = Bounds.decode("{x:2, y:3, width:4, height:5}");
    Bounds bnd3a = new Bounds(2, 3, 4, 5);
    Bounds bnd4 = new Bounds(4, 4, 4, 5);
    // -> {3, 4, 4, 5}
    Bounds bnd5 = bnd3a.translate(1, 1);
    bnd5 = bnd5.expand(-2, -4);
    Bounds bnd5a = new Bounds(3, 4, 2, 1);
    Bounds bnd5b = new Bounds(4, 3, 1, 2);
    Bounds bndN = new Bounds(0, 0, 8, 9);
    Bounds bndAll = bnd1.union(bnd0).union(bnd2).union(bnd3).union(bnd4);
    Bounds bnd6 = Bounds.decode("2, 3;  4,  5");
    Bounds bnd6a = new Bounds(2, 3, 4, 5);
    assertEquals(Bounds.EMPTY, bnd0);
    assertNotEquals(bndMinus1, bnd0);
    assertNotEquals(bnd0, bnd1);
    assertEquals(bnd10a, bnd10b);
    assertEquals(bnd10.getLocation(), p10);
    assertEquals(bnd10.getSize(), dim1);
    assertEquals(bnd2, bnd3);
    assertEquals(bnd3, bnd3a);
    assertEquals(bndMinus1.getSize(), dim0);
    assertEquals(bnd0.getSize(), dim0);
    assertEquals(bnd1.getSize(), dim1);
    assertFalse(bnd1.contains(bnd0));
    assertFalse(bndMinus1.intersects(bnd0));
    assertFalse(bnd0.intersects(bnd1));
    assertEquals(bnd0.intersect(bnd1), new Bounds(1, 1, -1, -1));
    assertTrue(bnd5a.intersects(bnd5b));
    assertTrue(bnd0.union(bnd1).equals(new Bounds(0, 0, 2, 2)));
    assertFalse(bnd0.equals(bnd1));
    assertTrue(bnd5.equals(bnd5a));
    assertEquals(bndN, bndAll);
    assertEquals(bnd6, bnd6a);
    assertEquals(bnd6a.toString(), "Bounds [2,3;4x5]");
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Dimensions(org.apache.pivot.wtk.Dimensions) Point(org.apache.pivot.wtk.Point) Test(org.junit.Test)

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