Search in sources :

Example 16 with Bounds

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

the class TextPaneSkinTextNodeView method getCharacterBounds.

@Override
public Bounds getCharacterBounds(int offset) {
    Bounds characterBounds = null;
    if (textLayout != null) {
        // If the offest == length, then use the right hand edge of the previous
        // offset instead -- this is for positioning the caret at the end of the text
        int length = textLayout.getCharacterCount();
        int ix = (offset == length) ? offset - 1 : offset;
        Shape glyphShape = textLayout.getLogicalHighlightShape(ix, ix + 1);
        Rectangle2D glyphBounds2D = glyphShape.getBounds2D();
        if (offset == length) {
            characterBounds = new Bounds((int) Math.ceil(glyphBounds2D.getX() + glyphBounds2D.getWidth()), 0, 1, getHeight());
        } else {
            characterBounds = new Bounds((int) Math.floor(glyphBounds2D.getX()), 0, (int) Math.ceil(glyphBounds2D.getWidth()), getHeight());
        }
    }
    return characterBounds;
}
Also used : Shape(java.awt.Shape) Bounds(org.apache.pivot.wtk.Bounds) Rectangle2D(java.awt.geom.Rectangle2D)

Example 17 with Bounds

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

the class TranslationDecorator method prepare.

@Override
public Graphics2D prepare(Component component, Graphics2D graphics) {
    if (clip) {
        Bounds decoratedBounds = component.getDecoratedBounds();
        graphics.clipRect(decoratedBounds.x - component.getX(), decoratedBounds.y - component.getY(), decoratedBounds.width, decoratedBounds.height);
    }
    graphics.translate(x, y);
    return graphics;
}
Also used : Bounds(org.apache.pivot.wtk.Bounds)

Example 18 with Bounds

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

the class TerraTableViewHeaderSkin method mouseDown.

@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
    boolean consumed = super.mouseDown(component, button, x, y);
    if (button == Mouse.Button.LEFT) {
        TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
        TableView tableView = tableViewHeader.getTableView();
        if (tableView != null) {
            int headerIndex = getHeaderAt(x);
            if (headerIndex != -1) {
                Bounds headerBounds = getHeaderBounds(headerIndex);
                TableView.Column column = tableView.getColumns().get(headerIndex);
                if (columnsResizable && !column.isRelative() && column.getWidth() != -1 && x > headerBounds.x + headerBounds.width - RESIZE_HANDLE_SIZE) {
                    resizeHeaderIndex = headerIndex;
                } else if (headersPressable) {
                    pressedHeaderIndex = headerIndex;
                    repaintComponent(headerBounds);
                }
            }
        }
    }
    return consumed;
}
Also used : TableViewHeader(org.apache.pivot.wtk.TableViewHeader) Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint) TableView(org.apache.pivot.wtk.TableView)

Example 19 with Bounds

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

the class TerraTableViewHeaderSkin method getHeaderBounds.

@Override
public Bounds getHeaderBounds(int headerIndex) {
    Bounds headerBounds = null;
    TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
    TableView tableView = tableViewHeader.getTableView();
    if (tableView != null) {
        Utils.checkZeroBasedIndex(headerIndex, headerWidths.getLength());
        int cellX = 0;
        for (int i = 0; i < headerIndex; i++) {
            cellX += (headerWidths.get(i).intValue() + 1);
        }
        headerBounds = new Bounds(cellX, 0, headerWidths.get(headerIndex).intValue(), getHeight() - 1);
    }
    return headerBounds;
}
Also used : TableViewHeader(org.apache.pivot.wtk.TableViewHeader) Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint) TableView(org.apache.pivot.wtk.TableView)

Example 20 with Bounds

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

the class TerraTableViewHeaderSkin method mouseMove.

@Override
public boolean mouseMove(Component component, int x, int y) {
    boolean consumed = super.mouseMove(component, x, y);
    TableViewHeader tableViewHeader = (TableViewHeader) getComponent();
    TableView tableView = tableViewHeader.getTableView();
    if (tableView != null) {
        if (resizeHeaderIndex != -1 && Mouse.getCapturer() != tableViewHeader) {
            Mouse.capture(tableViewHeader);
        }
        if (Mouse.getCapturer() == tableViewHeader) {
            TableView.Column column = tableView.getColumns().get(resizeHeaderIndex);
            Bounds headerBounds = getHeaderBounds(resizeHeaderIndex);
            int columnWidth = Math.max(x - headerBounds.x, MINIMUM_COLUMN_WIDTH);
            column.setWidth(columnWidth, false);
        } else {
            int headerIndex = getHeaderAt(x);
            if (headerIndex != -1 && columnsResizable) {
                Bounds headerBounds = getHeaderBounds(headerIndex);
                TableView.Column column = tableView.getColumns().get(headerIndex);
                if (!column.isRelative() && column.getWidth() != -1 && x > headerBounds.x + headerBounds.width - RESIZE_HANDLE_SIZE) {
                    tableViewHeader.setCursor(Cursor.RESIZE_EAST);
                } else {
                    tableViewHeader.setCursor((Cursor) null);
                }
            } else {
                tableViewHeader.setCursor((Cursor) null);
            }
        }
    }
    return consumed;
}
Also used : TableViewHeader(org.apache.pivot.wtk.TableViewHeader) Bounds(org.apache.pivot.wtk.Bounds) GradientPaint(java.awt.GradientPaint) TableView(org.apache.pivot.wtk.TableView)

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