Search in sources :

Example 31 with Dimensions

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

the class TerraTabPaneSkin method layout.

@Override
public void layout() {
    TabPane tabPane = (TabPane) getComponent();
    int width = getWidth();
    int height = getHeight();
    int tabX = 0;
    int tabY = 0;
    int tabWidth = 0;
    int tabHeight = 0;
    Component corner = tabPane.getCorner();
    Dimensions buttonPanoramaSize = tabButtonPanorama.getPreferredSize();
    switch(tabOrientation) {
        case HORIZONTAL:
            {
                int buttonPanoramaWidth = Math.min(width, buttonPanoramaSize.width);
                int buttonPanoramaHeight = buttonPanoramaSize.height;
                int buttonPanoramaY = 0;
                if (corner != null) {
                    int cornerWidth = Math.max(width - buttonPanoramaWidth - 2, corner.getPreferredWidth());
                    if (cornerWidth > width - 2) {
                        cornerWidth = Math.max(width - 2, 0);
                    }
                    if (buttonPanoramaWidth + 2 + cornerWidth > width) {
                        buttonPanoramaWidth = Math.max(width - 2 - cornerWidth, 0);
                    }
                    int cornerHeight = Math.max(corner.getPreferredHeight(-1), buttonPanoramaSize.height - 1);
                    int cornerX = width - cornerWidth;
                    int cornerY = Math.max(buttonPanoramaHeight - cornerHeight - 1, 0);
                    buttonPanoramaY = Math.max(cornerHeight - buttonPanoramaHeight + 1, 0);
                    corner.setLocation(cornerX, cornerY);
                    corner.setSize(cornerWidth, cornerHeight);
                }
                tabButtonPanorama.setLocation(0, buttonPanoramaY);
                tabButtonPanorama.setSize(buttonPanoramaWidth, buttonPanoramaHeight);
                tabX = padding.left + 1;
                tabY = padding.top + buttonPanoramaY + buttonPanoramaHeight;
                tabWidth = Math.max(width - (padding.left + padding.right + 2), 0);
                tabHeight = Math.max(height - (padding.top + padding.bottom + buttonPanoramaY + buttonPanoramaHeight + 1), 0);
                break;
            }
        case VERTICAL:
            {
                int buttonPanoramaWidth = buttonPanoramaSize.width;
                int buttonPanoramaHeight = Math.min(height, buttonPanoramaSize.height);
                int buttonPanoramaX = 0;
                if (corner != null) {
                    int cornerHeight = Math.max(height - buttonPanoramaHeight - 2, corner.getPreferredHeight());
                    if (cornerHeight > height - 2) {
                        cornerHeight = Math.max(height - 2, 0);
                    }
                    if (buttonPanoramaHeight + 2 + cornerHeight > height) {
                        buttonPanoramaHeight = Math.max(height - 2 - cornerHeight, 0);
                    }
                    int cornerWidth = Math.max(corner.getPreferredWidth(-1), buttonPanoramaSize.width - 1);
                    int cornerX = Math.max(buttonPanoramaWidth - cornerWidth - 1, 0);
                    int cornerY = height - cornerHeight;
                    buttonPanoramaX = Math.max(cornerWidth - buttonPanoramaWidth + 1, 0);
                    corner.setLocation(cornerX, cornerY);
                    corner.setSize(cornerWidth, cornerHeight);
                }
                tabButtonPanorama.setLocation(buttonPanoramaX, 0);
                tabButtonPanorama.setSize(buttonPanoramaWidth, buttonPanoramaHeight);
                tabX = padding.left + buttonPanoramaX + buttonPanoramaWidth;
                tabY = padding.top + 1;
                tabWidth = Math.max(width - (padding.left + padding.right + buttonPanoramaX + buttonPanoramaWidth + 1), 0);
                tabHeight = Math.max(height - (padding.top + padding.bottom + 2), 0);
                break;
            }
        default:
            {
                break;
            }
    }
    // Lay out the tabs
    for (Component tab : tabPane.getTabs()) {
        tab.setLocation(tabX, tabY);
        if (selectionChangeTransition != null && selectionChangeTransition.isRunning()) {
            clipDecorator.setSize(tabWidth, tabHeight);
            switch(tabOrientation) {
                case HORIZONTAL:
                    {
                        tab.setSize(tabWidth, getPreferredTabHeight(tabWidth));
                        break;
                    }
                case VERTICAL:
                    {
                        tab.setSize(getPreferredTabWidth(tabHeight), tabHeight);
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
        } else {
            tab.setSize(tabWidth, tabHeight);
        }
    }
}
Also used : TabPane(org.apache.pivot.wtk.TabPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 32 with Dimensions

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

the class TerraPaletteSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = 0;
    int preferredHeight = 0;
    Palette palette = (Palette) getComponent();
    Component content = palette.getContent();
    Dimensions preferredTitleBarSize = titleBarTablePane.getPreferredSize();
    preferredWidth = preferredTitleBarSize.width;
    preferredHeight = preferredTitleBarSize.height;
    if (content != null) {
        Dimensions preferredContentSize = content.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, preferredContentSize.width);
        preferredHeight += preferredContentSize.height;
    }
    preferredWidth += padding.getWidth() + 2;
    preferredHeight += padding.getHeight() + 4;
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Palette(org.apache.pivot.wtk.Palette) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 33 with Dimensions

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

the class TerraPaletteSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    Palette palette = (Palette) getComponent();
    Component content = palette.getContent();
    Dimensions preferredTitleBarSize = titleBarTablePane.getPreferredSize();
    preferredWidth = preferredTitleBarSize.width;
    if (content != null) {
        if (height != -1) {
            height = Math.max(height - preferredTitleBarSize.height - 4 - padding.getHeight(), 0);
        }
        preferredWidth = Math.max(preferredWidth, content.getPreferredWidth(height));
    }
    preferredWidth += padding.getWidth() + 2;
    return preferredWidth;
}
Also used : Palette(org.apache.pivot.wtk.Palette) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 34 with Dimensions

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

the class TerraPanoramaSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    Dimensions preferredSize = null;
    // The panorama's preferred size is the preferred size of the view
    Panorama panorama = (Panorama) getComponent();
    Component view = panorama.getView();
    if (view == null) {
        preferredSize = Dimensions.ZERO;
    } else {
        preferredSize = view.getPreferredSize();
    }
    return preferredSize;
}
Also used : Panorama(org.apache.pivot.wtk.Panorama) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 35 with Dimensions

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

the class TerraPushButtonSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    PushButton pushButton = (PushButton) getComponent();
    Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
    dataRenderer.render(pushButton.getButtonData(), pushButton, false);
    Dimensions preferredContentSize = dataRenderer.getPreferredSize();
    int preferredWidth = preferredContentSize.width + paddingWidth();
    int preferredHeight = preferredContentSize.height + paddingHeight();
    // Adjust for preferred aspect ratio
    float aspectRatio = (float) preferredWidth / (float) preferredHeight;
    if (!Float.isNaN(minimumAspectRatio) && aspectRatio < minimumAspectRatio) {
        preferredWidth = (int) (preferredHeight * minimumAspectRatio);
    }
    if (!Float.isNaN(maximumAspectRatio) && aspectRatio > maximumAspectRatio) {
        preferredHeight = (int) (preferredWidth / maximumAspectRatio);
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) Dimensions(org.apache.pivot.wtk.Dimensions) PushButton(org.apache.pivot.wtk.PushButton) 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