Search in sources :

Example 66 with Dimensions

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

the class TerraFormSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight = 0;
    Form form = (Form) getComponent();
    Form.SectionSequence sections = form.getSections();
    // Determine the field width constraint
    int fieldWidth = (fill && width != -1) ? getFieldWidth(width) : -1;
    for (int sectionIndex = 0, sectionCount = sections.getLength(); sectionIndex < sectionCount; sectionIndex++) {
        Form.Section section = sections.get(sectionIndex);
        if (sectionIndex > 0 || section.getHeading() != null) {
            Separator separator = separators.get(sectionIndex);
            preferredHeight += separator.getPreferredHeight(width);
            preferredHeight += verticalSpacing;
        }
        for (int fieldIndex = 0, fieldCount = section.getLength(); fieldIndex < fieldCount; fieldIndex++) {
            Component field = section.get(fieldIndex);
            if (field.isVisible()) {
                // Determine the label size and baseline
                Label label = labels.get(sectionIndex).get(fieldIndex);
                Dimensions labelSize = label.getPreferredSize();
                int labelAscent = label.getBaseline(labelSize.width, labelSize.height);
                int labelDescent = labelSize.height - labelAscent;
                // Determine the field size and baseline
                Dimensions fieldSize;
                if (fill && fieldWidth != -1) {
                    fieldSize = new Dimensions(fieldWidth, field.getPreferredHeight(fieldWidth));
                } else {
                    fieldSize = field.getPreferredSize();
                }
                int fieldAscent = field.getBaseline(fieldSize.width, fieldSize.height);
                if (fieldAscent == -1) {
                    fieldAscent = fieldSize.height;
                }
                int fieldDescent = fieldSize.height - fieldAscent;
                // Determine the row height
                int maximumAscent = Math.max(labelAscent, fieldAscent);
                int maximumDescent = Math.max(labelDescent, fieldDescent);
                int rowHeight = maximumAscent + maximumDescent;
                preferredHeight += rowHeight;
                if (fieldIndex > 0) {
                    preferredHeight += verticalSpacing;
                }
            }
        }
    }
    preferredHeight += (padding.top + padding.bottom);
    return preferredHeight;
}
Also used : Form(org.apache.pivot.wtk.Form) Label(org.apache.pivot.wtk.Label) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) Separator(org.apache.pivot.wtk.Separator)

Example 67 with Dimensions

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

the class TerraFrameSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = 0;
    int preferredHeight = 0;
    Frame frame = (Frame) getComponent();
    // Include title bar width plus left/right title bar borders
    Dimensions titleBarSize = titleBarTablePane.getPreferredSize();
    preferredWidth = Math.max(preferredWidth, titleBarSize.width + 2);
    // Include title bar height plus top/bottom title bar borders
    preferredHeight += titleBarSize.height + 2;
    // Include menu bar size
    MenuBar menuBar = frame.getMenuBar();
    if (menuBar != null) {
        Dimensions preferredMenuBarSize = menuBar.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, preferredMenuBarSize.width);
        preferredHeight += preferredMenuBarSize.height;
    }
    Component content = frame.getContent();
    if (content != null) {
        Dimensions preferredContentSize = content.getPreferredSize();
        preferredWidth = Math.max(preferredWidth, preferredContentSize.width);
        preferredHeight += preferredContentSize.height;
    }
    // Add padding, borders, and content bevel
    preferredWidth += (padding.left + padding.right) + 2;
    preferredHeight += (padding.top + padding.bottom) + (showContentBevel ? 1 : 0) + 2;
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Frame(org.apache.pivot.wtk.Frame) Dimensions(org.apache.pivot.wtk.Dimensions) MenuBar(org.apache.pivot.wtk.MenuBar) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) GradientPaint(java.awt.GradientPaint)

Example 68 with Dimensions

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

the class TerraSheetSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    Dimensions preferredSize = Dimensions.ZERO;
    Sheet sheet = (Sheet) getComponent();
    Component content = sheet.getContent();
    if (content != null) {
        preferredSize = content.getPreferredSize();
    }
    // Account for border in the size
    return preferredSize.expand(2).expand(padding);
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Sheet(org.apache.pivot.wtk.Sheet)

