Search in sources :

Example 26 with Bounds

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

the class TerraTextInputSkin method updateSelection.

private void updateSelection() {
    TextInput textInput = (TextInput) getComponent();
    int height = getHeight();
    int selectionStart = textInput.getSelectionStart();
    int selectionLength = textInput.getSelectionLength();
    int n = textInput.getCharacterCount();
    Bounds leadingSelectionBounds;
    if (selectionStart < n) {
        leadingSelectionBounds = getCharacterBounds(selectionStart);
    } else {
        // The insertion point is after the last character
        int x = padding.left + 1 - scrollLeft + getAlignmentDeltaX(textLayout);
        if (n > 0) {
            x += getTextWidth(textLayout);
        }
        int y = padding.top + 1;
        leadingSelectionBounds = new Bounds(x, y, 0, height - (padding.top + padding.bottom + 2));
    }
    if (composedTextCaret != null) {
        caret = getCaretRectangle(composedTextCaret);
    } else {
        caret = leadingSelectionBounds.toRectangle();
    }
    caret.width = 1;
    if (selectionLength > 0) {
        Bounds trailingSelectionBounds = getCharacterBounds(selectionStart + selectionLength - 1);
        selection = new Rectangle(leadingSelectionBounds.x, leadingSelectionBounds.y, trailingSelectionBounds.x + trailingSelectionBounds.width - leadingSelectionBounds.x, trailingSelectionBounds.y + trailingSelectionBounds.height - leadingSelectionBounds.y);
    } else {
        selection = null;
    }
}
Also used : Bounds(org.apache.pivot.wtk.Bounds) Rectangle(java.awt.Rectangle) TextInput(org.apache.pivot.wtk.TextInput)

Example 27 with Bounds

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

the class TerraTreeViewSkin method selectedPathAdded.

// TreeViewSelectionListener methods
@Override
public void selectedPathAdded(TreeView treeView, Path path) {
    // Update the node info
    NodeInfo nodeInfo = getNodeInfoAt(path);
    nodeInfo.setSelected(true);
    if (treeView.isValid()) {
        Bounds nodeBounds = getNodeBounds(nodeInfo);
        if (nodeBounds != null) {
            // Ensure that the selection is visible
            Bounds visibleSelectionBounds = treeView.getVisibleArea(nodeBounds);
            if (visibleSelectionBounds.height < nodeBounds.height) {
                treeView.scrollAreaToVisible(nodeBounds);
            }
        }
    } else {
        validateSelection = true;
    }
    // Repaint the node
    repaintNode(nodeInfo);
}
Also used : Bounds(org.apache.pivot.wtk.Bounds)

Example 28 with Bounds

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

the class TerraTreeViewSkin method getNodeBounds.

/**
 * @return The bounding box defined by the specified node, or <tt>null</tt> if
 * the node is not currently visible.
 * @param nodeInfo The node information to search for.
 */
protected final Bounds getNodeBounds(NodeInfo nodeInfo) {
    Bounds bounds = null;
    int index = visibleNodes.indexOf(nodeInfo);
    if (index >= 0) {
        int nodeHeight = getNodeHeight();
        int nodeY = index * (nodeHeight + VERTICAL_SPACING);
        bounds = new Bounds(0, nodeY, getWidth(), nodeHeight);
    }
    return bounds;
}
Also used : Bounds(org.apache.pivot.wtk.Bounds)

Example 29 with Bounds

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

the class TerraTreeViewSkin method getNodeBounds.

@Override
public Bounds getNodeBounds(Path path) {
    Bounds nodeBounds = null;
    NodeInfo nodeInfo = getNodeInfoAt(path);
    if (nodeInfo != null) {
        nodeBounds = getNodeBounds(nodeInfo);
    }
    return nodeBounds;
}
Also used : Bounds(org.apache.pivot.wtk.Bounds)

Example 30 with Bounds

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

the class TerraTreeViewSkin method scrollSelectionToVisible.

/**
 * Scrolls the last visible (expanded) selected node into viewport
 * visibility. If no such node exists, nothing happens. <p> This should only
 * be called when the tree view is valid.
 */
private void scrollSelectionToVisible() {
    TreeView treeView = (TreeView) getComponent();
    Sequence<Path> selectedPaths = treeView.getSelectedPaths();
    int n = selectedPaths.getLength();
    if (n > 0) {
        Bounds nodeBounds = null;
        for (int i = n - 1; i >= 0 && nodeBounds == null; i--) {
            NodeInfo nodeInfo = getNodeInfoAt(selectedPaths.get(i));
            nodeBounds = getNodeBounds(nodeInfo);
        }
        if (nodeBounds != null) {
            Bounds visibleSelectionBounds = treeView.getVisibleArea(nodeBounds);
            if (visibleSelectionBounds != null && visibleSelectionBounds.height < nodeBounds.height) {
                treeView.scrollAreaToVisible(nodeBounds);
            }
        }
    }
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) GeneralPath(java.awt.geom.GeneralPath) Bounds(org.apache.pivot.wtk.Bounds) TreeView(org.apache.pivot.wtk.TreeView)

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