use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class MovieViewSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
MovieView movieView = (MovieView) getComponent();
Movie movie = movieView.getMovie();
return (movie == null) ? Dimensions.ZERO : new Dimensions(Math.round(movie.getWidth() * scale), Math.round(movie.getHeight() * scale));
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class SeparatorSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
int preferredWidth = 0;
int preferredHeight = thickness;
Separator separator = (Separator) getComponent();
String heading = separator.getHeading();
if (heading != null && heading.length() > 0) {
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
Rectangle2D headingBounds = font.getStringBounds(heading, fontRenderContext);
LineMetrics lm = font.getLineMetrics(heading, fontRenderContext);
preferredWidth = (int) Math.ceil(headingBounds.getWidth());
preferredHeight = Math.max((int) Math.ceil(lm.getAscent() + lm.getDescent() + lm.getLeading()), preferredHeight);
}
preferredHeight += padding.getHeight();
preferredWidth += padding.getWidth();
return new Dimensions(preferredWidth, preferredHeight);
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class MenuItemSkin method buttonPressed.
@Override
public void buttonPressed(Button button) {
Menu.Item menuItem = (Menu.Item) getComponent();
Menu menu = menuItem.getMenu();
if (menu != null && !menuPopup.isOpen()) {
// Size and position the popup
Display display = menuItem.getDisplay();
Dimensions displaySize = display.getSize();
Point location = menuItem.mapPointToAncestor(display, getWidth(), 0);
menuPopup.setLocation(location.x, location.y);
int width = getWidth();
// If the popup extends over the right edge of the display,
// move it so that the right edge of the popup lines up with the
// left edge of the menu item
int popupWidth = menuPopup.getPreferredWidth();
if (location.x + popupWidth > displaySize.width) {
menuPopup.setX(location.x - width - popupWidth);
}
menuPopup.open(menuItem.getWindow());
menuPopup.requestFocus();
}
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class TextPaneSkinSpanView method getPreferredSize.
@Override
public Dimensions getPreferredSize(int breakWidth) {
if (getLength() == 0) {
return Dimensions.ZERO;
}
TextPaneSkinNodeView nodeView = get(0);
Dimensions childDimensions = nodeView.getPreferredSize(breakWidth);
return childDimensions;
}
use of org.apache.pivot.wtk.Dimensions in project pivot by apache.
the class InsetsTest method test.
@Test
public void test() {
Insets i0 = Insets.NONE;
Insets i0a = new Insets(0);
Insets i1 = new Insets(1);
Insets i1a = new Insets(1, 1, 1, 1);
Insets i2 = new Insets(2);
Insets i2a = new Insets(2.0f);
Insets i2b = Insets.decode("[ 2, 2, 2, 2 ]");
Insets i3 = new Insets(1, 2, 3, 4);
Insets i3a = Insets.decode("{top:1, left:2, bottom:3, right:4}");
Insets i4 = new Insets(5, 6, 7, 8);
Insets i4a = Insets.decode("5, 6; 7, 8");
Dimensions dim5 = new Dimensions(5);
Insets i5 = new Insets(dim5);
Insets i5a = new Insets(2, 2, 3, 3);
Dimensions dim5a = i5.getSize();
Dimensions dim5b = i5a.getSize();
assertEquals(i0, i0a);
assertEquals(i1, i1a);
assertEquals(i2, i2a);
assertEquals(i2, i2b);
assertEquals(i3, i3a);
assertEquals(i3.toString(), "Insets [1, 2, 3, 4]");
assertEquals(i0.getWidth(), 0);
assertEquals(i0.getHeight(), 0);
assertEquals(i3.getWidth(), 6);
assertEquals(i3.getHeight(), 4);
assertEquals(i4, i4a);
assertEquals(i4a.getWidth(), 14);
assertEquals(i4a.getHeight(), 12);
assertEquals(i4a.toString(), "Insets [5, 6, 7, 8]");
assertEquals(i5, i5a);
assertEquals(dim5, dim5a);
assertEquals(dim5a, dim5b);
assertEquals(i5.toString(), "Insets [2, 2, 3, 3]");
}
Aggregations