Search in sources :

Example 1 with Bounds

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

the class ScrollPaneSkin method scrollTopChanged.

// ViewportListener methods
@Override
public void scrollTopChanged(Viewport viewport, int previousScrollTop) {
    // NOTE we don't invalidate the component here because we need only
    // reposition the view and row header. Invalidating would yield
    // the correct positioning, but it would do much more work than needed.
    ScrollPane scrollPane = (ScrollPane) viewport;
    Component view = scrollPane.getView();
    Component rowHeader = scrollPane.getRowHeader();
    Component columnHeader = scrollPane.getColumnHeader();
    int columnHeaderHeight = 0;
    if (columnHeader != null) {
        columnHeaderHeight = columnHeader.getHeight();
    }
    int scrollTop = scrollPane.getScrollTop();
    if (view != null && view.isShowing() && isOptimizeScrolling()) {
        Bounds blitArea = view.getVisibleArea();
        int blitX = blitArea.x + view.getX();
        int blitY = blitArea.y + view.getY();
        int blitWidth = blitArea.width;
        int blitHeight = blitArea.height;
        if (rowHeader != null) {
            // Blit the row header as well
            int rowHeaderWidth = rowHeader.getWidth();
            blitX -= rowHeaderWidth;
            blitWidth += rowHeaderWidth;
        }
        int deltaScrollTop = scrollTop - previousScrollTop;
        blitY += Math.max(deltaScrollTop, 0);
        blitHeight -= Math.abs(deltaScrollTop);
        Graphics2D graphics = scrollPane.getGraphics();
        graphics.copyArea(blitX, blitY, blitWidth, blitHeight, 0, -deltaScrollTop);
        scrollPane.setConsumeRepaint(true);
        try {
            view.setLocation(view.getX(), columnHeaderHeight - scrollTop);
            if (rowHeader != null) {
                rowHeader.setLocation(0, columnHeaderHeight - scrollTop);
            }
        } finally {
            scrollPane.setConsumeRepaint(false);
        }
        boolean repaintAllViewport = scrollPane.isRepaintAllViewport();
        if (!repaintAllViewport) {
            scrollPane.repaint(blitX, (columnHeaderHeight + (deltaScrollTop > 0 ? blitHeight : 0)), blitWidth, Math.abs(deltaScrollTop), true);
        } else {
            Bounds viewportBounds = getViewportBounds();
            scrollPane.repaint(viewportBounds.x, viewportBounds.y, viewportBounds.width, viewportBounds.height, true);
        }
    } else {
        if (view != null) {
            view.setLocation(view.getX(), columnHeaderHeight - scrollTop);
        }
        if (rowHeader != null) {
            rowHeader.setLocation(0, columnHeaderHeight - scrollTop);
        }
    }
    if (scrollTop >= 0 && scrollTop <= getMaxScrollTop()) {
        verticalScrollBar.setValue(scrollTop);
    }
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) Bounds(org.apache.pivot.wtk.Bounds) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D)

Example 2 with Bounds

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

the class ScrollPaneSkin method getViewportBounds.

// Viewport.Skin methods
@Override
public Bounds getViewportBounds() {
    int x = 0;
    int y = 0;
    int width = getWidth();
    int height = getHeight();
    ScrollPane scrollPane = (ScrollPane) getComponent();
    Component rowHeader = scrollPane.getRowHeader();
    if (rowHeader != null) {
        int rowHeaderWidth = rowHeader.getWidth();
        x += rowHeaderWidth;
        width -= rowHeaderWidth;
    }
    Component columnHeader = scrollPane.getColumnHeader();
    if (columnHeader != null) {
        int columnHeaderHeight = columnHeader.getHeight();
        y += columnHeaderHeight;
        height -= columnHeaderHeight;
    }
    if (horizontalScrollBar.isVisible()) {
        height -= horizontalScrollBar.getHeight();
    }
    if (verticalScrollBar.isVisible()) {
        width -= verticalScrollBar.getWidth();
    }
    return new Bounds(x, y, width, height);
}
Also used : ScrollPane(org.apache.pivot.wtk.ScrollPane) Bounds(org.apache.pivot.wtk.Bounds) Component(org.apache.pivot.wtk.Component) Paint(java.awt.Paint)

Example 3 with Bounds

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

