use of org.apache.pivot.wtk.TreeView in project pivot by apache.
the class TerraTreeViewSkin method getBaseline.
@Override
public int getBaseline(int width, int height) {
int baseline = -1;
if (visibleNodes.getLength() > 0) {
TreeView treeView = (TreeView) getComponent();
TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer();
NodeInfo nodeInfo = visibleNodes.get(0);
int nodeWidth = width - (nodeInfo.depth - 1) * (indent + spacing);
int nodeHeight = getNodeHeight();
boolean expanded = false;
boolean selected = nodeInfo.isSelected();
boolean highlighted = nodeInfo.isHighlighted();
boolean disabled = nodeInfo.isDisabled();
if (showBranchControls) {
if (nodeInfo instanceof BranchInfo) {
BranchInfo branchInfo = (BranchInfo) nodeInfo;
expanded = branchInfo.isExpanded();
}
nodeWidth -= (indent + spacing);
}
TreeView.NodeCheckState checkState = TreeView.NodeCheckState.UNCHECKED;
if (treeView.getCheckmarksEnabled()) {
checkState = nodeInfo.getCheckState();
nodeWidth -= (Math.max(indent, CHECKBOX.getWidth()) + spacing);
}
nodeRenderer.render(nodeInfo.data, nodeInfo.getPath(), 0, treeView, expanded, selected, checkState, highlighted, disabled);
baseline = nodeRenderer.getBaseline(nodeWidth, nodeHeight);
}
return baseline;
}
use of org.apache.pivot.wtk.TreeView in project pivot by apache.
the class TerraTreeViewSkin method getPreferredWidth.
@Override
public int getPreferredWidth(int height) {
TreeView treeView = (TreeView) getComponent();
TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer();
int preferredWidth = 0;
VisibleNodeIterator visibleNodeIterator = new VisibleNodeIterator();
while (visibleNodeIterator.hasNext()) {
NodeInfo nodeInfo = visibleNodeIterator.next();
int nodeWidth = (nodeInfo.depth - 1) * (indent + spacing);
nodeRenderer.render(nodeInfo.data, visibleNodeIterator.getPath(), visibleNodeIterator.getRowIndex(), treeView, false, false, TreeView.NodeCheckState.UNCHECKED, false, false);
nodeWidth += nodeRenderer.getPreferredWidth(-1);
preferredWidth = Math.max(preferredWidth, nodeWidth);
}
if (showBranchControls) {
preferredWidth += indent + spacing;
}
if (treeView.getCheckmarksEnabled()) {
preferredWidth += Math.max(CHECKBOX.getWidth(), indent) + spacing;
}
return preferredWidth;
}
use of org.apache.pivot.wtk.TreeView in project pivot by apache.
the class TerraTreeViewSkin method keyReleased.
/**
* {@link KeyCode#SPACE SPACE} toggles check mark selection when select mode
* is {@link SelectMode#SINGLE}
*/
@Override
public boolean keyReleased(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
boolean consumed = false;
TreeView treeView = (TreeView) getComponent();
if (keyCode == Keyboard.KeyCode.SPACE) {
if (treeView.getCheckmarksEnabled() && treeView.getSelectMode() == TreeView.SelectMode.SINGLE) {
Path selectedPath = treeView.getSelectedPath();
if (selectedPath != null) {
NodeInfo nodeInfo = getNodeInfoAt(selectedPath);
if (!nodeInfo.isCheckmarkDisabled()) {
treeView.setNodeChecked(selectedPath, !treeView.isNodeChecked(selectedPath));
}
}
}
} else {
consumed = super.keyReleased(component, keyCode, keyLocation);
}
return consumed;
}
use of org.apache.pivot.wtk.TreeView in project pivot by apache.
the class TerraTreeViewSkin method mouseDown.
@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
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;
// Only proceed if the user DIDN'T click on a checkbox
if (!treeView.getCheckmarksEnabled() || nodeInfo.isCheckmarkDisabled() || x < nodeX + checkboxX || x >= nodeX + checkboxX + checkboxWidth || y < nodeY + checkboxY || y >= nodeY + checkboxY + checkboxHeight) {
Path path = nodeInfo.getPath();
// a branch. If so, expand/collapse the branch
if (showBranchControls && nodeInfo instanceof BranchInfo && x >= baseNodeX && x < baseNodeX + indent) {
BranchInfo branchInfo = (BranchInfo) nodeInfo;
treeView.setBranchExpanded(path, !branchInfo.isExpanded());
consumed = true;
}
// the selection state of the node
if (!consumed) {
TreeView.SelectMode selectMode = treeView.getSelectMode();
if (button == Mouse.Button.LEFT) {
Keyboard.Modifier commandModifier = Platform.getCommandModifier();
if (Keyboard.isPressed(commandModifier) && selectMode == TreeView.SelectMode.MULTI) {
// Toggle the item's selection state
if (nodeInfo.isSelected()) {
treeView.removeSelectedPath(path);
} else {
treeView.addSelectedPath(path);
}
} else if (Keyboard.isPressed(commandModifier) && selectMode == TreeView.SelectMode.SINGLE) {
// Toggle the item's selection state
if (nodeInfo.isSelected()) {
treeView.clearSelection();
} else {
treeView.setSelectedPath(path);
}
} else {
if (selectMode != TreeView.SelectMode.NONE) {
if (nodeInfo.isSelected()) {
selectPath = path;
} else {
treeView.setSelectedPath(path);
}
}
}
}
}
}
}
treeView.requestFocus();
}
return consumed;
}
use of org.apache.pivot.wtk.TreeView in project pivot by apache.
the class TerraTreeViewSkin method install.
@Override
public void install(Component component) {
super.install(component);
TreeView treeView = (TreeView) component;
treeView.getTreeViewListeners().add(this);
treeView.getTreeViewBranchListeners().add(this);
treeView.getTreeViewNodeListeners().add(this);
treeView.getTreeViewNodeStateListeners().add(this);
treeView.getTreeViewSelectionListeners().add(this);
treeDataChanged(treeView, null);
}
Aggregations