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);
}
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);
}
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;
}
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);
}
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]");
}
Aggregations