I al using GraphStream to import a file after parsing it and creating nodes with attributes. What I want after I create the nodes is to edit theirs attribute in the GUI. Like I have in the right side the Graph and in the left side to appear the properties of the node I click on, in text boxes. Than to save these properties.
My code:
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
LayersGraph lg=new LayersGraph();
Viewer viewer=new Viewer ( lg.graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
viewer.enableAutoLayout();
ViewerPipe fromViewer=viewer.newViewerPipe();
lg.createGraph();
View view=viewer.addDefaultView(false);
clisten=new NodeClickListener(fromViewer,view,lg.graph);
fromViewer.addViewerListener((ViewerListener) clisten);
frame.getContentPane().add((Component) view);
JTextArea textArea = new JTextArea();
frame.getContentPane().add(textArea, BorderLayout.WEST);
textArea.setText("The graph has etc....");
The NodeClickListener:
public class NodeClickListener implements ViewerListener , MouseInputListener{
public boolean loop = true;
private ViewerPipe vpipe = null;
private View vw = null;
private Graph graph = null;
public HashMap<String,String> attributes=new HashMap<String,String>();
/**
* Constructor
* @param vpipe - Viewer Pipe of the graph UI
* @param vw - View of the current graph in swing
* @param g - graph object for the current graph in use
*/
public NodeClickListener(ViewerPipe vpipe, View vw, Graph g) {
this.loop=true;
this.vpipe = vpipe;
this.vw = vw;
this.graph = g;
// Keep piping back while grph is out to hook mouse clicks
this.vw.addMouseListener(this);
}
/**
* Close the view when graph is no longer needed and detach all listners
* @param id - not used, but inherited by interface
*/
public void viewClosed(String id) {
loop = false;
vw.removeMouseListener(this);
}
/**
* Button push hook to label nodes/edges
* @param id - string id of node
*/
public void buttonPushed(String id) {
System.out.println("Button pushed on node "+id);
Node n = graph.getNode(id);
//String _ui_label = n.getAttribute("_ui.label");
String ui_label = n.getAttribute("ui.label");
System.out.println("ui_label: "+ui_label);
for(String key:n.getEachAttributeKey()){
Object value=n.getAttribute(key);
System.out.println("Key: "+key+" Value: "+value.toString());
attributes.put(key, value.toString());
}
}
I want to send the attributes to the form and in form to create dynamically labels and text boxes for each node clicked in order to be able to edit the properties. Anyone has any idea about how can I do this? It may be also a problem of synchronization between the threads?
Thanks