the class TextAreaSkinParagraphView method getCharacterBounds.

public Bounds getCharacterBounds(int index) {
    Bounds characterBounds = null;
    CharSequence characters = paragraph.getCharacters();
    int characterCount = characters.length();
    int rowIndex, xLocal, widthLocal;
    if (index == characterCount) {
        // This is the terminator character
        rowIndex = rows.getLength() - 1;
        Row row = rows.get(rowIndex);
        Rectangle2D glyphVectorBounds = row.glyphVector.getLogicalBounds();
        xLocal = (int) Math.floor(glyphVectorBounds.getWidth());
        widthLocal = PARAGRAPH_TERMINATOR_WIDTH;
    } else {
        // This is a visible character
        rowIndex = getRowAt(index);
        Row row = rows.get(rowIndex);
        Shape glyphBounds = row.glyphVector.getGlyphLogicalBounds(index - row.offset);
        Rectangle2D glyphBounds2D = glyphBounds.getBounds2D();
        xLocal = (int) Math.floor(glyphBounds2D.getX());
        widthLocal = (int) Math.ceil(glyphBounds2D.getWidth());
    }
    Font font = textAreaSkin.getFont();
    FontRenderContext fontRenderContext = Platform.getFontRenderContext();
    LineMetrics lm = font.getLineMetrics("", fontRenderContext);
    float rowHeight = lm.getAscent() + lm.getDescent();
    characterBounds = new Bounds(xLocal, (int) Math.floor(rowIndex * rowHeight), widthLocal, (int) Math.ceil(rowHeight));
    return characterBounds;
}
Also used : Shape(java.awt.Shape) Bounds(org.apache.pivot.wtk.Bounds) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Font(java.awt.Font)

Example 4 with Bounds

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

the class TextAreaSkin method getCharacterBounds.

@Override
public Bounds getCharacterBounds(int index) {
    Bounds characterBounds = null;
    if (paragraphViews.getLength() > 0) {
        TextArea textArea = (TextArea) getComponent();
        TextAreaSkinParagraphView paragraphView = paragraphViews.get(textArea.getParagraphAt(index));
        characterBounds = paragraphView.getCharacterBounds(index - paragraphView.getParagraph().getOffset());
        characterBounds = new Bounds(characterBounds.x + paragraphView.getX(), characterBounds.y + paragraphView.getY(), characterBounds.width, characterBounds.height);
    }
    return characterBounds;
}
Also used : TextArea(org.apache.pivot.wtk.TextArea) Bounds(org.apache.pivot.wtk.Bounds)

Example 5 with Bounds

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

the class TextAreaSkin method mouseMove.

@Override
public boolean mouseMove(Component component, int x, int y) {
    boolean consumed = super.mouseMove(component, x, y);
    if (Mouse.getCapturer() == component) {
        TextArea textArea = (TextArea) getComponent();
        Bounds visibleArea = textArea.getVisibleArea();
        visibleArea = new Bounds(visibleArea.x, visibleArea.y, visibleArea.width, visibleArea.height);
        // if it's inside the visible area, stop the scroll timer
        if (y >= visibleArea.y && y < visibleArea.y + visibleArea.height) {
            // Stop the scroll selection timer
            if (scheduledScrollSelectionCallback != null) {
                scheduledScrollSelectionCallback.cancel();
                scheduledScrollSelectionCallback = null;
            }
            scrollDirection = null;
        } else {
            // if it's outside the visible area, start the scroll timer
            if (scheduledScrollSelectionCallback == null) {
                scrollDirection = (y < visibleArea.y) ? TextArea.ScrollDirection.UP : TextArea.ScrollDirection.DOWN;
                // Run the callback once now to scroll the selection
                // immediately, then scroll repeatedly
                scheduledScrollSelectionCallback = ApplicationContext.runAndScheduleRecurringCallback(scrollSelectionCallback, SCROLL_RATE);
            }
        }
        int index = getInsertionPoint(x, y);
        if (index != -1) {
            // Select the range
            if (index > anchor) {
                textArea.setSelection(anchor, index - anchor);
            } else {
                textArea.setSelection(index, anchor - index);
            }
        }
        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 : TextArea(org.apache.pivot.wtk.TextArea) Bounds(org.apache.pivot.wtk.Bounds)

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