use of org.apache.pivot.collections.Sequence.Tree.Path 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.collections.Sequence.Tree.Path 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);
}
}
}
}
use of org.apache.pivot.collections.Sequence.Tree.Path in project pivot by apache.
the class TreeView method getSelectedNode.
/**
* @return The selected object, or <tt>null</tt> if nothing is selected.
* Note that technically, the selected path could be backed by a
* <tt>null</tt> data value. If the caller wishes to distinguish between
* these cases, they can use <tt>getSelectedPath()</tt> instead.
*/
public Object getSelectedNode() {
Path path = getSelectedPath();
Object node = null;
if (path != null) {
node = Sequence.Tree.get(treeData, path);
}
return node;
}
use of org.apache.pivot.collections.Sequence.Tree.Path in project pivot by apache.
the class TreeViewNodeEditor method endEdit.
@Override
@SuppressWarnings("unchecked")
public void endEdit(boolean result) {
if (result) {
// Update the node data
String text = textInput.getText();
List<?> treeData = treeView.getTreeData();
TreeNode treeNode = (TreeNode) Sequence.Tree.get(treeData, path);
treeNode.setText(text);
// Get a reference to node's parent
int n = path.getLength();
List<TreeNode> parentData;
if (n == 1) {
parentData = (List<TreeNode>) treeData;
} else {
Path parentPath = new Path(path, n - 1);
parentData = (List<TreeNode>) Sequence.Tree.get(treeData, parentPath);
}
if (parentData.getComparator() == null) {
int index = path.get(n - 1);
parentData.remove(index, 1);
parentData.insert(treeNode, index);
} else {
parentData.remove(path.get(n - 1), 1);
parentData.add(treeNode);
// Re-select the node, and make sure it's visible
path = new Path(path, n - 1);
path.add(parentData.indexOf(treeNode));
treeView.setSelectedPath(path);
treeView.scrollAreaToVisible(treeView.getNodeBounds(path));
}
}
getOwner().moveToFront();
treeView.requestFocus();
treeView = null;
path = null;
close();
}
use of org.apache.pivot.collections.Sequence.Tree.Path in project pivot by apache.
the class BXMLExplorerDocument method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
treeView.setSelectMode(SelectMode.SINGLE);
treeView.setNodeRenderer(new MyTreeViewNodeRenderer());
treeView.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {
private final Decorator focusDecorator = new ShadeDecorator(0.2f, Color.RED);
private Component previousSelectedComponent = null;
@Override
public void selectedNodeChanged(TreeView treeViewArgument, Object previousSelectedNode) {
TreeNode node = (TreeNode) treeViewArgument.getSelectedNode();
if (previousSelectedComponent != null && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
previousSelectedComponent.getDecorators().remove(focusDecorator);
previousSelectedComponent = null;
}
if (node == null || !(node.getUserData() instanceof Component)) {
// TODO make the inspectors able to deal with things like
// TablePane.Row
componentPropertyInspector.setSource(null);
componentStyleInspector.setSource(null);
return;
}
Component selectedComp = (Component) node.getUserData();
if (selectedComp != null && selectedComp.getDecorators().indexOf(focusDecorator) == -1) {
selectedComp.getDecorators().add(focusDecorator);
previousSelectedComponent = selectedComp;
}
if (selectedComp instanceof FakeWindow) {
selectedComp = ((FakeWindow) selectedComp).window;
}
componentPropertyInspector.setSource(selectedComp);
componentStyleInspector.setSource(selectedComp);
}
@Override
public void selectedPathsChanged(TreeView treeViewArgument, Sequence<Path> previousSelectedPaths) {
// if the selection becomes empty, remove the decorator
if (treeViewArgument.getSelectedNode() == null && previousSelectedComponent != null && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
previousSelectedComponent.getDecorators().remove(focusDecorator);
}
}
});
playgroundCardPane.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
@Override
public boolean mouseClick(Component component, Button button, int x, int y, int count) {
if (count == 1) {
Component comp = playgroundCardPane.getDescendantAt(x, y);
if (comp != null) {
TreeNode treeNode = componentToTreeNode.get(comp);
Path path = getPathForNode(treeView, treeNode);
if (path != null) {
treeView.setSelectedPath(path);
return true;
}
}
}
return false;
}
});
reloadButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(org.apache.pivot.wtk.Button button) {
playgroundCardPane.remove(loadedComponent);
widgetToID = null;
componentToTreeNode = null;
loadedComponent = null;
try {
load(file);
} catch (RuntimeException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (IOException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (SerializationException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (ParserConfigurationException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (SAXException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
}
}
});
}
Aggregations