Search in sources :

Example 46 with Dimensions

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

the class ScrollPaneSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth = 0;
    ScrollPane scrollPane = (ScrollPane) getComponent();
    Component view = scrollPane.getView();
    if (view != null) {
        int preferredRowHeaderWidth = 0;
        Component rowHeader = scrollPane.getRowHeader();
        if (rowHeader != null) {
            preferredRowHeaderWidth = rowHeader.getPreferredWidth(-1);
        }
        int preferredColumnHeaderHeight = 0;
        Component columnHeader = scrollPane.getColumnHeader();
        if (columnHeader != null) {
            preferredColumnHeaderHeight = columnHeader.getPreferredHeight(-1);
        }
        ScrollBarPolicy verticalPolicy = scrollPane.getVerticalScrollBarPolicy();
        if (verticalPolicy != ScrollBarPolicy.FILL) {
            // Get the unconstrained preferred size of the view
            Dimensions preferredViewSize = view.getPreferredSize();
            if (verticalPolicy == ScrollBarPolicy.FILL_TO_CAPACITY) {
                if (height < 0) {
                    verticalPolicy = ScrollBarPolicy.AUTO;
                } else {
                    int preferredHeight = preferredViewSize.height + preferredColumnHeaderHeight;
                    if (preferredHeight < height) {
                        verticalPolicy = ScrollBarPolicy.FILL;
                    } else {
                        verticalPolicy = ScrollBarPolicy.AUTO;
                    }
                }
            }
            if (verticalPolicy == ScrollBarPolicy.ALWAYS || verticalPolicy == ScrollBarPolicy.NEVER || verticalPolicy == ScrollBarPolicy.AUTO) {
                preferredWidth = preferredViewSize.width + preferredRowHeaderWidth;
                // preferred width calculation
                if (verticalPolicy == ScrollBarPolicy.ALWAYS || (verticalPolicy == ScrollBarPolicy.AUTO && height > 0 && preferredViewSize.height + preferredColumnHeaderHeight > height)) {
                    preferredWidth += verticalScrollBar.getPreferredWidth(-1);
                }
            }
        }
        if (verticalPolicy == ScrollBarPolicy.FILL) {
            // Preferred width is the sum of the constrained preferred
            // width of the view and the unconstrained preferred width of
            // the row header
            int heightUpdated = height;
            if (heightUpdated >= 0) {
                // Subtract the unconstrained preferred height of the
                // column header from the height constraint
                heightUpdated = Math.max(heightUpdated - preferredColumnHeaderHeight, 0);
            }
            preferredWidth = view.getPreferredWidth(heightUpdated) + preferredRowHeaderWidth;
        }
    }
    return preferredWidth;
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) ScrollBarPolicy(org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint)

Example 47 with Dimensions

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

the class TextAreaSkin method setLineWidth.

public void setLineWidth(int lineWidth) {
    if (this.lineWidth != lineWidth) {
        this.lineWidth = lineWidth;
        int missingGlyphCode = font.getMissingGlyphCode();
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        GlyphVector missingGlyphVector = font.createGlyphVector(fontRenderContext, new int[] { missingGlyphCode });
        Rectangle2D textBounds = missingGlyphVector.getLogicalBounds();
        Rectangle2D maxCharBounds = font.getMaxCharBounds(fontRenderContext);
        averageCharacterSize = new Dimensions((int) Math.ceil(textBounds.getWidth()), (int) Math.ceil(maxCharBounds.getHeight()));
        invalidateComponent();
    }
}
Also used : GlyphVector(java.awt.font.GlyphVector) Rectangle2D(java.awt.geom.Rectangle2D) Dimensions(org.apache.pivot.wtk.Dimensions) FontRenderContext(java.awt.font.FontRenderContext)

Example 48 with Dimensions

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

the class TextPaneSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    int preferredWidth;
    if (documentView == null) {
        preferredWidth = 0;
    } else {
        Dimensions documentDimensions = documentView.getPreferredSize(Integer.MAX_VALUE);
        preferredWidth = documentDimensions.width + margin.getWidth();
    }
    return preferredWidth;
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions)

Example 49 with Dimensions

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

the class TextPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    int preferredHeight;
    int preferredWidth;
    if (documentView == null) {
        preferredWidth = 0;
        preferredHeight = 0;
    } else {
        Dimensions documentDimensions = documentView.getPreferredSize(Integer.MAX_VALUE);
        preferredWidth = documentDimensions.width + margin.getWidth();
        preferredHeight = documentDimensions.height + margin.getHeight();
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions)

Example 50 with Dimensions

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

the class TextPaneSkinComponentNodeView method getPreferredSize.

@Override
public Dimensions getPreferredSize(int breakWidth) {
    ComponentNode componentNode = (ComponentNode) getNode();
    Component component = componentNode.getComponent();
    if (component == null) {
        return new Dimensions(0, 0);
    }
    return new Dimensions(component.getPreferredWidth(), component.getPreferredHeight());
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) ComponentNode(org.apache.pivot.wtk.text.ComponentNode)

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