Search in sources :

Example 56 with Dimensions

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));
}
Also used : Movie(org.apache.pivot.wtk.media.Movie) Dimensions(org.apache.pivot.wtk.Dimensions) MovieView(org.apache.pivot.wtk.MovieView)

Example 57 with Dimensions

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);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Dimensions(org.apache.pivot.wtk.Dimensions) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Separator(org.apache.pivot.wtk.Separator)

Example 58 with Dimensions

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();
    }
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) Menu(org.apache.pivot.wtk.Menu) Point(org.apache.pivot.wtk.Point) Point(org.apache.pivot.wtk.Point) Display(org.apache.pivot.wtk.Display)

Example 59 with Dimensions

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;
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions)

Example 60 with Dimensions

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]");
}
Also used : Insets(org.apache.pivot.wtk.Insets) Dimensions(org.apache.pivot.wtk.Dimensions) 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