use of org.apache.pivot.wtk.TreeView in project pivot by apache.
the class TerraTreeViewSkin method mouseUp.
@Override
public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseUp(component, button, x, y);
TreeView treeView = (TreeView) getComponent();
if (selectPath != null && !treeView.getFirstSelectedPath().equals(treeView.getLastSelectedPath())) {
treeView.setSelectedPath(selectPath);
selectPath = null;
}
return consumed;
}
use of org.apache.pivot.wtk.TreeView in project pivot by apache.
the class TerraTreeViewSkin method getNodeIndent.
@Override
public int getNodeIndent(int depth) {
TreeView treeView = (TreeView) getComponent();
int nodeIndent = (depth - 1) * (indent + spacing);
if (showBranchControls) {
nodeIndent += indent + spacing;
}
if (treeView.getCheckmarksEnabled()) {
nodeIndent += Math.max(CHECKBOX.getWidth(), indent) + spacing;
}
return nodeIndent;
}
use of org.apache.pivot.wtk.TreeView in project pivot by apache.
the class TerraTreeViewSkin method keyPressed.
/**
* {@link KeyCode#UP UP} Selects the previous enabled node when select mode
* is not {@link SelectMode#NONE}<br> {@link KeyCode#DOWN DOWN} Selects the
* next enabled node when select mode is not {@link SelectMode#NONE}<p>
* {@link Modifier#SHIFT SHIFT} + {@link KeyCode#UP UP} Increases the
* selection size by including the previous enabled node when select mode is
* {@link SelectMode#MULTI}<br> {@link Modifier#SHIFT SHIFT} +
* {@link KeyCode#DOWN DOWN} Increases the selection size by including the
* next enabled node when select mode is {@link SelectMode#MULTI}
*/
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
boolean consumed = false;
TreeView treeView = (TreeView) getComponent();
TreeView.SelectMode selectMode = treeView.getSelectMode();
switch(keyCode) {
case Keyboard.KeyCode.UP:
{
if (selectMode != TreeView.SelectMode.NONE) {
Path firstSelectedPath = treeView.getFirstSelectedPath();
int index;
if (firstSelectedPath != null) {
NodeInfo previousSelectedNode = getNodeInfoAt(firstSelectedPath);
index = visibleNodes.indexOf(previousSelectedNode);
} else {
// Select the last visible node
index = visibleNodes.getLength();
}
NodeInfo newSelectedNode = null;
do {
newSelectedNode = (--index >= 0) ? visibleNodes.get(index) : null;
} while (newSelectedNode != null && newSelectedNode.isDisabled());
if (newSelectedNode != null) {
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT) && treeView.getSelectMode() == TreeView.SelectMode.MULTI) {
treeView.addSelectedPath(newSelectedNode.getPath());
} else {
treeView.setSelectedPath(newSelectedNode.getPath());
}
treeView.scrollAreaToVisible(getNodeBounds(newSelectedNode));
}
consumed = true;
}
break;
}
case Keyboard.KeyCode.DOWN:
{
if (selectMode != TreeView.SelectMode.NONE) {
Path lastSelectedPath = treeView.getLastSelectedPath();
int index;
if (lastSelectedPath != null) {
NodeInfo previousSelectedNode = getNodeInfoAt(lastSelectedPath);
index = visibleNodes.indexOf(previousSelectedNode);
} else {
// Select the first visible node
index = -1;
}
NodeInfo newSelectedNode = null;
int n = visibleNodes.getLength();
do {
newSelectedNode = (++index <= n - 1) ? visibleNodes.get(index) : null;
} while (newSelectedNode != null && newSelectedNode.isDisabled());
if (newSelectedNode != null) {
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT) && treeView.getSelectMode() == TreeView.SelectMode.MULTI) {
treeView.addSelectedPath(newSelectedNode.getPath());
} else {
treeView.setSelectedPath(newSelectedNode.getPath());
}
treeView.scrollAreaToVisible(getNodeBounds(newSelectedNode));
}
consumed = true;
}
break;
}
case Keyboard.KeyCode.LEFT:
{
if (showBranchControls) {
Sequence<Path> paths = treeView.getSelectedPaths();
if (paths != null && paths.getLength() > 0) {
Path path = paths.get(paths.getLength() - 1);
NodeInfo nodeInfo = getNodeInfoAt(path);
if (nodeInfo instanceof BranchInfo) {
BranchInfo branchInfo = (BranchInfo) nodeInfo;
if (branchInfo.isExpanded()) {
treeView.collapseBranch(branchInfo.getPath());
}
}
consumed = true;
}
}
break;
}
case Keyboard.KeyCode.RIGHT:
{
if (showBranchControls) {
Sequence<Path> paths = treeView.getSelectedPaths();
if (paths != null && paths.getLength() > 0) {
Path path = paths.get(paths.getLength() - 1);
NodeInfo nodeInfo = getNodeInfoAt(path);
if (nodeInfo instanceof BranchInfo) {
BranchInfo branchInfo = (BranchInfo) nodeInfo;
if (!branchInfo.isExpanded()) {
treeView.expandBranch(branchInfo.getPath());
}
}
consumed = true;
}
}
break;
}
default:
consumed = super.keyPressed(component, keyCode, keyLocation);
break;
}
if (consumed) {
clearHighlightedNode();
}
return consumed;
}
use of org.apache.pivot.wtk.TreeView in project pivot by apache.
the class TerraTreeViewSkin method mouseClick.
@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
boolean consumed = super.mouseClick(component, button, x, y, count);
if (!consumed) {
TreeView treeView = (TreeView) getComponent();
NodeInfo nodeInfo = getNodeInfoAt(y);
if (nodeInfo != null && !nodeInfo.isDisabled()) {
int nodeHeight = getNodeHeight();
int baseNodeX = (nodeInfo.depth - 1) * (indent + spacing);
int nodeX = baseNodeX + (showBranchControls ? indent + spacing : 0);
int nodeY = (y / (nodeHeight + VERTICAL_SPACING)) * (nodeHeight + VERTICAL_SPACING);
int checkboxWidth = CHECKBOX.getWidth();
int checkboxHeight = CHECKBOX.getHeight();
int checkboxX = Math.max(indent - checkboxWidth, 0) / 2;
int checkboxY = (nodeHeight - checkboxHeight) / 2;
if (treeView.getCheckmarksEnabled() && !nodeInfo.isCheckmarkDisabled() && x >= nodeX + checkboxX && x < nodeX + checkboxX + checkboxWidth && y >= nodeY + checkboxY && y < nodeY + checkboxY + checkboxHeight) {
Path path = nodeInfo.getPath();
treeView.setNodeChecked(path, !nodeInfo.isChecked());
} else {
if (selectPath != null && count == 1 && button == Mouse.Button.LEFT) {
TreeView.NodeEditor nodeEditor = treeView.getNodeEditor();
if (nodeEditor != null) {
if (nodeEditor.isEditing()) {
nodeEditor.endEdit(true);
}
nodeEditor.beginEdit(treeView, selectPath);
}
}
selectPath = null;
}
}
}
return consumed;
}
use of org.apache.pivot.wtk.TreeView in project pivot by apache.
the class TerraTreeViewSkin method getNodeHeight.
/**
* @return The fixed node height of this skin.
*/
protected int getNodeHeight() {
TreeView treeView = (TreeView) getComponent();
TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer();
nodeRenderer.render(null, null, -1, treeView, false, false, TreeView.NodeCheckState.UNCHECKED, false, false);
int nodeHeight = nodeRenderer.getPreferredHeight(-1);
if (treeView.getCheckmarksEnabled()) {
nodeHeight = Math.max(CHECKBOX.getHeight() + (2 * CHECKBOX_VERTICAL_PADDING), nodeHeight);
}
return nodeHeight;
}
Aggregations