Search in sources :

Example 6 with Dimensions

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

the class TextPaneSkin method getPreferredHeight.

@Override
public int getPreferredHeight(int width) {
    int preferredHeight;
    if (documentView == null || width == -1) {
        preferredHeight = 0;
    } else {
        int breakWidth;
        if (wrapText) {
            breakWidth = Math.max(width - margin.getWidth(), 0);
        } else {
            breakWidth = Integer.MAX_VALUE;
        }
        Dimensions documentDimensions = documentView.getPreferredSize(breakWidth);
        preferredHeight = documentDimensions.height + margin.getHeight();
    }
    return preferredHeight;
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions)

Example 7 with Dimensions

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

the class TextPaneSkinParagraphView method getPreferredSize.

@Override
public Dimensions getPreferredSize(int breakWidth) {
    // Break the views into multiple rows
    Paragraph paragraph = (Paragraph) getNode();
    ArrayList<Row> rowsLocal = new ArrayList<>();
    int offset = 0;
    ParagraphChildLayouter layouter = new ParagraphChildLayouter();
    Row row = new Row();
    for (TextPaneSkinNodeView nodeView : this) {
        nodeView.layout(Math.max(breakWidth - (row.width + PARAGRAPH_TERMINATOR_WIDTH), 0));
        int nodeViewWidth = nodeView.getWidth();
        if (row.width + nodeViewWidth > breakWidth && row.width > 0) {
            // The view is too big to fit in the remaining space,
            // and it is not the only view in this row
            rowsLocal.add(row);
            layouter.endRow(row);
            row = new Row();
            row.width = 0;
        }
        // Add the view to the row
        RowSegment segment = new RowSegment(nodeView, offset);
        row.rowSegments.add(segment);
        layouter.startSegment(segment);
        offset += nodeView.getCharacterCount();
        row.width += nodeViewWidth;
        // If the view was split into multiple views, add them to their own rows
        nodeView = getNext(nodeView);
        while (nodeView != null) {
            rowsLocal.add(row);
            layouter.endRow(row);
            row = new Row();
            nodeView.layout(breakWidth);
            segment = new RowSegment(nodeView, offset);
            row.rowSegments.add(segment);
            layouter.startSegment(segment);
            offset += nodeView.getCharacterCount();
            row.width = nodeView.getWidth();
            nodeView = getNext(nodeView);
        }
    }
    // Add the last row
    if (row.rowSegments.getLength() > 0) {
        rowsLocal.add(row);
        layouter.endRow(row);
    }
    // calculate paragraph width and adjust for alignment
    layouter.end(paragraph, rowsLocal);
    // Recalculate terminator bounds
    FontRenderContext fontRenderContext = Platform.getFontRenderContext();
    LineMetrics lm = getTextPaneSkin().getFont().getLineMetrics("", 0, 0, fontRenderContext);
    int terminatorHeight = (int) Math.ceil(lm.getHeight());
    int terminatorY;
    if (getCharacterCount() == 1) {
        // The terminator is the only character in this paragraph
        terminatorY = 0;
    } else {
        terminatorY = layouter.rowY - terminatorHeight;
    }
    Bounds terminatorBoundsLocal = new Bounds(layouter.x, terminatorY, PARAGRAPH_TERMINATOR_WIDTH, terminatorHeight);
    // Ensure that the paragraph is visible even when empty
    layouter.paragraphWidth += terminatorBoundsLocal.width;
    int height = Math.max(layouter.rowY, terminatorBoundsLocal.height);
    return new Dimensions(layouter.paragraphWidth, height);
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) ArrayList(org.apache.pivot.collections.ArrayList) Dimensions(org.apache.pivot.wtk.Dimensions) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Paragraph(org.apache.pivot.wtk.text.Paragraph)

Example 8 with Dimensions

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

