Search in sources :

Example 61 with Dimensions

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

the class TerraMenuSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = 0;
    int preferredHeight = 0;
    Menu menu = (Menu) getComponent();
    Menu.SectionSequence sections = menu.getSections();
    for (int i = 0, n = sections.getLength(); i < n; i++) {
        Menu.Section section = sections.get(i);
        for (Menu.Item item : section) {
            if (item.isVisible()) {
                preferredWidth = Math.max(item.getPreferredWidth(), preferredWidth);
                preferredHeight += item.getPreferredHeight();
            }
        }
        if (i > 0) {
            preferredHeight += sectionSpacing;
        }
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Item(org.apache.pivot.wtk.Menu.Item) Dimensions(org.apache.pivot.wtk.Dimensions) Section(org.apache.pivot.wtk.Menu.Section) Menu(org.apache.pivot.wtk.Menu)

Example 62 with Dimensions

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

the class TerraMeterSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    Meter meter = (Meter) getComponent();
    String text = meter.getText();
    int preferredWidth = 0;
    int preferredHeight = 0;
    if (text != null && text.length() > 0) {
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        Rectangle2D stringBounds = font.getStringBounds(text, fontRenderContext);
        preferredWidth = (int) Math.ceil(stringBounds.getWidth()) + 2;
        LineMetrics lm = font.getLineMetrics("", fontRenderContext);
        preferredHeight = (int) Math.ceil(lm.getHeight()) + 2;
    }
    // If meter has no content, its preferred size is hard coded by the class
    preferredWidth = Math.max(preferredWidth, DEFAULT_WIDTH);
    preferredHeight = Math.max(preferredHeight, DEFAULT_HEIGHT);
    Dimensions preferredSize;
    if (meter.getOrientation() == Orientation.HORIZONTAL) {
        preferredSize = new Dimensions(preferredWidth, preferredHeight);
    } else {
        preferredSize = new Dimensions(preferredHeight, preferredWidth);
    }
    return preferredSize;
}
Also used : Meter(org.apache.pivot.wtk.Meter) Rectangle2D(java.awt.geom.Rectangle2D) Dimensions(org.apache.pivot.wtk.Dimensions) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) GradientPaint(java.awt.GradientPaint)

Example 63 with Dimensions

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

the class TerraPanoramaSkin method layout.

@Override
public void layout() {
    Panorama panorama = (Panorama) getComponent();
    int width = getWidth();
    int height = getHeight();
    Component view = panorama.getView();
    if (view != null) {
        Dimensions viewSize = view.getPreferredSize();
        view.setSize(Math.max(width, viewSize.width), Math.max(height, viewSize.height));
        int viewWidth = view.getWidth();
        int viewHeight = view.getHeight();
        int maxScrollTop = getMaxScrollTop();
        if (panorama.getScrollTop() > maxScrollTop) {
            panorama.setScrollTop(maxScrollTop);
        }
        int maxScrollLeft = getMaxScrollLeft();
        if (panorama.getScrollLeft() > maxScrollLeft) {
            panorama.setScrollLeft(maxScrollLeft);
        }
        if (width < viewWidth) {
            // Show east/west buttons
            eastButton.setSize(eastButton.getPreferredWidth(), height);
            eastButton.setLocation(width - eastButton.getWidth(), 0);
            westButton.setSize(westButton.getPreferredWidth(), height);
            westButton.setLocation(0, 0);
        }
        if (height < viewHeight) {
            // Show north/south buttons
            northButton.setSize(width, northButton.getPreferredHeight());
            northButton.setLocation(0, 0);
            southButton.setSize(width, southButton.getPreferredHeight());
            southButton.setLocation(0, height - southButton.getHeight());
        }
    }
    updateScrollButtonVisibility();
}
Also used : Panorama(org.apache.pivot.wtk.Panorama) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 64 with Dimensions

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

the class TerraRadioButtonSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    RadioButton radioButton = (RadioButton) getComponent();
    Button.DataRenderer dataRenderer = radioButton.getDataRenderer();
    int preferredWidth = BUTTON_DIAMETER;
    int preferredHeight = BUTTON_DIAMETER;
    Object buttonData = radioButton.getButtonData();
    if (buttonData != null) {
        dataRenderer.render(buttonData, radioButton, false);
        preferredWidth += dataRenderer.getPreferredWidth(-1) + spacing * 2;
        preferredHeight = Math.max(preferredHeight, dataRenderer.getPreferredHeight(-1));
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : RadioButton(org.apache.pivot.wtk.RadioButton) Button(org.apache.pivot.wtk.Button) Dimensions(org.apache.pivot.wtk.Dimensions) RadioButton(org.apache.pivot.wtk.RadioButton) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint)

Example 65 with Dimensions

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

the class TerraScrollBarSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    ScrollBar scrollBar = (ScrollBar) getComponent();
    int preferredWidth = 0;
    int preferredHeight = 0;
    if (scrollBar.getOrientation() == Orientation.HORIZONTAL) {
        preferredWidth = DEFAULT_LENGTH;
        preferredHeight = DEFAULT_THICKNESS;
    } else {
        preferredWidth = DEFAULT_THICKNESS;
        preferredHeight = DEFAULT_LENGTH;
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) ScrollBar(org.apache.pivot.wtk.ScrollBar) GradientPaint(java.awt.GradientPaint)

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