JavaFX Get node by clicking on node - java

I want to get the node one column to the left of the node I clicked on. How can I do this? I’ve been trying all sort of things but I can’t figure it out...
Thanks!

Related

Collapsing nodes in Graphstream

Is there anyway I can collapse a certain number of nodes in a graph using graphstream? I have tried adding ui.hide attribute,but that is not what I want. Ideally I would want a + sign on the first node that is collapsed and then when I click on the + sign then the rest of the nodes should appear. Can anyone help me with this? TIA
Not exactly sure I got it right, but I guest you want to fold/unfold a tree, a bit like a package/file system view on a IDE (eclipse, netbean...).
If I am right then there are some tricks that can help you do that in GraphStream.
The ui.hide attribute, as you mentioned, used on nodes and edges.
The layout.frozen attribute that blocks the layout algorithm on the selected node and allows you to control its position. You may want to set the position of the "folded" right at the clicked node's position in order to give the "folding" visual feeling.
The ui.class attribute that allows you to assign CSS classes to nodes, and thus give a particular style to node folded/unfolded nodes (e.g. add a "plus" sign icon).
In order to get notified when a node is clicked you need to retrieve a ProxyPipe from the viewer and listen to modifications coming from that viewer. especially the ui.clicked attribute that is automatically assigned to nodes that get clicked.
ProxyPipe fromViewer = viewer.newViewerPipe();
fromViewer.addSink(new SinkAdapter(){
#Override
public void nodeAttributeAdded(String sourceId, long timeId, String nodeId, String attribute, Object value) {
if(attribute.equals("ui.clicked")){
// Being notified that a node was clicked...
}
}
});
Finally, you have to decide which node to collapse. I guess a simple iterator rooted at the clicked node is what you need.
// let n be the clicked node...
Iterator<Node> it = n.getBreadthFirstIterator(true);
while(it.hasNext()){
Node m = it.next();
for(Edge e : m.getLeavingEdgeSet()) {
e.setAttribute("ui.hide");
}
if(n != m) {
m.setAttribute("ui.hide");
}
}
Then the Layout algorithm will be troublesome regarding nodes positions and stabilisation limits but that not really important.
You'll find a working example in this gist where clicked nodes collapse their sub-trees :
https://gist.github.com/pigne/2d4c0cbe8583f8a8f6b03309becaff3f
Here is an example tree graph before collapsing sub-trees:
Same graph with node 13 and 15 collapsed after clicking:

Select the TreeNode before (java swing, tree)

I am looking for a way to select the TreeNode before the actually selected node (if no Node is selected, the first Node AFTER the root should be selected) on Button click. I am basically having a Hashtable ht and a JTree filled with nodes (all Nodes allowing Children).
Once i click a node, i want to look up in the Hashtable for that Object and the system should write something like "You selected the 'Object.name'". Then the user should be able to click a JButton and select the node before the clicked node. Of course there should also be this line with an updated 'Object.name'. Maybe there is even a way to update the GUI of the tree, so that the other TreeNode is shown as selected.
I have been trying around for quite a while with the treePath-Methods of the selectionModel and the TreeNodes (e.g. saving them in Lists and trying to select the Element before), but nothing seems to work. I am also not finding anything useful on Google or StackOverflow. I was thinking that it might work somehow with the getPreviousSibling-Method from the DefaultMutableTreeNode?
Last thing I tried:
DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode();
treeNode = (DefaultMutableTreeNode) getLastSelectedPathComponent();
setSelectionPath(new TreePath(((DefaultTreeModel) treeModel).getPathToRoot(treeNode.getPreviousSibling())));
Unfortunately I keep getting a NullPointerException:
in line 2 of this snippet (although I selected another TreeNode before, wich has a sibling before).
Can anyone please tell me what I did wrong or tell me what other way might work? :D If you need more information please have no regard in asking me.

Duplicating a JavaFx group node loaded from FXML in run time

I am trying duplicate a group node which i designed in scene builder. Then add the same to a vertical box below to the same node.
The group node contains a label, text field and a button. When i click the button it should add a duplicate group node below
I tried using
FXCollections.copy(dest, src);
by passing the observable list into it. But the vbox says duplicate id.
If there are any good ideas. pls let me know.

Interactive multiway tree/graph applet with mouse listeners

I have a graph in which the nodes have 0 or more successors and 0 or more predecessors.
I want to make a visualization (preferably through JAVA) such that:
There should be a search box. If I enter the id of the node the node should appear on the screen.
If I left click a node, it's children should appear below the node(in tree representation).
If I right click the node then it's parent should appear above the node.
If I double click any node then it should have same effect as searching the node(as in point 1)
I want to know what approach should I follow (any package etc.)? Is there some similar implementation whose code I may reuse?

Allow dynamic drag drop permissions using arrays

I have created two trees in gwt-ext one contains the values of nodes that can be dragged and other the nodes which can be dropped on. The problem being i am not able to set only a particular set of leaves mentioned in the array, from a tree to be dragged on other tree while the leaves which are not in the array cannot be dragged. I have enabled drag drop on the tree and then manually allow a leaf to disable drag but its not working. Tried it using the setallowdrag() method and also using setTreeAttribute("allowDrag",false) but don't know why it just doesn't work. Please help.
TreeNode n22=treePanel.getNodeById("ynode-121");
n22.setTreeAttribute("allowDrag","false");
n22.setAllowDrag(false);

Categories

Resources