the class GridPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    GridPane gridPane = (GridPane) getComponent();
    GridPane.RowSequence rows = gridPane.getRows();
    int columnCount = gridPane.getColumnCount();
    int rowCount = rows.getLength();
    Metadata metadata = new Metadata();
    // calculate the maximum preferred cellWidth and cellHeight
    int preferredCellHeight = 0;
    int preferredCellWidth = 0;
    for (int i = 0; i < rowCount; i++) {
        GridPane.Row row = rows.get(i);
        for (int j = 0, n = row.getLength(); j < n && j < columnCount; j++) {
            Component component = row.get(j);
            if (component != null && component.isVisible()) {
                Dimensions d = component.getPreferredSize();
                preferredCellHeight = Math.max(preferredCellHeight, d.height);
                preferredCellWidth = Math.max(preferredCellWidth, d.width);
            }
        }
    }
    // The preferred width of the grid pane is the sum of the column
    // widths, plus padding and spacing
    int preferredWidth = (metadata.visibleColumnCount * preferredCellWidth) + padding.getWidth();
    if (metadata.visibleColumnCount > 1) {
        preferredWidth += (metadata.visibleColumnCount - 1) * horizontalSpacing;
    }
    // The preferred height of the grid pane is the sum of the row
    // heights, plus padding and spacing
    int preferredHeight = (metadata.visibleRowCount * preferredCellHeight) + padding.getHeight();
    if (metadata.visibleRowCount > 1) {
        preferredHeight += (metadata.visibleRowCount - 1) * verticalSpacing;
    }
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : GridPane(org.apache.pivot.wtk.GridPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 9 with Dimensions

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

the class FillPaneSkin method getPreferredSize.

@Override
public Dimensions getPreferredSize() {
    FillPane fillPane = (FillPane) getComponent();
    int preferredWidth = 0;
    int preferredHeight = 0;
    switch(fillPane.getOrientation()) {
        case HORIZONTAL:
            {
                // Preferred width is the sum of the preferred widths of all
                // components
                int j = 0;
                for (int i = 0, n = fillPane.getLength(); i < n; i++) {
                    Component component = fillPane.get(i);
                    if (component.isVisible()) {
                        Dimensions preferredSize = component.getPreferredSize();
                        preferredWidth += preferredSize.width;
                        preferredHeight = Math.max(preferredSize.height, preferredHeight);
                        j++;
                    }
                }
                // Include spacing
                if (j > 1) {
                    preferredWidth += spacing * (j - 1);
                }
                break;
            }
        case VERTICAL:
            {
                // Preferred height is the sum of the preferred heights of all
                // components
                int j = 0;
                for (int i = 0, n = fillPane.getLength(); i < n; i++) {
                    Component component = fillPane.get(i);
                    if (component.isVisible()) {
                        Dimensions preferredSize = component.getPreferredSize();
                        preferredWidth = Math.max(preferredSize.width, preferredWidth);
                        preferredHeight += preferredSize.height;
                        j++;
                    }
                }
                // Include spacing
                if (j > 1) {
                    preferredHeight += spacing * (j - 1);
                }
                break;
            }
        default:
            {
                break;
            }
    }
    // Include padding
    preferredWidth += padding.getWidth();
    preferredHeight += padding.getHeight();
    return new Dimensions(preferredWidth, preferredHeight);
}
Also used : FillPane(org.apache.pivot.wtk.FillPane) Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component)

Example 10 with Dimensions

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

the class TextPaneSkinTextNodeView method getPreferredSize.

@Override
public Dimensions getPreferredSize(int breakWidth) {
    TextNode textNode = (TextNode) getNode();
    Font effectiveFont = getEffectiveFont();
    // For now, just get the committed text
    if (textNode.getCharacterCount() == 0) /* && composedText == null || composedText doesn't impinge on this node */
    {
        Dimensions charSize = GraphicsUtilities.getAverageCharacterSize(effectiveFont);
        return new Dimensions(0, charSize.height);
    } else {
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        // TODO: deal with composed text here
        AttributedCharacterIterator text = new AttributedStringCharacterIterator(textNode.getCharacters(), start, effectiveFont);
        // Note: we don't add the underline/strikethrough attributes here because
        // they shouldn't affect the sizing...
        TextLayout currentTextLayout;
        if (getTextPaneSkin().getWrapText()) {
            LineBreakMeasurer measurer = new LineBreakMeasurer(text, fontRenderContext);
            float wrappingWidth = (float) breakWidth;
            currentTextLayout = measurer.nextLayout(wrappingWidth);
        } else {
            // Not wrapping the text, then the width is of the whole thing
            currentTextLayout = new TextLayout(text, fontRenderContext);
        }
        return getTextSize(currentTextLayout);
    }
}
Also used : LineBreakMeasurer(java.awt.font.LineBreakMeasurer) Dimensions(org.apache.pivot.wtk.Dimensions) TextNode(org.apache.pivot.wtk.text.TextNode) FontRenderContext(java.awt.font.FontRenderContext) Font(java.awt.Font) AttributedCharacterIterator(java.text.AttributedCharacterIterator) AttributedStringCharacterIterator(org.apache.pivot.text.AttributedStringCharacterIterator) TextLayout(java.awt.font.TextLayout)

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