Example 69 with Dimensions

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

the class TerraSplitPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredWidth = splitterThickness;
    int preferredHeight = splitterThickness;
    SplitPane splitPane = (SplitPane) getComponent();
    Component topLeft = splitPane.getTopLeft();
    if (topLeft != null) {
        Dimensions size = topLeft.getPreferredSize();
        preferredWidth += size.width;
        preferredHeight += size.height;
    }
    Component bottomRight = splitPane.getBottomRight();
    if (bottomRight != null) {
        Dimensions size = bottomRight.getPreferredSize();
        preferredWidth += size.width;
        preferredHeight += size.height;
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) SplitPane(org.apache.pivot.wtk.SplitPane) Component(org.apache.pivot.wtk.Component)

Example 70 with Dimensions

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

the class TerraTabPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    TabPane tabPane = (TabPane) getComponent();
    int preferredWidth;
    int preferredHeight;
    Component selectedTab = tabPane.getSelectedTab();
    Component corner = tabPane.getCorner();
    switch(tabOrientation) {
        case HORIZONTAL:
            {
                if (selectedTab == null && selectionChangeTransition == null) {
                    preferredWidth = getPreferredTabWidth(-1) + (padding.left + padding.right + 2);
                    preferredHeight = 1;
                } else {
                    Dimensions preferredTabSize = getPreferredTabSize();
                    preferredWidth = preferredTabSize.width + (padding.left + padding.right + 2);
                    preferredHeight = preferredTabSize.height + (padding.top + padding.bottom);
                    if (selectionChangeTransition != null) {
                        float scale = selectionChangeTransition.getScale();
                        preferredHeight = (int) (preferredHeight * scale);
                    }
                    preferredHeight += 2;
                }
                int buttonAreaPreferredWidth = tabButtonPanorama.getPreferredWidth(-1);
                if (corner != null) {
                    buttonAreaPreferredWidth += corner.getPreferredWidth(-1);
                    preferredHeight += Math.max(corner.getPreferredHeight(-1), Math.max(tabButtonPanorama.getPreferredHeight(-1) - 1, 0));
                    // space between corner and
                    buttonAreaPreferredWidth += 2;
                // panorama
                } else {
                    preferredHeight += Math.max(tabButtonPanorama.getPreferredHeight(-1) - 1, 0);
                }
                preferredWidth = Math.max(preferredWidth, buttonAreaPreferredWidth);
                break;
            }
        case VERTICAL:
            {
                if (selectedTab == null && selectionChangeTransition == null) {
                    preferredWidth = 1;
                    preferredHeight = getPreferredTabHeight(-1) + (padding.top + padding.bottom + 2);
                } else {
                    Dimensions preferredTabSize = getPreferredTabSize();
                    preferredWidth = preferredTabSize.width + (padding.left + padding.right);
                    preferredHeight = preferredTabSize.height + (padding.top + padding.bottom + 2);
                    if (selectionChangeTransition != null) {
                        float scale = selectionChangeTransition.getScale();
                        preferredWidth = (int) (preferredWidth * scale);
                    }
                    preferredWidth += 2;
                }
                int buttonAreaPreferredHeight = tabButtonPanorama.getPreferredHeight(-1);
                if (corner != null) {
                    buttonAreaPreferredHeight += corner.getPreferredHeight(-1);
                    preferredWidth += Math.max(corner.getPreferredWidth(-1), Math.max(tabButtonPanorama.getPreferredWidth(-1) - 1, 0));
                    // space between corner and
                    buttonAreaPreferredHeight += 2;
                // panorama
                } else {
                    preferredWidth += Math.max(tabButtonPanorama.getPreferredWidth(-1) - 1, 0);
                }
                preferredHeight = Math.max(preferredHeight, buttonAreaPreferredHeight);
                break;
            }
        default:
            {
                preferredWidth = 0;
                preferredHeight = 0;
            }
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
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)

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