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;
}
}
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);
}
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;
}
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;
}
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);
}
}
}
}
Aggregations