How to display tree hierarchy in Java? - java

I have a table in a database named "Process"
This process table has 3 fields:
process_id
process_name
process_parent_id
Now I want to display this parent child hierarchy in Graphical format. So could you please suggest me the following:
Q1. Which data structure would be better to use so as to get data from the database and store in that data structure?
Q2. How to display that tree (process hierarchy) in graphical format?
EDIT:
I want the graphical format something like this:

Swing has a built-in control for displaying data in a Tree format called JTree. It also provides a data model called DefaultTreeModel which you can use to store the data. This link gives a pretty good explanation of using a JTree with a data model.
[Edit]:
To answer your updated question, a graph like that could quite well be handled by JGraph which would also provide the data model which seems to work similarly to the Tree model swing provides.

As others have suggested, using JTree is one possible solution. However, if you wish to have more control over the appearance of your tree I suggest checking out the JUNG graphing library. This can potentially give you great results but will require more work.

For the hierarchy in graphical format, what about a JTree ?
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

Re Q1: You could find on internet resources several Java implementations of Tree structure, for example this generic tree.
Re Q2: One alternative is using JTree. Check the Java Tutorial trail on How to use Trees
JGraphT could be a good starting point to build something like your example. Check the demo at http://jgrapht.sourceforge.net/visualizations.html

Related

Which Java node-based data structure to use?

I have to create a star shape (like a star topology in networking) with nodes in java for homework and I'm not sure which data structure to use. There should be a central node with periheral nodes pointing to it that are not linked directly to each other but are all linked through the central node. I am to achieve this using three classes apart from the class with the main method. I'm thinking a linked list or a stack or queue would not accomplish this since they all have a particular order which I don't know how to manipulate (but they're all I've been taught about thus far). Any suggestions or links or comments on where I could begin would be very appreciated!
I think in your case you need just to use Graph data structure, or to be more specific, if you are sure that you just need one node to be connected to all other nodes, you can use Tree.
Finally I think you need to look how to implement those data structures in JAVA, so look at this:
https://www.geeksforgeeks.org/graph-and-its-representations/
https://www.javatpoint.com/tree

My own graph representation for Neo4j

I have a graph that I want to explore in different ways. This graph is going to be explored by users and I cannot know in advance what information they want to retrieve from the graph. I like Cypher very much and I was wondering if I can use it as a frond-end but using my own representation of the graph.
Let me explain that: I cannot transform my graph into a Neo4j Graph for performance reasons. Hence, I was thinking that maybe I can use Cypher and a modification of Neo4j to explore the graph using my own representation of Node, Labels, Properties and so on.
I think this solution would be good because I can:
Reuse the parser and semantic checker of the language
Partially reuse the optimization engine, let's say the platform independent part.
I was exploring the source code at github and it seems really coupled to a specific implementation.
My questions:
Are you aware of some project using Cypher/Neo4j like this?
Are you aware of another graph database with a good query language that can be used like that?
Any suggestions on how to address the modifications to Neo4J
Just to explain a little bit why I cannot copy the graph. It is a graph that is already produced by another system. It changes a lot an it has easily 10000 nodes, I cannot monitor the graph modification to update the graph because it is, once again, time consuming. Even worse, I have to provide a mechanism to query the graph every five seconds.

Converting floor plans into hierarchical graphs

I'm developing a navigation application for android. I need to convert the floor map into a hierarchical graph. As far as I know after converting the map into a graph this will produce an XML file presenting the rooms as nodes. I have searched about hierarchical graph but all I got was theoretical explanation of the graphs.
While searching also I read something about GoogleOpenStreet. I read that it can be used to convert floor plans into graphs but also I didn't find anything about how to do it.
Can anyone suggest methods to do this using Java?
Since I found a solution, and no one answered it. I will answer it to help other people who have the same problem.
I didn't find a direct method to convert floor plans into hierarchical graphs, instead I used a graph editor to draw a graph that represent the floor plan and then used the resulting file ( which is similar to XML format) and parsed in.

Generating a tree visualization in java

I don't know what is the name of this visualization type, but I want to learn how to draw trees like the ones in this image:
I've seen this kind of visualization in many sites but I'm unable to know the technical term behind it.
That graph seems a lot like a force-directed layout. Painting those kind of images is not an easy task, depending on what are you trying to accomplish, you might want to use an existing framwork. If you want to use java you should see at gephi, if you can use an html approach you should definitely take a look at d3.js which is a javascript library for data visualization. They have neat examples: directed-force layout, and collapsible-force layout.
This particular image is done by Stephanie Posavec. You can learn about her design process from an interview she gave the folks at the Data Stories podcast. As far as I remember it, she partially crafts her visualizations by hand, so I'm not sure if you'll ever find an algorithm that does exactly this for you. For different tree layout algorithms, you can refer to treevis.net.

Java Graph Visualisation Library: Nodes with multiple connect points

Can anyone recommend a Java Graph Visualisation library in which graph nodes can be rendered with multiple connect points?
For example, supposing a graph node represents a processor that takes input from two sources and produces output. This would be visualised as 3 vertices. However, clearly each vertex has a defined role in the workflow and therefore ideally my node would appear with 3 distinct connection points that the user could attach vertices to.
I've taken a look at JUNG but I don't think it will suit my needs.
Any recommendations welcome; either on specific libraries or alternative approaches I can take.
You could try JGraph's java library
JGRAPH
It has a good amount of functionality and I have used it with success before. The only thing is that the documentation is a bit lacking, but if you read through some examples and code its pretty good when you get the hang of it.
Take a look at JGraph (http://www.jgraph.com/). I used jgraph-5.14.0.0 for a similar project before. Here are the graphs that I made for another project: https://github.com/eamocanu/spellcheck.graph/tree/master/graph%20photos

Categories

Resources