Search in sources :

Example 6 with Bounds

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

the class TextPaneSkin method getCaretRectangle.

private Rectangle getCaretRectangle(TextHitInfo textCaret) {
    TextPane textPane = getTextPane();
    AttributedStringCharacterIterator composedText = textPane.getComposedText();
    // Special case that tweaks the bounds at the end of line so that the entire
    // composed text width isn't added in here.... (yeah, I know it's ugly...)
    int selectionStart = textPane.getSelectionStart();
    this.doingCaretCalculations = true;
    Bounds selectionStartBounds = getCharacterBounds(selectionStart);
    this.doingCaretCalculations = false;
    // without the "doingCaretCalculations" flag to get back something non-null
    if (selectionStartBounds == null) {
        selectionStartBounds = getCharacterBounds(selectionStart);
        org.apache.pivot.util.Console.logMethod("****", "null selection bounds: selectionStart=%1$d, updated bounds=%2$s", selectionStart, selectionStartBounds);
    }
    return GraphicsUtilities.getCaretRectangle(textCaret, composedText, selectionStartBounds.x, selectionStartBounds.y);
}
Also used : TextPane(org.apache.pivot.wtk.TextPane) Bounds(org.apache.pivot.wtk.Bounds) AttributedStringCharacterIterator(org.apache.pivot.text.AttributedStringCharacterIterator)

Example 7 with Bounds

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

the class TextPaneSkin method mouseMove.

@Override
public boolean mouseMove(Component component, int x, int y) {
    boolean consumed = super.mouseMove(component, x, y);
    if (Mouse.getCapturer() == component) {
        TextPane textPane = getTextPane();
        Bounds visibleArea = textPane.getVisibleArea();
        visibleArea = new Bounds(visibleArea.x, visibleArea.y, visibleArea.width, visibleArea.height);
        if (y >= visibleArea.y && y < visibleArea.y + visibleArea.height) {
            // Stop the scroll selection timer
            if (scheduledScrollSelectionCallback != null) {
                scheduledScrollSelectionCallback.cancel();
                scheduledScrollSelectionCallback = null;
            }
            scrollDirection = null;
            int offset = getInsertionPoint(x, y);
            if (offset != -1) {
                // Select the range
                if (offset > anchor) {
                    textPane.setSelection(anchor, offset - anchor);
                } else {
                    textPane.setSelection(offset, anchor - offset);
                }
            }
        } else {
            if (scheduledScrollSelectionCallback == null) {
                scrollDirection = (y < visibleArea.y) ? TextPane.ScrollDirection.UP : TextPane.ScrollDirection.DOWN;
                scheduledScrollSelectionCallback = ApplicationContext.runAndScheduleRecurringCallback(scrollSelectionCallback, SCROLL_RATE);
            }
        }
        mouseX = x;
    } else {
        if (Mouse.isPressed(Mouse.Button.LEFT) && Mouse.getCapturer() == null && anchor != -1) {
            // Capture the mouse so we can select text
            Mouse.capture(component);
        }
    }
    return consumed;
}
Also used : TextPane(org.apache.pivot.wtk.TextPane) Bounds(org.apache.pivot.wtk.Bounds)

Example 8 with Bounds

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

the class TextPaneSkinElementView method paint.

@Override
public void paint(Graphics2D graphics) {
    // Determine the paint bounds
    Bounds paintBounds = new Bounds(0, 0, getWidth(), getHeight());
    Rectangle clipBounds = graphics.getClipBounds();
    if (clipBounds != null) {
        paintBounds = paintBounds.intersect(clipBounds);
    }
    for (TextPaneSkinNodeView nodeView : nodeViews) {
        paintChild(graphics, paintBounds, nodeView);
    }
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Rectangle(java.awt.Rectangle)

Example 9 with Bounds

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

the class TextPaneSkinParagraphView method getCharacterBounds.

@Override
public Bounds getCharacterBounds(int offset) {
    Bounds characterBounds = null;
    // This is really ugly, but *sometimes* during caret calculations we don't
    // want the terminator size here because it includes the composed text width.
    TextPaneSkin textPaneSkin = getTextPaneSkin();
    if (offset >= getCharacterCount() - 1 && (!textPaneSkin.doingCaretCalculations || rows.getLength() == 0)) {
        characterBounds = terminatorBounds;
    } else {
        if (rows != null) {
            for (int i = 0, n = rows.getLength(); i < n; i++) {
                Row row = rows.get(i);
                for (RowSegment segment : row.rowSegments) {
                    int nodeViewOffset = segment.offset;
                    int characterCount = segment.nodeView.getCharacterCount();
                    if (offset >= nodeViewOffset && offset < nodeViewOffset + characterCount) {
                        characterBounds = segment.nodeView.getCharacterBounds(offset - nodeViewOffset);
                        if (characterBounds != null) {
                            characterBounds = characterBounds.translate(segment.nodeView.getX(), segment.nodeView.getY());
                        }
                        break;
                    }
                }
            }
        }
        if (characterBounds != null) {
            characterBounds = characterBounds.intersect(0, 0, getWidth(), getHeight());
        }
    }
    return characterBounds;
}
Also used : Bounds(org.apache.pivot.wtk.Bounds)

Example 10 with Bounds

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

the class TextPaneSkinParagraphView method childLayout.

@Override
protected void childLayout(int breakWidth) {
    // Break the views into multiple rows
    Paragraph paragraph = (Paragraph) getNode();
    rows = 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
            rows.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) {
            rows.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) {
        rows.add(row);
        layouter.endRow(row);
    }
    // calculate paragraph width and adjust for alignment
    layouter.end(paragraph, rows);
    // 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;
    }
    terminatorBounds = new Bounds(layouter.x, terminatorY, PARAGRAPH_TERMINATOR_WIDTH, terminatorHeight);
    // Ensure that the paragraph is visible even when empty
    layouter.paragraphWidth += terminatorBounds.width;
    int height = Math.max(layouter.rowY, terminatorBounds.height);
    setSize(layouter.paragraphWidth, height);
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Paragraph(org.apache.pivot.wtk.text.Paragraph)

Aggregations

Bounds (org.apache.pivot.wtk.Bounds)77 Point (org.apache.pivot.wtk.Point)21 GradientPaint (java.awt.GradientPaint)15 Color (java.awt.Color)10 Graphics2D (java.awt.Graphics2D)9 Rectangle (java.awt.Rectangle)7 TableView (org.apache.pivot.wtk.TableView)7 BasicStroke (java.awt.BasicStroke)6 GeneralPath (java.awt.geom.GeneralPath)5 Button (org.apache.pivot.wtk.Button)5 Component (org.apache.pivot.wtk.Component)5 Span (org.apache.pivot.wtk.Span)5 TextArea (org.apache.pivot.wtk.TextArea)5 TextPane (org.apache.pivot.wtk.TextPane)5 FontRenderContext (java.awt.font.FontRenderContext)4 LineMetrics (java.awt.font.LineMetrics)4 Area (java.awt.geom.Area)4 RoundRectangle2D (java.awt.geom.RoundRectangle2D)4 ArrayList (org.apache.pivot.collections.ArrayList)4 ScrollPane (org.apache.pivot.wtk.ScrollPane)4